Commit 12e1cfcd authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

Revert "Refactor platform tests to avoid deprecated API"

This reverts commit 0347f00a.

Reason for revert: MSAN failures (https://ci.chromium.org/p/v8/builders/ci/V8%20Linux%20-%20arm64%20-%20sim%20-%20MSAN/29288)

Original change's description:
> Refactor platform tests to avoid deprecated API
> 
> The old tasks API is deprecated and we want to remove it in 8.0.
> Thus, this CL refactors the platform tests to use the new
> TaskRunner-based API, and removes redundant tests.
> 
> R=​ahaas@chromium.org
> 
> Bug: v8:9810
> Change-Id: Ie53c90184639e77b3247228059fd88290b233e0c
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1868619
> Reviewed-by: Andreas Haas <ahaas@chromium.org>
> Commit-Queue: Clemens Backes <clemensb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#64412}

TBR=ahaas@chromium.org,clemensb@chromium.org

Change-Id: I1b240df992425f25a2a4a9d33d27f6262d91c004
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:9810
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1871913Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64414}
parent 11e50bc3
...@@ -45,136 +45,196 @@ class DefaultPlatformWithMockTime : public DefaultPlatform { ...@@ -45,136 +45,196 @@ class DefaultPlatformWithMockTime : public DefaultPlatform {
double DefaultPlatformWithMockTime::mock_time_ = 0.0; double DefaultPlatformWithMockTime::mock_time_ = 0.0;
template <typename Platform> } // namespace
class PlatformTest : public ::testing::Test {
public:
PlatformTest() : task_runner_(platform_.GetForegroundTaskRunner(isolate())) {}
Isolate* isolate() { return reinterpret_cast<Isolate*>(dummy_); }
Platform* platform() { return &platform_; }
// These methods take ownership of the task. Tests might still reference them,
// if the tasks are expected to still exist.
void CallOnForegroundThread(Task* task) {
task_runner_->PostTask(std::unique_ptr<Task>(task));
}
void CallDelayedOnForegroundThread(Task* task, double delay_in_seconds) {
task_runner_->PostDelayedTask(std::unique_ptr<Task>(task),
delay_in_seconds);
}
void CallIdleOnForegroundThread(IdleTask* task) {
task_runner_->PostIdleTask(std::unique_ptr<IdleTask>(task));
}
bool PumpMessageLoop() { return platform_.PumpMessageLoop(isolate()); }
private:
Platform platform_;
InSequence in_sequence_;
std::shared_ptr<TaskRunner> task_runner_;
int dummy_; TEST(DefaultPlatformTest, PumpMessageLoop) {
}; InSequence s;
class DefaultPlatformTest : public PlatformTest<DefaultPlatform> {}; int dummy;
class DefaultPlatformTestWithMockTime Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
: public PlatformTest<DefaultPlatformWithMockTime> {};
} // namespace DefaultPlatform platform;
EXPECT_FALSE(platform.PumpMessageLoop(isolate));
TEST_F(DefaultPlatformTest, PumpMessageLoop) {
EXPECT_FALSE(platform()->PumpMessageLoop(isolate()));
StrictMock<MockTask>* task = new StrictMock<MockTask>; StrictMock<MockTask>* task = new StrictMock<MockTask>;
CallOnForegroundThread(task); platform.CallOnForegroundThread(isolate, task);
EXPECT_CALL(*task, Run()); EXPECT_CALL(*task, Run());
EXPECT_CALL(*task, Die()); EXPECT_CALL(*task, Die());
EXPECT_TRUE(PumpMessageLoop()); EXPECT_TRUE(platform.PumpMessageLoop(isolate));
EXPECT_FALSE(PumpMessageLoop()); EXPECT_FALSE(platform.PumpMessageLoop(isolate));
} }
TEST_F(DefaultPlatformTest, PumpMessageLoopWithTaskRunner) { TEST(DefaultPlatformTest, PumpMessageLoopWithTaskRunner) {
InSequence s;
int dummy;
Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
DefaultPlatform platform;
std::shared_ptr<TaskRunner> taskrunner = std::shared_ptr<TaskRunner> taskrunner =
platform()->GetForegroundTaskRunner(isolate()); platform.GetForegroundTaskRunner(isolate);
EXPECT_FALSE(PumpMessageLoop()); EXPECT_FALSE(platform.PumpMessageLoop(isolate));
StrictMock<MockTask>* task = new StrictMock<MockTask>; StrictMock<MockTask>* task = new StrictMock<MockTask>;
taskrunner->PostTask(std::unique_ptr<Task>(task)); taskrunner->PostTask(std::unique_ptr<Task>(task));
EXPECT_CALL(*task, Run()); EXPECT_CALL(*task, Run());
EXPECT_CALL(*task, Die()); EXPECT_CALL(*task, Die());
EXPECT_TRUE(PumpMessageLoop()); EXPECT_TRUE(platform.PumpMessageLoop(isolate));
EXPECT_FALSE(PumpMessageLoop()); EXPECT_FALSE(platform.PumpMessageLoop(isolate));
}
TEST(DefaultPlatformTest, PumpMessageLoopDelayed) {
InSequence s;
int dummy;
Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
DefaultPlatformWithMockTime platform;
EXPECT_FALSE(platform.PumpMessageLoop(isolate));
StrictMock<MockTask>* task1 = new StrictMock<MockTask>;
StrictMock<MockTask>* task2 = new StrictMock<MockTask>;
platform.CallDelayedOnForegroundThread(isolate, task2, 100);
platform.CallDelayedOnForegroundThread(isolate, task1, 10);
EXPECT_FALSE(platform.PumpMessageLoop(isolate));
platform.IncreaseTime(11);
EXPECT_CALL(*task1, Run());
EXPECT_CALL(*task1, Die());
EXPECT_TRUE(platform.PumpMessageLoop(isolate));
EXPECT_FALSE(platform.PumpMessageLoop(isolate));
platform.IncreaseTime(90);
EXPECT_CALL(*task2, Run());
EXPECT_CALL(*task2, Die());
EXPECT_TRUE(platform.PumpMessageLoop(isolate));
} }
TEST_F(DefaultPlatformTestWithMockTime, PumpMessageLoopDelayed) { TEST(DefaultPlatformTest, PumpMessageLoopDelayedWithTaskRunner) {
EXPECT_FALSE(PumpMessageLoop()); InSequence s;
int dummy;
Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
DefaultPlatformWithMockTime platform;
std::shared_ptr<TaskRunner> taskrunner =
platform.GetForegroundTaskRunner(isolate);
EXPECT_FALSE(platform.PumpMessageLoop(isolate));
StrictMock<MockTask>* task1 = new StrictMock<MockTask>; StrictMock<MockTask>* task1 = new StrictMock<MockTask>;
StrictMock<MockTask>* task2 = new StrictMock<MockTask>; StrictMock<MockTask>* task2 = new StrictMock<MockTask>;
CallDelayedOnForegroundThread(task2, 100); taskrunner->PostDelayedTask(std::unique_ptr<Task>(task2), 100);
CallDelayedOnForegroundThread(task1, 10); taskrunner->PostDelayedTask(std::unique_ptr<Task>(task1), 10);
EXPECT_FALSE(PumpMessageLoop()); EXPECT_FALSE(platform.PumpMessageLoop(isolate));
platform()->IncreaseTime(11); platform.IncreaseTime(11);
EXPECT_CALL(*task1, Run()); EXPECT_CALL(*task1, Run());
EXPECT_CALL(*task1, Die()); EXPECT_CALL(*task1, Die());
EXPECT_TRUE(PumpMessageLoop()); EXPECT_TRUE(platform.PumpMessageLoop(isolate));
EXPECT_FALSE(PumpMessageLoop()); EXPECT_FALSE(platform.PumpMessageLoop(isolate));
platform()->IncreaseTime(90); platform.IncreaseTime(90);
EXPECT_CALL(*task2, Run()); EXPECT_CALL(*task2, Run());
EXPECT_CALL(*task2, Die()); EXPECT_CALL(*task2, Die());
EXPECT_TRUE(PumpMessageLoop()); EXPECT_TRUE(platform.PumpMessageLoop(isolate));
} }
TEST_F(DefaultPlatformTestWithMockTime, PumpMessageLoopNoStarvation) { TEST(DefaultPlatformTest, PumpMessageLoopNoStarvation) {
EXPECT_FALSE(PumpMessageLoop()); InSequence s;
int dummy;
Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
DefaultPlatformWithMockTime platform;
EXPECT_FALSE(platform.PumpMessageLoop(isolate));
StrictMock<MockTask>* task1 = new StrictMock<MockTask>; StrictMock<MockTask>* task1 = new StrictMock<MockTask>;
StrictMock<MockTask>* task2 = new StrictMock<MockTask>; StrictMock<MockTask>* task2 = new StrictMock<MockTask>;
StrictMock<MockTask>* task3 = new StrictMock<MockTask>; StrictMock<MockTask>* task3 = new StrictMock<MockTask>;
CallOnForegroundThread(task1); platform.CallOnForegroundThread(isolate, task1);
CallDelayedOnForegroundThread(task2, 10); platform.CallDelayedOnForegroundThread(isolate, task2, 10);
platform()->IncreaseTime(11); platform.IncreaseTime(11);
EXPECT_CALL(*task1, Run()); EXPECT_CALL(*task1, Run());
EXPECT_CALL(*task1, Die()); EXPECT_CALL(*task1, Die());
EXPECT_TRUE(PumpMessageLoop()); EXPECT_TRUE(platform.PumpMessageLoop(isolate));
CallOnForegroundThread(task3); platform.CallOnForegroundThread(isolate, task3);
EXPECT_CALL(*task2, Run()); EXPECT_CALL(*task2, Run());
EXPECT_CALL(*task2, Die()); EXPECT_CALL(*task2, Die());
EXPECT_TRUE(PumpMessageLoop()); EXPECT_TRUE(platform.PumpMessageLoop(isolate));
EXPECT_CALL(*task3, Run()); EXPECT_CALL(*task3, Run());
EXPECT_CALL(*task3, Die()); EXPECT_CALL(*task3, Die());
EXPECT_TRUE(PumpMessageLoop()); EXPECT_TRUE(platform.PumpMessageLoop(isolate));
} }
TEST_F(DefaultPlatformTestWithMockTime,
PendingDelayedTasksAreDestroyedOnShutdown) { TEST(DefaultPlatformTest, PendingDelayedTasksAreDestroyedOnShutdown) {
StrictMock<MockTask>* task = new StrictMock<MockTask>; InSequence s;
CallDelayedOnForegroundThread(task, 10);
EXPECT_CALL(*task, Die()); int dummy;
Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
{
DefaultPlatformWithMockTime platform;
StrictMock<MockTask>* task = new StrictMock<MockTask>;
platform.CallDelayedOnForegroundThread(isolate, task, 10);
EXPECT_CALL(*task, Die());
}
} }
TEST_F(DefaultPlatformTestWithMockTime, RunIdleTasks) { TEST(DefaultPlatformTest, RunIdleTasks) {
InSequence s;
int dummy;
Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
DefaultPlatformWithMockTime platform;
StrictMock<MockIdleTask>* task = new StrictMock<MockIdleTask>; StrictMock<MockIdleTask>* task = new StrictMock<MockIdleTask>;
CallIdleOnForegroundThread(task); platform.CallIdleOnForegroundThread(isolate, task);
EXPECT_CALL(*task, Run(42.0 + 23.0)); EXPECT_CALL(*task, Run(42.0 + 23.0));
EXPECT_CALL(*task, Die()); EXPECT_CALL(*task, Die());
platform()->IncreaseTime(23.0); platform.IncreaseTime(23.0);
platform()->RunIdleTasks(isolate(), 42.0); platform.RunIdleTasks(isolate, 42.0);
} }
TEST_F(DefaultPlatformTestWithMockTime, TEST(DefaultPlatformTest, RunIdleTasksWithTaskRunner) {
PendingIdleTasksAreDestroyedOnShutdown) { InSequence s;
int dummy;
Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
DefaultPlatformWithMockTime platform;
std::shared_ptr<TaskRunner> taskrunner =
platform.GetForegroundTaskRunner(isolate);
StrictMock<MockIdleTask>* task = new StrictMock<MockIdleTask>; StrictMock<MockIdleTask>* task = new StrictMock<MockIdleTask>;
CallIdleOnForegroundThread(task); taskrunner->PostIdleTask(std::unique_ptr<IdleTask>(task));
EXPECT_CALL(*task, Run(42.0 + 23.0));
EXPECT_CALL(*task, Die()); EXPECT_CALL(*task, Die());
platform.IncreaseTime(23.0);
platform.RunIdleTasks(isolate, 42.0);
}
TEST(DefaultPlatformTest, PendingIdleTasksAreDestroyedOnShutdown) {
InSequence s;
int dummy;
Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
{
DefaultPlatformWithMockTime platform;
StrictMock<MockIdleTask>* task = new StrictMock<MockIdleTask>;
platform.CallIdleOnForegroundThread(isolate, task);
EXPECT_CALL(*task, Die());
}
} }
namespace { namespace {
...@@ -199,7 +259,7 @@ class TestBackgroundTask : public Task { ...@@ -199,7 +259,7 @@ class TestBackgroundTask : public Task {
} // namespace } // namespace
TEST(CustomDefaultPlatformTest, RunBackgroundTask) { TEST(DefaultPlatformTest, RunBackgroundTask) {
DefaultPlatform platform; DefaultPlatform platform;
platform.SetThreadPoolSize(1); platform.SetThreadPoolSize(1);
...@@ -213,7 +273,7 @@ TEST(CustomDefaultPlatformTest, RunBackgroundTask) { ...@@ -213,7 +273,7 @@ TEST(CustomDefaultPlatformTest, RunBackgroundTask) {
EXPECT_TRUE(task_executed); EXPECT_TRUE(task_executed);
} }
TEST(CustomDefaultPlatformTest, PostForegroundTaskAfterPlatformTermination) { TEST(DefaultPlatformTest, PostForegroundTaskAfterPlatformTermination) {
std::shared_ptr<TaskRunner> foreground_taskrunner; std::shared_ptr<TaskRunner> foreground_taskrunner;
{ {
DefaultPlatformWithMockTime platform; DefaultPlatformWithMockTime platform;
......
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