Changeset 4a60488 for tests/pybin


Ignore:
Timestamp:
Sep 27, 2019, 3:35:46 PM (6 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
90ce35aa
Parents:
8e1467d (diff), 849720f (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:

Merged from master taking the lvalue changes to expression and everything before that.

Location:
tests/pybin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/settings.py

    r8e1467d r4a60488  
    44from . import tools
    55
     6global original_path
     7
    68try :
     9        original_path = os.getcwd()
    710        testpath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0])))
    811        sys.path.append(testpath)
     
    1114        SRCDIR = os.path.abspath(config.SRCDIR)
    1215        BUILDDIR = os.path.abspath(config.BUILDDIR)
     16        distribute = config.DISTRIBUTE
    1317        os.chdir(testpath)
    1418
     
    1923class Architecture:
    2024        KnownArchitectures = {
    21                 'x64'                   : 'x64',
    22                 'x86-64'                : 'x64',
    23                 'x86_64'                : 'x64',
    24                 'x86'                   : 'x86',
     25                'x64'           : 'x64',
     26                'x86-64'        : 'x64',
     27                'x86_64'        : 'x64',
     28                'x86'           : 'x86',
     29                'aarch64'       : 'arm',
    2530                'i386'          : 'x86',
    2631                'i486'          : 'x86',
    2732                'i686'          : 'x86',
    2833                'Intel 80386'   : 'x86',
    29                 'arm'                   : 'arm',
    30                 'ARM'                   : 'arm',
     34                'arm'           : 'arm',
     35                'ARM'           : 'arm',
    3136        }
    3237
     
    4045                        canonical_host = Architecture.make_canonical( config.HOSTARCH )
    4146                except KeyError:
    42                         print("Unkown host architecture %s" % config.HOSTARCH, file=sys.stderr)
     47                        print("Unknown host architecture %s" % config.HOSTARCH, file=sys.stderr)
    4348                        sys.exit(1)
    4449
     
    4752                                arch = Architecture.make_canonical( arch )
    4853                        except KeyError:
    49                                 print("Unkown architecture %s" % arch, file=sys.stderr)
     54                                print("Unknown architecture %s" % arch, file=sys.stderr)
    5055                                sys.exit(1)
    5156
     
    8489                self.string = "debug" if value else "no debug"
    8590                self.flags  = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2")
     91                self.path   = "debug" if value else "nodebug"
    8692
    8793class Install:
    8894        def __init__(self, value):
    89                 self.string = "installed" if value else "in-tree"
    90                 self.flags  = """INSTALL_FLAGS=%s""" % ("" if value else "-in-tree")
     95                if value:
     96                        distribute = False
     97
     98                self.string = "installed" if value else "in tree"
     99                self.flags  = """installed=%s""" % ("yes" if value else "no")
    91100
    92101class Timeouts:
     
    105114def init( options ):
    106115        global arch
     116        global archive
     117        global debug
     118        global distcc
    107119        global dry_run
    108120        global generating
     121        global install
    109122        global make
    110         global debug
    111         global install
     123        global output_width
    112124        global timeout
    113         global output_width
    114125
    115         dry_run      = options.dry_run
     126        arch         = Architecture(options.arch)
     127        archive      = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
     128        debug        = Debug(options.debug)
     129        dry_run      = options.dry_run # must be called before tools.config_hash()
     130        distcc       = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash()
    116131        generating   = options.regenerate_expected
     132        install      = Install(options.install)
    117133        make         = ['make']
    118         debug        = Debug(options.debug)
    119         install      = Install(options.install)
    120         arch         = Architecture(options.arch)
     134        output_width = 24
    121135        timeout      = Timeouts(options.timeout, options.global_timeout)
    122         output_width = 24
    123136
     137        # if we distribute, distcc errors will fail tests, use log file for distcc
     138        # don't use "'DISTCC_LOG' not in os.environ" because it can be set to ''
     139        if distribute and not os.environ.get('DISTCC_LOG'):
     140                os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log'))
    124141
    125142def update_make_cmd(force, jobs):
     
    130147def validate():
    131148        errf = os.path.join(BUILDDIR, ".validate.err")
    132         make_ret, out = tools.make( ".validate", error_file = errf, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
     149        make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
    133150        if make_ret != 0:
    134151                with open (errf, "r") as myfile:
  • tests/pybin/tools.py

    r8e1467d r4a60488  
    22import argparse
    33import contextlib
     4import datetime
    45import fileinput
    56import multiprocessing
     
    2223
    2324# helper functions to run terminal commands
    24 def sh(*cmd, timeout = False, output = None, input = None, error = subprocess.STDOUT):
     25def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False):
    2526        cmd = list(cmd)
    2627
     28        if input_file and input_text:
     29                return 401, "Cannot use both text and file inputs"
     30
    2731        # if this is a dry_run, only print the commands that would be ran
    28         if settings.dry_run :
     32        if settings.dry_run and not ignore_dry_run:
    2933                cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd))
    30                 if output and not isinstance(output, int):
     34                if output_file and not isinstance(output_file, int):
    3135                        cmd += " > "
    32                         cmd += output
     36                        cmd += output_file
    3337
    3438                if error and not isinstance(error, int):
     
    3640                        cmd += error
    3741
    38                 if input and not isinstance(input, int) and os.path.isfile(input):
     42                if input_file and not isinstance(input_file, int) and os.path.isfile(input_file):
    3943                        cmd += " < "
    40                         cmd += input
     44                        cmd += input_file
    4145
    4246                print(cmd)
     
    4549        with contextlib.ExitStack() as onexit:
    4650                # add input redirection if needed
    47                 input = openfd(input, 'r', onexit, True)
     51                input_file = openfd(input_file, 'r', onexit, True)
    4852
    4953                # add output redirection if needed
    50                 output = openfd(output, 'w', onexit, False)
     54                output_file = openfd(output_file, 'w', onexit, False)
    5155
    5256                # add error redirection if needed
     
    5761                        proc = subprocess.run(
    5862                                cmd,
    59                                 stdin =input,
    60                                 stdout=output,
    61                                 stderr=error,
    62                                 timeout=settings.timeout.single if timeout else None
     63                                **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}),
     64                                stdout  = output_file,
     65                                stderr  = error,
     66                                timeout = settings.timeout.single if timeout else None
    6367                        )
     68
    6469                        return proc.returncode, proc.stdout.decode("utf-8") if proc.stdout else None
    6570                except subprocess.TimeoutExpired:
     
    7479                return False
    7580
    76         code, out = sh("file %s" % fname, output=subprocess.PIPE)
     81        code, out = sh("file %s" % fname, output_file=subprocess.PIPE)
    7782        if code != 0:
    7883                return False
     
    106111        if isinstance(files, str ): files = [ files ]
    107112        for file in files:
    108                 sh( 'rm', '-f', file, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
     113                sh( 'rm', '-f', file, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
    109114
    110115# Create 1 or more directory
     
    114119                p = os.path.normpath( file )
    115120                d = os.path.dirname ( p )
    116                 sh( 'mkdir', '-p', d, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
     121                sh( 'mkdir', '-p', d, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
    117122
    118123
     
    137142                lhs,
    138143                rhs,
    139                 output=subprocess.PIPE
     144                output_file=subprocess.PIPE
    140145        )
    141146
    142147# call make
    143 def make(target, *, flags = '', output = None, error = None, error_file = None, silent = False):
     148def make(target, *, flags = '', output_file = None, error = None, error_file = None, silent = False):
    144149        test_param = """test="%s" """ % (error_file) if error_file else None
    145150        cmd = [
     
    150155                settings.debug.flags,
    151156                settings.install.flags,
     157                settings.distcc if settings.distribute else None,
    152158                flags,
    153159                target
    154160        ]
    155161        cmd = [s for s in cmd if s]
    156         return sh(*cmd, output=output, error=error)
     162        return sh(*cmd, output_file=output_file, error=error)
    157163
    158164def which(program):
     
    200206# cat one file into the other
    201207def cat(source, dest):
    202         ret, _ = sh("cat", source, output=dest)
     208        ret, _ = sh("cat", source, output_file=dest)
    203209        return ret
    204210
     
    255261                        os.write(int(make_jobs_fds.group(3)), tokens)
    256262                else :
    257                         options.jobs = multiprocessing.cpu_count()
     263                        if settings.distribute:
     264                                ret, jstr = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True)
     265                                if ret == 0:
     266                                        options.jobs = int(jstr.strip())
     267                                else :
     268                                        options.jobs = multiprocessing.cpu_count()
     269                        else:
     270                                options.jobs = multiprocessing.cpu_count()
    258271        else :
    259272                force = True
     
    272285#               misc
    273286################################################################################
     287
     288# get hash for given configuration
     289def config_hash():
     290        path = os.path.normpath(os.path.join(
     291                settings.SRCDIR,
     292        ))
     293
     294        distcc_hash = os.path.join(settings.SRCDIR, '../tools/build/distcc_hash')
     295        config = "%s-%s" % (settings.arch.target, settings.debug.path)
     296        _, out = sh(distcc_hash, config, output_file=subprocess.PIPE, ignore_dry_run=True)
     297        return out.strip()
     298
     299# get pretty string for time of day
     300def pretty_now():
     301        ts = time.time()
     302        print(ts, file=sys.stderr)
     303        return datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S')
    274304
    275305# check if arguments is yes or no
     
    302332                return 1, "ERR No core dump"
    303333
    304         return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output=subprocess.PIPE)
     334        return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE)
     335
     336def core_archive(dst, name, exe):
     337        # Get the core dump
     338        core = os.path.join(os.getcwd(), "core" )
     339
     340        # update the path for this test
     341        dst  = os.path.join(dst, name)
     342
     343        # make a directory for this test
     344        # mkdir makes the parent directory only so add a dummy
     345        mkdir(os.path.join(dst, "dir"))
     346
     347        # moves the files
     348        mv( core, os.path.join(dst, "core" ) )
     349        mv( exe , os.path.join(dst, name   ) )
     350
     351        # return explanatory test
     352        return "Archiving %s (executable and core) to %s" % (os.path.relpath(exe, settings.BUILDDIR), os.path.relpath(dst, settings.original_path))
    305353
    306354class Timed:
Note: See TracChangeset for help on using the changeset viewer.