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