Changeset f1231f2
- Timestamp:
- Jul 14, 2016, 3:25:43 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 4e95b5c
- Parents:
- 9c791dd
- Location:
- src/tests
- Files:
-
- 2 added
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
src/tests/test.py
r9c791dd rf1231f2 15 15 # help functions 16 16 ################################################################################ 17 18 class Test: 19 def __init__(self, name, path): 20 self.name, self.path = name, path 21 22 def getMachineType(): 23 with open('Makefile') as file: 24 makefile = file.read() 25 m = re.search("CFA_FLAGS\s*=\s*-m(.*)", makefile) 26 return m.group(1) 27 17 28 def listTests(): 18 list = [splitext(f)[0] for f in listdir('./.expect') 29 machineType = getMachineType() 30 31 generic_list = map(lambda fname: Test(fname, fname), 32 [splitext(f)[0] for f in listdir('./.expect') 19 33 if not f.startswith('.') and f.endswith('.txt') 20 ] 21 22 return list 34 ]) 35 36 typed_list = map(lambda fname: Test( fname, "%s/%s" % (machineType, fname) ), 37 [splitext(f)[0] for f in listdir("./.expect/%s" % machineType) 38 if not f.startswith('.') and f.endswith('.txt') 39 ]) 40 41 return generic_list + typed_list 23 42 24 43 def sh(cmd, dry_run = False, print2stdout = True): … … 71 90 return False 72 91 92 def filterTests(testname) : 93 found = [test for test in allTests if test.name == testname] 94 return (found[0] if len(found) == 1 else Test(testname, testname) ) 95 73 96 ################################################################################ 74 97 # running test functions … … 76 99 def run_test_instance(test, generate, dry_run): 77 100 78 out_file = (".out/%s.log" % test ) if not generate else (".expect/%s.txt" % test)101 out_file = (".out/%s.log" % test.name) if not generate else (".expect/%s.txt" % test.path) 79 102 80 103 sh("rm -f %s" % out_file, dry_run) 81 sh("rm -f %s > /dev/null 2>&1" % test , dry_run)104 sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run) 82 105 83 106 # build, skipping to next test on error 84 make_ret, _ = sh("%s %s 2> %s 1> /dev/null" % (make_cmd, test , out_file), dry_run)107 make_ret, _ = sh("%s %s 2> %s 1> /dev/null" % (make_cmd, test.name, out_file), dry_run) 85 108 86 109 if make_ret == 0 : 87 110 # fetch optional input 88 stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test ) else ""89 90 if fileIsExecutable(test ) :111 stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test.path) else "" 112 113 if fileIsExecutable(test.name) : 91 114 # run test 92 sh("./%s %s > %s 2>&1" % (test , stdinput, out_file), dry_run)115 sh("./%s %s > %s 2>&1" % (test.name, stdinput, out_file), dry_run) 93 116 else : 94 117 # simply cat the result into the output 95 sh("cat %s > %s" % (test , out_file), dry_run)118 sh("cat %s > %s" % (test.name, out_file), dry_run) 96 119 97 120 retcode = 0 … … 101 124 102 125 if generate : 103 if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'. Stop." % test ) :126 if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'. Stop." % test.name) : 104 127 retcode = 1; 105 128 error = "\t\tNo make target for test %s!" % test … … 122 145 ".expect/%s.txt .out/%s.log") 123 146 124 retcode, error = sh(diff_cmd % (test , test), dry_run, False)147 retcode, error = sh(diff_cmd % (test.path, test.name), dry_run, False) 125 148 126 149 # clean the executable 127 sh("rm -f %s > /dev/null 2>&1" % test , dry_run)150 sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run) 128 151 129 152 return retcode, error … … 138 161 failed = False; 139 162 for t in tests: 140 print("%20s " % t , end="")163 print("%20s " % t.name, end="") 141 164 sys.stdout.flush() 142 165 test_failed, error = run_test_instance(t, generate, dry_run) … … 183 206 else : 184 207 tests = [] 185 for test in options.tests: 186 if test in allTests or options.regenerate_expected : 187 tests.append(test) 188 else : 189 print('ERROR: No expected file for test %s, ignoring it' % test, file=sys.stderr) 208 209 if options.regenerate_expected : 210 tests = map(filterTests, options.tests) 211 212 else : 213 for testname in options.tests: 214 test = [t for t in allTests if t.name == testname] 215 216 if len(test) != 0 : 217 tests.append( test[0] ) 218 else : 219 print('ERROR: No expected file for test %s, ignoring it' % testname, file=sys.stderr) 190 220 191 221 if len(tests) == 0 : … … 193 223 sys.exit(1) 194 224 195 tests.sort() 225 tests.sort(key=lambda t: t.name) 226 196 227 make_flags = environ.get('MAKEFLAGS') 197 228 make_cmd = "make" if make_flags and "-j" in make_flags else "make -j8" 198 229 199 230 if options.list : 200 print("\n".join( tests))231 print("\n".join(map(lambda t: "%s (%s)" % (t.name, t.path), tests))) 201 232 202 233 else :
Note: See TracChangeset
for help on using the changeset viewer.