source: tests/pybin/test_run.py@ a389ffe

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since a389ffe was 172a88d, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Tests now count failures, passes, timeouts and report the number

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[0ad0c55]1import os
2
3from pybin.tools import *
4
[bacc36c]5import pybin.settings
[0ad0c55]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 = ''
[a2f2fda]13 self.astv = ''
[0ad0c55]14
15 def toString(self):
[a2f2fda]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() )
[0ad0c55]17
[bacc36c]18 def prepare(self):
[a95c117]19 mkdir( (self.output_log(), self.error_log(), self.input() ) )
20 rm ( (self.output_log(), self.error_log(), self.target_executable()) )
[0ad0c55]21
[bacc36c]22 def expect(self):
[a2f2fda]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)) )
[0ad0c55]26
[bacc36c]27 def error_log(self):
[a95c117]28 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".err" , "%s.log" % self.name) )
[0ad0c55]29
[bacc36c]30 def output_log(self):
[a95c117]31 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, ".out" , "%s.log" % self.name) )
[0ad0c55]32
[bacc36c]33 def input(self):
[a95c117]34 return os.path.normpath( os.path.join(settings.SRCDIR , self.path, ".in" , "%s.txt" % self.name) )
[0ad0c55]35
[bacc36c]36 def target_output(self):
37 return self.output_log() if not settings.generating else self.expect()
38
[0ad0c55]39 def target(self):
[a95c117]40 return os.path.normpath( os.path.join(self.path, self.name) )
[bacc36c]41
[f85bc15]42 def target_executable(self):
[a95c117]43 return os.path.normpath( os.path.join(settings.BUILDDIR, self.path, self.name) )
[f85bc15]44
[64cf022]45 @staticmethod
46 def valid_name(name):
[bacc36c]47 return not name.endswith( ('.c', '.cc', '.cpp', '.cfa') )
48
[64cf022]49 @staticmethod
[a2f2fda]50 def new_target(target, arch, astv):
[bacc36c]51 test = Test()
52 test.name = os.path.basename(target)
[a95c117]53 test.path = os.path.relpath (os.path.dirname(target), settings.SRCDIR)
[41af19c]54 test.arch = arch.target if arch else ''
[a2f2fda]55 test.astv = astv.target if astv else ''
[bacc36c]56 return test
57
58
59class TestResult:
60 SUCCESS = 0
61 FAILURE = 1
62 TIMEOUT = 124
63
64 @classmethod
[ca54499]65 def toString( cls, retcode, duration ):
[bacc36c]66 if settings.generating :
[172a88d]67 if retcode == TestResult.SUCCESS: key = 'pass'; text = "Done "
68 elif retcode == TestResult.TIMEOUT: key = 'time'; text = "TIMEOUT"
69 else : key = 'fail'; text = "ERROR code %d" % retcode
[bacc36c]70 else :
[172a88d]71 if retcode == TestResult.SUCCESS: key = 'pass'; text = "PASSED "
72 elif retcode == TestResult.TIMEOUT: key = 'time'; text = "TIMEOUT"
73 else : key = 'fail'; text = "FAILED with code %d" % retcode
[ca54499]74
[76de075]75 text += " C%s - R%s" % (fmtDur(duration[0]), fmtDur(duration[1]))
[172a88d]76 return key, text
Note: See TracBrowser for help on using the repository browser.