Commit b8a01ce0 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/test-compiler to unittests

... /compiler/compiler-unittest.

- Add PrintExtension for adding print function.
- Add WithPrintExtensionMixin to register
PrintExtension.
- Add StreamerThread to run a ScriptStreamingTask
in a separate thread.

Bug: v8:12781
Change-Id: I9d3324f3a8dcf00b5b121db6007c9a3cb2972313
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3596442Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80084}
parent f7cc70de
...@@ -200,7 +200,6 @@ v8_source_set("cctest_sources") { ...@@ -200,7 +200,6 @@ v8_source_set("cctest_sources") {
"test-code-layout.cc", "test-code-layout.cc",
"test-code-pages.cc", "test-code-pages.cc",
"test-code-stub-assembler.cc", "test-code-stub-assembler.cc",
"test-compiler.cc",
"test-concurrent-descriptor-array.cc", "test-concurrent-descriptor-array.cc",
"test-concurrent-feedback-vector.cc", "test-concurrent-feedback-vector.cc",
"test-concurrent-js-array.cc", "test-concurrent-js-array.cc",
......
...@@ -257,6 +257,7 @@ v8_source_set("unittests_sources") { ...@@ -257,6 +257,7 @@ v8_source_set("unittests_sources") {
"compiler/common-operator-reducer-unittest.cc", "compiler/common-operator-reducer-unittest.cc",
"compiler/common-operator-unittest.cc", "compiler/common-operator-unittest.cc",
"compiler/compiler-test-utils.h", "compiler/compiler-test-utils.h",
"compiler/compiler-unittest.cc",
"compiler/constant-folding-reducer-unittest.cc", "compiler/constant-folding-reducer-unittest.cc",
"compiler/control-equivalence-unittest.cc", "compiler/control-equivalence-unittest.cc",
"compiler/control-flow-optimizer-unittest.cc", "compiler/control-flow-optimizer-unittest.cc",
......
...@@ -11,8 +11,10 @@ ...@@ -11,8 +11,10 @@
#include "include/libplatform/libplatform.h" #include "include/libplatform/libplatform.h"
#include "include/v8-array-buffer.h" #include "include/v8-array-buffer.h"
#include "include/v8-context.h" #include "include/v8-context.h"
#include "include/v8-extension.h"
#include "include/v8-local-handle.h" #include "include/v8-local-handle.h"
#include "include/v8-primitive.h" #include "include/v8-primitive.h"
#include "include/v8-template.h"
#include "src/api/api-inl.h" #include "src/api/api-inl.h"
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/base/utils/random-number-generator.h" #include "src/base/utils/random-number-generator.h"
...@@ -205,6 +207,62 @@ using TestWithContext = // ...@@ -205,6 +207,62 @@ using TestWithContext = //
WithDefaultPlatformMixin< // WithDefaultPlatformMixin< //
::testing::Test>>>>; ::testing::Test>>>>;
class PrintExtension : public v8::Extension {
public:
PrintExtension() : v8::Extension("v8/print", "native function print();") {}
v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) override {
return v8::FunctionTemplate::New(isolate, PrintExtension::Print);
}
static void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
for (int i = 0; i < args.Length(); i++) {
if (i != 0) printf(" ");
v8::HandleScope scope(args.GetIsolate());
v8::String::Utf8Value str(args.GetIsolate(), args[i]);
if (*str == nullptr) return;
printf("%s", *str);
}
printf("\n");
}
};
template <typename TMixin>
class WithPrintExtensionMixin : public TMixin {
public:
WithPrintExtensionMixin() = default;
~WithPrintExtensionMixin() override = default;
WithPrintExtensionMixin(const WithPrintExtensionMixin&) = delete;
WithPrintExtensionMixin& operator=(const WithPrintExtensionMixin&) = delete;
static void SetUpTestSuite() {
v8::RegisterExtension(std::make_unique<PrintExtension>());
TMixin::SetUpTestSuite();
}
static void TearDownTestSuite() { TMixin::TearDownTestSuite(); }
static constexpr const char* kPrintExtensionName = "v8/print";
};
// Run a ScriptStreamingTask in a separate thread.
class StreamerThread : public v8::base::Thread {
public:
static void StartThreadForTaskAndJoin(
v8::ScriptCompiler::ScriptStreamingTask* task) {
StreamerThread thread(task);
CHECK(thread.Start());
thread.Join();
}
explicit StreamerThread(v8::ScriptCompiler::ScriptStreamingTask* task)
: Thread(Thread::Options()), task_(task) {}
void Run() override { task_->Run(); }
private:
v8::ScriptCompiler::ScriptStreamingTask* task_;
};
namespace internal { namespace internal {
// Forward declarations. // Forward declarations.
......
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