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

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr no_list persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since b8f6002 was f85bc15, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Test now work outside of tree except for io2

  • Property mode set to 100644
File size: 2.6 KB
Line 
1import os
2
3from pybin.tools import *
4
5import pybin.settings
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)
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
29 def prepare(self):
30 sh("mkdir -p %s" % os.path.join(self.path, '.err'))
31 sh("mkdir -p %s" % os.path.join(self.path, '.out'))
32 sh("mkdir -p %s" % os.path.join(self.path, '.in' ))
33
34 def expect(self):
35 return ("%s.expect/%s%s.txt" % (os.path.join(settings.SRCDIR, self.path), self.name, '' if not self.arch else ".%s" % self.arch))
36
37 def error_log(self):
38 return ("%s.err/%s.log" % (os.path.join(settings.BUILDDIR, self.path), self.name))
39
40 def output_log(self):
41 return ("%s.out/%s.log" % (os.path.join(settings.BUILDDIR, self.path), self.name))
42
43 def input(self):
44 return ("%s.in/%s.txt" % (os.path.join(settings.SRCDIR, self.path), self.name))
45
46 def target_output(self):
47 return self.output_log() if not settings.generating else self.expect()
48
49 def target(self):
50 return os.path.join(self.path, self.name)
51
52 def target_executable(self):
53 return os.path.join(settings.BUILDDIR, self.path, self.name)
54
55 @classmethod
56 def valid_name(_, name):
57 return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') )
58
59 @classmethod
60 def from_target(_, target):
61 test = Test()
62 test.name = os.path.basename(target)
63 test.path = os.path.dirname (target)
64 test.arch = settings.arch.toString() if settings.arch.cross_compile else ''
65 return test
66
67
68class TestResult:
69 SUCCESS = 0
70 FAILURE = 1
71 TIMEOUT = 124
72
73 @classmethod
74 def toString( cls, retcode, duration ):
75 if settings.generating :
76 if retcode == TestResult.SUCCESS: text = "Done "
77 elif retcode == TestResult.TIMEOUT: text = "TIMEOUT"
78 else : text = "ERROR code %d" % retcode
79 else :
80 if retcode == TestResult.SUCCESS: text = "PASSED "
81 elif retcode == TestResult.TIMEOUT: text = "TIMEOUT"
82 else : text = "FAILED with code %d" % retcode
83
84 text += " C%s - R%s" % (cls.fmtDur(duration[0]), cls.fmtDur(duration[1]))
85 return text
86
87 @classmethod
88 def fmtDur( cls, duration ):
89 if duration :
90 hours, rem = divmod(duration, 3600)
91 minutes, rem = divmod(rem, 60)
92 seconds, millis = divmod(rem, 1)
93 return "%2d:%02d.%03d" % (minutes, seconds, millis * 1000)
94 return " n/a"
Note: See TracBrowser for help on using the repository browser.