Commit 859af1b7 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Add task runner to the platform in the streaming compilation cctests

The foreground task runner and the background task runner are the same.
Thereby we can get predictable behavior.

R=clemensh@chromium.org

Change-Id: I18f9c7277a344b7884d6de0c2159cc3f010576b4
Reviewed-on: https://chromium-review.googlesource.com/771833Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49383}
parent 009df6fb
...@@ -24,44 +24,66 @@ namespace wasm { ...@@ -24,44 +24,66 @@ namespace wasm {
class MockPlatform final : public TestPlatform { class MockPlatform final : public TestPlatform {
public: public:
MockPlatform() : old_platform_(i::V8::GetCurrentPlatform()) { MockPlatform() : task_runner_(std::make_shared<MockTaskRunner>()) {
// Now that it's completely constructed, make this the current platform. // Now that it's completely constructed, make this the current platform.
i::V8::SetPlatformForTesting(this); i::V8::SetPlatformForTesting(this);
} }
virtual ~MockPlatform() {
// Delete all remaining tasks in the queue. std::shared_ptr<TaskRunner> GetForegroundTaskRunner(
while (!tasks_.empty()) { v8::Isolate* isolate) override {
Task* task = tasks_.back(); return task_runner_;
tasks_.pop_back(); }
delete task;
} std::shared_ptr<TaskRunner> GetBackgroundTaskRunner(
i::V8::SetPlatformForTesting(old_platform_); v8::Isolate* isolate) override {
return task_runner_;
} }
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override { void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
tasks_.push_back(task); task_runner_->PostTask(std::unique_ptr<Task>(task));
} }
void CallOnBackgroundThread(v8::Task* task, void CallOnBackgroundThread(v8::Task* task,
ExpectedRuntime expected_runtime) override { ExpectedRuntime expected_runtime) override {
tasks_.push_back(task); task_runner_->PostTask(std::unique_ptr<Task>(task));
} }
bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; } bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
void ExecuteTasks() { void ExecuteTasks() { task_runner_->ExecuteTasks(); }
while (!tasks_.empty()) {
Task* task = tasks_.back();
tasks_.pop_back();
task->Run();
delete task;
}
}
private: private:
// We do not execute tasks concurrently, so we only need one list of tasks. class MockTaskRunner final : public TaskRunner {
std::vector<Task*> tasks_; public:
v8::Platform* old_platform_; void PostTask(std::unique_ptr<v8::Task> task) override {
tasks_.push_back(std::move(task));
}
void PostDelayedTask(std::unique_ptr<Task> task,
double delay_in_seconds) override {
UNREACHABLE();
};
void PostIdleTask(std::unique_ptr<IdleTask> task) override {
UNREACHABLE();
}
bool IdleTasksEnabled() override { return false; };
void ExecuteTasks() {
while (!tasks_.empty()) {
std::unique_ptr<Task> task = std::move(tasks_.back());
tasks_.pop_back();
task->Run();
}
}
private:
// We do not execute tasks concurrently, so we only need one list of tasks.
std::vector<std::unique_ptr<v8::Task>> tasks_;
};
std::shared_ptr<MockTaskRunner> task_runner_;
}; };
namespace { namespace {
......
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