v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc
jochen 1bdf908db0 Add a basic compiler dispatcher
It doesn't schedule steps yet, but there are tests.

BUG=v8:5215
R=rmcilroy@chromium.org,marja@chromium.org

Review-Url: https://codereview.chromium.org/2558293004
Cr-Commit-Position: refs/heads/master@{#41650}
2016-12-12 15:36:25 +00:00

62 lines
2.1 KiB
C++

// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "src/compiler-dispatcher/compiler-dispatcher.h"
#include "src/flags.h"
#include "src/handles.h"
#include "src/objects-inl.h"
#include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
typedef TestWithContext CompilerDispatcherTest;
TEST_F(CompilerDispatcherTest, Construct) {
std::unique_ptr<CompilerDispatcher> dispatcher(
new CompilerDispatcher(i_isolate(), FLAG_stack_size));
}
TEST_F(CompilerDispatcherTest, IsEnqueued) {
std::unique_ptr<CompilerDispatcher> dispatcher(
new CompilerDispatcher(i_isolate(), FLAG_stack_size));
const char script[] =
"function g() { var y = 1; function f(x) { return x * y }; return f; } "
"g();";
Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
ASSERT_FALSE(dispatcher->IsEnqueued(shared));
ASSERT_TRUE(dispatcher->Enqueue(shared));
ASSERT_TRUE(dispatcher->IsEnqueued(shared));
dispatcher->Abort(shared, CompilerDispatcher::BlockingBehavior::kBlock);
ASSERT_FALSE(dispatcher->IsEnqueued(shared));
}
TEST_F(CompilerDispatcherTest, FinishNow) {
std::unique_ptr<CompilerDispatcher> dispatcher(
new CompilerDispatcher(i_isolate(), FLAG_stack_size));
const char script[] =
"function g() { var y = 1; function f(x) { return x * y }; return f; } "
"g();";
Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
ASSERT_FALSE(shared->HasBaselineCode());
ASSERT_TRUE(dispatcher->Enqueue(shared));
ASSERT_TRUE(dispatcher->FinishNow(shared));
// Finishing removes the SFI from the queue.
ASSERT_FALSE(dispatcher->IsEnqueued(shared));
ASSERT_TRUE(shared->HasBaselineCode());
}
} // namespace internal
} // namespace v8