Changeset ae151cf for tests


Ignore:
Timestamp:
Oct 2, 2022, 10:00:43 PM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
815943f
Parents:
f704974 (diff), f92e7b9 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
tests
Files:
2 added
2 edited
5 moved

Legend:

Unmodified
Added
Removed
  • tests/pybin/tools.py

    rf704974 rae151cf  
    2323
    2424# helper functions to run terminal commands
    25 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False, pass_fds = []):
     25def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False, pass_fds = [], nice = False):
    2626        try:
    2727                cmd = list(cmd)
     
    5858                        error = openfd(error, 'w', onexit, False)
    5959
     60                        # prepare the parameters to the call
     61                        popen_kwargs = {
     62                                'stdout' : output_file,
     63                                'stderr' : error,
     64                                'pass_fds': pass_fds,
     65                        }
     66
     67                        # depending on how we are passing inputs we need to set a different argument to popen
     68                        if input_text:
     69                                popen_kwargs['input'] = bytes(input_text, encoding='utf-8')
     70                        else:
     71                                popen_kwargs['stdin'] = input_file
     72
     73                        # we might want to nice this so it's not to obnixious to users
     74                        if nice:
     75                                popen_kwargs['preexec_fn'] = lambda: os.nice(5)
     76
    6077                        # run the desired command
    6178                        # use with statement to make sure proc is cleaned
    6279                        # don't use subprocess.run because we want to send SIGABRT on exit
    63                         with subprocess.Popen(
    64                                 cmd,
    65                                 **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}),
    66                                 stdout  = output_file,
    67                                 stderr  = error,
    68                                 pass_fds = pass_fds
    69                         ) as proc:
    70 
     80                        with subprocess.Popen( cmd, **popen_kwargs ) as proc:
    7181                                try:
    7282                                        out, errout = proc.communicate(
  • tests/test.py

    rf704974 rae151cf  
    2323
    2424        def match_test(path):
    25                 match = re.search("^%s\/([\w\/\-_]*).expect\/([\w\-_]+)(\.[\w\-_]+)?\.txt$" % settings.SRCDIR, path)
     25                match = re.search("^%s\/([\w\/\-_]*).expect\/([\w\-_\+]+)(\.[\w\-_]+)?\.txt$" % settings.SRCDIR, path)
    2626                if match :
    2727                        test = Test()
     
    190190                                if settings.dry_run or is_exe(exe_file):
    191191                                        # run test
    192                                         retcode, _, _ = sh(exe_file, output_file=out_file, input_file=in_file, timeout=True)
     192                                        retcode, _, _ = sh(exe_file, output_file=out_file, input_file=in_file, timeout=True, nice=True)
    193193                                else :
    194194                                        # simply cat the result into the output
Note: See TracChangeset for help on using the changeset viewer.