Commit 80d40064 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] added inspector test runner [part 1]

- added a inspector folder,
- added related GN and gyp files,
- added task handling infrastructure for test runner.

BUG=chromium:635948
R=dgozman@chromium.org,alph@chromium.org

Committed: https://crrev.com/dc1c71c0dc8a5c4ade4aa291f2ddcd02e90c64b2
Review-Url: https://codereview.chromium.org/2361623006
Cr-Original-Commit-Position: refs/heads/master@{#39866}
Cr-Commit-Position: refs/heads/master@{#39918}
parent a5dfdb75
......@@ -3,6 +3,7 @@
# found in the LICENSE file.
import("../gni/isolate.gni")
import("//build_overrides/v8.gni")
group("gn_all") {
testonly = true
......@@ -20,6 +21,10 @@ group("gn_all") {
]
}
if (v8_enable_inspector_override) {
deps += [ "inspector:inspector-test" ]
}
if (v8_test_isolation_mode != "noop") {
deps += [
":benchmarks_run",
......
# 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.
import("../../gni/v8.gni")
v8_executable("inspector-test") {
testonly = true
sources = [
"task-runner.cc",
"task-runner.h",
]
configs = [
"../..:external_config",
"../..:internal_config_base",
]
deps = [
"../..:v8_libplatform",
"//build/config/sanitizers:deps",
"//build/win:default_exe_manifest",
]
if (is_component_build) {
# inspector-test can't be built against a shared library, so we
# need to depend on the underlying static target in that case.
deps += [ "../..:v8_maybe_snapshot" ]
} else {
deps += [ "../..:v8" ]
}
cflags = []
ldflags = []
}
include_rules = [
"-src",
"+src/base/macros.h",
"+src/base/platform/platform.h",
"+src/inspector/string-16.h",
"+src/locked-queue-inl.h",
]
\ No newline at end of file
dgozman@chromium.org
kozyatinskiy@chromium.org
# 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.
{
'variables': {
'v8_code': 1,
'inspector_protocol_sources': [
'task-runner.cc',
'task-runner.h',
],
},
'includes': ['../../gypfiles/toolchain.gypi', '../../gypfiles/features.gypi'],
'targets': [
{
'target_name': 'inspector-test',
'type': 'executable',
'dependencies': [
'../../src/v8.gyp:v8_libplatform',
],
'include_dirs': [
'../..',
],
'sources': [
'<@(inspector_protocol_sources)',
],
'conditions': [
['component=="shared_library"', {
# inspector-test can't be built against a shared library, so we
# need to depend on the underlying static target in that case.
'dependencies': ['../../src/v8.gyp:v8_maybe_snapshot'],
}, {
'dependencies': ['../../src/v8.gyp:v8'],
}],
],
},
],
}
// 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 "test/inspector/task-runner.h"
#if !defined(_WIN32) && !defined(_WIN64)
#include <unistd.h> // NOLINT
#endif // !defined(_WIN32) && !defined(_WIN64)
namespace {
const int kTaskRunnerIndex = 2;
void ReportUncaughtException(v8::Isolate* isolate,
const v8::TryCatch& try_catch) {
CHECK(try_catch.HasCaught());
v8::HandleScope handle_scope(isolate);
std::string message = *v8::String::Utf8Value(try_catch.Message()->Get());
fprintf(stderr, "Unhandle exception: %s\n", message.data());
}
} // namespace
TaskRunner::TaskRunner(v8::ExtensionConfiguration* extensions,
v8::base::Semaphore* ready_semaphore)
: Thread(Options("Task Runner")),
extensions_(extensions),
ready_semaphore_(ready_semaphore),
isolate_(nullptr),
process_queue_semaphore_(0),
nested_loop_count_(0) {
Start();
}
TaskRunner::~TaskRunner() { Join(); }
void TaskRunner::InitializeContext() {
v8::Isolate::CreateParams params;
params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
isolate_ = v8::Isolate::New(params);
isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);
v8::Local<v8::ObjectTemplate> global_template =
v8::ObjectTemplate::New(isolate_);
v8::Local<v8::Context> context =
v8::Context::New(isolate_, extensions_, global_template);
context->SetAlignedPointerInEmbedderData(kTaskRunnerIndex, this);
context_.Reset(isolate_, context);
if (ready_semaphore_) ready_semaphore_->Signal();
}
void TaskRunner::Run() {
InitializeContext();
RunMessageLoop(false);
}
void TaskRunner::RunMessageLoop(bool only_protocol) {
int loop_number = ++nested_loop_count_;
while (nested_loop_count_ == loop_number) {
TaskRunner::Task* task = GetNext(only_protocol);
v8::Isolate::Scope isolate_scope(isolate_);
v8::TryCatch try_catch(isolate_);
task->Run(isolate_, context_);
delete task;
if (try_catch.HasCaught()) {
ReportUncaughtException(isolate_, try_catch);
fflush(stdout);
fflush(stderr);
_exit(0);
}
}
}
void TaskRunner::QuitMessageLoop() {
DCHECK(nested_loop_count_ > 0);
--nested_loop_count_;
}
void TaskRunner::Append(Task* task) {
queue_.Enqueue(task);
process_queue_semaphore_.Signal();
}
TaskRunner::Task* TaskRunner::GetNext(bool only_protocol) {
for (;;) {
if (only_protocol) {
Task* task = nullptr;
if (queue_.Dequeue(&task)) {
if (task->is_inspector_task()) return task;
deffered_queue_.Enqueue(task);
}
} else {
Task* task = nullptr;
if (deffered_queue_.Dequeue(&task)) return task;
if (queue_.Dequeue(&task)) return task;
}
process_queue_semaphore_.Wait();
}
UNREACHABLE();
return nullptr;
}
TaskRunner* TaskRunner::FromContext(v8::Local<v8::Context> context) {
return static_cast<TaskRunner*>(
context->GetAlignedPointerFromEmbedderData(kTaskRunnerIndex));
}
ExecuteStringTask::ExecuteStringTask(const v8_inspector::String16& expression)
: expression_(expression) {}
void ExecuteStringTask::Run(v8::Isolate* isolate,
const v8::Global<v8::Context>& context) {
v8::MicrotasksScope microtasks_scope(isolate,
v8::MicrotasksScope::kRunMicrotasks);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> local_context = context.Get(isolate);
v8::Context::Scope context_scope(local_context);
v8::ScriptOrigin origin(v8::String::Empty(isolate));
v8::Local<v8::String> source =
v8::String::NewFromTwoByte(isolate, expression_.characters16(),
v8::NewStringType::kNormal,
expression_.length())
.ToLocalChecked();
v8::ScriptCompiler::Source scriptSource(source, origin);
v8::Local<v8::Script> script;
if (!v8::ScriptCompiler::Compile(local_context, &scriptSource)
.ToLocal(&script))
return;
v8::MaybeLocal<v8::Value> result;
result = script->Run(local_context);
}
// main to make compiler happy before other patch will be landed.
int main(int argc, char* argv[]) { return 0; }
// 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.
#ifndef V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_
#define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_
#include "include/v8-inspector.h"
#include "include/v8-platform.h"
#include "include/v8.h"
#include "src/base/macros.h"
#include "src/base/platform/platform.h"
#include "src/inspector/string-16.h"
#include "src/locked-queue-inl.h"
class TaskRunner : public v8::base::Thread {
public:
class Task {
public:
virtual ~Task() {}
virtual bool is_inspector_task() = 0;
virtual void Run(v8::Isolate* isolate,
const v8::Global<v8::Context>& context) = 0;
};
explicit TaskRunner(v8::ExtensionConfiguration* extensions,
v8::base::Semaphore* ready_semaphore);
virtual ~TaskRunner();
// Thread implementation.
void Run() override;
// Should be called from the same thread and only from task.
void RunMessageLoop(bool only_protocol);
void QuitMessageLoop();
// TaskRunner takes ownership.
void Append(Task* task);
static TaskRunner* FromContext(v8::Local<v8::Context>);
private:
void InitializeContext();
Task* GetNext(bool only_protocol);
v8::ExtensionConfiguration* extensions_;
v8::base::Semaphore* ready_semaphore_;
v8::Isolate* isolate_;
v8::Global<v8::Context> context_;
// deferred_queue_ combined with queue_ (in this order) have all tasks in the
// correct order.
// Sometimes we skip non-protocol tasks by moving them from queue_ to
// deferred_queue_.
v8::internal::LockedQueue<Task*> queue_;
v8::internal::LockedQueue<Task*> deffered_queue_;
v8::base::Semaphore process_queue_semaphore_;
int nested_loop_count_;
DISALLOW_COPY_AND_ASSIGN(TaskRunner);
};
class ExecuteStringTask : public TaskRunner::Task {
public:
explicit ExecuteStringTask(const v8_inspector::String16& expression);
bool is_inspector_task() override { return false; }
void Run(v8::Isolate* isolate,
const v8::Global<v8::Context>& context) override;
private:
v8_inspector::String16 expression_;
DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask);
};
#endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_
......@@ -203,7 +203,7 @@ class CppLintProcessor(SourceFileProcessor):
def GetPathsToSearch(self):
return ['src', 'include', 'samples', join('test', 'cctest'),
join('test', 'unittests')]
join('test', 'unittests'), join('test', 'inspector')]
def GetCpplintScript(self, prio_path):
for path in [prio_path] + os.environ["PATH"].split(os.pathsep):
......
......@@ -30,6 +30,7 @@ GYP_FILES = [
os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'),
os.path.join(V8_BASE, 'test', 'fuzzer', 'fuzzer.gyp'),
os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'),
os.path.join(V8_BASE, 'test', 'inspector', 'inspector.gyp'),
os.path.join(V8_BASE, 'testing', 'gmock.gyp'),
os.path.join(V8_BASE, 'testing', 'gtest.gyp'),
os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'),
......@@ -47,6 +48,7 @@ ALL_GYP_PREFIXES = [
os.path.join('test', 'common'),
os.path.join('test', 'fuzzer'),
os.path.join('test', 'unittests'),
os.path.join('test', 'inspector'),
]
GYP_UNSUPPORTED_FEATURES = [
......@@ -60,6 +62,7 @@ GN_FILES = [
os.path.join(V8_BASE, 'src', 'inspector', 'BUILD.gn'),
os.path.join(V8_BASE, 'test', 'cctest', 'BUILD.gn'),
os.path.join(V8_BASE, 'test', 'unittests', 'BUILD.gn'),
os.path.join(V8_BASE, 'test', 'inspector', 'BUILD.gn'),
os.path.join(V8_BASE, 'tools', 'BUILD.gn'),
]
......@@ -83,6 +86,7 @@ ALL_GN_PREFIXES = [
'testing',
os.path.join('test', 'cctest'),
os.path.join('test', 'unittests'),
os.path.join('test', 'inspector'),
]
def pathsplit(path):
......
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