Changeset 4a60488 for tests/pybin
- Timestamp:
- Sep 27, 2019, 3:35:46 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 90ce35aa
- Parents:
- 8e1467d (diff), 849720f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- tests/pybin
- Files:
-
- 2 edited
-
settings.py (modified) (8 diffs)
-
tools.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/settings.py
r8e1467d r4a60488 4 4 from . import tools 5 5 6 global original_path 7 6 8 try : 9 original_path = os.getcwd() 7 10 testpath = os.path.dirname(os.path.abspath(os.path.join(os.getcwd(), sys.argv[0]))) 8 11 sys.path.append(testpath) … … 11 14 SRCDIR = os.path.abspath(config.SRCDIR) 12 15 BUILDDIR = os.path.abspath(config.BUILDDIR) 16 distribute = config.DISTRIBUTE 13 17 os.chdir(testpath) 14 18 … … 19 23 class Architecture: 20 24 KnownArchitectures = { 21 'x64' : 'x64', 22 'x86-64' : 'x64', 23 'x86_64' : 'x64', 24 'x86' : 'x86', 25 'x64' : 'x64', 26 'x86-64' : 'x64', 27 'x86_64' : 'x64', 28 'x86' : 'x86', 29 'aarch64' : 'arm', 25 30 'i386' : 'x86', 26 31 'i486' : 'x86', 27 32 'i686' : 'x86', 28 33 'Intel 80386' : 'x86', 29 'arm' : 'arm',30 'ARM' : 'arm',34 'arm' : 'arm', 35 'ARM' : 'arm', 31 36 } 32 37 … … 40 45 canonical_host = Architecture.make_canonical( config.HOSTARCH ) 41 46 except KeyError: 42 print("Unk own host architecture %s" % config.HOSTARCH, file=sys.stderr)47 print("Unknown host architecture %s" % config.HOSTARCH, file=sys.stderr) 43 48 sys.exit(1) 44 49 … … 47 52 arch = Architecture.make_canonical( arch ) 48 53 except KeyError: 49 print("Unk own architecture %s" % arch, file=sys.stderr)54 print("Unknown architecture %s" % arch, file=sys.stderr) 50 55 sys.exit(1) 51 56 … … 84 89 self.string = "debug" if value else "no debug" 85 90 self.flags = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2") 91 self.path = "debug" if value else "nodebug" 86 92 87 93 class Install: 88 94 def __init__(self, value): 89 self.string = "installed" if value else "in-tree" 90 self.flags = """INSTALL_FLAGS=%s""" % ("" if value else "-in-tree") 95 if value: 96 distribute = False 97 98 self.string = "installed" if value else "in tree" 99 self.flags = """installed=%s""" % ("yes" if value else "no") 91 100 92 101 class Timeouts: … … 105 114 def init( options ): 106 115 global arch 116 global archive 117 global debug 118 global distcc 107 119 global dry_run 108 120 global generating 121 global install 109 122 global make 110 global debug 111 global install 123 global output_width 112 124 global timeout 113 global output_width114 125 115 dry_run = options.dry_run 126 arch = Architecture(options.arch) 127 archive = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None 128 debug = Debug(options.debug) 129 dry_run = options.dry_run # must be called before tools.config_hash() 130 distcc = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash() 116 131 generating = options.regenerate_expected 132 install = Install(options.install) 117 133 make = ['make'] 118 debug = Debug(options.debug) 119 install = Install(options.install) 120 arch = Architecture(options.arch) 134 output_width = 24 121 135 timeout = Timeouts(options.timeout, options.global_timeout) 122 output_width = 24123 136 137 # if we distribute, distcc errors will fail tests, use log file for distcc 138 # don't use "'DISTCC_LOG' not in os.environ" because it can be set to '' 139 if distribute and not os.environ.get('DISTCC_LOG'): 140 os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log')) 124 141 125 142 def update_make_cmd(force, jobs): … … 130 147 def validate(): 131 148 errf = os.path.join(BUILDDIR, ".validate.err") 132 make_ret, out = tools.make( ".validate", error_file = errf, output =subprocess.DEVNULL, error=subprocess.DEVNULL )149 make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) 133 150 if make_ret != 0: 134 151 with open (errf, "r") as myfile: -
tests/pybin/tools.py
r8e1467d r4a60488 2 2 import argparse 3 3 import contextlib 4 import datetime 4 5 import fileinput 5 6 import multiprocessing … … 22 23 23 24 # helper functions to run terminal commands 24 def sh(*cmd, timeout = False, output = None, input = None, error = subprocess.STDOUT):25 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False): 25 26 cmd = list(cmd) 26 27 28 if input_file and input_text: 29 return 401, "Cannot use both text and file inputs" 30 27 31 # if this is a dry_run, only print the commands that would be ran 28 if settings.dry_run :32 if settings.dry_run and not ignore_dry_run: 29 33 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 30 if output and not isinstance(output, int):34 if output_file and not isinstance(output_file, int): 31 35 cmd += " > " 32 cmd += output 36 cmd += output_file 33 37 34 38 if error and not isinstance(error, int): … … 36 40 cmd += error 37 41 38 if input and not isinstance(input, int) and os.path.isfile(input):42 if input_file and not isinstance(input_file, int) and os.path.isfile(input_file): 39 43 cmd += " < " 40 cmd += input 44 cmd += input_file 41 45 42 46 print(cmd) … … 45 49 with contextlib.ExitStack() as onexit: 46 50 # add input redirection if needed 47 input = openfd(input, 'r', onexit, True)51 input_file = openfd(input_file, 'r', onexit, True) 48 52 49 53 # add output redirection if needed 50 output = openfd(output, 'w', onexit, False)54 output_file = openfd(output_file, 'w', onexit, False) 51 55 52 56 # add error redirection if needed … … 57 61 proc = subprocess.run( 58 62 cmd, 59 stdin =input,60 stdout =output,61 stderr =error,62 timeout =settings.timeout.single if timeout else None63 **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}), 64 stdout = output_file, 65 stderr = error, 66 timeout = settings.timeout.single if timeout else None 63 67 ) 68 64 69 return proc.returncode, proc.stdout.decode("utf-8") if proc.stdout else None 65 70 except subprocess.TimeoutExpired: … … 74 79 return False 75 80 76 code, out = sh("file %s" % fname, output =subprocess.PIPE)81 code, out = sh("file %s" % fname, output_file=subprocess.PIPE) 77 82 if code != 0: 78 83 return False … … 106 111 if isinstance(files, str ): files = [ files ] 107 112 for file in files: 108 sh( 'rm', '-f', file, output =subprocess.DEVNULL, error=subprocess.DEVNULL )113 sh( 'rm', '-f', file, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) 109 114 110 115 # Create 1 or more directory … … 114 119 p = os.path.normpath( file ) 115 120 d = os.path.dirname ( p ) 116 sh( 'mkdir', '-p', d, output =subprocess.DEVNULL, error=subprocess.DEVNULL )121 sh( 'mkdir', '-p', d, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) 117 122 118 123 … … 137 142 lhs, 138 143 rhs, 139 output =subprocess.PIPE144 output_file=subprocess.PIPE 140 145 ) 141 146 142 147 # call make 143 def make(target, *, flags = '', output = None, error = None, error_file = None, silent = False):148 def make(target, *, flags = '', output_file = None, error = None, error_file = None, silent = False): 144 149 test_param = """test="%s" """ % (error_file) if error_file else None 145 150 cmd = [ … … 150 155 settings.debug.flags, 151 156 settings.install.flags, 157 settings.distcc if settings.distribute else None, 152 158 flags, 153 159 target 154 160 ] 155 161 cmd = [s for s in cmd if s] 156 return sh(*cmd, output =output, error=error)162 return sh(*cmd, output_file=output_file, error=error) 157 163 158 164 def which(program): … … 200 206 # cat one file into the other 201 207 def cat(source, dest): 202 ret, _ = sh("cat", source, output =dest)208 ret, _ = sh("cat", source, output_file=dest) 203 209 return ret 204 210 … … 255 261 os.write(int(make_jobs_fds.group(3)), tokens) 256 262 else : 257 options.jobs = multiprocessing.cpu_count() 263 if settings.distribute: 264 ret, jstr = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True) 265 if ret == 0: 266 options.jobs = int(jstr.strip()) 267 else : 268 options.jobs = multiprocessing.cpu_count() 269 else: 270 options.jobs = multiprocessing.cpu_count() 258 271 else : 259 272 force = True … … 272 285 # misc 273 286 ################################################################################ 287 288 # get hash for given configuration 289 def config_hash(): 290 path = os.path.normpath(os.path.join( 291 settings.SRCDIR, 292 )) 293 294 distcc_hash = os.path.join(settings.SRCDIR, '../tools/build/distcc_hash') 295 config = "%s-%s" % (settings.arch.target, settings.debug.path) 296 _, out = sh(distcc_hash, config, output_file=subprocess.PIPE, ignore_dry_run=True) 297 return out.strip() 298 299 # get pretty string for time of day 300 def pretty_now(): 301 ts = time.time() 302 print(ts, file=sys.stderr) 303 return datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S') 274 304 275 305 # check if arguments is yes or no … … 302 332 return 1, "ERR No core dump" 303 333 304 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output=subprocess.PIPE) 334 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE) 335 336 def core_archive(dst, name, exe): 337 # Get the core dump 338 core = os.path.join(os.getcwd(), "core" ) 339 340 # update the path for this test 341 dst = os.path.join(dst, name) 342 343 # make a directory for this test 344 # mkdir makes the parent directory only so add a dummy 345 mkdir(os.path.join(dst, "dir")) 346 347 # moves the files 348 mv( core, os.path.join(dst, "core" ) ) 349 mv( exe , os.path.join(dst, name ) ) 350 351 # return explanatory test 352 return "Archiving %s (executable and core) to %s" % (os.path.relpath(exe, settings.BUILDDIR), os.path.relpath(dst, settings.original_path)) 305 353 306 354 class Timed:
Note:
See TracChangeset
for help on using the changeset viewer.