[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 = {
|
---|
[41af19c] | 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',
|
---|
[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 |
|
---|
[136f86b] | 79 | def filter(self, tests):
|
---|
| 80 | return [test for test in tests if not test.arch or self.target == test.arch]
|
---|
[f3b9efc] | 81 | return True if not arch else self.target == arch
|
---|
| 82 |
|
---|
[64cf022] | 83 | @staticmethod
|
---|
| 84 | def make_canonical(arch):
|
---|
[f3b9efc] | 85 | return Architecture.KnownArchitectures[arch]
|
---|
| 86 |
|
---|
[bacc36c] | 87 |
|
---|
[f3b9efc] | 88 | class Debug:
|
---|
| 89 | def __init__(self, value):
|
---|
| 90 | self.string = "debug" if value else "no debug"
|
---|
[a45fc7b] | 91 | self.flags = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2")
|
---|
[d65f92c] | 92 | self.path = "debug" if value else "nodebug"
|
---|
[bacc36c] | 93 |
|
---|
[a5121bf] | 94 | class Install:
|
---|
| 95 | def __init__(self, value):
|
---|
[d65f92c] | 96 | if value:
|
---|
| 97 | distribute = False
|
---|
| 98 |
|
---|
[abec2f8] | 99 | self.string = "installed" if value else "in tree"
|
---|
[158b026] | 100 | self.flags = """installed=%s""" % ("yes" if value else "no")
|
---|
[a5121bf] | 101 |
|
---|
[afe8882] | 102 | class Timeouts:
|
---|
| 103 | def __init__(self, ts, tg):
|
---|
| 104 | self.single = Timeouts.check(ts)
|
---|
| 105 | self.total = Timeouts.check(tg)
|
---|
| 106 |
|
---|
[64cf022] | 107 | @staticmethod
|
---|
| 108 | def check(value):
|
---|
[afe8882] | 109 | if value < 1:
|
---|
| 110 | print("Timeouts must be at least 1 second", file=sys.stderr)
|
---|
| 111 | sys.exit(1)
|
---|
| 112 |
|
---|
| 113 | return value
|
---|
| 114 |
|
---|
[bacc36c] | 115 | def init( options ):
|
---|
[136f86b] | 116 | global all_arch
|
---|
| 117 | global all_debug
|
---|
| 118 | global all_install
|
---|
[bacc36c] | 119 | global arch
|
---|
[6daaee3] | 120 | global archive
|
---|
[136f86b] | 121 | global continue_
|
---|
[6daaee3] | 122 | global debug
|
---|
[bacc36c] | 123 | global dry_run
|
---|
| 124 | global generating
|
---|
[a5121bf] | 125 | global install
|
---|
[6daaee3] | 126 | global make
|
---|
[5bf1f3e] | 127 | global output_width
|
---|
[6daaee3] | 128 | global timeout
|
---|
[d658183] | 129 | global timeout2gdb
|
---|
[bacc36c] | 130 |
|
---|
[41af19c] | 131 | all_arch = [Architecture(o) for o in list(dict.fromkeys(options.arch ))] if options.arch else [Architecture(None)]
|
---|
[136f86b] | 132 | all_debug = [Debug(o) for o in list(dict.fromkeys(options.debug ))]
|
---|
| 133 | all_install = [Install(o) for o in list(dict.fromkeys(options.install))]
|
---|
[6daaee3] | 134 | archive = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
|
---|
[136f86b] | 135 | continue_ = options.continue_
|
---|
[8209e70] | 136 | dry_run = options.dry_run # must be called before tools.config_hash()
|
---|
[5bf1f3e] | 137 | generating = options.regenerate_expected
|
---|
[6daaee3] | 138 | make = ['make']
|
---|
[5bf1f3e] | 139 | output_width = 24
|
---|
[6daaee3] | 140 | timeout = Timeouts(options.timeout, options.global_timeout)
|
---|
[d658183] | 141 | timeout2gdb = options.timeout_with_gdb
|
---|
[bacc36c] | 142 |
|
---|
[17bc05b] | 143 | # if we distribute, distcc errors will fail tests, use log file for distcc
|
---|
| 144 | # don't use "'DISTCC_LOG' not in os.environ" because it can be set to ''
|
---|
[d65f92c] | 145 | if distribute and not os.environ.get('DISTCC_LOG'):
|
---|
| 146 | os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log'))
|
---|
[f85bc15] | 147 |
|
---|
[5bf1f3e] | 148 | def update_make_cmd(force, jobs):
|
---|
[bacc36c] | 149 | global make
|
---|
| 150 |
|
---|
[a45fc7b] | 151 | make = ['make'] if not force else ['make', "-j%i" % jobs]
|
---|
[28582b2] | 152 |
|
---|
| 153 | def validate():
|
---|
[136f86b] | 154 | """Validate the current configuration and update globals"""
|
---|
| 155 |
|
---|
| 156 | global distcc
|
---|
| 157 | distcc = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash()
|
---|
[afe8882] | 158 | errf = os.path.join(BUILDDIR, ".validate.err")
|
---|
[d65f92c] | 159 | make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
|
---|
[28582b2] | 160 | if make_ret != 0:
|
---|
[afe8882] | 161 | with open (errf, "r") as myfile:
|
---|
[28582b2] | 162 | error=myfile.read()
|
---|
[575a6e5] | 163 | print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr)
|
---|
[28582b2] | 164 | print(" verify returned : \n%s" % error, file=sys.stderr)
|
---|
[afe8882] | 165 | tools.rm(errf)
|
---|
[28582b2] | 166 | sys.exit(1)
|
---|
| 167 |
|
---|
[d3c1c6a] | 168 | tools.rm(errf)
|
---|
| 169 |
|
---|
| 170 | def prep_output(tests):
|
---|
[5bf1f3e] | 171 | global output_width
|
---|
| 172 | output_width = max(map(lambda t: len(t.target()), tests))
|
---|