source: tests/pybin/settings.py@ dbb1073

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since dbb1073 was 99581ee, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Tests now support the --ast flag, Makefile still doesn't

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[f85bc15]1import os
[a45fc7b]2import subprocess
[f3b9efc]3import sys
[5b993e0]4from . import tools
[bacc36c]5
[dcfedca]6global original_path
7
[f85bc15]8try :
[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]19except:
20 print('ERROR: missing config.py, re-run configure script.', file=sys.stderr)
21 sys.exit(1)
22
[bacc36c]23class Architecture:
[f3b9efc]24 KnownArchitectures = {
[41af19c]25 'x64' : 'x64',
26 'x86-64' : 'x64',
27 'x86_64' : 'x64',
28 'x86' : 'x86',
[9509a412]29 'aarch64' : 'arm64',
30 'arm64' : 'arm64',
31 'ARM64' : 'arm64',
[41af19c]32 'i386' : 'x86',
33 'i486' : 'x86',
34 'i686' : 'x86',
35 'Intel 80386' : 'x86',
[9509a412]36 'arm' : 'arm32',
37 'ARM' : 'arm32',
38 'arm32' : 'arm32',
39 'ARM32' : 'arm32',
[f3b9efc]40 }
41
[575a6e5]42 CrossCompileFlags = {
[9509a412]43 'x64' : 'ARCH_FLAGS=-m64',
44 'x86' : 'ARCH_FLAGS=-m32',
45 'arm64': 'ARCH_FLAGS=',
46 'arm32': 'ARCH_FLAGS=',
[575a6e5]47 }
48
[f3b9efc]49 def __init__(self, arch):
[575a6e5]50 try:
[5bf1f3e]51 canonical_host = Architecture.make_canonical( config.HOSTARCH )
[575a6e5]52 except KeyError:
[d82892a]53 print("Unknown host architecture %s" % config.HOSTARCH, file=sys.stderr)
[575a6e5]54 sys.exit(1)
55
[f3b9efc]56 if arch:
57 try:
[5bf1f3e]58 arch = Architecture.make_canonical( arch )
[f3b9efc]59 except KeyError:
[d82892a]60 print("Unknown architecture %s" % arch, file=sys.stderr)
[f3b9efc]61 sys.exit(1)
[575a6e5]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
[47c1928]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)
[575a6e5]76
[f3b9efc]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
[136f86b]85 def filter(self, tests):
86 return [test for test in tests if not test.arch or self.target == test.arch]
[f3b9efc]87 return True if not arch else self.target == arch
88
[64cf022]89 @staticmethod
90 def make_canonical(arch):
[f3b9efc]91 return Architecture.KnownArchitectures[arch]
92
[bacc36c]93
[f3b9efc]94class Debug:
95 def __init__(self, value):
96 self.string = "debug" if value else "no debug"
[a45fc7b]97 self.flags = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2")
[d65f92c]98 self.path = "debug" if value else "nodebug"
[bacc36c]99
[99581ee]100class AST:
101 def __init__(self, ast):
102 if ast == "new":
103 self.string = "New AST"
104 self.flags = """AST_FLAGS=-XCFA,--new-ast"""
105 elif ast == "old":
106 self.string = "Old AST"
107 self.flags = """AST_FLAGS=-XCFA,--old-ast"""
108 elif ast == None:
109 self.string = "Default AST (%s)" % ("new" if config.NEWAST else "old")
110 self.flags = """AST_FLAGS="""
111 else:
112 print("""ERROR: Invalid ast configuration, must be "old", "new" or left unspecified, was %s""" % (value), file=sys.stderr)
113
[a5121bf]114class Install:
115 def __init__(self, value):
[d65f92c]116 if value:
117 distribute = False
118
[abec2f8]119 self.string = "installed" if value else "in tree"
[158b026]120 self.flags = """installed=%s""" % ("yes" if value else "no")
[a5121bf]121
[afe8882]122class Timeouts:
123 def __init__(self, ts, tg):
124 self.single = Timeouts.check(ts)
125 self.total = Timeouts.check(tg)
126
[64cf022]127 @staticmethod
128 def check(value):
[afe8882]129 if value < 1:
130 print("Timeouts must be at least 1 second", file=sys.stderr)
131 sys.exit(1)
132
133 return value
134
[bacc36c]135def init( options ):
[99581ee]136 global all_ast
[136f86b]137 global all_arch
138 global all_debug
139 global all_install
[99581ee]140 global ast
[bacc36c]141 global arch
[99581ee]142 global debug
[6daaee3]143 global archive
[99581ee]144 global install
145
[136f86b]146 global continue_
[bacc36c]147 global dry_run
148 global generating
[6daaee3]149 global make
[5bf1f3e]150 global output_width
[6daaee3]151 global timeout
[d658183]152 global timeout2gdb
[bacc36c]153
[99581ee]154 all_ast = [AST(o) for o in list(dict.fromkeys(options.ast ))] if options.ast else [AST(None)]
[41af19c]155 all_arch = [Architecture(o) for o in list(dict.fromkeys(options.arch ))] if options.arch else [Architecture(None)]
[136f86b]156 all_debug = [Debug(o) for o in list(dict.fromkeys(options.debug ))]
157 all_install = [Install(o) for o in list(dict.fromkeys(options.install))]
[6daaee3]158 archive = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
[136f86b]159 continue_ = options.continue_
[8209e70]160 dry_run = options.dry_run # must be called before tools.config_hash()
[5bf1f3e]161 generating = options.regenerate_expected
[6daaee3]162 make = ['make']
[5bf1f3e]163 output_width = 24
[6daaee3]164 timeout = Timeouts(options.timeout, options.global_timeout)
[d658183]165 timeout2gdb = options.timeout_with_gdb
[bacc36c]166
[17bc05b]167 # if we distribute, distcc errors will fail tests, use log file for distcc
168 # don't use "'DISTCC_LOG' not in os.environ" because it can be set to ''
[d65f92c]169 if distribute and not os.environ.get('DISTCC_LOG'):
170 os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log'))
[f85bc15]171
[5bf1f3e]172def update_make_cmd(force, jobs):
[bacc36c]173 global make
174
[a45fc7b]175 make = ['make'] if not force else ['make', "-j%i" % jobs]
[28582b2]176
177def validate():
[136f86b]178 """Validate the current configuration and update globals"""
179
180 global distcc
181 distcc = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash()
[afe8882]182 errf = os.path.join(BUILDDIR, ".validate.err")
[d65f92c]183 make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
[28582b2]184 if make_ret != 0:
[afe8882]185 with open (errf, "r") as myfile:
[28582b2]186 error=myfile.read()
[575a6e5]187 print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr)
[28582b2]188 print(" verify returned : \n%s" % error, file=sys.stderr)
[afe8882]189 tools.rm(errf)
[28582b2]190 sys.exit(1)
191
[d3c1c6a]192 tools.rm(errf)
193
194def prep_output(tests):
[5bf1f3e]195 global output_width
196 output_width = max(map(lambda t: len(t.target()), tests))
Note: See TracBrowser for help on using the repository browser.