Changeset bee653c for tests/pybin
- Timestamp:
- Mar 28, 2019, 6:35:21 PM (7 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:
- 2fabdc02, 9be2b60
- Parents:
- 8a25be9 (diff), b611fc3 (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) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/tools.py
r8a25be9 rbee653c 11 11 import subprocess 12 12 import sys 13 import tempfile 13 14 import time 14 15 import types 15 16 16 17 from pybin import settings 17 from subprocess import Popen, PIPE, STDOUT18 18 19 19 ################################################################################ … … 27 27 # if this is a dry_run, only print the commands that would be ran 28 28 if settings.dry_run : 29 print("cmd: %s" % ' '.join(cmd)) 29 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 30 if output and not isinstance(output, int): 31 cmd += " > " 32 cmd += output 33 34 if error and not isinstance(error, int): 35 cmd += " 2> " 36 cmd += error 37 38 if input and not isinstance(input, int) and os.path.isfile(input): 39 cmd += " < " 40 cmd += input 41 42 print(cmd) 30 43 return 0, None 31 44 32 45 with contextlib.ExitStack() as onexit: 33 46 # 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 47 input = openfd(input, 'r', onexit, True) 40 48 41 49 # 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) 50 output = openfd(output, 'w', onexit, False) 51 52 # add error redirection if needed 53 error = openfd(error, 'w', onexit, False) 45 54 46 55 # run the desired command … … 50 59 stdin =input, 51 60 stdout=output, 52 stderr= STDOUT,61 stderr=error, 53 62 timeout=settings.timeout.single if timeout else None 54 63 ) … … 78 87 def is_exe(fname): 79 88 return os.path.isfile(fname) and os.access(fname, os.X_OK) 89 90 def openfd(file, mode, exitstack, checkfile): 91 if not file: 92 return file 93 94 if isinstance(file, int): 95 return file 96 97 if checkfile and not os.path.isfile(file): 98 return None 99 100 file = open(file, mode) 101 exitstack.push(file) 102 return file 80 103 81 104 # Remove 1 or more files silently … … 146 169 return None 147 170 171 @contextlib.contextmanager 172 def tempdir(): 173 cwd = os.getcwd() 174 with tempfile.TemporaryDirectory() as temp: 175 os.chdir(temp) 176 try: 177 yield temp 178 finally: 179 os.chdir(cwd) 180 148 181 ################################################################################ 149 182 # file handling … … 246 279 247 280 def core_info(path): 281 if not os.path.isfile(path): 282 return 1, "ERR Executable path is wrong" 283 248 284 cmd = os.path.join(settings.SRCDIR, "pybin/print-core.gdb") 249 285 if not os.path.isfile(cmd): 250 286 return 1, "ERR Printing format for core dumps not found" 251 287 252 dname = os.path.dirname(path) 253 core = os.path.join(dname, "core" ) 254 if not os.path.isfile(path): 255 return 1, "ERR Executable path is wrong" 288 core = os.path.join(os.getcwd(), "core" ) 256 289 257 290 if not os.path.isfile(core):
Note:
See TracChangeset
for help on using the changeset viewer.