1 | import os |
---|
2 | |
---|
3 | from pybin.tools import * |
---|
4 | |
---|
5 | import pybin.settings |
---|
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 | |
---|
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' )) |
---|
21 | |
---|
22 | def expect(self): |
---|
23 | return ("%s/.expect/%s%s.txt" % (self.path, self.name, '' if not self.arch else ".%s" % self.arch)) |
---|
24 | |
---|
25 | def error_log(self): |
---|
26 | return ("%s/.err/%s.log" % (self.path, self.name)) |
---|
27 | |
---|
28 | def output_log(self): |
---|
29 | return ("%s/.out/%s.log" % (self.path, self.name)) |
---|
30 | |
---|
31 | def input(self): |
---|
32 | return ("%s/.in/%s.txt" % (self.path, self.name)) |
---|
33 | |
---|
34 | def target_output(self): |
---|
35 | return self.output_log() if not settings.generating else self.expect() |
---|
36 | |
---|
37 | def target(self): |
---|
38 | return os.path.join(self.path, self.name) |
---|
39 | |
---|
40 | @classmethod |
---|
41 | def valid_name(_, name): |
---|
42 | return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') ) |
---|
43 | |
---|
44 | @classmethod |
---|
45 | def from_target(_, target): |
---|
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 |
---|