source: tests/pybin/settings.py @ d65f92c

ADTarm-ehenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since d65f92c was d65f92c, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

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

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