Changeset d65f92c for tests/pybin


Ignore:
Timestamp:
Aug 15, 2019, 10:21:36 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5c4a473
Parents:
1ee048fd
Message:

Tests almost work, the only issue left is using -E and -CFA together

Location:
tests/pybin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/settings.py

    r1ee048fd rd65f92c  
    1111        SRCDIR = os.path.abspath(config.SRCDIR)
    1212        BUILDDIR = os.path.abspath(config.BUILDDIR)
     13        distribute = config.DISTRIBUTE
    1314        os.chdir(testpath)
    1415
     
    8586                self.string = "debug" if value else "no debug"
    8687                self.flags  = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2")
     88                self.path   = "debug" if value else "nodebug"
    8789
    8890class Install:
    8991        def __init__(self, value):
     92                if value:
     93                        distribute = False
     94
    9095                self.string = "installed" if value else "in-tree"
    9196                self.flags  = """INSTALL_FLAGS=%s""" % ("" if value else "-in-tree")
     
    113118        global timeout
    114119        global output_width
     120        global distcc
    115121
    116122        dry_run      = options.dry_run
     
    122128        timeout      = Timeouts(options.timeout, options.global_timeout)
    123129        output_width = 24
     130        distcc       = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash()
    124131
     132        if distribute and not os.environ.get('DISTCC_LOG'):
     133                os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log'))
    125134
    126135def update_make_cmd(force, jobs):
     
    131140def validate():
    132141        errf = os.path.join(BUILDDIR, ".validate.err")
    133         make_ret, out = tools.make( ".validate", error_file = errf, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
     142        make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
    134143        if make_ret != 0:
    135144                with open (errf, "r") as myfile:
  • tests/pybin/tools.py

    r1ee048fd rd65f92c  
    2222
    2323# helper functions to run terminal commands
    24 def sh(*cmd, timeout = False, output = None, input = None, error = subprocess.STDOUT):
     24def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT):
    2525        cmd = list(cmd)
     26
     27        if input_file and input_text:
     28                return 401, "Cannot use both text and file inputs"
    2629
    2730        # if this is a dry_run, only print the commands that would be ran
    2831        if settings.dry_run :
    2932                cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd))
    30                 if output and not isinstance(output, int):
     33                if output_file and not isinstance(output_file, int):
    3134                        cmd += " > "
    32                         cmd += output
     35                        cmd += output_file
    3336
    3437                if error and not isinstance(error, int):
     
    3639                        cmd += error
    3740
    38                 if input and not isinstance(input, int) and os.path.isfile(input):
     41                if input_file and not isinstance(input_file, int) and os.path.isfile(input_file):
    3942                        cmd += " < "
    40                         cmd += input
     43                        cmd += input_file
    4144
    4245                print(cmd)
     
    4548        with contextlib.ExitStack() as onexit:
    4649                # add input redirection if needed
    47                 input = openfd(input, 'r', onexit, True)
     50                input_file = openfd(input_file, 'r', onexit, True)
    4851
    4952                # add output redirection if needed
    50                 output = openfd(output, 'w', onexit, False)
     53                output_file = openfd(output_file, 'w', onexit, False)
    5154
    5255                # add error redirection if needed
     
    5760                        proc = subprocess.run(
    5861                                cmd,
    59                                 stdin =input,
    60                                 stdout=output,
    61                                 stderr=error,
    62                                 timeout=settings.timeout.single if timeout else None
     62                                **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}),
     63                                stdout  = output_file,
     64                                stderr  = error,
     65                                timeout = settings.timeout.single if timeout else None
    6366                        )
     67
    6468                        return proc.returncode, proc.stdout.decode("utf-8") if proc.stdout else None
    6569                except subprocess.TimeoutExpired:
     
    7478                return False
    7579
    76         code, out = sh("file %s" % fname, output=subprocess.PIPE)
     80        code, out = sh("file %s" % fname, output_file=subprocess.PIPE)
    7781        if code != 0:
    7882                return False
     
    106110        if isinstance(files, str ): files = [ files ]
    107111        for file in files:
    108                 sh( 'rm', '-f', file, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
     112                sh( 'rm', '-f', file, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
    109113
    110114# Create 1 or more directory
     
    114118                p = os.path.normpath( file )
    115119                d = os.path.dirname ( p )
    116                 sh( 'mkdir', '-p', d, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
     120                sh( 'mkdir', '-p', d, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
    117121
    118122
     
    137141                lhs,
    138142                rhs,
    139                 output=subprocess.PIPE
     143                output_file=subprocess.PIPE
    140144        )
    141145
    142146# call make
    143 def make(target, *, flags = '', output = None, error = None, error_file = None, silent = False):
     147def make(target, *, flags = '', output_file = None, error = None, error_file = None, silent = False):
    144148        test_param = """test="%s" """ % (error_file) if error_file else None
    145149        cmd = [
     
    150154                settings.debug.flags,
    151155                settings.install.flags,
     156                settings.distcc if settings.distribute else None,
    152157                flags,
    153158                target
    154159        ]
    155160        cmd = [s for s in cmd if s]
    156         return sh(*cmd, output=output, error=error)
     161        return sh(*cmd, output_file=output_file, error=error)
    157162
    158163def which(program):
     
    200205# cat one file into the other
    201206def cat(source, dest):
    202         ret, _ = sh("cat", source, output=dest)
     207        ret, _ = sh("cat", source, output_file=dest)
    203208        return ret
    204209
     
    273278################################################################################
    274279
     280# get hash for given configuration
     281def config_hash():
     282        path = os.path.normpath(os.path.join(
     283                settings.SRCDIR,
     284        ))
     285
     286        distcc_hash = os.path.join(settings.SRCDIR, '../tools/build/distcc_hash')
     287        config = "%s-%s" % (settings.arch.target, settings.debug.path)
     288        _, out = sh(distcc_hash, config, output_file=subprocess.PIPE)
     289        return out.strip()
     290
    275291# check if arguments is yes or no
    276292def yes_no(string):
     
    302318                return 1, "ERR No core dump"
    303319
    304         return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output=subprocess.PIPE)
     320        return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE)
    305321
    306322class Timed:
Note: See TracChangeset for help on using the changeset viewer.