Changeset cc9b520 for tests


Ignore:
Timestamp:
Mar 9, 2022, 7:59:46 PM (2 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

Location:
tests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/settings.py

    r5baa33c rcc9b520  
    192192        global distcc
    193193        distcc       = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash()
    194         errf = os.path.join(BUILDDIR, ".validate.err")
    195         make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
     194        make_ret, out, err = tools.make( ".validate", output_file=subprocess.PIPE, error=subprocess.PIPE )
    196195        if make_ret != 0:
    197                 with open (errf, "r") as myfile:
    198                         error=myfile.read()
    199196                print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr)
    200                 print("       verify returned : \n%s" % error, file=sys.stderr)
    201                 tools.rm(errf)
     197                print("       verify returned : \n%s" % err, file=sys.stderr)
    202198                sys.exit(1)
    203 
    204         tools.rm(errf)
    205199
    206200def prep_output(tests):
  • 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
  • tests/test.py

    r5baa33c rcc9b520  
    195195        # build, skipping to next test on error
    196196        with Timed() as comp_dur:
    197                 make_ret, _ = make( test.target(), output_file=subprocess.DEVNULL, error=out_file, error_file = err_file )
     197                make_ret, _, _ = make( test.target(), output_file=subprocess.DEVNULL, error=out_file, error_file = err_file )
    198198
    199199        # ----------
     
    208208                                if settings.dry_run or is_exe(exe_file):
    209209                                        # run test
    210                                         retcode, _ = sh(exe_file, output_file=out_file, input_file=in_file, timeout=True)
     210                                        retcode, _, _ = sh(exe_file, output_file=out_file, input_file=in_file, timeout=True)
    211211                                else :
    212212                                        # simply cat the result into the output
     
    226226                        else :
    227227                                # fetch return code and error from the diff command
    228                                 retcode, error = diff(cmp_file, out_file)
     228                                retcode, error, _ = diff(cmp_file, out_file)
    229229
    230230                else:
     
    235235                                error = "Output log can't be read, file is bigger than 1MB, see {} for actual error\n".format(out_file)
    236236
    237                         ret, info = core_info(exe_file)
    238                         error = error + info if error else info
     237                        ret, info, gdberr = core_info(exe_file)
     238                        if ret == 0:
     239                                error = error + info if error else info
     240                        else :
     241                                error = error + gdberr if error else gdberr
    239242
    240243                        if settings.archive:
     
    366369                        print(os.path.relpath(t.expect(), settings.SRCDIR), end=' ')
    367370                        print(os.path.relpath(t.input() , settings.SRCDIR), end=' ')
    368                         code, out = make_recon(t.target())
     371                        code, out, err = make_recon(t.target())
    369372
    370373                        if code != 0:
    371                                 print('ERROR: recond failed for test {}'.format(t.target()), file=sys.stderr)
     374                                print('ERROR: recond failed for test {}: {} \'{}\''.format(t.target(), code, err), file=sys.stderr)
    372375                                sys.exit(1)
    373376
Note: See TracChangeset for help on using the changeset viewer.