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