-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
build,test: add tests for binary linked with shared libnode #61463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joyeecheung
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
joyeecheung:fix-shared-pl-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #include <libplatform/libplatform.h> | ||
| #include <v8-cppgc.h> | ||
| #include <v8.h> | ||
|
|
||
| #include <cppgc/allocation.h> | ||
| #include <cppgc/default-platform.h> | ||
| #include <cppgc/garbage-collected.h> | ||
| #include <cppgc/heap.h> | ||
| #include <cppgc/member.h> | ||
| #include <cppgc/platform.h> | ||
| #include <cppgc/visitor.h> | ||
|
|
||
| class Wrappable : public v8::Object::Wrappable { | ||
| public: | ||
| void Trace(cppgc::Visitor* visitor) const override { | ||
| v8::Object::Wrappable::Trace(visitor); | ||
| } | ||
| }; | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform(); | ||
| v8::V8::InitializePlatform(platform.get()); | ||
| cppgc::InitializeProcess(platform->GetPageAllocator()); | ||
| v8::V8::Initialize(); | ||
|
|
||
| auto heap = v8::CppHeap::Create(platform.get(), v8::CppHeapCreateParams{{}}); | ||
| v8::Isolate::CreateParams create_params; | ||
| create_params.array_buffer_allocator = | ||
| v8::ArrayBuffer::Allocator::NewDefaultAllocator(); | ||
| create_params.cpp_heap = heap.release(); | ||
|
|
||
| v8::Isolate* isolate = v8::Isolate::New(create_params); | ||
| { | ||
| v8::Isolate::Scope isolate_scope(isolate); | ||
| v8::HandleScope handle_scope(isolate); | ||
| v8::Local<v8::Context> context = v8::Context::New(isolate); | ||
| v8::Context::Scope context_scope(context); | ||
|
|
||
| v8::Local<v8::Object> obj = v8::Object::New(isolate); | ||
| Wrappable* wrappable = cppgc::MakeGarbageCollected<Wrappable>( | ||
| isolate->GetCppHeap()->GetAllocationHandle()); | ||
| v8::Object::Wrap<v8::CppHeapPointerTag::kDefaultTag>( | ||
| isolate, obj, wrappable); | ||
| v8::Local<v8::String> source = | ||
| v8::String::NewFromUtf8Literal(isolate, "'Hello' + ', World!'"); | ||
| v8::Local<v8::Script> script = | ||
| v8::Script::Compile(context, source).ToLocalChecked(); | ||
| v8::Local<v8::Value> result = script->Run(context).ToLocalChecked(); | ||
| v8::String::Utf8Value utf8(isolate, result); | ||
| printf("%s\n", *utf8); | ||
| } | ||
|
|
||
| isolate->Dispose(); | ||
| cppgc::ShutdownProcess(); | ||
| v8::V8::Dispose(); | ||
| v8::V8::DisposePlatform(); | ||
| delete create_params.array_buffer_allocator; | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 'use strict'; | ||
|
|
||
| // This tests the V8 parts in the shared library work correctly. | ||
| // TODO(joyeecheung): also test that the Node.js parts work correctly, | ||
| // which can be done in embedtest just built in shared library mode. | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| if (!common.usesSharedLibrary) { | ||
| common.skip('Only tests builds linking against Node.js shared library'); | ||
| } | ||
|
|
||
| const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| const fs = require('fs'); | ||
|
|
||
| const binary = common.resolveBuiltBinary('shared_embedtest'); | ||
|
|
||
| if (!fs.existsSync(binary)) { | ||
| common.skip('shared_embedtest binary not built'); | ||
| } | ||
|
|
||
| spawnSyncAndAssert(binary, { | ||
| trim: true, | ||
| stdout: 'Hello, World!', | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested these platforms locally, in the CI this currently would only be exercised on Linux. For other platforms where people happen to build and use libnode, I guess there's no need to potentially break their test flow with this - if they care about this use case they can add the platform name into this mix to ensure it's tested in their workflow.