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

[test] Move cctest/test-factory to unittests/codegen/

... factory-unittest.

Bug: v8:12781
Change-Id: I862ab02526c21820ef3f12f663a598793bbc6bbd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3699499Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#81104}
parent c5005009
......@@ -179,7 +179,6 @@ v8_source_set("cctest_sources") {
"test-dictionary.cc",
"test-disasm-regex-helper.cc",
"test-disasm-regex-helper.h",
"test-factory.cc",
"test-feedback-vector.cc",
"test-feedback-vector.h",
"test-field-type-tracking.cc",
......
......@@ -988,8 +988,6 @@
'test-embedder-tracing/V8RegisteringEmbedderReference': [SKIP],
'test-external-string-tracker/ExternalString_ExternalBackingStoreSizeIncreasesAfterExternalization': [SKIP],
'test-external-string-tracker/ExternalString_ExternalBackingStoreSizeIncreasesMarkCompact': [SKIP],
'test-factory/Factory_CodeBuilder_BuildOOM': [SKIP],
'test-factory/Factory_CodeBuilder_TryBuildOOM': [SKIP],
'test-global-handles/FinalizerDiesAndKeepsPhantomAliveOnMarkCompact': [SKIP],
'test-global-handles/FinalizerWeakness': [SKIP],
'test-global-handles/GCFromWeakCallbacks': [SKIP],
......
......@@ -261,6 +261,7 @@ v8_source_set("unittests_sources") {
"codegen/code-pages-unittest.cc",
"codegen/code-stub-assembler-unittest.cc",
"codegen/code-stub-assembler-unittest.h",
"codegen/factory-unittest.cc",
"codegen/register-configuration-unittest.cc",
"codegen/source-position-table-unittest.cc",
"compiler-dispatcher/compiler-dispatcher-unittest.cc",
......
......@@ -9,13 +9,37 @@
#include "src/execution/isolate.h"
#include "src/handles/handles-inl.h"
#include "src/heap/heap-inl.h"
#include "test/cctest/cctest.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
namespace test_factory {
namespace {
using FactoryCodeBuilderTest = TestWithIsolate;
TEST_F(FactoryCodeBuilderTest, Factory_CodeBuilder) {
// Create a big function that ends up in CODE_LO_SPACE.
const int instruction_size =
i_isolate()->heap()->MaxRegularHeapObjectSize(AllocationType::kCode) + 1;
std::unique_ptr<byte[]> instructions(new byte[instruction_size]);
CodeDesc desc;
desc.buffer = instructions.get();
desc.buffer_size = instruction_size;
desc.instr_size = instruction_size;
desc.reloc_size = 0;
desc.constant_pool_size = 0;
desc.unwinding_info = nullptr;
desc.unwinding_info_size = 0;
desc.origin = nullptr;
Handle<Code> code =
Factory::CodeBuilder(i_isolate(), desc, CodeKind::WASM_FUNCTION).Build();
CHECK(i_isolate()->heap()->InSpace(*code, CODE_LO_SPACE));
#if VERIFY_HEAP
code->ObjectVerify(i_isolate());
#endif
}
// This needs to be large enough to create a new nosnap Isolate, but smaller
// than kMaximalCodeRangeSize so we can recover from the OOM.
......@@ -30,91 +54,49 @@ size_t NearHeapLimitCallback(void* raw_bool, size_t current_heap_limit,
return kInstructionSize * 2;
}
class SetupIsolateWithSmallHeap {
class FactoryCodeBuilderOOMTest : public TestWithIsolate {
public:
SetupIsolateWithSmallHeap() {
static void SetUpTestSuite() {
FLAG_max_old_space_size = kInstructionSize / MB / 2; // In MB.
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
isolate_ = reinterpret_cast<Isolate*>(v8::Isolate::New(create_params));
isolate_->heap()->AddNearHeapLimitCallback(NearHeapLimitCallback,
&oom_triggered_);
}
~SetupIsolateWithSmallHeap() {
reinterpret_cast<v8::Isolate*>(isolate_)->Dispose();
void SetUp() override {
isolate()->heap()->AddNearHeapLimitCallback(NearHeapLimitCallback,
&oom_triggered_);
}
Isolate* isolate() { return isolate_; }
bool oom_triggered() const { return oom_triggered_; }
private:
Isolate* isolate_;
bool oom_triggered_ = false;
};
} // namespace
TEST(Factory_CodeBuilder) {
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
// Create a big function that ends up in CODE_LO_SPACE.
const int instruction_size =
isolate->heap()->MaxRegularHeapObjectSize(AllocationType::kCode) + 1;
std::unique_ptr<byte[]> instructions(new byte[instruction_size]);
CodeDesc desc;
desc.buffer = instructions.get();
desc.buffer_size = instruction_size;
desc.instr_size = instruction_size;
desc.reloc_size = 0;
desc.constant_pool_size = 0;
desc.unwinding_info = nullptr;
desc.unwinding_info_size = 0;
desc.origin = nullptr;
Handle<Code> code =
Factory::CodeBuilder(isolate, desc, CodeKind::WASM_FUNCTION).Build();
CHECK(isolate->heap()->InSpace(*code, CODE_LO_SPACE));
#if VERIFY_HEAP
code->ObjectVerify(isolate);
#endif
}
UNINITIALIZED_TEST(Factory_CodeBuilder_BuildOOM) {
SetupIsolateWithSmallHeap isolate_scope;
HandleScope scope(isolate_scope.isolate());
TEST_F(FactoryCodeBuilderOOMTest, Factory_CodeBuilder_BuildOOM) {
std::unique_ptr<byte[]> instructions(new byte[kInstructionSize]);
CodeDesc desc;
desc.instr_size = kInstructionSize;
desc.buffer = instructions.get();
const Handle<Code> code = Factory::CodeBuilder(isolate_scope.isolate(), desc,
CodeKind::WASM_FUNCTION)
.Build();
const Handle<Code> code =
Factory::CodeBuilder(i_isolate(), desc, CodeKind::WASM_FUNCTION).Build();
CHECK(!code.is_null());
CHECK(isolate_scope.oom_triggered());
CHECK(oom_triggered());
}
UNINITIALIZED_TEST(Factory_CodeBuilder_TryBuildOOM) {
SetupIsolateWithSmallHeap isolate_scope;
HandleScope scope(isolate_scope.isolate());
TEST_F(FactoryCodeBuilderOOMTest, Factory_CodeBuilder_TryBuildOOM) {
std::unique_ptr<byte[]> instructions(new byte[kInstructionSize]);
CodeDesc desc;
desc.instr_size = kInstructionSize;
desc.buffer = instructions.get();
const MaybeHandle<Code> code =
Factory::CodeBuilder(isolate_scope.isolate(), desc,
CodeKind::WASM_FUNCTION)
Factory::CodeBuilder(i_isolate(), desc, CodeKind::WASM_FUNCTION)
.TryBuild();
CHECK(code.is_null());
CHECK(!isolate_scope.oom_triggered());
CHECK(!oom_triggered());
}
} // namespace test_factory
} // namespace internal
} // namespace v8
......@@ -199,6 +199,10 @@
# Access chunk metadata
'RootsTest.TestHeapRootsNotReadOnly': [SKIP],
'RootsTest.TestReadOnlyRoots': [SKIP],
# Expects OOM
'FactoryCodeBuilderOOMTest.Factory_CodeBuilder_BuildOOM': [SKIP],
'FactoryCodeBuilderOOMTest.Factory_CodeBuilder_TryBuildOOM': [SKIP],
}], # third_party_heap
##############################################################################
......
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