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
Line 
1import os
2import subprocess
3import sys
4from . import tools
5
6global original_path
7
8try :
9        original_path = os.getcwd()
10        testpath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0])))
11        sys.path.append(testpath)
12        import config
13
14        SRCDIR = os.path.abspath(config.SRCDIR)
15        BUILDDIR = os.path.abspath(config.BUILDDIR)
16        os.chdir(testpath)
17
18except:
19        print('ERROR: missing config.py, re-run configure script.', file=sys.stderr)
20        sys.exit(1)
21
22class Architecture:
23        KnownArchitectures = {
24                'x64'           : 'x64',
25                'x86-64'        : 'x64',
26                'x86_64'        : 'x64',
27                'x86'           : 'x86',
28                'aarch64'       : 'arm',
29                'i386'          : 'x86',
30                'i486'          : 'x86',
31                'i686'          : 'x86',
32                'Intel 80386'   : 'x86',
33                'arm'           : 'arm',
34                'ARM'           : 'arm',
35        }
36
37        CrossCompileFlags = {
38                'x64' : 'ARCH_FLAGS=-m64',
39                'x86' : 'ARCH_FLAGS=-m32',
40        }
41
42        def __init__(self, arch):
43                try:
44                        canonical_host = Architecture.make_canonical( config.HOSTARCH )
45                except KeyError:
46                        print("Unknown host architecture %s" % config.HOSTARCH, file=sys.stderr)
47                        sys.exit(1)
48
49                if arch:
50                        try:
51                                arch = Architecture.make_canonical( arch )
52                        except KeyError:
53                                print("Unknown architecture %s" % arch, file=sys.stderr)
54                                sys.exit(1)
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
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)
69
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
82        def make_canonical(_, arch):
83                return Architecture.KnownArchitectures[arch]
84
85
86class Debug:
87        def __init__(self, value):
88                self.string = "debug" if value else "no debug"
89                self.flags  = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2")
90
91class Install:
92        def __init__(self, value):
93                self.string = "installed" if value else "in-tree"
94                self.flags  = """INSTALL_FLAGS=%s""" % ("" if value else "-in-tree")
95
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
109def init( options ):
110        global arch
111        global dry_run
112        global generating
113        global make
114        global debug
115        global install
116        global timeout
117        global output_width
118        global archive
119
120        dry_run      = options.dry_run
121        generating   = options.regenerate_expected
122        make         = ['make']
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
128        archive      = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
129
130
131def update_make_cmd(force, jobs):
132        global make
133
134        make = ['make'] if not force else ['make', "-j%i" % jobs]
135
136def validate():
137        errf = os.path.join(BUILDDIR, ".validate.err")
138        make_ret, out = tools.make( ".validate", error_file = errf, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
139        if make_ret != 0:
140                with open (errf, "r") as myfile:
141                        error=myfile.read()
142                print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr)
143                print("       verify returned : \n%s" % error, file=sys.stderr)
144                tools.rm(errf)
145                sys.exit(1)
146
147        tools.rm(errf)
148
149def prep_output(tests):
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.