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