- Timestamp:
- Mar 27, 2019, 2:44:34 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 1241851, ce3d305
- Parents:
- 86fb8f2
- Location:
- tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/settings.py
r86fb8f2 ra45fc7b 1 1 import os 2 import subprocess 2 3 import sys 3 4 from . import tools … … 82 83 def __init__(self, value): 83 84 self.string = "debug" if value else "no debug" 84 self.flags = """DEBUG_FLAGS= "%s"""" % ("-debug -O0" if value else "-nodebug -O2")85 self.flags = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2") 85 86 86 87 class Install: 87 88 def __init__(self, value): 88 89 self.string = "installed" if value else "in-tree" 89 self.flags = """INSTALL_FLAGS= "%s"""" % ("" if value else "-in-tree")90 self.flags = """INSTALL_FLAGS=%s""" % ("" if value else "-in-tree") 90 91 91 92 class Timeouts: … … 114 115 dry_run = options.dry_run 115 116 generating = options.regenerate_expected 116 make = 'make'117 make = ['make'] 117 118 debug = Debug(options.debug) 118 119 install = Install(options.install) … … 125 126 global make 126 127 127 make = "make" if not force else ("make -j%i" % jobs)128 make = ['make'] if not force else ['make', "-j%i" % jobs] 128 129 129 130 def validate(): 130 131 errf = os.path.join(BUILDDIR, ".validate.err") 131 make_ret, _ = tools.make( ".validate", error_file = errf, redirects = "2> /dev/null 1> /dev/null",)132 make_ret, out = tools.make( ".validate", error_file = errf, output=subprocess.DEVNULL, error=subprocess.DEVNULL ) 132 133 if make_ret != 0: 133 134 with open (errf, "r") as myfile: -
tests/pybin/tools.py
r86fb8f2 ra45fc7b 1 1 import __main__ 2 2 import argparse 3 import contextlib 3 4 import fileinput 4 5 import multiprocessing … … 21 22 22 23 # helper functions to run terminal commands 23 def sh(cmd, print2stdout = True, timeout = False, output = None, input = None): 24 # add input redirection if needed 25 if input and os.path.isfile(input): 26 cmd += " < %s" % input 27 28 # add output redirection if needed 29 if output: 30 cmd += " > %s" % output 24 def sh(*cmd, timeout = False, output = None, input = None, error = subprocess.STDOUT): 25 cmd = list(cmd) 31 26 32 27 # if this is a dry_run, only print the commands that would be ran 33 28 if settings.dry_run : 34 print("cmd: %s" % cmd)29 print("cmd: %s" % ' '.join(cmd)) 35 30 return 0, None 36 31 37 # otherwise create a pipe and run the desired command 38 else : 32 with contextlib.ExitStack() as onexit: 33 # add input redirection if needed 34 if input and input != subprocess.DEVNULL: 35 if os.path.isfile(input): 36 input = open(input) 37 onexit.push(input) 38 else: 39 input = None 40 41 # add output redirection if needed 42 if output and output != subprocess.DEVNULL and output != subprocess.PIPE: 43 output = open(output, 'w') 44 onexit.push(output) 45 46 # run the desired command 39 47 try: 40 48 proc = subprocess.run( 41 49 cmd, 42 stdout=None if print2stdout else PIPE, 50 stdin =input, 51 stdout=output, 43 52 stderr=STDOUT, 44 shell=True,45 53 timeout=settings.timeout.single if timeout else None 46 54 ) … … 57 65 return False 58 66 59 code, out = sh("file %s" % fname, print2stdout = False)67 code, out = sh("file %s" % fname, output=subprocess.PIPE) 60 68 if code != 0: 61 69 return False … … 75 83 if isinstance(files, str ): files = [ files ] 76 84 for file in files: 77 sh( "rm -f %s > /dev/null 2>&1" % file)85 sh( 'rm', '-f', file, output=subprocess.DEVNULL, error=subprocess.DEVNULL ) 78 86 79 87 # Create 1 or more directory … … 83 91 p = os.path.normpath( file ) 84 92 d = os.path.dirname ( p ) 85 sh( "mkdir -p {}".format(d))93 sh( 'mkdir', '-p', d, output=subprocess.DEVNULL, error=subprocess.DEVNULL ) 86 94 87 95 … … 93 101 # diff two files 94 102 def diff( lhs, rhs ): 95 # diff the output of the files96 diff_cmd = ("diff --text "97 "--old-group-format='\t\tmissing lines :\n"98 "%%<' \\\n"99 "--new-group-format='\t\tnew lines :\n"100 "%%>' \\\n"101 "--unchanged-group-format='%%=' \\"102 "--changed-group-format='\t\texpected :\n"103 "%%<"104 "\t\tgot :\n"105 "%%>\n' \\\n"106 "--new-line-format='\t\t%%dn\t%%L' \\\n"107 "--old-line-format='\t\t%%dn\t%%L' \\\n"108 "--unchanged-line-format='' \\\n"109 "%s %s")110 111 103 # fetch return code and error from the diff command 112 return sh(diff_cmd % (lhs, rhs), False) 104 return sh( 105 '''diff''', 106 '''--text''', 107 '''--old-group-format=\t\tmissing lines :\n%<''', 108 '''--new-line-format=\t\t%dn\t%L''', 109 '''--new-group-format=\t\tnew lines : \n%>''', 110 '''--old-line-format=\t\t%dn\t%L''', 111 '''--unchanged-group-format=%=''', 112 '''--changed-group-format=\t\texpected :\n%<\t\tgot :\n%>''', 113 '''--unchanged-line-format=''', 114 lhs, 115 rhs, 116 output=subprocess.PIPE 117 ) 113 118 114 119 # call make 115 def make(target, flags = '', redirects = '', error_file = None, silent = False):116 test_param = """test="%s" """ % (error_file) if error_file else ''117 cmd = ' '.join([118 settings.make,119 '-s' if silent else '',120 def make(target, *, flags = '', output = None, error = None, error_file = None, silent = False): 121 test_param = """test="%s" """ % (error_file) if error_file else None 122 cmd = [ 123 *settings.make, 124 '-s' if silent else None, 120 125 test_param, 121 126 settings.arch.flags, … … 123 128 settings.install.flags, 124 129 flags, 125 target ,126 redirects127 ])128 return sh( cmd)130 target 131 ] 132 cmd = [s for s in cmd if s] 133 return sh(*cmd, output=output, error=error) 129 134 130 135 def which(program): … … 146 151 # move a file 147 152 def mv(source, dest): 148 ret, _ = sh("mv %s %s" % (source, dest))153 ret, _ = sh("mv", source, dest) 149 154 return ret 150 155 151 156 # cat one file into the other 152 157 def cat(source, dest): 153 ret, _ = sh("cat %s > %s" % (source, dest))158 ret, _ = sh("cat", source, output=dest) 154 159 return ret 155 160 … … 253 258 return 1, "ERR No core dump" 254 259 255 return sh( "gdb -n %s %s -batch -x %s" % (path, core, cmd), print2stdout=False)260 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output=subprocess.PIPE) 256 261 257 262 class Timed: -
tests/test.py
r86fb8f2 ra45fc7b 141 141 # build, skipping to next test on error 142 142 with Timed() as comp_dur: 143 make_ret, _ = make( test.target(), redirects = ("2> %s 1> /dev/null" % out_file), error_file = err_file )143 make_ret, _ = make( test.target(), output=subprocess.DEVNULL, error=out_file, error_file = err_file ) 144 144 145 145 # if the make command succeds continue otherwise skip to diff … … 195 195 196 196 #print result with error if needed 197 text = name_txt + result_txt197 text = '\t' + name_txt + result_txt 198 198 out = sys.stdout 199 199 if error : … … 212 212 def run_tests(tests, jobs) : 213 213 # clean the sandbox from previous commands 214 make('clean', redirects = '> /dev/null 2>&1')214 make('clean', output=subprocess.DEVNULL, error=subprocess.DEVNULL) 215 215 216 216 # create the executor for our jobs and handle the signal properly … … 230 230 231 231 # clean the workspace 232 make('clean', redirects = '> /dev/null 2>&1')232 make('clean', output=subprocess.DEVNULL, error=subprocess.DEVNULL) 233 233 234 234 for failed in results:
Note: See TracChangeset
for help on using the changeset viewer.