Changes in tests/pybin/tools.py [d65f92c:143e6f3]
- File:
-
- 1 edited
-
tests/pybin/tools.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/tools.py
rd65f92c r143e6f3 2 2 import argparse 3 3 import contextlib 4 import datetime 4 5 import fileinput 5 6 import multiprocessing … … 22 23 23 24 # helper functions to run terminal commands 24 def sh(*cmd, timeout = False, output _file = None, input_file = None, input_text = None, error = subprocess.STDOUT):25 def sh(*cmd, timeout = False, output = None, input = None, error = subprocess.STDOUT): 25 26 cmd = list(cmd) 26 27 if input_file and input_text:28 return 401, "Cannot use both text and file inputs"29 27 30 28 # if this is a dry_run, only print the commands that would be ran 31 29 if settings.dry_run : 32 30 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 33 if output _file and not isinstance(output_file, int):31 if output and not isinstance(output, int): 34 32 cmd += " > " 35 cmd += output _file33 cmd += output 36 34 37 35 if error and not isinstance(error, int): … … 39 37 cmd += error 40 38 41 if input _file and not isinstance(input_file, int) and os.path.isfile(input_file):39 if input and not isinstance(input, int) and os.path.isfile(input): 42 40 cmd += " < " 43 cmd += input _file41 cmd += input 44 42 45 43 print(cmd) … … 48 46 with contextlib.ExitStack() as onexit: 49 47 # add input redirection if needed 50 input _file = openfd(input_file, 'r', onexit, True)48 input = openfd(input, 'r', onexit, True) 51 49 52 50 # add output redirection if needed 53 output _file = openfd(output_file, 'w', onexit, False)51 output = openfd(output, 'w', onexit, False) 54 52 55 53 # add error redirection if needed … … 60 58 proc = subprocess.run( 61 59 cmd, 62 **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}),63 stdout = output_file,64 stderr =error,65 timeout =settings.timeout.single if timeout else None60 stdin =input, 61 stdout=output, 62 stderr=error, 63 timeout=settings.timeout.single if timeout else None 66 64 ) 67 68 65 return proc.returncode, proc.stdout.decode("utf-8") if proc.stdout else None 69 66 except subprocess.TimeoutExpired: … … 78 75 return False 79 76 80 code, out = sh("file %s" % fname, output _file=subprocess.PIPE)77 code, out = sh("file %s" % fname, output=subprocess.PIPE) 81 78 if code != 0: 82 79 return False … … 110 107 if isinstance(files, str ): files = [ files ] 111 108 for file in files: 112 sh( 'rm', '-f', file, output _file=subprocess.DEVNULL, error=subprocess.DEVNULL )109 sh( 'rm', '-f', file, output=subprocess.DEVNULL, error=subprocess.DEVNULL ) 113 110 114 111 # Create 1 or more directory … … 118 115 p = os.path.normpath( file ) 119 116 d = os.path.dirname ( p ) 120 sh( 'mkdir', '-p', d, output _file=subprocess.DEVNULL, error=subprocess.DEVNULL )117 sh( 'mkdir', '-p', d, output=subprocess.DEVNULL, error=subprocess.DEVNULL ) 121 118 122 119 … … 141 138 lhs, 142 139 rhs, 143 output _file=subprocess.PIPE140 output=subprocess.PIPE 144 141 ) 145 142 146 143 # call make 147 def make(target, *, flags = '', output _file= None, error = None, error_file = None, silent = False):144 def make(target, *, flags = '', output = None, error = None, error_file = None, silent = False): 148 145 test_param = """test="%s" """ % (error_file) if error_file else None 149 146 cmd = [ … … 154 151 settings.debug.flags, 155 152 settings.install.flags, 156 settings.distcc if settings.distribute else None,157 153 flags, 158 154 target 159 155 ] 160 156 cmd = [s for s in cmd if s] 161 return sh(*cmd, output _file=output_file, error=error)157 return sh(*cmd, output=output, error=error) 162 158 163 159 def which(program): … … 205 201 # cat one file into the other 206 202 def cat(source, dest): 207 ret, _ = sh("cat", source, output _file=dest)203 ret, _ = sh("cat", source, output=dest) 208 204 return ret 209 205 … … 278 274 ################################################################################ 279 275 280 # get hash for given configuration 281 def config_hash(): 282 path = os.path.normpath(os.path.join( 283 settings.SRCDIR, 284 )) 285 286 distcc_hash = os.path.join(settings.SRCDIR, '../tools/build/distcc_hash') 287 config = "%s-%s" % (settings.arch.target, settings.debug.path) 288 _, out = sh(distcc_hash, config, output_file=subprocess.PIPE) 289 return out.strip() 276 def pretty_now(): 277 ts = time.time() 278 print(ts, file=sys.stderr) 279 return datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S') 290 280 291 281 # check if arguments is yes or no … … 318 308 return 1, "ERR No core dump" 319 309 320 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE) 310 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output=subprocess.PIPE) 311 312 def core_archive(dst, name, exe): 313 # Get the core dump 314 core = os.path.join(os.getcwd(), "core" ) 315 316 # update the path for this test 317 dst = os.path.join(dst, name) 318 319 # make a directory for this test 320 # mkdir makes the parent directory only so add a dummy 321 mkdir(os.path.join(dst, "dir")) 322 323 # moves the files 324 mv( core, os.path.join(dst, "core" ) ) 325 mv( exe , os.path.join(dst, name ) ) 326 327 # return explanatory test 328 return "Archiving %s (executable and core) to %s" % (os.path.relpath(exe, settings.BUILDDIR), os.path.relpath(dst, settings.original_path)) 321 329 322 330 class Timed:
Note:
See TracChangeset
for help on using the changeset viewer.