Changeset f806b61 for tests/pybin/tools.py
- Timestamp:
- Mar 28, 2019, 5:19:52 PM (4 years ago)
- Branches:
- arm-eh, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b611fc3
- Parents:
- ea62265
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/tools.py
rea62265 rf806b61 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 cmd = " cmd: {}".format(' '.join(cmd))30 if output and output != subprocess.DEVNULL and output != subprocess.PIPE:29 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 30 if output and not isinstance(output, int): 31 31 cmd += " > " 32 32 cmd += output 33 33 34 if error and error != subprocess.DEVNULL and error != subprocess.PIPE and error != subprocess.STDOUT:34 if error and not isinstance(error, int): 35 35 cmd += " 2> " 36 36 cmd += error 37 37 38 if input and input != subprocess.DEVNULLand os.path.isfile(input):38 if input and not isinstance(input, int) and os.path.isfile(input): 39 39 cmd += " < " 40 40 cmd += input … … 45 45 with contextlib.ExitStack() as onexit: 46 46 # add input redirection if needed 47 if input and input != subprocess.DEVNULL: 48 if os.path.isfile(input): 49 input = open(input) 50 onexit.push(input) 51 else: 52 input = None 47 input = openfd(input, 'r', onexit, True) 53 48 54 49 # add output redirection if needed 55 if output and output != subprocess.DEVNULL and output != subprocess.PIPE: 56 output = open(output, 'w') 57 onexit.push(output) 50 output = openfd(output, 'w', onexit, False) 51 52 # add error redirection if needed 53 error = openfd(error, 'w', onexit, False) 58 54 59 55 # run the desired command … … 63 59 stdin =input, 64 60 stdout=output, 65 stderr= STDOUT,61 stderr=error, 66 62 timeout=settings.timeout.single if timeout else None 67 63 ) … … 91 87 def is_exe(fname): 92 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 93 103 94 104 # Remove 1 or more files silently … … 159 169 return None 160 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 161 181 ################################################################################ 162 182 # file handling … … 259 279 260 280 def core_info(path): 281 if not os.path.isfile(path): 282 return 1, "ERR Executable path is wrong" 283 261 284 cmd = os.path.join(settings.SRCDIR, "pybin/print-core.gdb") 262 285 if not os.path.isfile(cmd): 263 286 return 1, "ERR Printing format for core dumps not found" 264 287 265 dname = os.path.dirname(path) 266 core = os.path.join(dname, "core" ) 267 if not os.path.isfile(path): 268 return 1, "ERR Executable path is wrong" 288 core = os.path.join(os.getcwd(), "core" ) 269 289 270 290 if not os.path.isfile(core):
Note: See TracChangeset
for help on using the changeset viewer.