1 | import os
|
---|
2 |
|
---|
3 | from pybin.tools import *
|
---|
4 |
|
---|
5 | import pybin.settings
|
---|
6 | import datetime
|
---|
7 |
|
---|
8 | from string import Template
|
---|
9 |
|
---|
10 | class DeltaTemplate(Template):
|
---|
11 | delimiter = "%"
|
---|
12 |
|
---|
13 | def 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
|
---|
20 | class 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" % (self.path, self.name, '' if not self.arch else ".%s" % self.arch))
|
---|
36 |
|
---|
37 | def error_log(self):
|
---|
38 | return ("%s/.err/%s.log" % (self.path, self.name))
|
---|
39 |
|
---|
40 | def output_log(self):
|
---|
41 | return ("%s/.out/%s.log" % (self.path, self.name))
|
---|
42 |
|
---|
43 | def input(self):
|
---|
44 | return ("%s/.in/%s.txt" % (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 | @classmethod
|
---|
53 | def valid_name(_, name):
|
---|
54 | return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') )
|
---|
55 |
|
---|
56 | @classmethod
|
---|
57 | def from_target(_, target):
|
---|
58 | test = Test()
|
---|
59 | test.name = os.path.basename(target)
|
---|
60 | test.path = os.path.dirname (target)
|
---|
61 | test.arch = settings.arch.toString() if settings.arch.cross_compile else ''
|
---|
62 | return test
|
---|
63 |
|
---|
64 |
|
---|
65 | class TestResult:
|
---|
66 | SUCCESS = 0
|
---|
67 | FAILURE = 1
|
---|
68 | TIMEOUT = 124
|
---|
69 |
|
---|
70 | @classmethod
|
---|
71 | def toString( cls, retcode, duration ):
|
---|
72 | if settings.generating :
|
---|
73 | if retcode == TestResult.SUCCESS: text = "Done "
|
---|
74 | elif retcode == TestResult.TIMEOUT: text = "TIMEOUT"
|
---|
75 | else : text = "ERROR code %d" % retcode
|
---|
76 | else :
|
---|
77 | if retcode == TestResult.SUCCESS: text = "PASSED "
|
---|
78 | elif retcode == TestResult.TIMEOUT: text = "TIMEOUT"
|
---|
79 | else : text = "FAILED with code %d" % retcode
|
---|
80 |
|
---|
81 | text += " C%s - R%s" % (cls.fmtDur(duration[0]), cls.fmtDur(duration[1]))
|
---|
82 | return text
|
---|
83 |
|
---|
84 | @classmethod
|
---|
85 | def fmtDur( cls, duration ):
|
---|
86 | if duration :
|
---|
87 | hours, rem = divmod(duration, 3600)
|
---|
88 | minutes, rem = divmod(rem, 60)
|
---|
89 | seconds, millis = divmod(rem, 1)
|
---|
90 | return "%2d:%02d.%03d" % (minutes, seconds, millis * 1000)
|
---|
91 | return " n/a"
|
---|