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",
44 "prioeq" : ["P" , "eq" , None],
45 "priolt" : ["P" , "lt" , None],
46 "priogt" : ["P" , "gt" , None],
47 "nprioeq" : ["N" , "eq" , None],
48 "npriolt" : ["N" , "lt" , None],
49 "npriogt" : ["N" , "gt" , None],
50 "unlocked" : ["M" , "eq" , 0],
51 "trylock" : ["M" , "eq" , 1],
52 "blocked" : ["M" , "eq" , 2],
53 "blockedwake" : ["M" , "eq" , 3],
54 "locked" : ["M" , "eq" , 4],
55 "opcodeeq" : ["O" , "eq" , None],
56 "opcodelt" : ["O" , "lt" , None],
57 "opcodegt" : ["O" , "gt" , None],
58 "eventeq" : ["E" , "eq" , None],
59 "eventlt" : ["E" , "lt" , None],
60 "eventgt" : ["E" , "gt" , None],
63 # Print usage information
65 print "rt-tester.py <-c -h -q -t> <testfile>"
66 print " -c display comments after first command"
68 print " -q quiet mode"
69 print " -t test mode (syntax check)"
70 print " testfile: read test specification from testfile"
71 print " otherwise from stdin"
74 # Print progress when not in quiet mode
79 # Analyse a status value
80 def analyse(val, top, arg):
85 intval = intval / (10 ** int(arg))
89 argval = int(cmd_opcodes.get(arg, arg))
93 # progress("%d %s %d" %(intval, top[1], argval))
95 if top[1] == "eq" and intval == argval:
97 if top[1] == "lt" and intval < argval:
99 if top[1] == "gt" and intval > argval:
103 # Parse the commandline
105 (options, arguments) = getopt.getopt(sys.argv[1:],'chqt')
106 except getopt.GetoptError, ex:
110 # Parse commandline options
111 for option, value in options:
122 # Select the input source
125 fd = open(arguments[0])
127 sys.stderr.write("File not found %s\n" %(arguments[0]))
134 # Read the test patterns
143 parts = line.split(":")
145 if not parts or len(parts) < 1:
148 if len(parts[0]) == 0:
151 if parts[0].startswith("#"):
161 cmd = parts[0].strip().lower()
162 opc = parts[1].strip().lower()
163 tid = parts[2].strip()
164 dat = parts[3].strip()
167 # Test or wait for a status value
168 if cmd == "t" or cmd == "w":
169 testop = test_opcodes[opc]
171 fname = "%s%s%s" %(sysfsprefix, tid, statusfile)
178 fsta = open(fname, 'r')
179 status = fsta.readline().strip()
181 stat = status.split(",")
184 if s.startswith(testop[0]):
185 # Seperate status value
187 query = analyse(val, testop, dat)
189 if query or cmd == "t":
192 progress(" " + status)
195 sys.stderr.write("Test failed in line %d\n" %(linenr))
198 # Issue a command to the tester
200 cmdnr = cmd_opcodes[opc]
201 # Build command string and sys filename
202 cmdstr = "%s:%s" %(cmdnr, dat)
203 fname = "%s%s%s" %(sysfsprefix, tid, commandfile)
207 fcmd = open(fname, 'w')
212 sys.stderr.write(str(ex))
213 sys.stderr.write("\nSyntax error in line %d\n" %(linenr))