Changeset cde3891 for tests/test.py


Ignore:
Timestamp:
Jan 23, 2019, 4:52:16 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
a200795
Parents:
9b086ca (diff), 1d832f4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/test.py

    r9b086ca rcde3891  
    1919
    2020        def matchTest(path):
    21                 match = re.search("%s\/([\w\/\-_]*).expect\/([\w\-_]+)(\.[\w\-_]+)?\.txt" % settings.SRCDIR, path)
     21                match = re.search("^%s\/([\w\/\-_]*).expect\/([\w\-_]+)(\.[\w\-_]+)?\.txt$" % settings.SRCDIR, path)
    2222                if match :
    2323                        test = Test()
     
    3434# reads the directory ./.expect and indentifies the tests
    3535def listTests( includes, excludes ):
    36         includes = [canonicalPath( i ) for i in includes] if includes else None
    37         excludes = [canonicalPath( i ) for i in excludes] if excludes else None
    38 
    3936        # tests directly in the .expect folder will always be processed
    4037        test_list = findTests()
     
    124121#               running test functions
    125122################################################################################
    126 # fix the absolute paths in the output
    127 def fixoutput( fname ):
    128         if not is_ascii(fname):
    129                 return
    130 
    131         file_replace(fname, "%s/" % settings.SRCDIR, "")
    132 
     123def success(val):
     124        return val == 0 or settings.dry_run
     125
     126def isExe(file):
     127        return settings.dry_run or fileIsExecutable(file)
     128
     129def noRule(file, target):
     130        return not settings.dry_run and fileContainsOnly(file, "make: *** No rule to make target `%s'.  Stop." % target)
    133131
    134132# logic to run a single test and return the result (No handling of printing or other test framework logic)
     
    146144
    147145        # build, skipping to next test on error
    148         before = time.time()
    149         make_ret, _ = make( test.target(),
    150                 redirects  = "2> %s 1> /dev/null" % out_file,
    151                 error_file = err_file
    152         )
    153         after = time.time()
    154 
    155         comp_dur = after - before
    156 
     146        with Timed() as comp_dur:
     147                make_ret, _ = make( test.target(),      redirects  = ("2> %s 1> /dev/null" % out_file), error_file = err_file )
     148
     149        # if the make command succeds continue otherwise skip to diff
    157150        run_dur = None
    158 
    159         # if the make command succeds continue otherwise skip to diff
    160         if make_ret == 0 or settings.dry_run:
    161                 before = time.time()
    162                 if settings.dry_run or fileIsExecutable(exe_file) :
    163                         # run test
    164                         retcode, _ = sh("timeout %d %s > %s 2>&1" % (settings.timeout.single, exe_file, out_file), input = in_file)
    165                 else :
    166                         # simply cat the result into the output
    167                         retcode, _ = sh("cat %s > %s" % (exe_file, out_file))
    168 
    169                 after = time.time()
    170                 run_dur = after - before
     151        if success(make_ret):
     152                with Timed() as run_dur:
     153                        if isExe(exe_file):
     154                                # run test
     155                                retcode = run(exe_file, out_file, in_file)
     156                        else :
     157                                # simply cat the result into the output
     158                                retcode = cat(exe_file, out_file)
    171159        else:
    172                 retcode, _ = sh("mv %s %s" % (err_file, out_file))
    173 
    174 
    175         if retcode == 0:
    176                 # fixoutput(out_file)
     160                retcode = mv(err_file, out_file)
     161
     162        if success(retcode):
    177163                if settings.generating :
    178164                        # if we are ounly generating the output we still need to check that the test actually exists
    179                         if not settings.dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'.  Stop." % test.target()) :
    180                                 retcode = 1;
     165                        if noRule(out_file, test.target()) :
     166                                retcode = 1
    181167                                error = "\t\tNo make target for test %s!" % test.target()
    182                                 sh("rm %s" % out_file, False)
     168                                rm(out_file)
    183169                        else:
    184170                                error = None
     
    191177                        error = myfile.read()
    192178
     179                ret, info = coreInfo(exe_file)
     180                error = error + info
     181
     182
    193183
    194184        # clean the executable
    195         sh("rm -f %s > /dev/null 2>&1" % test.target())
    196 
    197         return retcode, error, [comp_dur, run_dur]
     185        rm(exe_file)
     186
     187        return retcode, error, [comp_dur.duration, run_dur.duration if run_dur else None]
    198188
    199189# run a single test and handle the errors, outputs, printing, exception handling, etc.
     
    202192        with SignalHandling():
    203193                # print formated name
    204                 name_txt = "%20s  " % t.name
     194                name_txt = "%24s  " % t.name
    205195
    206196                retcode, error, duration = run_single_test(t)
     
    266256        allTests = listTests( options.include, options.exclude )
    267257
     258
    268259        # if user wants all tests than no other treatement of the test list is required
    269260        if options.all or options.list or options.list_comp or options.include :
Note: See TracChangeset for help on using the changeset viewer.