Commit 70979cfb authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Chromium LUCI CQ

Fix animation throughput reporter test flakiness

* I give up using mock time because it still doesn't drive
  begin frame correctly.
* Factor out the TestReporter as a ThroughputReporterTesterBase template.
* Changed animation_throughput_reporter_unittest to use it.
Bug: 1157649

Change-Id: I876167808bc6c11872de64bfc9bc6e4263592f1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2581519Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841281}
parent 640f5b3d
...@@ -151,6 +151,8 @@ static_library("test_support") { ...@@ -151,6 +151,8 @@ static_library("test_support") {
"test/test_suite.h", "test/test_suite.h",
"test/test_utils.cc", "test/test_utils.cc",
"test/test_utils.h", "test/test_utils.h",
"test/throughput_report_checker.cc",
"test/throughput_report_checker.h",
] ]
if (is_android) { if (is_android) {
......
...@@ -47,14 +47,14 @@ void AnimationThroughputReporterTestBase::TearDown() { ...@@ -47,14 +47,14 @@ void AnimationThroughputReporterTestBase::TearDown() {
void AnimationThroughputReporterTestBase::Advance( void AnimationThroughputReporterTestBase::Advance(
const base::TimeDelta& delta) { const base::TimeDelta& delta) {
#if BUILDFLAG(IS_CHROMEOS_ASH) run_loop_ = std::make_unique<base::RunLoop>();
task_environment_.FastForwardBy(delta);
#else
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), delta); FROM_HERE, run_loop_->QuitClosure(), delta);
run_loop.Run(); run_loop_->Run();
#endif }
void AnimationThroughputReporterTestBase::QuitRunLoop() {
run_loop_->Quit();
} }
} // namespace ui } // namespace ui
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/test/test_compositor_host.h" #include "ui/compositor/test/test_compositor_host.h"
namespace base {
class RunLoop;
}
namespace ui { namespace ui {
class TestContextFactories; class TestContextFactories;
...@@ -39,13 +43,11 @@ class AnimationThroughputReporterTestBase : public testing::Test { ...@@ -39,13 +43,11 @@ class AnimationThroughputReporterTestBase : public testing::Test {
// Advances the time by |delta|. // Advances the time by |delta|.
void Advance(const base::TimeDelta& delta); void Advance(const base::TimeDelta& delta);
void QuitRunLoop();
private: private:
base::test::TaskEnvironment task_environment_{ base::test::TaskEnvironment task_environment_{
#if BUILDFLAG(IS_CHROMEOS_ASH) base::test::TaskEnvironment::MainThreadType::UI};
base::test::TaskEnvironment::TimeSource::MOCK_TIME,
#endif
base::test::TaskEnvironment::MainThreadType::UI
};
std::unique_ptr<TestContextFactories> context_factories_; std::unique_ptr<TestContextFactories> context_factories_;
std::unique_ptr<TestCompositorHost> host_; std::unique_ptr<TestCompositorHost> host_;
...@@ -54,6 +56,8 @@ class AnimationThroughputReporterTestBase : public testing::Test { ...@@ -54,6 +56,8 @@ class AnimationThroughputReporterTestBase : public testing::Test {
// A timer to generate continuous compositor frames to trigger throughput // A timer to generate continuous compositor frames to trigger throughput
// data being transferred back. // data being transferred back.
base::RepeatingTimer frame_generation_timer_; base::RepeatingTimer frame_generation_timer_;
std::unique_ptr<base::RunLoop> run_loop_;
}; };
} // namespace ui } // namespace ui
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/compositor/test/throughput_report_checker.h"
#include "base/time/time.h"
#include "ui/compositor/test/animation_throughput_reporter_test_base.h"
namespace ui {
bool ThroughputReportChecker::WaitUntilReported() {
DCHECK(!reported_);
test_base_->Advance(base::TimeDelta::FromSeconds(5));
return reported_;
}
void ThroughputReportChecker::OnReport(
const cc::FrameSequenceMetrics::CustomReportData&) {
reported_ = true;
if (fail_if_reported_)
ADD_FAILURE() << "It should not be reported.";
test_base_->QuitRunLoop();
}
} // namespace ui
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_
#define UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_
#include <memory>
#include "base/bind.h"
#include "cc/metrics/frame_sequence_metrics.h"
namespace ui {
class AnimationThroughputReporterTestBase;
class ThroughputReportChecker {
public:
using ReportRepeatingCallback = base::RepeatingCallback<void(
const cc::FrameSequenceMetrics::CustomReportData&)>;
using ReportOnceCallback = base::OnceCallback<void(
const cc::FrameSequenceMetrics::CustomReportData&)>;
explicit ThroughputReportChecker(
AnimationThroughputReporterTestBase* test_base,
bool fail_if_reported = false)
: test_base_(test_base), fail_if_reported_(fail_if_reported) {}
ThroughputReportChecker(const ThroughputReportChecker&) = delete;
ThroughputReportChecker& operator=(const ThroughputReportChecker&) = delete;
~ThroughputReportChecker() = default;
bool reported() const { return reported_; }
void reset() { reported_ = false; }
ReportRepeatingCallback repeating_callback() {
return base::BindRepeating(&ThroughputReportChecker::OnReport,
base::Unretained(this));
}
ReportOnceCallback once_callback() {
return base::BindOnce(&ThroughputReportChecker::OnReport,
base::Unretained(this));
}
// It waits until reported up to 5 seconds timeout. Returns true if it's
// reported.
bool WaitUntilReported();
private:
void OnReport(const cc::FrameSequenceMetrics::CustomReportData&);
AnimationThroughputReporterTestBase* test_base_;
bool reported_ = false;
bool fail_if_reported_ = false;
};
} // namespace ui
#endif // UI_COMPOSITOR_TEST_THROUGHPUT_REPORT_CHECKER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment