def _run_single_test(self, binary_name, test): server_process = ServerProcess( self._port, binary_name, Runner.command_for_port(self._port, [ self._port._build_path(binary_name), '--gtest_filter={}'.format(test) ]), env=self._port.environment_for_api_tests()) try: deadline = time.time() + self._timeout server_process.start() if not test.split('.')[1].startswith('DISABLED_'): stdout_line = server_process.read_stdout_line(deadline) else: stdout_line = None if not stdout_line and server_process.timed_out: status = Runner.STATUS_TIMEOUT elif not stdout_line and server_process.has_crashed(): status = Runner.STATUS_CRASHED elif not stdout_line: status = Runner.STATUS_DISABLED elif '**PASS**' in stdout_line: status = Runner.STATUS_PASSED else: status = Runner.STATUS_FAILED finally: output_buffer = server_process.pop_all_buffered_stdout( ) + server_process.pop_all_buffered_stderr() server_process.stop() self._caller.post('ended_test', '{}.{}'.format(binary_name, test), status, self._filter_noisy_output(output_buffer))
def _run_shard_with_binary(self, binary_name, tests): remaining_tests = list(tests) # Try to run the shard in a single process. while remaining_tests and not self._port.get_option('run_singly'): starting_length = len(remaining_tests) server_process = ServerProcess( self._port, binary_name, Runner.command_for_port(self._port, [ self._port._build_path(binary_name), '--gtest_filter={}'.format(':'.join(remaining_tests)) ]), env=self._port.environment_for_api_tests()) try: deadline = time.time() + self._timeout last_test = None last_status = None stdout_buffer = '' server_process.start() while remaining_tests: stdout = server_process.read_stdout_line(deadline) # If we've triggered a timeout, we don't know which test caused it. Break out and run singly. if stdout is None and server_process.timed_out: break if stdout is None and server_process.has_crashed(): # It's possible we crashed before printing anything. if last_status == Runner.STATUS_PASSED: last_test = None else: last_status = Runner.STATUS_CRASHED break assert stdout is not None stdout_split = stdout.rstrip().split(' ') if len(stdout_split) != 2 or not ( stdout_split[0].startswith('**') and stdout_split[0].endswith('**')): stdout_buffer += stdout continue if last_test is not None: remaining_tests.remove(last_test) self.post('ended_test', '{}.{}'.format(binary_name, last_test), last_status, stdout_buffer) deadline = time.time() + self._timeout stdout_buffer = '' if '**PASS**' == stdout_split[0]: last_status = Runner.STATUS_PASSED else: last_status = Runner.STATUS_FAILED last_test = stdout_split[1] # We assume that stderr is only relevant if there is a crash (meaning we triggered an assert) if last_test: remaining_tests.remove(last_test) stdout_buffer += server_process.pop_all_buffered_stdout() stderr_buffer = server_process.pop_all_buffered_stderr( ) if last_status == Runner.STATUS_CRASHED else '' self.post('log', output=stdout_buffer + stderr_buffer) self.post( 'ended_test', '{}.{}'.format(binary_name, last_test), last_status, self._filter_noisy_output(stdout_buffer + stderr_buffer)) if server_process.timed_out: break # If we weren't able to determine the results for any tests, we need to run what remains singly. if starting_length == len(remaining_tests): break finally: server_process.stop() # Now, just try and run the rest of the tests singly. for test in remaining_tests: self._run_single_test(binary_name, test)