source: tests/pybin/test_run.py@ 1097bb7

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 1097bb7 was bf71cfd, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Moved up many directories in source

  • Property mode set to 100644
File size: 2.7 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 mkdir( (self.output_log(), self.error_log(), self.input() ) )
31 rm ( (self.output_log(), self.error_log(), self.target_executable()) )
32
33 def expect(self):
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)) )
35
36 def error_log(self):
37 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".err" , "%s.log" % self.name) )
38
39 def output_log(self):
40 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".out" , "%s.log" % self.name) )
41
42 def input(self):
43 return os.path.normpath( os.path.join(settings.SRCDIR , self.path, ".in" , "%s.txt" % self.name) )
44
45 def target_output(self):
46 return self.output_log() if not settings.generating else self.expect()
47
48 def target(self):
49 return os.path.normpath( os.path.join(self.path, self.name) )
50
51 def target_executable(self):
52 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, self.name) )
53
54 @classmethod
55 def valid_name(_, name):
56 return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') )
57
58 @classmethod
59 def from_target(_, target):
60 test = Test()
61 test.name = os.path.basename(target)
62 test.path = os.path.relpath (os.path.dirname(target), settings.SRCDIR)
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
73 def toString( cls, retcode, duration ):
74 if settings.generating :
75 if retcode == TestResult.SUCCESS: text = "Done "
76 elif retcode == TestResult.TIMEOUT: text = "TIMEOUT"
77 else : text = "ERROR code %d" % retcode
78 else :
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.