source: tests/pybin/settings.py @ 2b10f95

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2b10f95 was 5bf1f3e, checked in by tdelisle <tdelisle@…>, 5 years ago

Code review of test.py and pybin

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