source: src/tests/test.py @ 245510f

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 245510f was 245510f, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

updated Jenkinsfile and test.py to limit redundant output

  • Property mode set to 100644
File size: 4.1 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, dry_run):
35        sh("rm -f .out/%s.log" % test, dry_run)
36        sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
37
38        # build, skipping to next test on error
39        sh("make -j 1 %s >> .out/%s.log 2>&1" % (test, test), dry_run)
40
41        # fetch optional input
42        stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else ""
43
44        # run test
45        sh("./%s %s >> .out/%s.log 2>&1" % (test, stdinput, test), dry_run)
46
47        # touch expected files so empty output are supported by default
48        sh("touch .expect/%s.txt" % test, dry_run)
49
50        # diff the output of the files
51        retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run)
52
53        # clean the executable
54        sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
55
56        return retcode
57
58def run_tests(tests, dry_run) :
59        sh('make clean > /dev/null 2>&1', dry_run)
60
61        failed = False;
62        for t in tests:
63                print("%10s  " % t, end="")
64                sys.stdout.flush()
65                test_failed = run_test_instance(t, dry_run)
66                failed = test_failed or failed
67                print("FAILED" if test_failed else "PASSED")
68
69        sh('make clean > /dev/null 2>&1', dry_run)
70
71        return 0 if failed else 1
72
73################################################################################
74#               generate expectation functions
75################################################################################
76def generate_test_expect(test):
77        sh("rm -f .out/%s.log" % test, False)
78        sh("rm -f %s > /dev/null 2>&1" % test, False)
79
80        # build, skipping to next test on error
81        sh("make -j 8 %s > .expect/%s.txt 2>&1" % (test, test), False)
82
83        # fetch optional input
84        stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else ""
85
86        # run test
87        sh("./%s %s >> .expect/%s.txt 2>&1" % (test, stdinput, test), False)
88
89        # clean the executable
90        sh("rm -f %s > /dev/null 2>&1" % test, False)
91
92def generate_expect(tests) :
93        sh('make clean > /dev/null 2>&1', False)
94
95        print( "Regenerate tests for" )
96
97        print( ", ".join( tests ) )
98
99        for t in tests:
100                generate_test_expect( t )
101
102        print( "Done" )
103
104        sh('make clean > /dev/null 2>&1', False)
105
106################################################################################
107#               main loop
108################################################################################
109parser = argparse.ArgumentParser(description='Script which runs cforall tests')
110parser.add_argument('--dry-run', help='Don\'t run the tests, only output the commands', action='store_true')
111parser.add_argument('--all', help='Run all test available', action='store_true')
112parser.add_argument('--generate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')
113parser.add_argument('tests', metavar='test', type=str, nargs='*', help='a list of tests to run')
114
115options = parser.parse_args()
116
117tests = listTests()
118
119if options.all :
120        if len(options.tests) > 0 :
121                print('ERROR: cannot specify tests with \'--all\' option', file=sys.stderr)
122                sys.exit(1)
123
124        if options.generate_expected :
125                generate_expect( tests )
126        else :
127                sys.exit( run_tests(tests, options.dry_run) )
128
129else :
130        if len(options.tests) == 0 :
131                print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr)
132                parser.print_help()
133                sys.exit(1)
134
135        if options.generate_expected :
136                generate_expect( options.tests )
137        else :
138                sys.exit( run_tests(options.tests, options.dry_run) )
139
140sys.exit(0)
Note: See TracBrowser for help on using the repository browser.