def RunTest(test): command = [test_runner, test] + test_runner_runtime_options if test_runner_under_valgrind: command = ['valgrind'] + command p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p_out, p_err = p.communicate() rc = p.poll() if rc == 0: with n_tests_passed.get_lock(): n_tests_passed.value += 1 else: with n_tests_failed.get_lock(): n_tests_failed.value += 1 printer.__print_lock__.acquire() printer.UpdateProgress(start_time, n_tests_passed.value, n_tests_failed.value, n_tests, test, prevent_next_overwrite = (rc != 0), has_lock = True, prefix = progress_prefix) if rc != 0: printer.Print('FAILED: ' + test, has_lock = True) printer.Print(printer.COLOUR_RED + ' '.join(command) + printer.NO_COLOUR, has_lock = True) printer.Print(p_out, has_lock = True) printer.__print_lock__.release()
def Run(self, jobs, verbose, run_function): def InitGlobals(): # Initialisation. self.start_time = time.time() self.n_tests = len(self.queue) if self.n_tests == 0: printer.Print('No tests to run.') return False Test.n_tests_passed.value = 0 Test.n_tests_failed.value = 0 Test.n_tests_skipped.value = 0 self.tests_skipped.clear() return True thread_pool.Multithread(run_function, self.queue, jobs, InitGlobals) printer.UpdateProgress(self.start_time, Test.n_tests_passed.value, Test.n_tests_failed.value, self.n_tests, Test.n_tests_skipped.value, self.n_known_failures, '== Done ==', prevent_next_overwrite=True, prefix=self.progress_prefix) n_tests_features = 0 features = set() for reason, n_tests in list(self.tests_skipped.items()): m = re.match(REGEXP_MISSING_FEATURES, reason) if m: if verbose: printer.Print( "%d tests skipped because the following features are not " "available '%s'" % (n_tests, m.group(1))) else: n_tests_features += n_tests features.update(m.group(1).split(', ')) else: printer.Print("%d tests skipped because '%s'" % (n_tests, reason)) n_tests_other = 0 if n_tests_features > 0: printer.Print("%d tests skipped because the CPU does not support " "the following features: '%s'" % (n_tests_features, ", ".join(features))) for reason, n_tests in list(self.known_failures.items()): printer.Print("%d tests skipped because '%s'" % (n_tests, reason)) # Empty the queue now that the tests have been run. self.queue = [] # `0` indicates success return Test.n_tests_failed.value
def RunTests(test_runner_command, filters, runtime_options, under_valgrind=False, jobs=1, prefix=''): global test_runner global test_runner_runtime_options global test_runner_under_valgrind global n_tests global start_time global progress_prefix tests = GetTests(test_runner_command, filters) tests = FilterKnownTestFailures(tests, under_valgrind=under_valgrind) if n_tests == 0: printer.Print('No tests to run.') return 0 with __run_tests_lock__: # Initialisation. start_time = time.time() test_runner = test_runner_command test_runner_runtime_options = runtime_options test_runner_under_valgrind = under_valgrind n_tests = len(tests) n_tests_passed.value = 0 n_tests_failed.value = 0 progress_prefix = prefix pool = multiprocessing.Pool(jobs) # The '.get(9999999)' is a workaround to allow killing the test script with # ctrl+C from the shell. This bug is documented at # http://bugs.python.org/issue8296. work = pool.map_async(RunTest, tests).get(9999999) pool.close() pool.join() printer.UpdateProgress(start_time, n_tests_passed.value, n_tests_failed.value, n_tests, '== Done ==', prevent_next_overwrite=True, prefix=progress_prefix) # `0` indicates success return n_tests_failed.value
def RunTest(test): command = test.args['command'] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p_out, p_err = p.communicate() rc = p.poll() if rc == 0: skipped = False lines = p_out.split('\n') skipped_id = "SKIPPED: " for i in range(len(lines)): if lines[i].startswith(skipped_id): skipped = True reason = lines[i][len(skipped_id):] with Test.n_tests_skipped.get_lock(): Test.n_tests_skipped.value += 1 test.shared.tests_skipped.setdefault(reason, 0) test.shared.tests_skipped[reason] += 1 break if not skipped: with Test.n_tests_passed.get_lock(): Test.n_tests_passed.value += 1 else: with Test.n_tests_failed.get_lock(): Test.n_tests_failed.value += 1 printer.__print_lock__.acquire() printer.UpdateProgress(test.shared.start_time, Test.n_tests_passed.value, Test.n_tests_failed.value, test.shared.n_tests, Test.n_tests_skipped.value, test.shared.n_known_failures, test.name, prevent_next_overwrite=(rc != 0), has_lock=True, prefix=test.shared.progress_prefix) if rc != 0: printer.Print('FAILED: ' + test.name, has_lock=True) printer.Print(printer.COLOUR_RED + ' '.join(command) + printer.NO_COLOUR, has_lock=True) printer.Print(p_out, has_lock=True) printer.__print_lock__.release()
def RunTest(test): cmd = " ".join(test.args['command']) rc, p_out = util.getstatusoutput(cmd) if rc != 0: # This usually happens when the compiler hits a '#error' because of # a missing define. printer.Print("%sFATAL ERROR: failed to run command '%s': %s%s" % (printer.COLOUR_RED, cmd, p_out, printer.NO_COLOUR)) p_out = FilterClangTidyLines(p_out.split('\n')) failed = (len(p_out) > 0) or (rc != 0) if failed: with Test.n_tests_failed.get_lock(): Test.n_tests_failed.value += 1 else: with Test.n_tests_passed.get_lock(): Test.n_tests_passed.value += 1 printer.__print_lock__.acquire() printer.UpdateProgress(test.shared.start_time, Test.n_tests_passed.value, Test.n_tests_failed.value, test.shared.n_tests, Test.n_tests_skipped.value, test.shared.n_known_failures, test.name, prevent_next_overwrite=failed, has_lock=True, prefix=test.shared.progress_prefix) if failed: printer.Print(printer.COLOUR_RED + 'FAILED: ' + cmd + printer.NO_COLOUR, has_lock=True) printer.Print(p_out, has_lock=True) printer.__print_lock__.release()
def RunTest(test): filename = test.args['filename'] clang_format = test.args['clang_format'] in_place = test.args['in_place'] rc = 0 cmd_format = [clang_format, filename] temp_file, temp_file_name = tempfile.mkstemp(prefix='clang_format_') cmd_format_string = '$ ' + ' '.join(cmd_format) + ' > %s' % temp_file_name p_format = subprocess.Popen(cmd_format, stdout=temp_file, stderr=subprocess.STDOUT) rc += p_format.wait() cmd_diff = ['diff', '--unified', filename, temp_file_name] cmd_diff_string = '$ ' + ' '.join(cmd_diff) p_diff = subprocess.Popen(cmd_diff, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if util.IsCommandAvailable('colordiff') and not is_output_redirected: p_colordiff = subprocess.Popen(['colordiff', '--unified'], stdin=p_diff.stdout, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, unused = p_colordiff.communicate() else: out, unused = p_diff.communicate() rc += p_diff.wait() if in_place: cmd_format = [clang_format, '-i', filename] p_format = subprocess.Popen(cmd_format, stdout=temp_file, stderr=subprocess.STDOUT) if rc != 0: with Test.n_tests_failed.get_lock(): Test.n_tests_failed.value += 1 else: with Test.n_tests_passed.get_lock(): Test.n_tests_passed.value += 1 printer.__print_lock__.acquire() printer.UpdateProgress(test.shared.start_time, Test.n_tests_passed.value, Test.n_tests_failed.value, test.shared.n_tests, Test.n_tests_skipped.value, test.shared.n_known_failures, test.name, prevent_next_overwrite=rc != 0, has_lock=True, prefix=test.shared.progress_prefix) if rc != 0: printer.Print('Incorrectly formatted file: ' + filename + '\n' + \ cmd_format_string + '\n' + \ cmd_diff_string + '\n' + \ out, has_lock = True) printer.__print_lock__.release() os.remove(temp_file_name)