source: tests/pybin/test_run.py @ d82892a

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since d82892a was f9128a5, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Fixed cross compilation bug in tests

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