def ListTests(self, current_path, path, mode, variant_flags): executable = 'cctest' if utils.IsWindows(): executable += '.exe' executable = join(self.context.buildspace, executable) if not exists(executable): executable = join('obj', 'test', mode, 'cctest') if utils.IsWindows(): executable += '.exe' executable = join(self.context.buildspace, executable) output = test.Execute([executable, '--list'], self.context) if output.exit_code != 0: print output.stdout print output.stderr return [] result = [] for test_desc in output.stdout.strip().split(): raw_test, dependency = test_desc.split('<') relative_path = raw_test.split('/') full_path = current_path + relative_path if dependency != '': dependency = relative_path[0] + '/' + dependency if self.Contains(path, full_path): result.append( CcTestCase(full_path, executable, mode, raw_test, dependency, self.context, variant_flags)) result.sort() return result
def ListTests(self, current_path, path, mode, variant_flags): executable = 'preparser' if utils.IsWindows(): executable += '.exe' executable = join(self.context.buildspace, executable) if not isfile(executable): executable = join('obj', 'preparser', mode, 'preparser') if utils.IsWindows(): executable += '.exe' executable = join(self.context.buildspace, executable) expectations = self.GetExpectations() result = [] # Find all .js files in tests/preparser directory. filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")] filenames.sort() for file in filenames: throws = None; if (file in expectations): throws = expectations[file] result.append(PreparserTestCase(self.root, current_path + [file], executable, mode, throws, self.context, None)) # Find all .pyt files in test/preparser directory. filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")] filenames.sort() for file in filenames: # Each file as a python source file to be executed in a specially # created environment (defining the Template and Test functions) self.ParsePythonTestTemplates(result, file, executable, current_path, mode) return result
def ProcessEditorArchive(arch, archive, outDir): tempDir = join(GetEditorTemp(), 'editor.out') try: os.makedirs(tempDir) except OSError: # Directory already exists. pass if utils.IsWindows(): f = zipfile.ZipFile(archive) f.extractall(tempDir) f.close() else: subprocess.call(['unzip', '-q', archive, '-d', tempDir]) if arch == 'x64': if utils.GuessOS() == 'macos': inifile = join(tempDir, 'dart', 'DartEditor.app', 'Contents', 'MacOS', 'DartEditor.ini') else: inifile = join(tempDir, 'dart', 'DartEditor.ini') Modify64BitDartEditorIni(inifile) for src in glob.glob(join(tempDir, 'dart', '*')): shutil.move(src, outDir) shutil.rmtree(tempDir) os.unlink(archive)
def __init__(self, cases, context, start_time): self.abort = False self.terminate = False self.cases = cases self.start_time = start_time self.queue = Queue.Queue(len(cases)) self.batch_queues = {} self.context = context # Extract batchable cases. found_cmds = {} for case in cases: cmd = case.case.GetCommand()[0] if not utils.IsWindows(): # Diagnostic check for executable (if an absolute pathname) if not cmd in found_cmds: if os.path.isabs(cmd) and not os.path.isfile(cmd): msg = "Can't find command %s\n" % cmd msg += '(Did you build first? ' msg += 'Are you running in the correct directory?)' raise Exception(msg) else: found_cmds[cmd] = 1 if case.case.IsBatchable(): if not cmd in self.batch_queues: self.batch_queues[cmd] = Queue.Queue(len(cases)) self.batch_queues[cmd].put(case) else: self.queue.put_nowait(case)
def main(argv): (options, args) = get_options() target = os.path.relpath(args[0]) if os.path.exists(target): # If the packages directory already exists, delete the current links inside # it. This is necessary, otherwise we can end up having links in there # pointing to directories which no longer exist (on incremental builds). for link in os.listdir(target): full_link = os.path.join(target, link) if os.path.isdir(full_link) and utils.IsWindows(): # It seems like python on Windows is treating pseudo symlinks to # directories as directories. os.rmdir(full_link) else: os.remove(full_link) else: os.makedirs(target) for source in args[1:]: # Assume the source directory is named ".../NAME/lib". (name, lib) = os.path.split(source) if lib != 'lib': name = source # Remove any addtional path components preceding NAME. (path, name) = os.path.split(name) orig_source = source if utils.GuessOS() == 'win32': source = os.path.relpath(source) else: source = os.path.relpath(source, start=target) exit_code = make_link(source, os.path.join(target, name), orig_source) if exit_code != 0: return exit_code create_timestamp_file(options) return 0
def GetExecutable(self, mode, arch, path): """Returns the name of the executable used to run the test.""" if self.executable is not None: return self.executable if utils.IsWindows() and not path.endswith('.exe'): return path + '.exe' else: return path
def findAbiVersion(version): cmd = ['cipd', 'instances', 'dart/abiversions/%d' % version] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=utils.IsWindows(), cwd=utils.DART_DIR) return procWait(p) == 0
def GetVm(self, mode): if mode == 'debug': name = 'build/debug/node_g' else: name = 'build/default/node' if utils.IsWindows() and not name.endswith('.exe'): name = name + '.exe' return name
def GetDartRunner(mode, arch, component): build_root = utils.GetBuildRoot(utils.GuessOS(), mode, arch) if component == 'frog': return os.path.join(build_root, 'frog', 'bin', 'frog') else: suffix = '' if utils.IsWindows(): suffix = '.exe' return os.path.join(build_root, 'dart') + suffix
def HasCrashed(self): if utils.IsWindows(): return 0x80000000 & self.output.exit_code and not (0x3FFFFF00 & self.output.exit_code) else: # Timed out tests will have exit_code -signal.SIGTERM. if self.output.timed_out: return False return self.output.exit_code < 0 and \ self.output.exit_code != -signal.SIGABRT
def RunProcess(context, timeout, args, **rest): """Handles the OS specific details of running a task and saving results.""" if context.verbose: print '#', ' '.join(args) popen_args = args prev_error_mode = SEM_INVALID_VALUE if utils.IsWindows(): popen_args = '"' + subprocess.list2cmdline(args) + '"' if context.suppress_dialogs: # Try to change the error mode to avoid dialogs on fatal errors. Don't # touch any existing error mode flags by merging the existing error mode. # See http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx. error_mode = SEM_NOGPFAULTERRORBOX prev_error_mode = Win32SetErrorMode(error_mode) Win32SetErrorMode(error_mode | prev_error_mode) process = subprocess.Popen(shell=utils.IsWindows(), args=popen_args, **rest) if (utils.IsWindows() and context.suppress_dialogs and prev_error_mode != SEM_INVALID_VALUE): Win32SetErrorMode(prev_error_mode) # Compute the end time - if the process crosses this limit we # consider it timed out. if timeout is None: end_time = None else: end_time = time.time() + timeout timed_out = False # Repeatedly check the exit code from the process in a # loop and keep track of whether or not it times out. exit_code = None sleep_time = INITIAL_SLEEP_TIME while exit_code is None: if (not end_time is None) and (time.time() >= end_time): # Kill the process and wait for it to exit. KillProcessWithID(process.pid) # Drain the output pipe from the process to avoid deadlock process.communicate() exit_code = process.wait() timed_out = True else: exit_code = process.poll() time.sleep(sleep_time) sleep_time *= SLEEP_TIME_FACTOR if sleep_time > MAX_SLEEP_TIME: sleep_time = MAX_SLEEP_TIME return (process, exit_code, timed_out)
def GetExecutable(self, mode, arch, name): """Returns the name of the executable used to run the test.""" if self.executable is not None: return self.executable path = os.path.abspath( os.path.join(self.GetBuildRoot(mode, arch), name)) if utils.IsWindows() and not path.endswith('.exe'): return path + '.exe' else: return path
def RunProcess(context, timeout, args, **rest): if context.verbose: print "#", " ".join(args) popen_args = args prev_error_mode = SEM_INVALID_VALUE process = None if utils.IsWindows(): if context.suppress_dialogs: # Try to change the error mode to avoid dialogs on fatal errors. Don't # touch any existing error mode flags by merging the existing error mode. # See http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx. error_mode = SEM_NOGPFAULTERRORBOX prev_error_mode = Win32SetErrorMode(error_mode) Win32SetErrorMode(error_mode | prev_error_mode) process = subprocess.Popen(shell=utils.IsWindows(), args=popen_args, **rest) else: process = subprocess.Popen(shell=utils.IsWindows(), args=popen_args, preexec_fn=os.setsid, **rest) if utils.IsWindows( ) and context.suppress_dialogs and prev_error_mode != SEM_INVALID_VALUE: Win32SetErrorMode(prev_error_mode) # Compute the end time - if the process crosses this limit we # consider it timed out. if timeout is None: end_time = None else: end_time = time.time() + timeout timed_out = False # Repeatedly check the exit code from the process in a # loop and keep track of whether or not it times out. exit_code = None sleep_time = INITIAL_SLEEP_TIME pgid = None if not utils.IsWindows(): pgid = os.getpgid(process.pid) while exit_code is None: if (not end_time is None) and (time.time() >= end_time): # Kill the process and wait for it to exit. KillProcessWithID(process.pid) if not utils.IsWindows(): os.killpg(pgid, signal.SIGTERM) exit_code = process.wait() timed_out = True else: exit_code = process.poll() time.sleep(sleep_time) sleep_time = sleep_time * SLEEP_TIME_FACTOR if sleep_time > MAX_SLEEP_TIME: sleep_time = MAX_SLEEP_TIME if not utils.IsWindows(): try: os.killpg(pgid, signal.SIGTERM) except: pass return (process, exit_code, timed_out)
def GetDartC(self, mode, arch): """Returns the path to the Dart --> JS compiler.""" dartc = os.path.abspath( os.path.join(self.GetBuildRoot(mode, arch), 'compiler', 'bin', 'dartc')) if utils.IsWindows(): dartc += '.exe' command = [dartc] # Add the flags from the context to the command line. command += self.flags return command
def GetCommand(self): if utils.IsWindows() and "BB_PYTHON" in os.environ: bbpython = os.environ["BB_PYTHON"] if bbpython.startswith('"') and bbpython.endswith('"'): bbpython = bbpython[1:-1] result = [bbpython] else: result = ['python'] result += [self.file + '/test.py'] return result
def main(argv): (options, args) = get_options() target = os.path.relpath(args[0]) if os.path.exists(target): # If the packages directory already exists, delete the current links inside # it. This is necessary, otherwise we can end up having links in there # pointing to directories which no longer exist (on incremental builds). for link in os.listdir(target): full_link = os.path.join(target, link) if os.path.isdir(full_link) and utils.IsWindows(): # It seems like python on Windows is treating pseudo symlinks to # directories as directories. os.rmdir(full_link) else: os.remove(full_link) else: os.makedirs(target) linked_names = {} for source in args[1:]: # Assume the source directory is named ".../NAME/lib". split = source.split(':') name = None if len(split) == 2: (source, name) = split (path, lib) = os.path.split(source) if lib != 'lib': path = source # Remove any additional path components preceding NAME, if one wasn't # specified explicitly. if not name: (_, name) = os.path.split(path) # We have an issue with left-behind checkouts in third_party/pkg and # third_party/pkg_tested when we move entries in DEPS. This reports them. if name in linked_names: print 'Duplicate directory %s is linked to both %s and %s.' % ( name, linked_names[name], path) if name in old_directories: print old_directories[name] return 1 linked_names[name] = path orig_source = source if utils.GuessOS() == 'win32': source = os.path.relpath(source) else: source = os.path.relpath(source, start=target) exit_code = make_link(options.quiet, source, os.path.join(target, name), orig_source) if exit_code != 0: return exit_code create_timestamp_file(options) return 0
def ProcessOptions(options, args): # Fix broken boolean parsing in argparse, where False ends up being True. if (options.silent is not None) and (options.silent == "True"): options.silent = True elif (options.silent is None) or (options.silent == "False"): options.silent = False else: print "--silent expects 'True' or 'False' argument." return False if (options.sdk is not None) and (options.sdk == "True"): options.sdk = True elif (options.sdk is None) or (options.sdk == "False"): options.sdk = False else: print "--sdk expects 'True' or 'False' argument." return False # Required options. if options.command is None or options.directory is None: return False # If a dart2js execuble was provided, try and use that. # TODO(whesse): Drop the dart2js-executable option if it isn't used. if options.dart2js_executable is not None: try: if 0 == RunCommand([options.dart2js_executable, '--version'], always_silent=True): return True except OSError as e: pass options.dart2js_executable = None # Use the checked in dart2js executable. if options.sdk and utils.CheckedInSdkCheckExecutable(): dart2js_binary = 'dart2js.bat' if utils.IsWindows() else 'dart2js' options.dart2js_executable = os.path.join(utils.CheckedInSdkPath(), 'bin', dart2js_binary) try: if 0 == RunCommand([options.dart2js_executable, '--version'], always_silent=True): return True except OSError as e: pass options.dart2js_executable = None # We need a dart executable and will run from source return (options.dart_executable is not None)
def main(): abi_version = int(utils.GetAbiVersion()) oldest_abi_version = int(utils.GetOldestSupportedAbiVersion()) cmd = ['cipd', 'ensure', '-root', 'tools/abiversions', '-ensure-file', '-'] ensure_file = '' for i in xrange(oldest_abi_version, abi_version): ensure_file += '@Subdir %d\ndart/abiversions/%d latest\n\n' % (i, i) if not ensure_file: return 0 p = subprocess.Popen(cmd, stdin = subprocess.PIPE, shell = utils.IsWindows(), cwd = utils.DART_DIR) p.communicate(ensure_file) p.stdin.close() return p.wait()
def ListTests(self, current_path, path, mode, variant_flags): executable = join('obj', 'preparser', mode, 'preparser') if utils.IsWindows(): executable += '.exe' executable = join(self.context.buildspace, executable) # Find all .js files in tests/preparser directory. filenames = [ f[:-3] for f in os.listdir(self.root) if f.endswith(".js") ] filenames.sort() result = [] for file in filenames: result.append( PreparserTestCase(self.root, current_path + [file], executable, mode, self.context)) return result
def HasCrashed(self): """Returns True if the test should be considered testing.CRASH.""" if utils.IsWindows(): if self.output.exit_code == 3: # The VM uses std::abort to terminate on asserts. # std::abort terminates with exit code 3 on Windows. return True return (0x80000000 & self.output.exit_code and not 0x3FFFFF00 & self.output.exit_code) else: # Timed out tests will have exit_code -signal.SIGTERM. if self.output.timed_out: return False if self.output.exit_code == 253: # The Java dartc runners exit 253 in case of unhandled exceptions. return True return self.output.exit_code < 0
def GetVm(self, mode): name = './launchtest.sh' # Currently GYP does not support output_dir for MSVS. # http://code.google.com/p/gyp/issues/detail?id=40 # It will put the builds into Release/node.exe or Debug/node.exe if utils.IsWindows(): out_dir = os.path.join(dirname(__file__), "..", "out") if not exists(out_dir): if mode == 'debug': name = os.path.abspath('Debug/node.exe') else: name = os.path.abspath('Release/node.exe') else: name = os.path.abspath(name + '.exe') return name
def BuildGnCommand(args, mode, arch, target_os, sanitizer, out_dir): gn = os.path.join(DART_ROOT, 'buildtools', 'gn.exe' if utils.IsWindows() else 'gn') if not os.path.isfile(gn): raise Exception("Couldn't find the gn binary at path: " + gn) # TODO(infra): Re-enable --check. Many targets fail to use # public_deps to re-expose header files to their dependents. # See dartbug.com/32364 command = [gn, 'gen', out_dir] gn_args = ToCommandLine( ToGnArgs(args, mode, arch, target_os, sanitizer, args.verify_sdk_hash)) gn_args += GetGNArgs(args) if args.ide: command.append(ide_switch(HOST_OS)) command.append('--args=%s' % ' '.join(gn_args)) return command
def ListTests(self, current_path, path, arch, mode): all_tests = [current_path + [t] for t in self.Ls(self.root)] result = [] # Skip these tests on Windows, as pseudo terminals are not available if utils.IsWindows(): print ("Skipping pseudo-tty tests, as pseudo terminals are not available" " on Windows.") return result for test in all_tests: if self.Contains(path, test): file_prefix = join(self.root, reduce(join, test[1:], "")) file_path = file_prefix + ".js" output_path = file_prefix + ".out" if not exists(output_path): raise Exception("Could not find %s" % output_path) result.append(TTYTestCase(test, file_path, output_path, arch, mode, self.context, self)) return result
def Main(): args = sys.argv[1:] tools_dir = os.path.dirname(os.path.realpath(__file__)) dart_binary_prefix = os.path.join(tools_dir, 'testing', 'bin') if utils.IsWindows(): dart_binary = os.path.join(dart_binary_prefix, 'windows', 'dart.exe') else: dart_binary = os.path.join(dart_binary_prefix, utils.GuessOS(), 'dart') current_directory = os.path.abspath(''); client = os.path.abspath(os.path.join(tools_dir, '..')); if current_directory == os.path.join(client, 'runtime'): dart_script_name = 'test-runtime.dart' else: dart_script_name = 'test.dart' dart_test_script = string.join([tools_dir, dart_script_name], os.sep) command = [dart_binary, dart_test_script] + args exit_code = subprocess.call(command) utils.DiagnoseExitCode(exit_code, command) return exit_code
def GetCompileCommand(self, fatal_static_type_errors=False): """Returns cmdline as an array to invoke the compiler on this test.""" # We need an absolute path because the compilation will run # in a temporary directory. build_root = utils.GetBuildRoot(OS_GUESS, self.mode, 'dartc') dartc = os.path.abspath( os.path.join(build_root, 'compiler', 'bin', 'dartc')) if utils.IsWindows(): dartc += '.exe' cmd = [dartc, '--work', self.temp_dir] if self.mode == 'release': cmd += ['--optimize'] cmd += self.vm_options cmd += ['--out', self.GetScriptPath()] if fatal_static_type_errors: # TODO(zundel): update to --fatal_type_errors for both VM and Compiler cmd.append('-fatal-type-errors') cmd.append(self.GetTestScriptFile()) return cmd
def Main(argv): starttime = time.time() args = parse_args(argv) gn = os.path.join(DART_ROOT, 'buildtools', 'gn.exe' if utils.IsWindows() else 'gn') if not os.path.isfile(gn): print("Couldn't find the gn binary at path: " + gn) return 1 commands = [] for target_os in args.os: for mode in args.mode: for arch in args.arch: for sanitizer in args.sanitizer: out_dir = GetOutDir(mode, arch, target_os, sanitizer, args.no_nnbd) # TODO(infra): Re-enable --check. Many targets fail to use # public_deps to re-expose header files to their dependents. # See dartbug.com/32364 command = [gn, 'gen', out_dir] gn_args = ToCommandLine( ToGnArgs(args, mode, arch, target_os, sanitizer, args.no_nnbd)) gn_args += GetGNArgs(args) if args.verbose: print("gn gen --check in %s" % out_dir) if args.ide: command.append(ide_switch(HOST_OS)) command.append('--args=%s' % ' '.join(gn_args)) commands.append(command) pool = multiprocessing.Pool(args.workers) results = pool.map(RunCommand, commands, chunksize=1) for r in results: if r != 0: print(r.strip()) return 1 endtime = time.time() if args.verbose: print("GN Time: %.3f seconds" % (endtime - starttime)) return 0
def ProcessEditorArchive(archive, outDir): tempDir = join(GetEditorTemp(), 'editor.out') try: os.makedirs(tempDir) except OSError: # Directory already exists. pass if utils.IsWindows(): f = zipfile.ZipFile(archive) f.extractall(tempDir) f.close() else: subprocess.call(['unzip', '-q', archive, '-d', tempDir]) for src in glob.glob(join(tempDir, 'dart', '*')): shutil.move(src, outDir) shutil.rmtree(tempDir) os.unlink(archive)
def GetVm(self, arch, mode): if arch == 'none': name = 'out/Debug/iojs' if mode == 'debug' else 'out/Release/iojs' else: name = 'out/%s.%s/iojs' % (arch, mode) # Currently GYP does not support output_dir for MSVS. # http://code.google.com/p/gyp/issues/detail?id=40 # It will put the builds into Release/iojs.exe or Debug/iojs.exe if utils.IsWindows(): out_dir = os.path.join(dirname(__file__), "..", "out") if not exists(out_dir): if mode == 'debug': name = os.path.abspath('Debug/iojs.exe') else: name = os.path.abspath('Release/iojs.exe') else: name = os.path.abspath(name + '.exe') return name
def __init__(self, work_queue, tasks, progress, batch_cmd): super(BatchRunner, self).__init__(work_queue, tasks, progress) self.runners = {} self.last_activity = {} self.context = progress.context # Scale the number of tasks to the nubmer of CPUs on the machine # 1:1 is too much of an overload on many machines in batch mode, # so scale the ratio of threads to CPUs back. On Windows running # more than one task is not safe. if tasks == testing.USE_DEFAULT_CPUS: if utils.IsWindows(): tasks = 1 else: tasks = .75 * testing.HOST_CPUS # Start threads for i in xrange(tasks): thread = threading.Thread(target=self.RunThread, args=[batch_cmd, i]) self.threads.append(thread) thread.daemon = True thread.start()
def GetVm(self, mode): name = self.vm_root + SUFFIX[mode] if utils.IsWindows() and not name.endswith('.exe'): name = name + '.exe' return name