Chromium Code Reviews| Index: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc |
| diff --git a/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc b/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc |
| index 5a8a49cf7f4139947cce24fb6a51d8b681d15fb2..fb90b2762cdf56d9b97f711769325d7291fdfeb1 100644 |
| --- a/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc |
| +++ b/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc |
| @@ -7,10 +7,12 @@ |
| #include "include/v8.h" |
| #include "src/api.h" |
| #include "src/ast/scopes.h" |
| +#include "src/base/platform/semaphore.h" |
| #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
| #include "src/flags.h" |
| #include "src/isolate-inl.h" |
| #include "src/parsing/parse-info.h" |
| +#include "src/v8.h" |
| #include "test/unittests/test-utils.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -19,6 +21,25 @@ namespace internal { |
| typedef TestWithContext CompilerDispatcherJobTest; |
| +class IgnitionCompilerDispatcherJobTest : public TestWithContext { |
| + public: |
| + static void SetUpTestCase() { |
|
jochen (gone - plz use gerrit)
2016/08/26 15:05:48
any reason you don't use the per-test case SetUp()
rmcilroy
2016/09/05 16:17:22
We need to set the flag before we create the isola
|
| + old_flag_ = i::FLAG_ignition_staging; |
| + i::FLAG_ignition = true; |
| + TestWithContext::SetUpTestCase(); |
| + } |
| + |
| + static void TearDownTestCase() { |
| + TestWithContext::TearDownTestCase(); |
| + i::FLAG_ignition = old_flag_; |
| + } |
| + |
| + private: |
| + static bool old_flag_; |
| +}; |
|
jochen (gone - plz use gerrit)
2016/08/26 15:05:48
DISALLOW_COPY_AND_ASSIGN plz
rmcilroy
2016/09/05 16:17:22
Done.
|
| + |
| +bool IgnitionCompilerDispatcherJobTest::old_flag_; |
| + |
| namespace { |
| const char test_script[] = "(x) { x*x; }"; |
| @@ -237,5 +258,50 @@ TEST_F(CompilerDispatcherJobTest, CompileFailureToFinalize) { |
| ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
| } |
| +class CompileTask : public Task { |
| + public: |
| + CompileTask(CompilerDispatcherJob* job, base::Semaphore* semaphore) |
| + : job_(job), semaphore_(semaphore) {} |
| + |
| + void Run() override { |
| + job_->Compile(); |
| + semaphore_->Signal(); |
| + } |
| + |
| + private: |
| + CompilerDispatcherJob* job_; |
| + base::Semaphore* semaphore_; |
| +}; |
|
jochen (gone - plz use gerrit)
2016/08/26 15:05:48
disallow copy & assign and a virtual dtor please
rmcilroy
2016/09/05 16:17:22
Done.
|
| + |
| +TEST_F(IgnitionCompilerDispatcherJobTest, CompileOnBackgroundThread) { |
| + const char* raw_script = |
| + "(a, b) {\n" |
| + " var c = a + b;\n" |
| + " function bar() { return b }\n" |
| + " var d = { foo: 100, bar : bar() }\n" |
| + " return bar;" |
| + "}"; |
| + ScriptResource script(raw_script, strlen(raw_script)); |
| + std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
| + i_isolate(), CreateFunction(i_isolate(), &script), 100)); |
| + |
| + job->PrepareToParseOnMainThread(); |
| + job->Parse(); |
| + job->FinalizeParsingOnMainThread(); |
| + job->PrepareToCompileOnMainThread(); |
| + ASSERT_TRUE(job->can_compile_on_background_thread()); |
| + |
| + base::Semaphore semaphore(0); |
| + CompileTask* background_task = new CompileTask(job.get(), &semaphore); |
| + V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task, |
| + Platform::kShortRunningTask); |
| + semaphore.Wait(); |
| + ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); |
| + ASSERT_TRUE(job->status() == CompileJobStatus::kDone); |
| + |
| + job->ResetOnMainThread(); |
| + ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
| +} |
| + |
| } // namespace internal |
| } // namespace v8 |