Exemplo n.º 1
0
    def __init__(self,
                 test_name,
                 retry_attempt=0,
                 failures=None,
                 test_run_time=None,
                 reftest_type=None,
                 pid=None,
                 references=None,
                 device_failed=False,
                 crash_site=None,
                 command=None):
        self.test_name = test_name
        self.failures = failures or []
        self.test_run_time = test_run_time or 0  # The time taken to execute the test itself.
        self.has_stderr = any(failure.has_stderr for failure in self.failures)
        self.reftest_type = reftest_type or []
        self.pid = pid
        self.references = references or []
        self.device_failed = device_failed
        self.has_repaint_overlay = any(failure.has_repaint_overlay
                                       for failure in self.failures)
        self.crash_site = crash_site
        self.retry_attempt = retry_attempt
        self.command = command

        results = set([f.result for f in self.failures] or [ResultType.Pass])
        assert len(results) <= 2, (
            'single_test_runner.py incorrectly reported results %s for test %s'
            % (', '.join(results), test_name))
        if len(results) == 2:
            assert (
                (ResultType.Timeout in results
                 and ResultType.Failure in results) or
                (ResultType.Crash in results and ResultType.Failure in results)
            ), ('Allowed combination of 2 results are 1. TIMEOUT and FAIL 2. CRASH and FAIL'
                'Test %s reported the following results %s' %
                (test_name, ', '.join(results)))
            if ResultType.Timeout in results:
                self.type = ResultType.Timeout
            else:
                self.type = ResultType.Crash
        else:
            # FIXME: Setting this in the constructor makes this class hard to mutate.
            self.type = results.pop()

        # These are set by the worker, not by the driver, so they are not passed to the constructor.
        self.worker_name = ''
        self.shard_name = ''
        self.total_run_time = 0  # The time taken to run the test plus any references, compute diffs, etc.
        self.test_number = None
        self.artifacts = Artifacts(self.results_directory,
                                   self.filesystem,
                                   retry_attempt,
                                   ARTIFACTS_SUB_DIR,
                                   repeat_tests=self.repeat_tests)
    def test_repeated_test_artifacts(self):
        host = MockSystemHost()
        port = Port(host, 'baseport')
        artifacts = Artifacts('/dir', host.filesystem, repeat_tests=True)

        def init_test_failure(test_failure):
            test_failure.port = port
            test_failure.filesystem = host.filesystem
            test_failure.test_name = 'foo.html'
            test_failure.result_directory = '/dir'

        pass_with_stderr = PassWithStderr(
            DriverOutput(None, None, None, None, error=b'pass with stderr'))
        init_test_failure(pass_with_stderr)
        crash = FailureCrash(
            DriverOutput(None,
                         None,
                         None,
                         None,
                         crash=True,
                         error=b'crash stderr'))
        init_test_failure(crash)
        timeout = FailureTimeout(
            DriverOutput(None, None, None, None, error=b'timeout with stderr'))
        init_test_failure(timeout)

        pass_with_stderr.create_artifacts(artifacts)
        self.assertEqual('pass with stderr',
                         host.filesystem.read_text_file('/dir/foo-stderr.txt'))

        crash.create_artifacts(artifacts)
        self.assertEqual('crash stderr',
                         host.filesystem.read_text_file('/dir/foo-stderr.txt'))

        timeout.create_artifacts(artifacts)
        self.assertEqual('timeout with stderr',
                         host.filesystem.read_text_file('/dir/foo-stderr.txt'))

        pass_with_stderr.create_artifacts(artifacts)
        self.assertEqual('timeout with stderr',
                         host.filesystem.read_text_file('/dir/foo-stderr.txt'))