source: src/tests/pybin/test_run.py @ c198b69

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since c198b69 was a95c117, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Fixed handling of paths when regenerating tests

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[0ad0c55]1import os
2
3from pybin.tools import *
4
[bacc36c]5import pybin.settings
[ca54499]6import datetime
7
8from string import Template
9
10class DeltaTemplate(Template):
11    delimiter = "%"
12
13def strfdelta(tdelta, fmt):
14    d["H"], rem = divmod(tdelta.seconds, 3600)
15    d["M"], d["S"] = divmod(rem, 60)
16    t = DeltaTemplate(fmt)
17    return t.substitute(**d)
[0ad0c55]18
19# Test class that defines what a test is
20class Test:
21        def __init__(self):
22                self.name = ''
23                self.path = ''
24                self.arch = ''
25
26        def toString(self):
27                return "{:25s} ({:5s} {:s})".format( self.name, self.arch if self.arch else "Any", self.target() )
28
[bacc36c]29        def prepare(self):
[a95c117]30                mkdir( (self.output_log(), self.error_log(), self.input()            ) )
31                rm   ( (self.output_log(), self.error_log(), self.target_executable()) )
[0ad0c55]32
[bacc36c]33        def expect(self):
[a95c117]34                return os.path.normpath( os.path.join(settings.SRCDIR  , self.path, ".expect", "%s%s.txt" % (self.name,'' if not self.arch else ".%s" % self.arch)) )
[0ad0c55]35
[bacc36c]36        def error_log(self):
[a95c117]37                return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".err"   , "%s.log" % self.name) )
[0ad0c55]38
[bacc36c]39        def output_log(self):
[a95c117]40                return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".out"   , "%s.log" % self.name) )
[0ad0c55]41
[bacc36c]42        def input(self):
[a95c117]43                return os.path.normpath( os.path.join(settings.SRCDIR  , self.path, ".in"    , "%s.txt" % self.name) )
[0ad0c55]44
[bacc36c]45        def target_output(self):
46                return self.output_log() if not settings.generating else self.expect()
47
[0ad0c55]48        def target(self):
[a95c117]49                return os.path.normpath( os.path.join(self.path, self.name) )
[bacc36c]50
[f85bc15]51        def target_executable(self):
[a95c117]52                return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, self.name) )
[f85bc15]53
[bacc36c]54        @classmethod
[f3b9efc]55        def valid_name(_, name):
[bacc36c]56                return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') )
57
58        @classmethod
[f3b9efc]59        def from_target(_, target):
[bacc36c]60                test = Test()
61                test.name = os.path.basename(target)
[a95c117]62                test.path = os.path.relpath (os.path.dirname(target), settings.SRCDIR)
[bacc36c]63                test.arch = settings.arch.toString() if settings.arch.cross_compile else ''
64                return test
65
66
67class TestResult:
68        SUCCESS = 0
69        FAILURE = 1
70        TIMEOUT = 124
71
72        @classmethod
[ca54499]73        def toString( cls, retcode, duration ):
[bacc36c]74                if settings.generating :
[ca54499]75                        if   retcode == TestResult.SUCCESS:     text = "Done   "
76                        elif retcode == TestResult.TIMEOUT:     text = "TIMEOUT"
77                        else :                                          text = "ERROR code %d" % retcode
[bacc36c]78                else :
[ca54499]79                        if   retcode == TestResult.SUCCESS:     text = "PASSED "
80                        elif retcode == TestResult.TIMEOUT:     text = "TIMEOUT"
81                        else :                                          text = "FAILED with code %d" % retcode
82
83                text += "    C%s - R%s" % (cls.fmtDur(duration[0]), cls.fmtDur(duration[1]))
84                return text
85
86        @classmethod
87        def fmtDur( cls, duration ):
88                if duration :
89                        hours, rem = divmod(duration, 3600)
90                        minutes, rem = divmod(rem, 60)
91                        seconds, millis = divmod(rem, 1)
92                        return "%2d:%02d.%03d" % (minutes, seconds, millis * 1000)
93                return " n/a"
Note: See TracBrowser for help on using the repository browser.