[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 = {
|
---|
| 21 | 'x64' : 'x64',
|
---|
| 22 | 'x86-64' : 'x64',
|
---|
[552f5cb] | 23 | 'x86_64' : 'x64',
|
---|
[f3b9efc] | 24 | 'x86' : 'x86',
|
---|
| 25 | 'i386' : 'x86',
|
---|
| 26 | 'i486' : 'x86',
|
---|
| 27 | 'i686' : 'x86',
|
---|
| 28 | 'Intel 80386' : 'x86',
|
---|
| 29 | 'arm' : 'arm',
|
---|
| 30 | 'ARM' : 'arm',
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[575a6e5] | 33 | CrossCompileFlags = {
|
---|
| 34 | 'x64' : 'ARCH_FLAGS=-m64',
|
---|
| 35 | 'x86' : 'ARCH_FLAGS=-m32',
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[f3b9efc] | 38 | def __init__(self, arch):
|
---|
[575a6e5] | 39 | try:
|
---|
[5bf1f3e] | 40 | canonical_host = Architecture.make_canonical( config.HOSTARCH )
|
---|
[575a6e5] | 41 | except KeyError:
|
---|
| 42 | print("Unkown host architecture %s" % config.HOSTARCH, file=sys.stderr)
|
---|
| 43 | sys.exit(1)
|
---|
| 44 |
|
---|
[f3b9efc] | 45 | if arch:
|
---|
| 46 | try:
|
---|
[5bf1f3e] | 47 | arch = Architecture.make_canonical( arch )
|
---|
[f3b9efc] | 48 | except KeyError:
|
---|
[575a6e5] | 49 | print("Unkown architecture %s" % arch, file=sys.stderr)
|
---|
[f3b9efc] | 50 | sys.exit(1)
|
---|
[575a6e5] | 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
|
---|
[47c1928] | 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)
|
---|
[575a6e5] | 65 |
|
---|
[f3b9efc] | 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
|
---|
[5bf1f3e] | 78 | def make_canonical(_, arch):
|
---|
[f3b9efc] | 79 | return Architecture.KnownArchitectures[arch]
|
---|
| 80 |
|
---|
[bacc36c] | 81 |
|
---|
[f3b9efc] | 82 | class Debug:
|
---|
| 83 | def __init__(self, value):
|
---|
| 84 | self.string = "debug" if value else "no debug"
|
---|
[a45fc7b] | 85 | self.flags = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2")
|
---|
[bacc36c] | 86 |
|
---|
[a5121bf] | 87 | class Install:
|
---|
| 88 | def __init__(self, value):
|
---|
| 89 | self.string = "installed" if value else "in-tree"
|
---|
[a45fc7b] | 90 | self.flags = """INSTALL_FLAGS=%s""" % ("" if value else "-in-tree")
|
---|
[a5121bf] | 91 |
|
---|
[afe8882] | 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 |
|
---|
[bacc36c] | 105 | def init( options ):
|
---|
| 106 | global arch
|
---|
| 107 | global dry_run
|
---|
| 108 | global generating
|
---|
| 109 | global make
|
---|
[209383b] | 110 | global debug
|
---|
[a5121bf] | 111 | global install
|
---|
[afe8882] | 112 | global timeout
|
---|
[5bf1f3e] | 113 | global output_width
|
---|
[bacc36c] | 114 |
|
---|
[5bf1f3e] | 115 | dry_run = options.dry_run
|
---|
| 116 | generating = options.regenerate_expected
|
---|
[a45fc7b] | 117 | make = ['make']
|
---|
[5bf1f3e] | 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
|
---|
[bacc36c] | 123 |
|
---|
[f85bc15] | 124 |
|
---|
[5bf1f3e] | 125 | def update_make_cmd(force, jobs):
|
---|
[bacc36c] | 126 | global make
|
---|
| 127 |
|
---|
[a45fc7b] | 128 | make = ['make'] if not force else ['make', "-j%i" % jobs]
|
---|
[28582b2] | 129 |
|
---|
| 130 | def validate():
|
---|
[afe8882] | 131 | errf = os.path.join(BUILDDIR, ".validate.err")
|
---|
[a45fc7b] | 132 | make_ret, out = tools.make( ".validate", error_file = errf, output=subprocess.DEVNULL, error=subprocess.DEVNULL )
|
---|
[28582b2] | 133 | if make_ret != 0:
|
---|
[afe8882] | 134 | with open (errf, "r") as myfile:
|
---|
[28582b2] | 135 | error=myfile.read()
|
---|
[575a6e5] | 136 | print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr)
|
---|
[28582b2] | 137 | print(" verify returned : \n%s" % error, file=sys.stderr)
|
---|
[afe8882] | 138 | tools.rm(errf)
|
---|
[28582b2] | 139 | sys.exit(1)
|
---|
| 140 |
|
---|
[d3c1c6a] | 141 | tools.rm(errf)
|
---|
| 142 |
|
---|
| 143 | def prep_output(tests):
|
---|
[5bf1f3e] | 144 | global output_width
|
---|
| 145 | output_width = max(map(lambda t: len(t.target()), tests))
|
---|