Changeset f1ee72e for src/tests/test.py
- Timestamp:
- Jun 23, 2016, 12:23:00 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, 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:
- 4d3ca1d8
- Parents:
- c2931ea (diff), d56c05d0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/test.py
rc2931ea rf1ee72e 2 2 from __future__ import print_function 3 3 4 from os import listdir 5 from os.path import isfile, join 4 from os import listdir, environ 5 from os.path import isfile, join, splitext 6 6 from subprocess import Popen, PIPE, STDOUT 7 7 8 8 import argparse 9 import os 10 import re 9 11 import sys 10 12 … … 13 15 ################################################################################ 14 16 def listTests(): 15 list = [f.rstrip('.c') for f in listdir('.') 16 if not f.startswith('.') and ( 17 not isfile(f) or f.endswith('.c') 18 )] 17 list = [splitext(f)[0] for f in listdir('./.expect') 18 if not f.startswith('.') and f.endswith('.txt') 19 ] 19 20 20 21 return list … … 29 30 return proc.returncode 30 31 32 def file_replace(fname, pat, s_after): 33 # first, see if the pattern is even in the file. 34 with open(fname) as f: 35 if not any(re.search(pat, line) for line in f): 36 return # pattern does not occur in file so we are done. 37 38 # pattern is in the file, so perform replace operation. 39 with open(fname) as f: 40 out_fname = fname + ".tmp" 41 out = open(out_fname, "w") 42 for line in f: 43 out.write(re.sub(pat, s_after, line)) 44 out.close() 45 os.rename(out_fname, fname) 46 47 def fix_MakeLevel(file) : 48 if environ.get('MAKELEVEL') : 49 file_replace(file, "make\[%i\]" % int(environ.get('MAKELEVEL')), 'make' ) 50 51 31 52 ################################################################################ 32 53 # running test functions … … 40 61 41 62 # build, skipping to next test on error 42 make_ret = sh("make -j 8 %s > %s 2>&1" % (test, out_file), dry_run)63 make_ret = sh("make -j 8 %s 2> %s 1> /dev/null" % (test, out_file), dry_run) 43 64 44 65 if make_ret == 0 : … … 50 71 51 72 retcode = 0 73 74 fix_MakeLevel(out_file) 75 52 76 if not generate : 53 # touch expected files so empty output are supported by default54 sh("touch .expect/%s.txt" % test, dry_run)55 56 77 # diff the output of the files 57 78 retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run) … … 67 88 68 89 if generate : 69 print( "Regenerate tests for: ", end="" ) 70 print( ", ".join( tests ) ) 90 print( "Regenerate tests for: " ) 71 91 72 92 failed = False; 73 93 for t in tests: 74 if not generate : 75 print("%20s " % t, end="") 94 print("%20s " % t, end="") 76 95 sys.stdout.flush() 77 96 test_failed = run_test_instance(t, generate, dry_run) … … 80 99 if not generate : 81 100 print("FAILED" if test_failed else "PASSED") 101 else : 102 print( "Done" ) 82 103 83 104 sh('make clean > /dev/null 2>&1', dry_run) 84 105 85 if generate : 86 print( "Done" ) 87 88 return 0 if failed else 1 106 return 1 if failed else 0 89 107 90 108 ################################################################################ … … 93 111 parser = argparse.ArgumentParser(description='Script which runs cforall tests') 94 112 parser.add_argument('--dry-run', help='Don\'t run the tests, only output the commands', action='store_true') 113 parser.add_argument('--list', help='List all test available', action='store_true') 95 114 parser.add_argument('--all', help='Run all test available', action='store_true') 96 parser.add_argument('-- generate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')115 parser.add_argument('--regenerate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true') 97 116 parser.add_argument('tests', metavar='test', type=str, nargs='*', help='a list of tests to run') 98 117 99 118 options = parser.parse_args() 100 119 101 if len(options.tests) > 0 and options.all : 120 if (len(options.tests) > 0 and options.all and not options.list) \ 121 or (len(options.tests) == 0 and not options.all and not options.list) : 102 122 print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr) 103 123 parser.print_help() 104 124 sys.exit(1) 105 125 106 tests = listTests() if options.all else options.tests 126 allTests = listTests() 107 127 108 sys.exit( run_tests(tests, options.generate_expected, options.dry_run) ) 128 if options.all or options.list : 129 tests = allTests 130 131 else : 132 tests = [] 133 for test in options.tests: 134 if test in allTests : 135 tests.append(test) 136 else : 137 print('ERROR: No expected file for test %s, ignoring it' % test, file=sys.stderr) 138 139 if len(tests) == 0 : 140 print('ERROR: No valid test to run', file=sys.stderr) 141 sys.exit(1) 142 143 if options.list : 144 print("\n".join(tests)) 145 146 else : 147 sys.exit( run_tests(tests, options.regenerate_expected, options.dry_run) )
Note:
See TracChangeset
for help on using the changeset viewer.