Changes in src/tests/test.py [122cac7:f6ed7fd]
- File:
-
- 1 edited
-
src/tests/test.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/test.py
r122cac7 rf6ed7fd 2 2 from __future__ import print_function 3 3 4 from os import listdir , environ5 from os.path import isfile, join , splitext4 from os import listdir 5 from os.path import isfile, join 6 6 from subprocess import Popen, PIPE, STDOUT 7 7 8 8 import argparse 9 import os10 import re11 9 import sys 12 10 … … 15 13 ################################################################################ 16 14 def listTests(): 17 list = [splitext(f)[0] for f in listdir('./.expect') 18 if not f.startswith('.') and f.endswith('.txt') 19 ] 15 list = [f.rstrip('.c') for f in listdir('.') 16 if not f.startswith('.') and ( 17 not isfile(f) or f.endswith('.c') 18 )] 20 19 21 20 return list … … 30 29 return proc.returncode 31 30 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 52 31 ################################################################################ 53 32 # running test functions … … 61 40 62 41 # build, skipping to next test on error 63 make_ret = sh("make -j 8 %s 2> %s 1> /dev/null" % (test, out_file), dry_run)42 make_ret = sh("make -j 8 %s > %s 2>&1" % (test, out_file), dry_run) 64 43 65 44 if make_ret == 0 : … … 71 50 72 51 retcode = 0 52 if not generate : 53 # touch expected files so empty output are supported by default 54 sh("touch .expect/%s.txt" % test, dry_run) 73 55 74 fix_MakeLevel(out_file)75 76 if not generate :77 56 # diff the output of the files 78 57 retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run) … … 88 67 89 68 if generate : 90 print( "Regenerate tests for: " ) 69 print( "Regenerate tests for: ", end="" ) 70 print( ", ".join( tests ) ) 91 71 92 72 failed = False; 93 73 for t in tests: 94 print("%20s " % t, end="") 74 if not generate : 75 print("%20s " % t, end="") 95 76 sys.stdout.flush() 96 77 test_failed = run_test_instance(t, generate, dry_run) … … 99 80 if not generate : 100 81 print("FAILED" if test_failed else "PASSED") 101 else :102 print( "Done" )103 82 104 83 sh('make clean > /dev/null 2>&1', dry_run) 105 84 106 return 1 if failed else 0 85 if generate : 86 print( "Done" ) 87 88 return 0 if failed else 1 107 89 108 90 ################################################################################ … … 111 93 parser = argparse.ArgumentParser(description='Script which runs cforall tests') 112 94 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')114 95 parser.add_argument('--all', help='Run all test available', 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')96 parser.add_argument('--generate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true') 116 97 parser.add_argument('tests', metavar='test', type=str, nargs='*', help='a list of tests to run') 117 98 118 99 options = parser.parse_args() 119 100 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) : 101 if len(options.tests) > 0 and options.all : 122 102 print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr) 123 103 parser.print_help() 124 104 sys.exit(1) 125 105 126 allTests = listTests() 106 tests = listTests() if options.all else options.tests 127 107 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) ) 108 sys.exit( run_tests(tests, options.generate_expected, options.dry_run) )
Note:
See TracChangeset
for help on using the changeset viewer.