Changeset 1bb2488 for tests/pybin/tools.py
- Timestamp:
- Mar 26, 2019, 11:15:49 AM (6 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:
- 2b10f95, ae6b6cf
- Parents:
- 5bf1f3e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/tools.py
r5bf1f3e r1bb2488 8 8 import signal 9 9 import stat 10 import subprocess 10 11 import sys 11 12 import time … … 20 21 21 22 # helper functions to run terminal commands 22 def sh(cmd, print2stdout = True, input = None):23 def sh(cmd, print2stdout = True, timeout = False, output = None, input = None): 23 24 # add input redirection if needed 24 25 if input and os.path.isfile(input): 25 26 cmd += " < %s" % input 27 28 # add output redirection if needed 29 if output: 30 cmd += " > %s" % output 26 31 27 32 # if this is a dry_run, only print the commands that would be ran … … 32 37 # otherwise create a pipe and run the desired command 33 38 else : 34 proc = Popen(cmd, stdout=None if print2stdout else PIPE, stderr=STDOUT, shell=True) 35 out, err = proc.communicate() 36 return proc.returncode, out 39 proc = subprocess.run( 40 cmd, 41 stdout=None if print2stdout else PIPE, 42 stderr=STDOUT, 43 shell=True, 44 timeout=settings.timeout.single if timeout else None 45 ) 46 return proc.returncode, proc.stdout 37 47 38 48 def is_ascii(fname): … … 128 138 return None 129 139 130 def run(exe, output, input):131 ret, _ = sh("timeout %d %s > %s 2>&1" % (settings.timeout.single, exe, output), input = input)132 return ret133 134 140 ################################################################################ 135 141 # file handling … … 208 214 return min( options.jobs, len(tests) ), force 209 215 210 # setup a proper processor pool with correct signal handling211 def setup_pool(jobs):212 original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)213 pool = multiprocessing.Pool(jobs)214 signal.signal(signal.SIGINT, original_sigint_handler)215 216 return pool217 218 # handle signals in scope219 class SignalHandling():220 def __enter__(self):221 # enable signal handling222 signal.signal(signal.SIGINT, signal.SIG_DFL)223 224 def __exit__(self, type, value, traceback):225 # disable signal handling226 signal.signal(signal.SIGINT, signal.SIG_IGN)227 228 229 216 # enable core dumps for all the test children 230 217 resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) … … 245 232 column = which('column') 246 233 if column: 247 cmd = "%s 2> /dev/null" % column 248 proc = Popen(cmd, stdin=PIPE, stderr=None, shell=True) 249 proc.communicate(input=bytes(text + "\n", "UTF-8")) 234 subprocess.run(column, input=bytes(text + "\n", "UTF-8")) 250 235 else: 251 236 print(text)
Note: See TracChangeset
for help on using the changeset viewer.