コード例 #1
0
    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())

        status = Runner.STATUS_RUNNING
        if test.split('.')[1].startswith(
                'DISABLED_') and not self._port.get_option('force'):
            status = Runner.STATUS_DISABLED

        try:
            deadline = time.time() + self._timeout
            if status != Runner.STATUS_DISABLED:
                server_process.start()

            stdout_buffer = ''
            stderr_buffer = ''
            while status == Runner.STATUS_RUNNING:
                stdout_line, stderr_line = server_process.read_either_stdout_or_stderr_line(
                    deadline)
                if not stderr_line and not stdout_line:
                    break

                if stderr_line:
                    stderr_buffer += stderr_line
                    self.post('log', output=stderr_line[:-1])
                if stdout_line:
                    if '**PASS**' in stdout_line:
                        status = Runner.STATUS_PASSED
                    elif '**FAIL**' in stdout_line:
                        status = Runner.STATUS_FAILED
                    else:
                        stdout_buffer += stdout_line
                        self.post('log', output=stdout_line[:-1])

            if status == Runner.STATUS_DISABLED:
                pass
            elif server_process.timed_out:
                status = Runner.STATUS_TIMEOUT
            elif server_process.has_crashed():
                status = Runner.STATUS_CRASHED
            elif status == Runner.STATUS_RUNNING:
                status = Runner.STATUS_FAILED

        finally:
            remaining_stderr = server_process.pop_all_buffered_stderr()
            remaining_stdout = server_process.pop_all_buffered_stdout()
            self.post('log', output=remaining_stderr + remaining_stdout)
            output_buffer = stderr_buffer + stdout_buffer + remaining_stderr + remaining_stdout
            server_process.stop()

        self.post('ended_test', '{}.{}'.format(binary_name, test), status,
                  self._filter_noisy_output(output_buffer))
コード例 #2
0
    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))
コード例 #3
0
    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)
コード例 #4
0
    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())

        status = Runner.STATUS_RUNNING
        if test.split('.')[1].startswith(
                'DISABLED_') and not self._port.get_option('force'):
            status = Runner.STATUS_DISABLED

        stdout_buffer = ''
        stderr_buffer = ''

        try:
            deadline = time.time() + self._timeout
            if status != Runner.STATUS_DISABLED:
                server_process.start()

            while status == Runner.STATUS_RUNNING:
                stdout_line, stderr_line = server_process.read_either_stdout_or_stderr_line(
                    deadline)
                if not stderr_line and not stdout_line:
                    break

                if stderr_line:
                    stderr_line = string_utils.decode(stderr_line,
                                                      target_type=str)
                    stderr_buffer += stderr_line
                    _log.error(stderr_line[:-1])
                if stdout_line:
                    stdout_line = string_utils.decode(stdout_line,
                                                      target_type=str)
                    if '**PASS**' in stdout_line:
                        status = Runner.STATUS_PASSED
                    elif '**FAIL**' in stdout_line:
                        status = Runner.STATUS_FAILED
                    else:
                        stdout_buffer += stdout_line
                        _log.error(stdout_line[:-1])

            if status == Runner.STATUS_DISABLED:
                pass
            elif server_process.timed_out:
                status = Runner.STATUS_TIMEOUT
            elif server_process.has_crashed():
                status = Runner.STATUS_CRASHED
            elif status == Runner.STATUS_RUNNING:
                status = Runner.STATUS_FAILED

        finally:
            remaining_stderr = string_utils.decode(
                server_process.pop_all_buffered_stderr(), target_type=str)
            remaining_stdout = string_utils.decode(
                server_process.pop_all_buffered_stdout(), target_type=str)
            for line in (remaining_stdout +
                         remaining_stderr).splitlines(False):
                _log.error(line)
            output_buffer = stderr_buffer + stdout_buffer + remaining_stderr + remaining_stdout
            server_process.stop()

        TaskPool.Process.queue.send(
            TaskPool.Task(
                report_result,
                None,
                TaskPool.Process.name,
                '{}.{}'.format(binary_name, test),
                status,
                self._filter_noisy_output(output_buffer),
            ))