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