source: tests/pybin/settings.py @ 143e6f3

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 143e6f3 was dcfedca, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Test script can now archive errors (copy executables and core dumps to a specified directory)
run --help command for detail

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[f85bc15]1import os
[a45fc7b]2import subprocess
[f3b9efc]3import sys
[5b993e0]4from . import tools
[bacc36c]5
[dcfedca]6global original_path
7
[f85bc15]8try :
[dcfedca]9        original_path = os.getcwd()
[afe8882]10        testpath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0])))
11        sys.path.append(testpath)
[552f5cb]12        import config
[f85bc15]13
[552f5cb]14        SRCDIR = os.path.abspath(config.SRCDIR)
15        BUILDDIR = os.path.abspath(config.BUILDDIR)
[afe8882]16        os.chdir(testpath)
17
[f85bc15]18except:
19        print('ERROR: missing config.py, re-run configure script.', file=sys.stderr)
20        sys.exit(1)
21
[bacc36c]22class Architecture:
[f3b9efc]23        KnownArchitectures = {
[a8d4b59]24                'x64'           : 'x64',
25                'x86-64'        : 'x64',
26                'x86_64'        : 'x64',
27                'x86'           : 'x86',
28                'aarch64'       : 'arm',
[f3b9efc]29                'i386'          : 'x86',
30                'i486'          : 'x86',
31                'i686'          : 'x86',
32                'Intel 80386'   : 'x86',
[a8d4b59]33                'arm'           : 'arm',
34                'ARM'           : 'arm',
[f3b9efc]35        }
36
[575a6e5]37        CrossCompileFlags = {
38                'x64' : 'ARCH_FLAGS=-m64',
39                'x86' : 'ARCH_FLAGS=-m32',
40        }
41
[f3b9efc]42        def __init__(self, arch):
[575a6e5]43                try:
[5bf1f3e]44                        canonical_host = Architecture.make_canonical( config.HOSTARCH )
[575a6e5]45                except KeyError:
[d82892a]46                        print("Unknown host architecture %s" % config.HOSTARCH, file=sys.stderr)
[575a6e5]47                        sys.exit(1)
48
[f3b9efc]49                if arch:
50                        try:
[5bf1f3e]51                                arch = Architecture.make_canonical( arch )
[f3b9efc]52                        except KeyError:
[d82892a]53                                print("Unknown architecture %s" % arch, file=sys.stderr)
[f3b9efc]54                                sys.exit(1)
[575a6e5]55
56                if arch and arch != canonical_host:
57                        self.target = arch
58                        self.cross_compile = True
59                else:
60                        self.target = canonical_host
61                        self.cross_compile = False
[47c1928]62
63
64                try :
65                        self.flags = Architecture.CrossCompileFlags[self.target]
66                except KeyError:
67                        print("Cross compilation not available for architecture %s" % self.target, file=sys.stderr)
68                        sys.exit(1)
[575a6e5]69
[f3b9efc]70                self.string = self.target
71
72        def update(self):
73                if not self.cross_compile:
74                        self.target = machine_default()
75                        self.string = self.target
76                        print("updated to %s" % self.target)
77
78        def match(self, arch):
79                return True if not arch else self.target == arch
80
81        @classmethod
[5bf1f3e]82        def make_canonical(_, arch):
[f3b9efc]83                return Architecture.KnownArchitectures[arch]
84
[bacc36c]85
[f3b9efc]86class Debug:
87        def __init__(self, value):
88                self.string = "debug" if value else "no debug"
[a45fc7b]89                self.flags  = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2")
[bacc36c]90
[a5121bf]91class Install:
92        def __init__(self, value):
93                self.string = "installed" if value else "in-tree"
[a45fc7b]94                self.flags  = """INSTALL_FLAGS=%s""" % ("" if value else "-in-tree")
[a5121bf]95
[afe8882]96class Timeouts:
97        def __init__(self, ts, tg):
98                self.single = Timeouts.check(ts)
99                self.total  = Timeouts.check(tg)
100
101        @classmethod
102        def check(_, value):
103                if value < 1:
104                        print("Timeouts must be at least 1 second", file=sys.stderr)
105                        sys.exit(1)
106
107                return value
108
[bacc36c]109def init( options ):
110        global arch
111        global dry_run
112        global generating
113        global make
[209383b]114        global debug
[a5121bf]115        global install
[afe8882]116        global timeout
[5bf1f3e]117        global output_width
[dcfedca]118        global archive
[bacc36c]119
[5bf1f3e]120        dry_run      = options.dry_run
121        generating   = options.regenerate_expected
[a45fc7b]122        make         = ['make']
[5bf1f3e]123        debug        = Debug(options.debug)
124        install      = Install(options.install)
125        arch         = Architecture(options.arch)
126        timeout      = Timeouts(options.timeout, options.global_timeout)
127        output_width = 24
[dcfedca]128        archive      = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
[bacc36c]129
[f85bc15]130
[5bf1f3e]131def update_make_cmd(force, jobs):
[bacc36c]132        global make
133
[a45fc7b]134        make = ['make'] if not force else ['make', "-j%i" % jobs]
[28582b2]135
136def validate():
[afe8882]137        errf = os.path.join(BUILDDIR, ".validate.err")
[a45fc7b]138        make_ret, out = tools.make( ".validate", error_file = errf, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
[28582b2]139        if make_ret != 0:
[afe8882]140                with open (errf, "r") as myfile:
[28582b2]141                        error=myfile.read()
[575a6e5]142                print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr)
[28582b2]143                print("       verify returned : \n%s" % error, file=sys.stderr)
[afe8882]144                tools.rm(errf)
[28582b2]145                sys.exit(1)
146
[d3c1c6a]147        tools.rm(errf)
148
149def prep_output(tests):
[5bf1f3e]150        global output_width
151        output_width = max(map(lambda t: len(t.target()), tests))
Note: See TracBrowser for help on using the repository browser.