[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): |
---|
[0fc91db1] | 15 | return "{:25s} ({:5s} arch: {:s})".format( self.name, self.arch if self.arch else "Any", self.target() ) |
---|
[0ad0c55] | 16 | |
---|
[bacc36c] | 17 | def prepare(self): |
---|
[a95c117] | 18 | mkdir( (self.output_log(), self.error_log(), self.input() ) ) |
---|
| 19 | rm ( (self.output_log(), self.error_log(), self.target_executable()) ) |
---|
[0ad0c55] | 20 | |
---|
[bacc36c] | 21 | def expect(self): |
---|
[a2f2fda] | 22 | arch = '' if not self.arch else ".%s" % self.arch |
---|
[0fc91db1] | 23 | return os.path.normpath( os.path.join(settings.SRCDIR , self.path, ".expect", "%s%s.txt" % (self.name,arch)) ) |
---|
[0ad0c55] | 24 | |
---|
[bacc36c] | 25 | def error_log(self): |
---|
[a95c117] | 26 | return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".err" , "%s.log" % self.name) ) |
---|
[0ad0c55] | 27 | |
---|
[bacc36c] | 28 | def output_log(self): |
---|
[a95c117] | 29 | return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".out" , "%s.log" % self.name) ) |
---|
[0ad0c55] | 30 | |
---|
[b24cbaf] | 31 | # one file that goes to the test's stdin |
---|
[bacc36c] | 32 | def input(self): |
---|
[a95c117] | 33 | return os.path.normpath( os.path.join(settings.SRCDIR , self.path, ".in" , "%s.txt" % self.name) ) |
---|
[0ad0c55] | 34 | |
---|
[b24cbaf] | 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 | |
---|
[bacc36c] | 39 | def target_output(self): |
---|
| 40 | return self.output_log() if not settings.generating else self.expect() |
---|
| 41 | |
---|
[0ad0c55] | 42 | def target(self): |
---|
[a95c117] | 43 | return os.path.normpath( os.path.join(self.path, self.name) ) |
---|
[bacc36c] | 44 | |
---|
[f85bc15] | 45 | def target_executable(self): |
---|
[a95c117] | 46 | return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, self.name) ) |
---|
[f85bc15] | 47 | |
---|
[767a8ef] | 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 | |
---|
[64cf022] | 58 | @staticmethod |
---|
| 59 | def valid_name(name): |
---|
[bacc36c] | 60 | return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') ) |
---|
| 61 | |
---|
[64cf022] | 62 | @staticmethod |
---|
[0fc91db1] | 63 | def new_target(target, arch): |
---|
[bacc36c] | 64 | test = Test() |
---|
| 65 | test.name = os.path.basename(target) |
---|
[a95c117] | 66 | test.path = os.path.relpath (os.path.dirname(target), settings.SRCDIR) |
---|
[41af19c] | 67 | test.arch = arch.target if arch else '' |
---|
[bacc36c] | 68 | return test |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | class TestResult: |
---|
| 72 | SUCCESS = 0 |
---|
| 73 | FAILURE = 1 |
---|
| 74 | TIMEOUT = 124 |
---|
| 75 | |
---|
| 76 | @classmethod |
---|
[ca54499] | 77 | def toString( cls, retcode, duration ): |
---|
[bacc36c] | 78 | if settings.generating : |
---|
[172a88d] | 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 |
---|
[bacc36c] | 82 | else : |
---|
[172a88d] | 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 |
---|
[ca54499] | 86 | |
---|
[76de075] | 87 | text += " C%s - R%s" % (fmtDur(duration[0]), fmtDur(duration[1])) |
---|
[172a88d] | 88 | return key, text |
---|