[f85bc15] | 1 | import os |
---|
[a45fc7b] | 2 | import subprocess |
---|
[f3b9efc] | 3 | import sys |
---|
[5b993e0] | 4 | from . import tools |
---|
[bacc36c] | 5 | |
---|
[dcfedca] | 6 | global original_path |
---|
| 7 | |
---|
[f85bc15] | 8 | try : |
---|
[dcfedca] | 9 | original_path = os.getcwd() |
---|
[afe8882] | 10 | testpath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0]))) |
---|
| 11 | sys.path.append(testpath) |
---|
[552f5cb] | 12 | import config |
---|
[f85bc15] | 13 | |
---|
[552f5cb] | 14 | SRCDIR = os.path.abspath(config.SRCDIR) |
---|
| 15 | BUILDDIR = os.path.abspath(config.BUILDDIR) |
---|
[d65f92c] | 16 | distribute = config.DISTRIBUTE |
---|
[afe8882] | 17 | os.chdir(testpath) |
---|
| 18 | |
---|
[f85bc15] | 19 | except: |
---|
| 20 | print('ERROR: missing config.py, re-run configure script.', file=sys.stderr) |
---|
| 21 | sys.exit(1) |
---|
| 22 | |
---|
[bacc36c] | 23 | class Architecture: |
---|
[f3b9efc] | 24 | KnownArchitectures = { |
---|
[a8d4b59] | 25 | 'x64' : 'x64', |
---|
| 26 | 'x86-64' : 'x64', |
---|
| 27 | 'x86_64' : 'x64', |
---|
| 28 | 'x86' : 'x86', |
---|
| 29 | 'aarch64' : 'arm', |
---|
[f3b9efc] | 30 | 'i386' : 'x86', |
---|
| 31 | 'i486' : 'x86', |
---|
| 32 | 'i686' : 'x86', |
---|
| 33 | 'Intel 80386' : 'x86', |
---|
[a8d4b59] | 34 | 'arm' : 'arm', |
---|
| 35 | 'ARM' : 'arm', |
---|
[f3b9efc] | 36 | } |
---|
| 37 | |
---|
[575a6e5] | 38 | CrossCompileFlags = { |
---|
| 39 | 'x64' : 'ARCH_FLAGS=-m64', |
---|
| 40 | 'x86' : 'ARCH_FLAGS=-m32', |
---|
| 41 | } |
---|
| 42 | |
---|
[f3b9efc] | 43 | def __init__(self, arch): |
---|
[575a6e5] | 44 | try: |
---|
[5bf1f3e] | 45 | canonical_host = Architecture.make_canonical( config.HOSTARCH ) |
---|
[575a6e5] | 46 | except KeyError: |
---|
[d82892a] | 47 | print("Unknown host architecture %s" % config.HOSTARCH, file=sys.stderr) |
---|
[575a6e5] | 48 | sys.exit(1) |
---|
| 49 | |
---|
[f3b9efc] | 50 | if arch: |
---|
| 51 | try: |
---|
[5bf1f3e] | 52 | arch = Architecture.make_canonical( arch ) |
---|
[f3b9efc] | 53 | except KeyError: |
---|
[d82892a] | 54 | print("Unknown architecture %s" % arch, file=sys.stderr) |
---|
[f3b9efc] | 55 | sys.exit(1) |
---|
[575a6e5] | 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 |
---|
[47c1928] | 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) |
---|
[575a6e5] | 70 | |
---|
[f3b9efc] | 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 |
---|
[5bf1f3e] | 83 | def make_canonical(_, arch): |
---|
[f3b9efc] | 84 | return Architecture.KnownArchitectures[arch] |
---|
| 85 | |
---|
[bacc36c] | 86 | |
---|
[f3b9efc] | 87 | class Debug: |
---|
| 88 | def __init__(self, value): |
---|
| 89 | self.string = "debug" if value else "no debug" |
---|
[a45fc7b] | 90 | self.flags = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2") |
---|
[d65f92c] | 91 | self.path = "debug" if value else "nodebug" |
---|
[bacc36c] | 92 | |
---|
[a5121bf] | 93 | class Install: |
---|
| 94 | def __init__(self, value): |
---|
[d65f92c] | 95 | if value: |
---|
| 96 | distribute = False |
---|
| 97 | |
---|
[abec2f8] | 98 | self.string = "installed" if value else "in tree" |
---|
[158b026] | 99 | self.flags = """installed=%s""" % ("yes" if value else "no") |
---|
[a5121bf] | 100 | |
---|
[afe8882] | 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 | |
---|
[bacc36c] | 114 | def init( options ): |
---|
| 115 | global arch |
---|
[6daaee3] | 116 | global archive |
---|
| 117 | global debug |
---|
| 118 | global distcc |
---|
[bacc36c] | 119 | global dry_run |
---|
| 120 | global generating |
---|
[a5121bf] | 121 | global install |
---|
[6daaee3] | 122 | global make |
---|
[5bf1f3e] | 123 | global output_width |
---|
[6daaee3] | 124 | global timeout |
---|
[d658183] | 125 | global timeout2gdb |
---|
[bacc36c] | 126 | |
---|
[6daaee3] | 127 | arch = Architecture(options.arch) |
---|
| 128 | archive = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None |
---|
| 129 | debug = Debug(options.debug) |
---|
[8209e70] | 130 | dry_run = options.dry_run # must be called before tools.config_hash() |
---|
[6daaee3] | 131 | distcc = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash() |
---|
[5bf1f3e] | 132 | generating = options.regenerate_expected |
---|
| 133 | install = Install(options.install) |
---|
[6daaee3] | 134 | make = ['make'] |
---|
[5bf1f3e] | 135 | output_width = 24 |
---|
[6daaee3] | 136 | timeout = Timeouts(options.timeout, options.global_timeout) |
---|
[d658183] | 137 | timeout2gdb = options.timeout_with_gdb |
---|
[bacc36c] | 138 | |
---|
[17bc05b] | 139 | # if we distribute, distcc errors will fail tests, use log file for distcc |
---|
| 140 | # don't use "'DISTCC_LOG' not in os.environ" because it can be set to '' |
---|
[d65f92c] | 141 | if distribute and not os.environ.get('DISTCC_LOG'): |
---|
| 142 | os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log')) |
---|
[f85bc15] | 143 | |
---|
[5bf1f3e] | 144 | def update_make_cmd(force, jobs): |
---|
[bacc36c] | 145 | global make |
---|
| 146 | |
---|
[a45fc7b] | 147 | make = ['make'] if not force else ['make', "-j%i" % jobs] |
---|
[28582b2] | 148 | |
---|
| 149 | def validate(): |
---|
[afe8882] | 150 | errf = os.path.join(BUILDDIR, ".validate.err") |
---|
[d65f92c] | 151 | make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) |
---|
[28582b2] | 152 | if make_ret != 0: |
---|
[afe8882] | 153 | with open (errf, "r") as myfile: |
---|
[28582b2] | 154 | error=myfile.read() |
---|
[575a6e5] | 155 | print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr) |
---|
[28582b2] | 156 | print(" verify returned : \n%s" % error, file=sys.stderr) |
---|
[afe8882] | 157 | tools.rm(errf) |
---|
[28582b2] | 158 | sys.exit(1) |
---|
| 159 | |
---|
[d3c1c6a] | 160 | tools.rm(errf) |
---|
| 161 | |
---|
| 162 | def prep_output(tests): |
---|
[5bf1f3e] | 163 | global output_width |
---|
| 164 | output_width = max(map(lambda t: len(t.target()), tests)) |
---|