Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc

Issue 2278153003: [Ignition] Add test of bytecode compilation on background thread. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 IgnitionCompilerDispatcherJobTest() {}
27 ~IgnitionCompilerDispatcherJobTest() override {}
28
29 static void SetUpTestCase() {
30 old_flag_ = i::FLAG_ignition;
31 i::FLAG_ignition = true;
32 TestWithContext::SetUpTestCase();
33 }
34
35 static void TearDownTestCase() {
36 TestWithContext::TearDownTestCase();
37 i::FLAG_ignition = old_flag_;
38 }
39
40 private:
41 static bool old_flag_;
42 DISALLOW_COPY_AND_ASSIGN(IgnitionCompilerDispatcherJobTest);
43 };
44
45 bool IgnitionCompilerDispatcherJobTest::old_flag_;
46
22 namespace { 47 namespace {
23 48
24 const char test_script[] = "(x) { x*x; }"; 49 const char test_script[] = "(x) { x*x; }";
25 50
26 class ScriptResource : public v8::String::ExternalOneByteStringResource { 51 class ScriptResource : public v8::String::ExternalOneByteStringResource {
27 public: 52 public:
28 ScriptResource(const char* data, size_t length) 53 ScriptResource(const char* data, size_t length)
29 : data_(data), length_(length) {} 54 : data_(data), length_(length) {}
30 ~ScriptResource() override = default; 55 ~ScriptResource() override = default;
31 56
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 job->Compile(); 255 job->Compile();
231 ASSERT_FALSE(job->FinalizeCompilingOnMainThread()); 256 ASSERT_FALSE(job->FinalizeCompilingOnMainThread());
232 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); 257 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed);
233 ASSERT_TRUE(i_isolate()->has_pending_exception()); 258 ASSERT_TRUE(i_isolate()->has_pending_exception());
234 259
235 i_isolate()->clear_pending_exception(); 260 i_isolate()->clear_pending_exception();
236 job->ResetOnMainThread(); 261 job->ResetOnMainThread();
237 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); 262 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
238 } 263 }
239 264
265 class CompileTask : public Task {
266 public:
267 CompileTask(CompilerDispatcherJob* job, base::Semaphore* semaphore)
268 : job_(job), semaphore_(semaphore) {}
269 ~CompileTask() override {}
270
271 void Run() override {
272 job_->Compile();
273 semaphore_->Signal();
274 }
275
276 private:
277 CompilerDispatcherJob* job_;
278 base::Semaphore* semaphore_;
279 DISALLOW_COPY_AND_ASSIGN(CompileTask);
280 };
281
282 TEST_F(IgnitionCompilerDispatcherJobTest, CompileOnBackgroundThread) {
283 const char* raw_script =
284 "(a, b) {\n"
285 " var c = a + b;\n"
286 " function bar() { return b }\n"
287 " var d = { foo: 100, bar : bar() }\n"
288 " return bar;"
289 "}";
290 ScriptResource script(raw_script, strlen(raw_script));
291 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
292 i_isolate(), CreateFunction(i_isolate(), &script), 100));
293
294 job->PrepareToParseOnMainThread();
295 job->Parse();
296 job->FinalizeParsingOnMainThread();
297 job->PrepareToCompileOnMainThread();
298 ASSERT_TRUE(job->can_compile_on_background_thread());
299
300 base::Semaphore semaphore(0);
301 CompileTask* background_task = new CompileTask(job.get(), &semaphore);
302 V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task,
303 Platform::kShortRunningTask);
304 semaphore.Wait();
305 ASSERT_TRUE(job->FinalizeCompilingOnMainThread());
306 ASSERT_TRUE(job->status() == CompileJobStatus::kDone);
307
308 job->ResetOnMainThread();
309 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
310 }
311
240 } // namespace internal 312 } // namespace internal
241 } // namespace v8 313 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698