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