source: src/tests/test.py@ e5b96bf

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since e5b96bf was fbaebc6, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

fixed small errors in test.py

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#!python
2from __future__ import print_function
3
4from os import listdir
5from os.path import isfile, join, splitext
6from subprocess import Popen, PIPE, STDOUT
7
8import argparse
9import sys
10
11################################################################################
12# help functions
13################################################################################
14def listTests():
15 list = [splitext(f)[0] for f in listdir('./.expect')
16 if not f.startswith('.') and f.endswith('.txt')
17 ]
18
19 return list
20
21def sh(cmd, dry_run):
22 if dry_run :
23 print("cmd: %s" % cmd)
24 return 0
25 else :
26 proc = Popen(cmd, stderr=STDOUT, shell=True)
27 proc.communicate()
28 return proc.returncode
29
30################################################################################
31# running test functions
32################################################################################
33def run_test_instance(test, generate, dry_run):
34
35 out_file = (".out/%s.log" % test) if not generate else (".expect/%s.txt" % test)
36
37 sh("rm -f %s" % out_file, dry_run)
38 sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
39
40 # build, skipping to next test on error
41 make_ret = sh("make -j 8 %s 2> %s 1> /dev/null" % (test, out_file), dry_run)
42
43 if make_ret == 0 :
44 # fetch optional input
45 stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else ""
46
47 # run test
48 sh("./%s %s > %s 2>&1" % (test, stdinput, out_file), dry_run)
49
50 retcode = 0
51 if not generate :
52 # diff the output of the files
53 retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run)
54
55 # clean the executable
56 sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
57
58 return retcode
59
60def run_tests(tests, generate, dry_run) :
61 sh('make clean > /dev/null 2>&1', dry_run)
62 sh('mkdir -p .out .expect', dry_run)
63
64 if generate :
65 print( "Regenerate tests for: " )
66
67 failed = False;
68 for t in tests:
69 print("%20s " % t, end="")
70 sys.stdout.flush()
71 test_failed = run_test_instance(t, generate, dry_run)
72 failed = test_failed or failed
73
74 if not generate :
75 print("FAILED" if test_failed else "PASSED")
76 else :
77 print( "Done" )
78
79 sh('make clean > /dev/null 2>&1', dry_run)
80
81 return 0 if failed else 1
82
83################################################################################
84# main loop
85################################################################################
86parser = argparse.ArgumentParser(description='Script which runs cforall tests')
87parser.add_argument('--dry-run', help='Don\'t run the tests, only output the commands', action='store_true')
88parser.add_argument('--list', help='List all test available', action='store_true')
89parser.add_argument('--all', help='Run all test available', action='store_true')
90parser.add_argument('--regenerate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')
91parser.add_argument('tests', metavar='test', type=str, nargs='*', help='a list of tests to run')
92
93options = parser.parse_args()
94
95if (len(options.tests) > 0 and options.all and not options.list) \
96or (len(options.tests) == 0 and not options.all and not options.list) :
97 print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr)
98 parser.print_help()
99 sys.exit(1)
100
101allTests = listTests()
102
103if options.all or options.list :
104 tests = allTests
105
106else :
107 tests = []
108 for test in options.tests:
109 if test in allTests :
110 tests.append(test)
111 else :
112 print('ERROR: No expected file for test %s, ignoring it' % test, file=sys.stderr)
113
114 if len(tests) == 0 :
115 print('ERROR: No valid test to run', file=sys.stderr)
116 sys.exit(1)
117
118if options.list :
119 print("\n".join(tests))
120
121else :
122 sys.exit( run_tests(tests, options.regenerate_expected, options.dry_run) )
Note: See TracBrowser for help on using the repository browser.