Ignore:
Timestamp:
Mar 9, 2022, 7:59:46 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
b053083
Parents:
5baa33c
Message:

Clean-up error handling in test scripts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/tools.py

    r5baa33c rcc9b520  
    7070
    7171                                try:
    72                                         out, _ = proc.communicate(
     72                                        out, errout = proc.communicate(
    7373                                                timeout = settings.timeout.single if timeout else None
    7474                                        )
    7575
    76                                         return proc.returncode, out.decode("latin-1") if out else None
     76                                        return proc.returncode, out.decode("latin-1") if out else None, errout.decode("latin-1") if errout else None
    7777                                except subprocess.TimeoutExpired:
    7878                                        if settings.timeout2gdb:
    7979                                                print("Process {} timeout".format(proc.pid))
    8080                                                proc.communicate()
    81                                                 return 124, str(None)
     81                                                return 124, str(None), "Subprocess Timeout 2 gdb"
    8282                                        else:
    8383                                                proc.send_signal(signal.SIGABRT)
    8484                                                proc.communicate()
    85                                                 return 124, str(None)
     85                                                return 124, str(None), "Subprocess Timeout 2 gdb"
    8686
    8787        except Exception as ex:
     
    106106                return (False, "No file")
    107107
    108         code, out = sh("file", fname, output_file=subprocess.PIPE)
     108        code, out, err = sh("file", fname, output_file=subprocess.PIPE)
    109109        if code != 0:
    110                 return (False, "'file EXPECT' failed with code {}".format(code))
     110                return (False, "'file EXPECT' failed with code {} '{}'".format(code, err))
    111111
    112112        match = re.search(".*: (.*)", out)
     
    242242# move a file
    243243def mv(source, dest):
    244         ret, _ = sh("mv", source, dest)
     244        ret, _, _ = sh("mv", source, dest)
    245245        return ret
    246246
    247247# cat one file into the other
    248248def cat(source, dest):
    249         ret, _ = sh("cat", source, output_file=dest)
     249        ret, _, _ = sh("cat", source, output_file=dest)
    250250        return ret
    251251
     
    291291################################################################################
    292292def jobserver_version():
    293         make_ret, out = sh('make', '.test_makeflags', '-j2', output_file=subprocess.PIPE)
     293        make_ret, out, err = sh('make', '.test_makeflags', '-j2', output_file=subprocess.PIPE, error=subprocess.PIPE)
    294294        if make_ret != 0:
    295                 with open (errf, "r") as myfile:
    296                         error=myfile.read()
    297295                print("ERROR: cannot find Makefile jobserver version", file=sys.stderr)
    298                 print("       test returned : \n%s" % out, file=sys.stderr)
     296                print("       test returned : {} '{}'".format(make_ret, err), file=sys.stderr)
    299297                sys.exit(1)
    300298
     
    302300        if not re_jobs:
    303301                print("ERROR: cannot find Makefile jobserver version", file=sys.stderr)
    304                 print("       MAKEFLAGS are : \n%s" % out, file=sys.stderr)
     302                print("       MAKEFLAGS are : '{}'".format(out), file=sys.stderr)
    305303                sys.exit(1)
    306304
     
    344342                # remote hardware is allowed
    345343                # how much do we have?
    346                 ret, jstr = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True)
     344                ret, jstr, _ = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True)
    347345                return int(jstr.strip()) if ret == 0 else multiprocessing.cpu_count()
    348346        else:
     
    445443        distcc_hash = os.path.join(settings.SRCDIR, '../tools/build/distcc_hash')
    446444        config = "%s-%s" % (settings.arch.target, settings.debug.path)
    447         _, out = sh(distcc_hash, config, output_file=subprocess.PIPE, ignore_dry_run=True)
     445        _, out, _ = sh(distcc_hash, config, output_file=subprocess.PIPE, ignore_dry_run=True)
    448446        return out.strip()
    449447
Note: See TracChangeset for help on using the changeset viewer.