[0ad0c55] | 1 | import os |
---|
| 2 | |
---|
| 3 | from pybin.tools import * |
---|
| 4 | |
---|
[bacc36c] | 5 | import pybin.settings |
---|
[0ad0c55] | 6 | |
---|
| 7 | # Test class that defines what a test is |
---|
| 8 | class 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 | |
---|
[bacc36c] | 17 | def prepare(self): |
---|
| 18 | sh("mkdir -p %s" % os.path.join(self.path, '.err')) |
---|
| 19 | sh("mkdir -p %s" % os.path.join(self.path, '.out')) |
---|
| 20 | sh("mkdir -p %s" % os.path.join(self.path, '.in' )) |
---|
[0ad0c55] | 21 | |
---|
[bacc36c] | 22 | def expect(self): |
---|
[f3b9efc] | 23 | return ("%s/.expect/%s%s.txt" % (self.path, self.name, '' if not self.arch else ".%s" % self.arch)) |
---|
[0ad0c55] | 24 | |
---|
[bacc36c] | 25 | def error_log(self): |
---|
[0ad0c55] | 26 | return ("%s/.err/%s.log" % (self.path, self.name)) |
---|
| 27 | |
---|
[bacc36c] | 28 | def output_log(self): |
---|
[0ad0c55] | 29 | return ("%s/.out/%s.log" % (self.path, self.name)) |
---|
| 30 | |
---|
[bacc36c] | 31 | def input(self): |
---|
[0ad0c55] | 32 | return ("%s/.in/%s.txt" % (self.path, self.name)) |
---|
| 33 | |
---|
[bacc36c] | 34 | def target_output(self): |
---|
| 35 | return self.output_log() if not settings.generating else self.expect() |
---|
| 36 | |
---|
[0ad0c55] | 37 | def target(self): |
---|
[bacc36c] | 38 | return os.path.join(self.path, self.name) |
---|
| 39 | |
---|
| 40 | @classmethod |
---|
[f3b9efc] | 41 | def valid_name(_, name): |
---|
[bacc36c] | 42 | return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') ) |
---|
| 43 | |
---|
| 44 | @classmethod |
---|
[f3b9efc] | 45 | def from_target(_, target): |
---|
[bacc36c] | 46 | test = Test() |
---|
| 47 | test.name = os.path.basename(target) |
---|
| 48 | test.path = os.path.dirname (target) |
---|
| 49 | test.arch = settings.arch.toString() if settings.arch.cross_compile else '' |
---|
| 50 | return test |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | class TestResult: |
---|
| 54 | SUCCESS = 0 |
---|
| 55 | FAILURE = 1 |
---|
| 56 | TIMEOUT = 124 |
---|
| 57 | |
---|
| 58 | @classmethod |
---|
| 59 | def toString( cls, retcode ): |
---|
| 60 | if settings.generating : |
---|
| 61 | if retcode == TestResult.SUCCESS: return "Done" |
---|
| 62 | elif retcode == TestResult.TIMEOUT: return "TIMEOUT" |
---|
| 63 | else : return "ERROR code %d" % retcode |
---|
| 64 | else : |
---|
| 65 | if retcode == TestResult.SUCCESS: return "PASSED" |
---|
| 66 | elif retcode == TestResult.TIMEOUT: return "TIMEOUT" |
---|
| 67 | else : return "FAILED with code %d" % retcode |
---|