| 1 | import os
|
|---|
| 2 | import subprocess
|
|---|
| 3 | import sys
|
|---|
| 4 | from . import tools
|
|---|
| 5 |
|
|---|
| 6 | global original_path
|
|---|
| 7 |
|
|---|
| 8 | try :
|
|---|
| 9 | original_path = os.getcwd()
|
|---|
| 10 | testpath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0])))
|
|---|
| 11 | sys.path.append(testpath)
|
|---|
| 12 | import config
|
|---|
| 13 |
|
|---|
| 14 | SRCDIR = os.path.abspath(config.SRCDIR)
|
|---|
| 15 | BUILDDIR = os.path.abspath(config.BUILDDIR)
|
|---|
| 16 | distribute = config.DISTRIBUTE
|
|---|
| 17 | os.chdir(testpath)
|
|---|
| 18 |
|
|---|
| 19 | except:
|
|---|
| 20 | print('ERROR: missing config.py, re-run configure script.', file=sys.stderr)
|
|---|
| 21 | sys.exit(1)
|
|---|
| 22 |
|
|---|
| 23 | class Architecture:
|
|---|
| 24 | KnownArchitectures = {
|
|---|
| 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',
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | CrossCompileFlags = {
|
|---|
| 39 | 'x64' : 'ARCH_FLAGS=-m64',
|
|---|
| 40 | 'x86' : 'ARCH_FLAGS=-m32',
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | def __init__(self, arch):
|
|---|
| 44 | try:
|
|---|
| 45 | canonical_host = Architecture.make_canonical( config.HOSTARCH )
|
|---|
| 46 | except KeyError:
|
|---|
| 47 | print("Unknown host architecture %s" % config.HOSTARCH, file=sys.stderr)
|
|---|
| 48 | sys.exit(1)
|
|---|
| 49 |
|
|---|
| 50 | if arch:
|
|---|
| 51 | try:
|
|---|
| 52 | arch = Architecture.make_canonical( arch )
|
|---|
| 53 | except KeyError:
|
|---|
| 54 | print("Unknown architecture %s" % arch, file=sys.stderr)
|
|---|
| 55 | sys.exit(1)
|
|---|
| 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
|
|---|
| 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)
|
|---|
| 70 |
|
|---|
| 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 filter(self, tests):
|
|---|
| 80 | return [test for test in tests if not test.arch or self.target == test.arch]
|
|---|
| 81 | return True if not arch else self.target == arch
|
|---|
| 82 |
|
|---|
| 83 | @staticmethod
|
|---|
| 84 | def make_canonical(arch):
|
|---|
| 85 | return Architecture.KnownArchitectures[arch]
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | class Debug:
|
|---|
| 89 | def __init__(self, value):
|
|---|
| 90 | self.string = "debug" if value else "no debug"
|
|---|
| 91 | self.flags = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2")
|
|---|
| 92 | self.path = "debug" if value else "nodebug"
|
|---|
| 93 |
|
|---|
| 94 | class Install:
|
|---|
| 95 | def __init__(self, value):
|
|---|
| 96 | if value:
|
|---|
| 97 | distribute = False
|
|---|
| 98 |
|
|---|
| 99 | self.string = "installed" if value else "in tree"
|
|---|
| 100 | self.flags = """installed=%s""" % ("yes" if value else "no")
|
|---|
| 101 |
|
|---|
| 102 | class Timeouts:
|
|---|
| 103 | def __init__(self, ts, tg):
|
|---|
| 104 | self.single = Timeouts.check(ts)
|
|---|
| 105 | self.total = Timeouts.check(tg)
|
|---|
| 106 |
|
|---|
| 107 | @staticmethod
|
|---|
| 108 | def check(value):
|
|---|
| 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 |
|
|---|
| 115 | def init( options ):
|
|---|
| 116 | global all_arch
|
|---|
| 117 | global all_debug
|
|---|
| 118 | global all_install
|
|---|
| 119 | global arch
|
|---|
| 120 | global archive
|
|---|
| 121 | global continue_
|
|---|
| 122 | global debug
|
|---|
| 123 | global dry_run
|
|---|
| 124 | global generating
|
|---|
| 125 | global install
|
|---|
| 126 | global make
|
|---|
| 127 | global output_width
|
|---|
| 128 | global timeout
|
|---|
| 129 | global timeout2gdb
|
|---|
| 130 |
|
|---|
| 131 | all_arch = [Architecture(o) for o in list(dict.fromkeys(options.arch ))] if options.arch else [Architecture(None)]
|
|---|
| 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))]
|
|---|
| 134 | archive = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
|
|---|
| 135 | continue_ = options.continue_
|
|---|
| 136 | dry_run = options.dry_run # must be called before tools.config_hash()
|
|---|
| 137 | generating = options.regenerate_expected
|
|---|
| 138 | make = ['make']
|
|---|
| 139 | output_width = 24
|
|---|
| 140 | timeout = Timeouts(options.timeout, options.global_timeout)
|
|---|
| 141 | timeout2gdb = options.timeout_with_gdb
|
|---|
| 142 |
|
|---|
| 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 ''
|
|---|
| 145 | if distribute and not os.environ.get('DISTCC_LOG'):
|
|---|
| 146 | os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log'))
|
|---|
| 147 |
|
|---|
| 148 | def update_make_cmd(force, jobs):
|
|---|
| 149 | global make
|
|---|
| 150 |
|
|---|
| 151 | make = ['make'] if not force else ['make', "-j%i" % jobs]
|
|---|
| 152 |
|
|---|
| 153 | def validate():
|
|---|
| 154 | """Validate the current configuration and update globals"""
|
|---|
| 155 |
|
|---|
| 156 | global distcc
|
|---|
| 157 | distcc = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash()
|
|---|
| 158 | errf = os.path.join(BUILDDIR, ".validate.err")
|
|---|
| 159 | make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
|
|---|
| 160 | if make_ret != 0:
|
|---|
| 161 | with open (errf, "r") as myfile:
|
|---|
| 162 | error=myfile.read()
|
|---|
| 163 | print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr)
|
|---|
| 164 | print(" verify returned : \n%s" % error, file=sys.stderr)
|
|---|
| 165 | tools.rm(errf)
|
|---|
| 166 | sys.exit(1)
|
|---|
| 167 |
|
|---|
| 168 | tools.rm(errf)
|
|---|
| 169 |
|
|---|
| 170 | def prep_output(tests):
|
|---|
| 171 | global output_width
|
|---|
| 172 | output_width = max(map(lambda t: len(t.target()), tests))
|
|---|