Changeset 1fcc2f3 for tests/pybin
- Timestamp:
- Nov 7, 2019, 2:49:24 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- f2d1335
- Parents:
- 396b830 (diff), d056d0d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
tests/pybin/tools.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/tools.py
r396b830 r1fcc2f3 24 24 # helper functions to run terminal commands 25 25 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False): 26 cmd = list(cmd) 27 28 if input_file and input_text: 29 return 401, "Cannot use both text and file inputs" 30 31 # if this is a dry_run, only print the commands that would be ran 32 if settings.dry_run and not ignore_dry_run: 33 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 34 if output_file and not isinstance(output_file, int): 35 cmd += " > " 36 cmd += output_file 37 38 if error and not isinstance(error, int): 39 cmd += " 2> " 40 cmd += error 41 42 if input_file and not isinstance(input_file, int) and os.path.isfile(input_file): 43 cmd += " < " 44 cmd += input_file 45 46 print(cmd) 47 return 0, None 48 49 with contextlib.ExitStack() as onexit: 50 # add input redirection if needed 51 input_file = openfd(input_file, 'r', onexit, True) 52 53 # add output redirection if needed 54 output_file = openfd(output_file, 'w', onexit, False) 55 56 # add error redirection if needed 57 error = openfd(error, 'w', onexit, False) 58 59 # run the desired command 60 try: 61 proc = subprocess.run( 26 try: 27 cmd = list(cmd) 28 29 if input_file and input_text: 30 return 401, "Cannot use both text and file inputs" 31 32 # if this is a dry_run, only print the commands that would be ran 33 if settings.dry_run and not ignore_dry_run: 34 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 35 if output_file and not isinstance(output_file, int): 36 cmd += " > " 37 cmd += output_file 38 39 if error and not isinstance(error, int): 40 cmd += " 2> " 41 cmd += error 42 43 if input_file and not isinstance(input_file, int) and os.path.isfile(input_file): 44 cmd += " < " 45 cmd += input_file 46 47 print(cmd) 48 return 0, None 49 50 with contextlib.ExitStack() as onexit: 51 # add input redirection if needed 52 input_file = openfd(input_file, 'r', onexit, True) 53 54 # add output redirection if needed 55 output_file = openfd(output_file, 'w', onexit, False) 56 57 # add error redirection if needed 58 error = openfd(error, 'w', onexit, False) 59 60 # run the desired command 61 # use with statement to make sure proc is cleaned 62 # don't use subprocess.run because we want to send SIGABRT on exit 63 with subprocess.Popen( 62 64 cmd, 63 65 **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}), 64 66 stdout = output_file, 65 stderr = error, 66 timeout = settings.timeout.single if timeout else None 67 ) 68 69 return proc.returncode, proc.stdout.decode("utf-8") if proc.stdout else None 70 except subprocess.TimeoutExpired: 71 return 124, str(None) 67 stderr = error 68 ) as proc: 69 70 try: 71 out, _ = proc.communicate( 72 timeout = settings.timeout.single if timeout else None 73 ) 74 75 return proc.returncode, out.decode("utf-8") if out else None 76 except subprocess.TimeoutExpired: 77 proc.send_signal(signal.SIGABRT) 78 proc.communicate() 79 return 124, str(None) 80 81 except Exception as ex: 82 print ("Unexpected error: %s" % ex) 83 raise 72 84 73 85 def is_ascii(fname): … … 343 355 # make a directory for this test 344 356 # mkdir makes the parent directory only so add a dummy 345 mkdir(os.path.join(dst, "dir"))357 mkdir(os.path.join(dst, name )) 346 358 347 359 # moves the files
Note:
See TracChangeset
for help on using the changeset viewer.