[0ad0c55] | 1 | import os |
---|
| 2 | |
---|
| 3 | from pybin.tools import * |
---|
| 4 | |
---|
[bacc36c] | 5 | import pybin.settings |
---|
[ca54499] | 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) |
---|
[0ad0c55] | 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 | |
---|
[bacc36c] | 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' )) |
---|
[0ad0c55] | 33 | |
---|
[bacc36c] | 34 | def expect(self): |
---|
[f3b9efc] | 35 | return ("%s/.expect/%s%s.txt" % (self.path, self.name, '' if not self.arch else ".%s" % self.arch)) |
---|
[0ad0c55] | 36 | |
---|
[bacc36c] | 37 | def error_log(self): |
---|
[0ad0c55] | 38 | return ("%s/.err/%s.log" % (self.path, self.name)) |
---|
| 39 | |
---|
[bacc36c] | 40 | def output_log(self): |
---|
[0ad0c55] | 41 | return ("%s/.out/%s.log" % (self.path, self.name)) |
---|
| 42 | |
---|
[bacc36c] | 43 | def input(self): |
---|
[0ad0c55] | 44 | return ("%s/.in/%s.txt" % (self.path, self.name)) |
---|
| 45 | |
---|
[bacc36c] | 46 | def target_output(self): |
---|
| 47 | return self.output_log() if not settings.generating else self.expect() |
---|
| 48 | |
---|
[0ad0c55] | 49 | def target(self): |
---|
[bacc36c] | 50 | return os.path.join(self.path, self.name) |
---|
| 51 | |
---|
| 52 | @classmethod |
---|
[f3b9efc] | 53 | def valid_name(_, name): |
---|
[bacc36c] | 54 | return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') ) |
---|
| 55 | |
---|
| 56 | @classmethod |
---|
[f3b9efc] | 57 | def from_target(_, target): |
---|
[bacc36c] | 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 |
---|
[ca54499] | 71 | def toString( cls, retcode, duration ): |
---|
[bacc36c] | 72 | if settings.generating : |
---|
[ca54499] | 73 | if retcode == TestResult.SUCCESS: text = "Done " |
---|
| 74 | elif retcode == TestResult.TIMEOUT: text = "TIMEOUT" |
---|
| 75 | else : text = "ERROR code %d" % retcode |
---|
[bacc36c] | 76 | else : |
---|
[ca54499] | 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" |
---|