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
RevLine 
[efc15918]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################################################################################
[3c1d702]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)
[245510f]39        sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
[efc15918]40
41        # build, skipping to next test on error
[f6ed7fd]42        make_ret = sh("make -j 8 %s > %s 2>&1" % (test, out_file), dry_run)
[efc15918]43
[3c1d702]44        if make_ret == 0 :
45                # fetch optional input
46                stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else ""
[efc15918]47
[3c1d702]48                # run test
49                sh("./%s %s > %s 2>&1" % (test, stdinput, out_file), dry_run)
[efc15918]50
[3c1d702]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)
[efc15918]55
[3c1d702]56                # diff the output of the files
57                retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run)
[efc15918]58
59        # clean the executable
[245510f]60        sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
[efc15918]61
62        return retcode
63
[3c1d702]64def run_tests(tests, generate, dry_run) :
[efc15918]65        sh('make clean > /dev/null 2>&1', dry_run)
[3c1d702]66        sh('mkdir -p .out .expect', dry_run)
67
68        if generate :
69                print( "Regenerate tests for: ", end="" )
70                print( ", ".join( tests ) )
[efc15918]71
72        failed = False;
73        for t in tests:
[3c1d702]74                if not generate :
75                        print("%20s  " % t, end="")
[efc15918]76                sys.stdout.flush()
[3c1d702]77                test_failed = run_test_instance(t, generate, dry_run)
[efc15918]78                failed = test_failed or failed
79
[3c1d702]80                if not generate :
81                        print("FAILED" if test_failed else "PASSED")
[efc15918]82
[3c1d702]83        sh('make clean > /dev/null 2>&1', dry_run)
[efc15918]84
[3c1d702]85        if generate :
86                print( "Done" )
[efc15918]87
[3c1d702]88        return 0 if failed else 1
[efc15918]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
[3c1d702]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)
[efc15918]105
[3c1d702]106tests = listTests() if options.all else options.tests
[efc15918]107
[3c1d702]108sys.exit( run_tests(tests, options.generate_expected, options.dry_run) )
Note: See TracBrowser for help on using the repository browser.