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