Changes in tests/pybin/tools.py [143e6f3:34e1494]
- File:
-
- 1 edited
-
tests/pybin/tools.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/tools.py
r143e6f3 r34e1494 23 23 24 24 # helper functions to run terminal commands 25 def sh(*cmd, timeout = False, output = None, input = None, error = subprocess.STDOUT):25 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False): 26 26 cmd = list(cmd) 27 27 28 if input_file and input_text: 29 return 401, "Cannot use both text and file inputs" 30 28 31 # if this is a dry_run, only print the commands that would be ran 29 if settings.dry_run :32 if settings.dry_run and not ignore_dry_run: 30 33 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 31 if output and not isinstance(output, int):34 if output_file and not isinstance(output_file, int): 32 35 cmd += " > " 33 cmd += output 36 cmd += output_file 34 37 35 38 if error and not isinstance(error, int): … … 37 40 cmd += error 38 41 39 if input and not isinstance(input, int) and os.path.isfile(input):42 if input_file and not isinstance(input_file, int) and os.path.isfile(input_file): 40 43 cmd += " < " 41 cmd += input 44 cmd += input_file 42 45 43 46 print(cmd) … … 46 49 with contextlib.ExitStack() as onexit: 47 50 # add input redirection if needed 48 input = openfd(input, 'r', onexit, True)51 input_file = openfd(input_file, 'r', onexit, True) 49 52 50 53 # add output redirection if needed 51 output = openfd(output, 'w', onexit, False)54 output_file = openfd(output_file, 'w', onexit, False) 52 55 53 56 # add error redirection if needed … … 58 61 proc = subprocess.run( 59 62 cmd, 60 stdin =input,61 stdout =output,62 stderr =error,63 timeout =settings.timeout.single if timeout else None63 **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}), 64 stdout = output_file, 65 stderr = error, 66 timeout = settings.timeout.single if timeout else None 64 67 ) 68 65 69 return proc.returncode, proc.stdout.decode("utf-8") if proc.stdout else None 66 70 except subprocess.TimeoutExpired: … … 75 79 return False 76 80 77 code, out = sh("file %s" % fname, output =subprocess.PIPE)81 code, out = sh("file %s" % fname, output_file=subprocess.PIPE) 78 82 if code != 0: 79 83 return False … … 107 111 if isinstance(files, str ): files = [ files ] 108 112 for file in files: 109 sh( 'rm', '-f', file, output =subprocess.DEVNULL, error=subprocess.DEVNULL )113 sh( 'rm', '-f', file, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) 110 114 111 115 # Create 1 or more directory … … 115 119 p = os.path.normpath( file ) 116 120 d = os.path.dirname ( p ) 117 sh( 'mkdir', '-p', d, output =subprocess.DEVNULL, error=subprocess.DEVNULL )121 sh( 'mkdir', '-p', d, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) 118 122 119 123 … … 138 142 lhs, 139 143 rhs, 140 output =subprocess.PIPE144 output_file=subprocess.PIPE 141 145 ) 142 146 143 147 # call make 144 def make(target, *, flags = '', output = None, error = None, error_file = None, silent = False):148 def make(target, *, flags = '', output_file = None, error = None, error_file = None, silent = False): 145 149 test_param = """test="%s" """ % (error_file) if error_file else None 146 150 cmd = [ … … 151 155 settings.debug.flags, 152 156 settings.install.flags, 157 settings.distcc if settings.distribute else None, 153 158 flags, 154 159 target 155 160 ] 156 161 cmd = [s for s in cmd if s] 157 return sh(*cmd, output =output, error=error)162 return sh(*cmd, output_file=output_file, error=error) 158 163 159 164 def which(program): … … 201 206 # cat one file into the other 202 207 def cat(source, dest): 203 ret, _ = sh("cat", source, output =dest)208 ret, _ = sh("cat", source, output_file=dest) 204 209 return ret 205 210 … … 256 261 os.write(int(make_jobs_fds.group(3)), tokens) 257 262 else : 258 options.jobs = multiprocessing.cpu_count() 263 if settings.distribute: 264 ret, jstr = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True) 265 if ret == 0: 266 options.jobs = int(jstr.strip()) 267 else : 268 options.jobs = multiprocessing.cpu_count() 269 else: 270 options.jobs = multiprocessing.cpu_count() 259 271 else : 260 272 force = True … … 274 286 ################################################################################ 275 287 288 # get hash for given configuration 289 def config_hash(): 290 path = os.path.normpath(os.path.join( 291 settings.SRCDIR, 292 )) 293 294 distcc_hash = os.path.join(settings.SRCDIR, '../tools/build/distcc_hash') 295 config = "%s-%s" % (settings.arch.target, settings.debug.path) 296 _, out = sh(distcc_hash, config, output_file=subprocess.PIPE, ignore_dry_run=True) 297 return out.strip() 298 299 # get pretty string for time of day 276 300 def pretty_now(): 277 301 ts = time.time() … … 308 332 return 1, "ERR No core dump" 309 333 310 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output =subprocess.PIPE)334 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE) 311 335 312 336 def core_archive(dst, name, exe):
Note:
See TracChangeset
for help on using the changeset viewer.