5 # (C) 2006 Thomas Gleixner <tglx@linutronix.de>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 as
9 # published by the Free Software Foundation.
22 sysfsprefix
= "/sys/devices/system/rttest/rttest"
23 statusfile
= "/status"
24 commandfile
= "/command"
33 "lockintnowait" : "6",
42 "prioeq" : ["P" , "eq" , None],
43 "priolt" : ["P" , "lt" , None],
44 "priogt" : ["P" , "gt" , None],
45 "nprioeq" : ["N" , "eq" , None],
46 "npriolt" : ["N" , "lt" , None],
47 "npriogt" : ["N" , "gt" , None],
48 "unlocked" : ["M" , "eq" , 0],
49 "trylock" : ["M" , "eq" , 1],
50 "blocked" : ["M" , "eq" , 2],
51 "blockedwake" : ["M" , "eq" , 3],
52 "locked" : ["M" , "eq" , 4],
53 "opcodeeq" : ["O" , "eq" , None],
54 "opcodelt" : ["O" , "lt" , None],
55 "opcodegt" : ["O" , "gt" , None],
56 "eventeq" : ["E" , "eq" , None],
57 "eventlt" : ["E" , "lt" , None],
58 "eventgt" : ["E" , "gt" , None],
61 # Print usage information
63 print "rt-tester.py <-c -h -q -t> <testfile>"
64 print " -c display comments after first command"
66 print " -q quiet mode"
67 print " -t test mode (syntax check)"
68 print " testfile: read test specification from testfile"
69 print " otherwise from stdin"
72 # Print progress when not in quiet mode
77 # Analyse a status value
78 def analyse(val
, top
, arg
):
83 intval
= intval
/ (10 ** int(arg
))
87 argval
= int(cmd_opcodes
.get(arg
, arg
))
91 # progress("%d %s %d" %(intval, top[1], argval))
93 if top
[1] == "eq" and intval
== argval
:
95 if top
[1] == "lt" and intval
< argval
:
97 if top
[1] == "gt" and intval
> argval
:
101 # Parse the commandline
103 (options
, arguments
) = getopt
.getopt(sys
.argv
[1:],'chqt')
104 except getopt
.GetoptError
, ex
:
108 # Parse commandline options
109 for option
, value
in options
:
120 # Select the input source
123 fd
= open(arguments
[0])
125 sys
.stderr
.write("File not found %s\n" %(arguments
[0]))
132 # Read the test patterns
141 parts
= line
.split(":")
143 if not parts
or len(parts
) < 1:
146 if len(parts
[0]) == 0:
149 if parts
[0].startswith("#"):
159 cmd
= parts
[0].strip().lower()
160 opc
= parts
[1].strip().lower()
161 tid
= parts
[2].strip()
162 dat
= parts
[3].strip()
165 # Test or wait for a status value
166 if cmd
== "t" or cmd
== "w":
167 testop
= test_opcodes
[opc
]
169 fname
= "%s%s%s" %(sysfsprefix
, tid
, statusfile
)
176 fsta
= open(fname
, 'r')
177 status
= fsta
.readline().strip()
179 stat
= status
.split(",")
182 if s
.startswith(testop
[0]):
183 # Separate status value
185 query
= analyse(val
, testop
, dat
)
187 if query
or cmd
== "t":
190 progress(" " + status
)
193 sys
.stderr
.write("Test failed in line %d\n" %(linenr))
196 # Issue a command to the tester
198 cmdnr
= cmd_opcodes
[opc
]
199 # Build command string and sys filename
200 cmdstr
= "%s:%s" %(cmdnr
, dat
)
201 fname
= "%s%s%s" %(sysfsprefix
, tid
, commandfile
)
205 fcmd
= open(fname
, 'w')
210 sys
.stderr
.write(str(ex
))
211 sys
.stderr
.write("\nSyntax error in line %d\n" %(linenr))