| 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'     : 'arm64', | 
|---|
| 30 | 'arm64'       : 'arm64', | 
|---|
| 31 | 'ARM64'       : 'arm64', | 
|---|
| 32 | 'i386'        : 'x86', | 
|---|
| 33 | 'i486'        : 'x86', | 
|---|
| 34 | 'i686'        : 'x86', | 
|---|
| 35 | 'Intel 80386' : 'x86', | 
|---|
| 36 | 'arm'         : 'arm32', | 
|---|
| 37 | 'ARM'         : 'arm32', | 
|---|
| 38 | 'arm32'       : 'arm32', | 
|---|
| 39 | 'ARM32'       : 'arm32', | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | CrossCompileFlags = { | 
|---|
| 43 | 'x64'  : 'ARCH_FLAGS=-m64', | 
|---|
| 44 | 'x86'  : 'ARCH_FLAGS=-m32', | 
|---|
| 45 | 'arm64': 'ARCH_FLAGS=', | 
|---|
| 46 | 'arm32': 'ARCH_FLAGS=', | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | def __init__(self, arch): | 
|---|
| 50 | try: | 
|---|
| 51 | canonical_host = Architecture.make_canonical( config.HOSTARCH ) | 
|---|
| 52 | except KeyError: | 
|---|
| 53 | print("Unknown host architecture %s" % config.HOSTARCH, file=sys.stderr) | 
|---|
| 54 | sys.exit(1) | 
|---|
| 55 |  | 
|---|
| 56 | if arch: | 
|---|
| 57 | try: | 
|---|
| 58 | arch = Architecture.make_canonical( arch ) | 
|---|
| 59 | except KeyError: | 
|---|
| 60 | print("Unknown architecture %s" % arch, file=sys.stderr) | 
|---|
| 61 | sys.exit(1) | 
|---|
| 62 |  | 
|---|
| 63 | if arch and arch != canonical_host: | 
|---|
| 64 | self.target = arch | 
|---|
| 65 | self.cross_compile = True | 
|---|
| 66 | else: | 
|---|
| 67 | self.target = canonical_host | 
|---|
| 68 | self.cross_compile = False | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | try : | 
|---|
| 72 | self.flags = Architecture.CrossCompileFlags[self.target] | 
|---|
| 73 | except KeyError: | 
|---|
| 74 | print("Cross compilation not available for architecture %s" % self.target, file=sys.stderr) | 
|---|
| 75 | sys.exit(1) | 
|---|
| 76 |  | 
|---|
| 77 | self.string = self.target | 
|---|
| 78 |  | 
|---|
| 79 | def update(self): | 
|---|
| 80 | if not self.cross_compile: | 
|---|
| 81 | self.target = machine_default() | 
|---|
| 82 | self.string = self.target | 
|---|
| 83 | print("updated to %s" % self.target) | 
|---|
| 84 |  | 
|---|
| 85 | def filter(self, tests): | 
|---|
| 86 | return [test for test in tests if not test.arch or self.target == test.arch] | 
|---|
| 87 |  | 
|---|
| 88 | @staticmethod | 
|---|
| 89 | def make_canonical(arch): | 
|---|
| 90 | return Architecture.KnownArchitectures[arch] | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 | class Debug: | 
|---|
| 94 | def __init__(self, value): | 
|---|
| 95 | self.string = "debug" if value else "no debug" | 
|---|
| 96 | self.flags  = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2") | 
|---|
| 97 | self.path   = "debug" if value else "nodebug" | 
|---|
| 98 |  | 
|---|
| 99 | class AST: | 
|---|
| 100 | def __init__(self, ast): | 
|---|
| 101 | if ast == "new": | 
|---|
| 102 | self.target = ast | 
|---|
| 103 | self.string = "New AST" | 
|---|
| 104 | self.flags  = """AST_FLAGS=-XCFA,--new-ast""" | 
|---|
| 105 | elif ast == "old": | 
|---|
| 106 | self.target = ast | 
|---|
| 107 | self.string = "Old AST" | 
|---|
| 108 | self.flags  = """AST_FLAGS=-XCFA,--old-ast""" | 
|---|
| 109 | elif ast == None: | 
|---|
| 110 | self.target = "new" if config.NEWAST else "old" | 
|---|
| 111 | self.string = "Default AST (%s)" % self.target | 
|---|
| 112 | self.flags  = """AST_FLAGS=""" | 
|---|
| 113 | else: | 
|---|
| 114 | print("""ERROR: Invalid ast configuration, must be "old", "new" or left unspecified, was %s""" % (value), file=sys.stderr) | 
|---|
| 115 | sys.exit(1) | 
|---|
| 116 |  | 
|---|
| 117 | def filter(self, tests): | 
|---|
| 118 |  | 
|---|
| 119 | return [test for test in tests if not test.astv or self.target == test.astv] | 
|---|
| 120 |  | 
|---|
| 121 | class Install: | 
|---|
| 122 | def __init__(self, value): | 
|---|
| 123 | if value: | 
|---|
| 124 | distribute = False | 
|---|
| 125 |  | 
|---|
| 126 | self.string = "installed" if value else "in tree" | 
|---|
| 127 | self.flags  = """installed=%s""" % ("yes" if value else "no") | 
|---|
| 128 |  | 
|---|
| 129 | class Timeouts: | 
|---|
| 130 | def __init__(self, ts, tg): | 
|---|
| 131 | self.single = Timeouts.check(ts) | 
|---|
| 132 | self.total  = Timeouts.check(tg) | 
|---|
| 133 |  | 
|---|
| 134 | @staticmethod | 
|---|
| 135 | def check(value): | 
|---|
| 136 | if value < 1: | 
|---|
| 137 | print("Timeouts must be at least 1 second", file=sys.stderr) | 
|---|
| 138 | sys.exit(1) | 
|---|
| 139 |  | 
|---|
| 140 | return value | 
|---|
| 141 |  | 
|---|
| 142 | def init( options ): | 
|---|
| 143 | global all_ast | 
|---|
| 144 | global all_arch | 
|---|
| 145 | global all_debug | 
|---|
| 146 | global all_install | 
|---|
| 147 | global ast | 
|---|
| 148 | global arch | 
|---|
| 149 | global debug | 
|---|
| 150 | global archive | 
|---|
| 151 | global install | 
|---|
| 152 |  | 
|---|
| 153 | global continue_ | 
|---|
| 154 | global dry_run | 
|---|
| 155 | global generating | 
|---|
| 156 | global make | 
|---|
| 157 | global output_width | 
|---|
| 158 | global timeout | 
|---|
| 159 | global timeout2gdb | 
|---|
| 160 |  | 
|---|
| 161 | all_ast      = [AST(o)          for o in list(dict.fromkeys(options.ast    ))] if options.ast  else [AST(None)] | 
|---|
| 162 | all_arch     = [Architecture(o) for o in list(dict.fromkeys(options.arch   ))] if options.arch else [Architecture(None)] | 
|---|
| 163 | all_debug    = [Debug(o)        for o in list(dict.fromkeys(options.debug  ))] | 
|---|
| 164 | all_install  = [Install(o)      for o in list(dict.fromkeys(options.install))] | 
|---|
| 165 | archive      = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None | 
|---|
| 166 | continue_    = options.continue_ | 
|---|
| 167 | dry_run      = options.dry_run # must be called before tools.config_hash() | 
|---|
| 168 | generating   = options.regenerate_expected | 
|---|
| 169 | make         = ['make'] | 
|---|
| 170 | output_width = 24 | 
|---|
| 171 | timeout      = Timeouts(options.timeout, options.global_timeout) | 
|---|
| 172 | timeout2gdb  = options.timeout_with_gdb | 
|---|
| 173 |  | 
|---|
| 174 | # if we distribute, distcc errors will fail tests, use log file for distcc | 
|---|
| 175 | # don't use "'DISTCC_LOG' not in os.environ" because it can be set to '' | 
|---|
| 176 | if distribute and not os.environ.get('DISTCC_LOG'): | 
|---|
| 177 | os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log')) | 
|---|
| 178 |  | 
|---|
| 179 | def update_make_cmd(force, jobs): | 
|---|
| 180 | global make | 
|---|
| 181 |  | 
|---|
| 182 | make = ['make'] if not force else ['make', "-j%i" % jobs] | 
|---|
| 183 |  | 
|---|
| 184 | def validate(): | 
|---|
| 185 | """Validate the current configuration and update globals""" | 
|---|
| 186 |  | 
|---|
| 187 | global distcc | 
|---|
| 188 | distcc       = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash() | 
|---|
| 189 | errf = os.path.join(BUILDDIR, ".validate.err") | 
|---|
| 190 | make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) | 
|---|
| 191 | if make_ret != 0: | 
|---|
| 192 | with open (errf, "r") as myfile: | 
|---|
| 193 | error=myfile.read() | 
|---|
| 194 | print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr) | 
|---|
| 195 | print("       verify returned : \n%s" % error, file=sys.stderr) | 
|---|
| 196 | tools.rm(errf) | 
|---|
| 197 | sys.exit(1) | 
|---|
| 198 |  | 
|---|
| 199 | tools.rm(errf) | 
|---|
| 200 |  | 
|---|
| 201 | def prep_output(tests): | 
|---|
| 202 | global output_width | 
|---|
| 203 | output_width = max(map(lambda t: len(t.target()), tests)) | 
|---|