Changeset 1bb2488


Ignore:
Timestamp:
Mar 26, 2019, 11:15:49 AM (3 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
2b10f95, ae6b6cf
Parents:
5bf1f3e
Message:

No longer need to use popen and signal handling in test.py

Location:
tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/tools.py

    r5bf1f3e r1bb2488  
    88import signal
    99import stat
     10import subprocess
    1011import sys
    1112import time
     
    2021
    2122# helper functions to run terminal commands
    22 def sh(cmd, print2stdout = True, input = None):
     23def sh(cmd, print2stdout = True, timeout = False, output = None, input = None):
    2324        # add input redirection if needed
    2425        if input and os.path.isfile(input):
    2526                cmd += " < %s" % input
     27
     28        # add output redirection if needed
     29        if output:
     30                cmd += " > %s" % output
    2631
    2732        # if this is a dry_run, only print the commands that would be ran
     
    3237        # otherwise create a pipe and run the desired command
    3338        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
    3747
    3848def is_ascii(fname):
     
    128138    return None
    129139
    130 def run(exe, output, input):
    131         ret, _ = sh("timeout %d %s > %s 2>&1" % (settings.timeout.single, exe, output), input = input)
    132         return ret
    133 
    134140################################################################################
    135141#               file handling
     
    208214        return min( options.jobs, len(tests) ), force
    209215
    210 # setup a proper processor pool with correct signal handling
    211 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 pool
    217 
    218 # handle signals in scope
    219 class SignalHandling():
    220         def __enter__(self):
    221                 # enable signal handling
    222                 signal.signal(signal.SIGINT, signal.SIG_DFL)
    223 
    224         def __exit__(self, type, value, traceback):
    225                 # disable signal handling
    226                 signal.signal(signal.SIGINT, signal.SIG_IGN)
    227 
    228 
    229216# enable core dumps for all the test children
    230217resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
     
    245232        column = which('column')
    246233        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"))
    250235        else:
    251236                print(text)
  • tests/test.py

    r5bf1f3e r1bb2488  
    149149                        if settings.dry_run or is_exe(exe_file):
    150150                                # run test
    151                                 retcode = run(exe_file, out_file, in_file)
     151                                retcode, _ = sh(exe_file, output=out_file, input=in_file, timeout=True)
    152152                        else :
    153153                                # simply cat the result into the output
     
    185185# run a single test and handle the errors, outputs, printing, exception handling, etc.
    186186def run_test_worker(t) :
    187         with SignalHandling():
     187        try :
    188188                # print formated name
    189189                name_txt = '{0:{width}}  '.format(t.target(), width=settings.output_width)
     
    205205                sys.stderr.flush()
    206206
    207         return retcode != TestResult.SUCCESS
     207                return retcode != TestResult.SUCCESS
     208        except KeyboardInterrupt:
     209                False
    208210
    209211# run the given list of tests with the given parameters
     
    213215
    214216        # create the executor for our jobs and handle the signal properly
    215         pool = setup_pool(jobs)
     217        pool = multiprocessing.Pool(jobs)
    216218
    217219        # for each test to run
Note: See TracChangeset for help on using the changeset viewer.