source: tests/pybin/test_run.py @ 0fc91db1

ADTast-experimentalpthread-emulation
Last change on this file since 0fc91db1 was 0fc91db1, checked in by Thierry Delisle <tdelisle@…>, 20 months ago

Removed old ast from configure and tests.py

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import os
2
3from pybin.tools import *
4
5import pybin.settings
6
7# Test class that defines what a test is
8class 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        def input(self):
32                return os.path.normpath( os.path.join(settings.SRCDIR  , self.path, ".in"    , "%s.txt" % 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.normpath( os.path.join(self.path, self.name) )
39
40        def target_executable(self):
41                return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, self.name) )
42
43        def format_target(self, width):
44                target = self.target()
45                length = len(target)
46                if length < width:
47                        return '{0:{width}}'.format(target, width=width)
48                elif length == width:
49                        return target
50                else:
51                        return '...' + target[3-width:]
52
53        @staticmethod
54        def valid_name(name):
55                return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') )
56
57        @staticmethod
58        def new_target(target, arch):
59                test = Test()
60                test.name = os.path.basename(target)
61                test.path = os.path.relpath (os.path.dirname(target), settings.SRCDIR)
62                test.arch = arch.target if arch else ''
63                return test
64
65
66class TestResult:
67        SUCCESS = 0
68        FAILURE = 1
69        TIMEOUT = 124
70
71        @classmethod
72        def toString( cls, retcode, duration ):
73                if settings.generating :
74                        if   retcode == TestResult.SUCCESS:     key = 'pass'; text = "Done   "
75                        elif retcode == TestResult.TIMEOUT:     key = 'time'; text = "TIMEOUT"
76                        else :  key = 'fail';   text = "ERROR code %d" % retcode
77                else :
78                        if   retcode == TestResult.SUCCESS:     key = 'pass'; text = "PASSED "
79                        elif retcode == TestResult.TIMEOUT:     key = 'time'; text = "TIMEOUT"
80                        else :  key = 'fail';   text = "FAILED with code %d" % retcode
81
82                text += "    C%s - R%s" % (fmtDur(duration[0]), fmtDur(duration[1]))
83                return key, text
Note: See TracBrowser for help on using the repository browser.