| [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 | 
 | 
|---|
| [bacc36c] | 31 |         def input(self):
 | 
|---|
| [a95c117] | 32 |                 return os.path.normpath( os.path.join(settings.SRCDIR  , self.path, ".in"    , "%s.txt" % self.name) )
 | 
|---|
| [0ad0c55] | 33 | 
 | 
|---|
| [bacc36c] | 34 |         def target_output(self):
 | 
|---|
 | 35 |                 return self.output_log() if not settings.generating else self.expect()
 | 
|---|
 | 36 | 
 | 
|---|
| [0ad0c55] | 37 |         def target(self):
 | 
|---|
| [a95c117] | 38 |                 return os.path.normpath( os.path.join(self.path, self.name) )
 | 
|---|
| [bacc36c] | 39 | 
 | 
|---|
| [f85bc15] | 40 |         def target_executable(self):
 | 
|---|
| [a95c117] | 41 |                 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, self.name) )
 | 
|---|
| [f85bc15] | 42 | 
 | 
|---|
| [767a8ef] | 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 | 
 | 
|---|
| [64cf022] | 53 |         @staticmethod
 | 
|---|
 | 54 |         def valid_name(name):
 | 
|---|
| [bacc36c] | 55 |                 return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') )
 | 
|---|
 | 56 | 
 | 
|---|
| [64cf022] | 57 |         @staticmethod
 | 
|---|
| [0fc91db1] | 58 |         def new_target(target, arch):
 | 
|---|
| [bacc36c] | 59 |                 test = Test()
 | 
|---|
 | 60 |                 test.name = os.path.basename(target)
 | 
|---|
| [a95c117] | 61 |                 test.path = os.path.relpath (os.path.dirname(target), settings.SRCDIR)
 | 
|---|
| [41af19c] | 62 |                 test.arch = arch.target if arch else ''
 | 
|---|
| [bacc36c] | 63 |                 return test
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | class TestResult:
 | 
|---|
 | 67 |         SUCCESS = 0
 | 
|---|
 | 68 |         FAILURE = 1
 | 
|---|
 | 69 |         TIMEOUT = 124
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 |         @classmethod
 | 
|---|
| [ca54499] | 72 |         def toString( cls, retcode, duration ):
 | 
|---|
| [bacc36c] | 73 |                 if settings.generating :
 | 
|---|
| [172a88d] | 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
 | 
|---|
| [bacc36c] | 77 |                 else :
 | 
|---|
| [172a88d] | 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
 | 
|---|
| [ca54499] | 81 | 
 | 
|---|
| [76de075] | 82 |                 text += "    C%s - R%s" % (fmtDur(duration[0]), fmtDur(duration[1]))
 | 
|---|
| [172a88d] | 83 |                 return key, text
 | 
|---|