Changeset f1231f2 for src/tests


Ignore:
Timestamp:
Jul 14, 2016, 3:25:43 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
4e95b5c
Parents:
9c791dd
Message:

added support for tests that differ between 32bit and 64bit versions

Location:
src/tests
Files:
2 added
1 edited
2 moved

Legend:

Unmodified
Added
Removed
  • src/tests/test.py

    r9c791dd rf1231f2  
    1515#               help functions
    1616################################################################################
     17
     18class Test:
     19    def __init__(self, name, path):
     20        self.name, self.path = name, path
     21
     22def getMachineType():
     23        with open('Makefile') as file:
     24                makefile = file.read()
     25                m = re.search("CFA_FLAGS\s*=\s*-m(.*)", makefile)
     26                return m.group(1)
     27
    1728def listTests():
    18         list = [splitext(f)[0] for f in listdir('./.expect')
     29        machineType = getMachineType()
     30
     31        generic_list = map(lambda fname: Test(fname, fname),
     32                [splitext(f)[0] for f in listdir('./.expect')
    1933                if not f.startswith('.') and f.endswith('.txt')
    20                 ]
    21 
    22         return list
     34                ])
     35
     36        typed_list = map(lambda fname: Test( fname, "%s/%s" % (machineType, fname) ),
     37                [splitext(f)[0] for f in listdir("./.expect/%s" % machineType)
     38                if not f.startswith('.') and f.endswith('.txt')
     39                ])
     40
     41        return generic_list + typed_list
    2342
    2443def sh(cmd, dry_run = False, print2stdout = True):
     
    7190                return False
    7291
     92def filterTests(testname) :
     93        found = [test for test in allTests if test.name == testname]
     94        return (found[0] if len(found) == 1 else Test(testname, testname) )
     95
    7396################################################################################
    7497#               running test functions
     
    7699def run_test_instance(test, generate, dry_run):
    77100
    78         out_file = (".out/%s.log" % test) if not generate else (".expect/%s.txt" % test)
     101        out_file = (".out/%s.log" % test.name) if not generate else (".expect/%s.txt" % test.path)
    79102
    80103        sh("rm -f %s" % out_file, dry_run)
    81         sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
     104        sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run)
    82105
    83106        # build, skipping to next test on error
    84         make_ret, _ = sh("%s %s 2> %s 1> /dev/null" % (make_cmd, test, out_file), dry_run)
     107        make_ret, _ = sh("%s %s 2> %s 1> /dev/null" % (make_cmd, test.name, out_file), dry_run)
    85108
    86109        if make_ret == 0 :
    87110                # fetch optional input
    88                 stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else ""
    89 
    90                 if fileIsExecutable(test) :
     111                stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test.path) else ""
     112
     113                if fileIsExecutable(test.name) :
    91114                        # run test
    92                         sh("./%s %s > %s 2>&1" % (test, stdinput, out_file), dry_run)
     115                        sh("./%s %s > %s 2>&1" % (test.name, stdinput, out_file), dry_run)
    93116                else :
    94117                        # simply cat the result into the output
    95                         sh("cat %s > %s" % (test, out_file), dry_run)
     118                        sh("cat %s > %s" % (test.name, out_file), dry_run)
    96119
    97120        retcode = 0
     
    101124
    102125        if generate :
    103                 if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'.  Stop." % test) :
     126                if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'.  Stop." % test.name) :
    104127                        retcode = 1;
    105128                        error = "\t\tNo make target for test %s!" % test
     
    122145                                        ".expect/%s.txt .out/%s.log")
    123146
    124                 retcode, error = sh(diff_cmd % (test, test), dry_run, False)
     147                retcode, error = sh(diff_cmd % (test.path, test.name), dry_run, False)
    125148
    126149        # clean the executable
    127         sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
     150        sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run)
    128151
    129152        return retcode, error
     
    138161        failed = False;
    139162        for t in tests:
    140                 print("%20s  " % t, end="")
     163                print("%20s  " % t.name, end="")
    141164                sys.stdout.flush()
    142165                test_failed, error = run_test_instance(t, generate, dry_run)
     
    183206else :
    184207        tests = []
    185         for test in options.tests:
    186                 if test in allTests or options.regenerate_expected :
    187                         tests.append(test)
    188                 else :
    189                         print('ERROR: No expected file for test %s, ignoring it' % test, file=sys.stderr)
     208
     209        if options.regenerate_expected :
     210                tests = map(filterTests, options.tests)
     211
     212        else :
     213                for testname in options.tests:
     214                        test = [t for t in allTests if t.name == testname]
     215
     216                        if len(test) != 0 :
     217                                tests.append( test[0] )
     218                        else :
     219                                print('ERROR: No expected file for test %s, ignoring it' % testname, file=sys.stderr)
    190220
    191221        if len(tests) == 0 :
     
    193223                sys.exit(1)
    194224
    195 tests.sort()
     225tests.sort(key=lambda t: t.name)
     226
    196227make_flags = environ.get('MAKEFLAGS')
    197228make_cmd = "make" if make_flags and "-j" in make_flags else "make -j8"
    198229
    199230if options.list :
    200         print("\n".join(tests))
     231        print("\n".join(map(lambda t: "%s (%s)" % (t.name, t.path), tests)))
    201232
    202233else :
Note: See TracChangeset for help on using the changeset viewer.