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} arch: {:s})".format( self.name, self.arch if self.arch else "Any", self.target() ) |
---|
16 | |
---|
17 | def prepare(self): |
---|
18 | mkdir( (self.output_log(), self.error_log(), self.input() ) ) |
---|
19 | rm ( (self.output_log(), self.error_log(), self.target_executable()) ) |
---|
20 | |
---|
21 | def expect(self): |
---|
22 | arch = '' if not self.arch else ".%s" % self.arch |
---|
23 | return os.path.normpath( os.path.join(settings.SRCDIR , self.path, ".expect", "%s%s.txt" % (self.name,arch)) ) |
---|
24 | |
---|
25 | def error_log(self): |
---|
26 | return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".err" , "%s.log" % self.name) ) |
---|
27 | |
---|
28 | def output_log(self): |
---|
29 | return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".out" , "%s.log" % self.name) ) |
---|
30 | |
---|
31 | # one file that goes to the test's stdin |
---|
32 | def input(self): |
---|
33 | return os.path.normpath( os.path.join(settings.SRCDIR , self.path, ".in" , "%s.txt" % self.name) ) |
---|
34 | |
---|
35 | # several files available for this test to open |
---|
36 | def inputs_all(self): |
---|
37 | return os.path.normpath( os.path.join(settings.SRCDIR , self.path, ".in" , "%s.*" % self.name) ) |
---|
38 | |
---|
39 | def target_output(self): |
---|
40 | return self.output_log() if not settings.generating else self.expect() |
---|
41 | |
---|
42 | def target(self): |
---|
43 | return os.path.normpath( os.path.join(self.path, self.name) ) |
---|
44 | |
---|
45 | def target_executable(self): |
---|
46 | return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, self.name) ) |
---|
47 | |
---|
48 | def format_target(self, width): |
---|
49 | target = self.target() |
---|
50 | length = len(target) |
---|
51 | if length < width: |
---|
52 | return '{0:{width}}'.format(target, width=width) |
---|
53 | elif length == width: |
---|
54 | return target |
---|
55 | else: |
---|
56 | return '...' + target[3-width:] |
---|
57 | |
---|
58 | @staticmethod |
---|
59 | def valid_name(name): |
---|
60 | return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') ) |
---|
61 | |
---|
62 | @staticmethod |
---|
63 | def new_target(target, arch): |
---|
64 | test = Test() |
---|
65 | test.name = os.path.basename(target) |
---|
66 | test.path = os.path.relpath (os.path.dirname(target), settings.SRCDIR) |
---|
67 | test.arch = arch.target if arch else '' |
---|
68 | return test |
---|
69 | |
---|
70 | |
---|
71 | class TestResult: |
---|
72 | SUCCESS = 0 |
---|
73 | FAILURE = 1 |
---|
74 | TIMEOUT = 124 |
---|
75 | |
---|
76 | @classmethod |
---|
77 | def toString( cls, retcode, duration ): |
---|
78 | if settings.generating : |
---|
79 | if retcode == TestResult.SUCCESS: key = 'pass'; text = "Done " |
---|
80 | elif retcode == TestResult.TIMEOUT: key = 'time'; text = "TIMEOUT" |
---|
81 | else : key = 'fail'; text = "ERROR code %d" % retcode |
---|
82 | else : |
---|
83 | if retcode == TestResult.SUCCESS: key = 'pass'; text = "PASSED " |
---|
84 | elif retcode == TestResult.TIMEOUT: key = 'time'; text = "TIMEOUT" |
---|
85 | else : key = 'fail'; text = "FAILED with code %d" % retcode |
---|
86 | |
---|
87 | text += " C%s - R%s" % (fmtDur(duration[0]), fmtDur(duration[1])) |
---|
88 | return key, text |
---|