Changeset c2d5e28


Ignore:
Timestamp:
May 11, 2017, 3:29:00 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
9738e74
Parents:
6a4f3d4
Message:

Tests can now timeout individually

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/test.py

    r6a4f3d4 rc2d5e28  
    2323    def __init__(self, name, path):
    2424        self.name, self.path = name, path
     25
     26class TestResult:
     27        SUCCESS = 0
     28        FAILURE = 1
     29        TIMEOUT = 124
    2530
    2631# parses the Makefile to find the machine type (32-bit / 64-bit)
     
    163168        make_ret, _ = sh("""%s test=yes EXTRA_FLAGS="%s" %s 2> %s 1> /dev/null""" % (make_cmd, options, test.name, out_file), dry_run)
    164169
     170        retcode = 0
     171        error = None
     172
    165173        # if the make command succeds continue otherwise skip to diff
    166174        if make_ret == 0 :
     
    170178                if fileIsExecutable(test.name) :
    171179                        # run test
    172                         sh("./%s %s > %s 2>&1" % (test.name, stdinput, out_file), dry_run)
     180                        retcode, _ = sh("timeout 60 ./%s %s > %s 2>&1" % (test.name, stdinput, out_file), dry_run)
    173181                else :
    174182                        # simply cat the result into the output
     
    179187                sh("mv %s %s" % (err_file, out_file), dry_run)
    180188
    181         retcode = 0
    182         error = None
    183 
    184         if generate :
    185                 # if we are ounly generating the output we still need to check that the test actually exists
    186                 if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'.  Stop." % test.name) :
    187                         retcode = 1;
    188                         error = "\t\tNo make target for test %s!" % test.name
    189                         sh("rm %s" % out_file, False)
    190 
    191         else :
    192                 # fetch return code and error from the diff command
    193                 retcode, error = diff(".expect/%s.txt" % test.path, ".out/%s.log" % test.name, dry_run)
    194 
     189        if retcode == 0:
     190                if generate :
     191                        # if we are ounly generating the output we still need to check that the test actually exists
     192                        if not dry_run and fileContainsOnly(out_file, "make: *** No rule to make target `%s'.  Stop." % test.name) :
     193                                retcode = 1;
     194                                error = "\t\tNo make target for test %s!" % test.name
     195                                sh("rm %s" % out_file, False)
     196                else :
     197                        # fetch return code and error from the diff command
     198                        retcode, error = diff(".expect/%s.txt" % test.path, ".out/%s.log" % test.name, dry_run)
    195199        # clean the executable
    196200        sh("rm -f %s > /dev/null 2>&1" % test.name, dry_run)
     
    205209        name_txt = "%20s  " % t.name
    206210
    207         #run the test instance and collect the result
    208         test_failed, error = run_single_test(t, generate, dry_run, debug)
     211        retcode, error = run_single_test(t, generate, dry_run, debug)
    209212
    210213        # update output based on current action
    211214        if generate :
    212                 failed_txt = "ERROR"
    213                 success_txt = "Done"
    214         else :
    215                 failed_txt = "FAILED"
    216                 success_txt = "PASSED"
     215                if   retcode == TestResult.SUCCESS:     result_txt = "Done"
     216                elif retcode == TestResult.TIMEOUT:     result_txt = "TIMEOUT"
     217                else :                                          result_txt = "ERROR"
     218        else :
     219                if   retcode == TestResult.SUCCESS:     result_txt = "PASSED"
     220                elif retcode == TestResult.TIMEOUT:     result_txt = "TIMEOUT"
     221                else :                                          result_txt = "FAILED"
    217222
    218223        #print result with error if needed
    219         text = name_txt + (failed_txt if test_failed else success_txt)
     224        text = name_txt + result_txt
    220225        out = sys.stdout
    221226        if error :
     
    223228                out = sys.stderr
    224229
    225         print(text, file = out);
     230        print(text, file = out)
    226231        sys.stdout.flush()
    227232        sys.stderr.flush()
    228233        signal.signal(signal.SIGINT, signal.SIG_IGN)
    229234
    230         return test_failed
     235        return retcode != TestResult.SUCCESS
    231236
    232237# run the given list of tests with the given parameters
Note: See TracChangeset for help on using the changeset viewer.