Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "include/v8.h" | 7 #include "include/v8.h" |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/base/platform/semaphore.h" | |
| 10 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" | 11 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
| 11 #include "src/flags.h" | 12 #include "src/flags.h" |
| 12 #include "src/isolate-inl.h" | 13 #include "src/isolate-inl.h" |
| 13 #include "src/parsing/parse-info.h" | 14 #include "src/parsing/parse-info.h" |
| 15 #include "src/v8.h" | |
| 14 #include "test/unittests/test-utils.h" | 16 #include "test/unittests/test-utils.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 namespace v8 { | 19 namespace v8 { |
| 18 namespace internal { | 20 namespace internal { |
| 19 | 21 |
| 20 typedef TestWithContext CompilerDispatcherJobTest; | 22 typedef TestWithContext CompilerDispatcherJobTest; |
| 21 | 23 |
| 24 class IgnitionCompilerDispatcherJobTest : public TestWithContext { | |
| 25 public: | |
| 26 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
| |
| 27 old_flag_ = i::FLAG_ignition_staging; | |
| 28 i::FLAG_ignition = true; | |
| 29 TestWithContext::SetUpTestCase(); | |
| 30 } | |
| 31 | |
| 32 static void TearDownTestCase() { | |
| 33 TestWithContext::TearDownTestCase(); | |
| 34 i::FLAG_ignition = old_flag_; | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 static bool old_flag_; | |
| 39 }; | |
|
jochen (gone - plz use gerrit)
2016/08/26 15:05:48
DISALLOW_COPY_AND_ASSIGN plz
rmcilroy
2016/09/05 16:17:22
Done.
| |
| 40 | |
| 41 bool IgnitionCompilerDispatcherJobTest::old_flag_; | |
| 42 | |
| 22 namespace { | 43 namespace { |
| 23 | 44 |
| 24 const char test_script[] = "(x) { x*x; }"; | 45 const char test_script[] = "(x) { x*x; }"; |
| 25 | 46 |
| 26 class ScriptResource : public v8::String::ExternalOneByteStringResource { | 47 class ScriptResource : public v8::String::ExternalOneByteStringResource { |
| 27 public: | 48 public: |
| 28 ScriptResource(const char* data, size_t length) | 49 ScriptResource(const char* data, size_t length) |
| 29 : data_(data), length_(length) {} | 50 : data_(data), length_(length) {} |
| 30 ~ScriptResource() override = default; | 51 ~ScriptResource() override = default; |
| 31 | 52 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 job->Compile(); | 251 job->Compile(); |
| 231 ASSERT_FALSE(job->FinalizeCompilingOnMainThread()); | 252 ASSERT_FALSE(job->FinalizeCompilingOnMainThread()); |
| 232 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); | 253 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); |
| 233 ASSERT_TRUE(i_isolate()->has_pending_exception()); | 254 ASSERT_TRUE(i_isolate()->has_pending_exception()); |
| 234 | 255 |
| 235 i_isolate()->clear_pending_exception(); | 256 i_isolate()->clear_pending_exception(); |
| 236 job->ResetOnMainThread(); | 257 job->ResetOnMainThread(); |
| 237 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | 258 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
| 238 } | 259 } |
| 239 | 260 |
| 261 class CompileTask : public Task { | |
| 262 public: | |
| 263 CompileTask(CompilerDispatcherJob* job, base::Semaphore* semaphore) | |
| 264 : job_(job), semaphore_(semaphore) {} | |
| 265 | |
| 266 void Run() override { | |
| 267 job_->Compile(); | |
| 268 semaphore_->Signal(); | |
| 269 } | |
| 270 | |
| 271 private: | |
| 272 CompilerDispatcherJob* job_; | |
| 273 base::Semaphore* semaphore_; | |
| 274 }; | |
|
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.
| |
| 275 | |
| 276 TEST_F(IgnitionCompilerDispatcherJobTest, CompileOnBackgroundThread) { | |
| 277 const char* raw_script = | |
| 278 "(a, b) {\n" | |
| 279 " var c = a + b;\n" | |
| 280 " function bar() { return b }\n" | |
| 281 " var d = { foo: 100, bar : bar() }\n" | |
| 282 " return bar;" | |
| 283 "}"; | |
| 284 ScriptResource script(raw_script, strlen(raw_script)); | |
| 285 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | |
| 286 i_isolate(), CreateFunction(i_isolate(), &script), 100)); | |
| 287 | |
| 288 job->PrepareToParseOnMainThread(); | |
| 289 job->Parse(); | |
| 290 job->FinalizeParsingOnMainThread(); | |
| 291 job->PrepareToCompileOnMainThread(); | |
| 292 ASSERT_TRUE(job->can_compile_on_background_thread()); | |
| 293 | |
| 294 base::Semaphore semaphore(0); | |
| 295 CompileTask* background_task = new CompileTask(job.get(), &semaphore); | |
| 296 V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task, | |
| 297 Platform::kShortRunningTask); | |
| 298 semaphore.Wait(); | |
| 299 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); | |
| 300 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); | |
| 301 | |
| 302 job->ResetOnMainThread(); | |
| 303 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | |
| 304 } | |
| 305 | |
| 240 } // namespace internal | 306 } // namespace internal |
| 241 } // namespace v8 | 307 } // namespace v8 |
| OLD | NEW |