| [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):
 | 
|---|
 | 15 |                 return "{:25s} ({:5s} {:s})".format( self.name, self.arch if self.arch else "Any", self.target() )
 | 
|---|
 | 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):
 | 
|---|
| [a95c117] | 22 |                 return os.path.normpath( os.path.join(settings.SRCDIR  , self.path, ".expect", "%s%s.txt" % (self.name,'' if not self.arch else ".%s" % self.arch)) )
 | 
|---|
| [0ad0c55] | 23 | 
 | 
|---|
| [bacc36c] | 24 |         def error_log(self):
 | 
|---|
| [a95c117] | 25 |                 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".err"   , "%s.log" % self.name) )
 | 
|---|
| [0ad0c55] | 26 | 
 | 
|---|
| [bacc36c] | 27 |         def output_log(self):
 | 
|---|
| [a95c117] | 28 |                 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".out"   , "%s.log" % self.name) )
 | 
|---|
| [0ad0c55] | 29 | 
 | 
|---|
| [bacc36c] | 30 |         def input(self):
 | 
|---|
| [a95c117] | 31 |                 return os.path.normpath( os.path.join(settings.SRCDIR  , self.path, ".in"    , "%s.txt" % self.name) )
 | 
|---|
| [0ad0c55] | 32 | 
 | 
|---|
| [bacc36c] | 33 |         def target_output(self):
 | 
|---|
 | 34 |                 return self.output_log() if not settings.generating else self.expect()
 | 
|---|
 | 35 | 
 | 
|---|
| [0ad0c55] | 36 |         def target(self):
 | 
|---|
| [a95c117] | 37 |                 return os.path.normpath( os.path.join(self.path, self.name) )
 | 
|---|
| [bacc36c] | 38 | 
 | 
|---|
| [f85bc15] | 39 |         def target_executable(self):
 | 
|---|
| [a95c117] | 40 |                 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, self.name) )
 | 
|---|
| [f85bc15] | 41 | 
 | 
|---|
| [64cf022] | 42 |         @staticmethod
 | 
|---|
 | 43 |         def valid_name(name):
 | 
|---|
| [bacc36c] | 44 |                 return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') )
 | 
|---|
 | 45 | 
 | 
|---|
| [64cf022] | 46 |         @staticmethod
 | 
|---|
 | 47 |         def new_target(target, arch):
 | 
|---|
| [bacc36c] | 48 |                 test = Test()
 | 
|---|
 | 49 |                 test.name = os.path.basename(target)
 | 
|---|
| [a95c117] | 50 |                 test.path = os.path.relpath (os.path.dirname(target), settings.SRCDIR)
 | 
|---|
| [41af19c] | 51 |                 test.arch = arch.target if arch else ''
 | 
|---|
| [bacc36c] | 52 |                 return test
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 | class TestResult:
 | 
|---|
 | 56 |         SUCCESS = 0
 | 
|---|
 | 57 |         FAILURE = 1
 | 
|---|
 | 58 |         TIMEOUT = 124
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 |         @classmethod
 | 
|---|
| [ca54499] | 61 |         def toString( cls, retcode, duration ):
 | 
|---|
| [bacc36c] | 62 |                 if settings.generating :
 | 
|---|
| [ca54499] | 63 |                         if   retcode == TestResult.SUCCESS:     text = "Done   "
 | 
|---|
 | 64 |                         elif retcode == TestResult.TIMEOUT:     text = "TIMEOUT"
 | 
|---|
 | 65 |                         else :                                          text = "ERROR code %d" % retcode
 | 
|---|
| [bacc36c] | 66 |                 else :
 | 
|---|
| [ca54499] | 67 |                         if   retcode == TestResult.SUCCESS:     text = "PASSED "
 | 
|---|
 | 68 |                         elif retcode == TestResult.TIMEOUT:     text = "TIMEOUT"
 | 
|---|
 | 69 |                         else :                                          text = "FAILED with code %d" % retcode
 | 
|---|
 | 70 | 
 | 
|---|
| [76de075] | 71 |                 text += "    C%s - R%s" % (fmtDur(duration[0]), fmtDur(duration[1]))
 | 
|---|
| [ca54499] | 72 |                 return text
 | 
|---|