source: src/tests/test.py @ 4b5857f

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 4b5857f was f6ed7fd, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

re-enable tests and tests now use 8 cores for compilation

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