Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: test/cctest/test-code-stub-assembler.cc

Issue 2072813003: [test] Move CodeAssembler tests to a separate file. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Minor cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/compiler/test-code-assembler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-code-stub-assembler.cc
diff --git a/test/cctest/test-code-stub-assembler.cc b/test/cctest/test-code-stub-assembler.cc
index 06555351f94727c328420fec0b09b4ac40ed92b6..539a0fd13cdb8daf40d9b31553c2471310e6bb8c 100644
--- a/test/cctest/test-code-stub-assembler.cc
+++ b/test/cctest/test-code-stub-assembler.cc
@@ -4,8 +4,8 @@
#include "src/base/utils/random-number-generator.h"
#include "src/ic/stub-cache.h"
-#include "src/interface-descriptors.h"
#include "src/isolate.h"
+#include "test/cctest/compiler/code-assembler-tester.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
@@ -14,251 +14,8 @@ namespace internal {
using compiler::FunctionTester;
using compiler::Node;
-class ZoneHolder {
- public:
- explicit ZoneHolder(Isolate* isolate) : zone_(isolate->allocator()) {}
- Zone* zone() { return &zone_; }
-
- private:
- Zone zone_;
-};
-
-// Inherit from ZoneHolder in order to create a zone that can be passed to
-// CodeStubAssembler base class constructor.
-class CodeStubAssemblerTester : private ZoneHolder, public CodeStubAssembler {
- public:
- // Test generating code for a stub.
- CodeStubAssemblerTester(Isolate* isolate,
- const CallInterfaceDescriptor& descriptor)
- : ZoneHolder(isolate),
- CodeStubAssembler(isolate, ZoneHolder::zone(), descriptor,
- Code::ComputeFlags(Code::STUB), "test"),
- scope_(isolate) {}
-
- // Test generating code for a JS function (e.g. builtins).
- CodeStubAssemblerTester(Isolate* isolate, int parameter_count)
- : ZoneHolder(isolate),
- CodeStubAssembler(isolate, ZoneHolder::zone(), parameter_count,
- Code::ComputeFlags(Code::FUNCTION), "test"),
- scope_(isolate) {}
-
- // This constructor is intended to be used for creating code objects with
- // specific flags.
- CodeStubAssemblerTester(Isolate* isolate, Code::Flags flags)
- : ZoneHolder(isolate),
- CodeStubAssembler(isolate, ZoneHolder::zone(), 0, flags, "test"),
- scope_(isolate) {}
-
- Handle<Code> GenerateCodeCloseAndEscape() {
- return scope_.CloseAndEscape(GenerateCode());
- }
-
- private:
- HandleScope scope_;
- LocalContext context_;
-};
-
-TEST(SimpleSmiReturn) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- m.Return(m.SmiTag(m.Int32Constant(37)));
- Handle<Code> code = m.GenerateCode();
- FunctionTester ft(descriptor, code);
- MaybeHandle<Object> result = ft.Call();
- CHECK_EQ(37, Handle<Smi>::cast(result.ToHandleChecked())->value());
-}
-
-TEST(SimpleIntPtrReturn) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- int test;
- m.Return(m.IntPtrConstant(reinterpret_cast<intptr_t>(&test)));
- Handle<Code> code = m.GenerateCode();
- FunctionTester ft(descriptor, code);
- MaybeHandle<Object> result = ft.Call();
- CHECK_EQ(reinterpret_cast<intptr_t>(&test),
- reinterpret_cast<intptr_t>(*result.ToHandleChecked()));
-}
-
-TEST(SimpleDoubleReturn) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- m.Return(m.NumberConstant(0.5));
- Handle<Code> code = m.GenerateCode();
- FunctionTester ft(descriptor, code);
- MaybeHandle<Object> result = ft.Call();
- CHECK_EQ(0.5, Handle<HeapNumber>::cast(result.ToHandleChecked())->value());
-}
-
-TEST(SimpleCallRuntime1Arg) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
- Node* b = m.SmiTag(m.Int32Constant(0));
- m.Return(m.CallRuntime(Runtime::kNumberToSmi, context, b));
- Handle<Code> code = m.GenerateCode();
- FunctionTester ft(descriptor, code);
- MaybeHandle<Object> result = ft.Call();
- CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
-}
-
-TEST(SimpleTailCallRuntime1Arg) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
- Node* b = m.SmiTag(m.Int32Constant(0));
- m.TailCallRuntime(Runtime::kNumberToSmi, context, b);
- Handle<Code> code = m.GenerateCode();
- FunctionTester ft(descriptor, code);
- MaybeHandle<Object> result = ft.Call();
- CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
-}
-
-TEST(SimpleCallRuntime2Arg) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
- Node* a = m.SmiTag(m.Int32Constant(2));
- Node* b = m.SmiTag(m.Int32Constant(4));
- m.Return(m.CallRuntime(Runtime::kMathPow, context, a, b));
- Handle<Code> code = m.GenerateCode();
- FunctionTester ft(descriptor, code);
- MaybeHandle<Object> result = ft.Call();
- CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
-}
-
-TEST(SimpleTailCallRuntime2Arg) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
- Node* a = m.SmiTag(m.Int32Constant(2));
- Node* b = m.SmiTag(m.Int32Constant(4));
- m.TailCallRuntime(Runtime::kMathPow, context, a, b);
- Handle<Code> code = m.GenerateCode();
- FunctionTester ft(descriptor, code);
- MaybeHandle<Object> result = ft.Call();
- CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
-}
-
-TEST(VariableMerge1) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
- CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
- Node* temp = m.Int32Constant(0);
- var1.Bind(temp);
- m.Branch(m.Int32Constant(1), &l1, &l2);
- m.Bind(&l1);
- CHECK_EQ(var1.value(), temp);
- m.Goto(&merge);
- m.Bind(&l2);
- CHECK_EQ(var1.value(), temp);
- m.Goto(&merge);
- m.Bind(&merge);
- CHECK_EQ(var1.value(), temp);
-}
-
-TEST(VariableMerge2) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
- CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
- Node* temp = m.Int32Constant(0);
- var1.Bind(temp);
- m.Branch(m.Int32Constant(1), &l1, &l2);
- m.Bind(&l1);
- CHECK_EQ(var1.value(), temp);
- m.Goto(&merge);
- m.Bind(&l2);
- Node* temp2 = m.Int32Constant(2);
- var1.Bind(temp2);
- CHECK_EQ(var1.value(), temp2);
- m.Goto(&merge);
- m.Bind(&merge);
- CHECK_NE(var1.value(), temp);
-}
-
-TEST(VariableMerge3) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
- CodeStubAssembler::Variable var2(&m, MachineRepresentation::kTagged);
- CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
- Node* temp = m.Int32Constant(0);
- var1.Bind(temp);
- var2.Bind(temp);
- m.Branch(m.Int32Constant(1), &l1, &l2);
- m.Bind(&l1);
- CHECK_EQ(var1.value(), temp);
- m.Goto(&merge);
- m.Bind(&l2);
- Node* temp2 = m.Int32Constant(2);
- var1.Bind(temp2);
- CHECK_EQ(var1.value(), temp2);
- m.Goto(&merge);
- m.Bind(&merge);
- CHECK_NE(var1.value(), temp);
- CHECK_NE(var1.value(), temp2);
- CHECK_EQ(var2.value(), temp);
-}
-
-TEST(VariableMergeBindFirst) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
- CodeStubAssembler::Label l1(&m), l2(&m), merge(&m, &var1), end(&m);
- Node* temp = m.Int32Constant(0);
- var1.Bind(temp);
- m.Branch(m.Int32Constant(1), &l1, &l2);
- m.Bind(&l1);
- CHECK_EQ(var1.value(), temp);
- m.Goto(&merge);
- m.Bind(&merge);
- CHECK(var1.value() != temp);
- CHECK(var1.value() != nullptr);
- m.Goto(&end);
- m.Bind(&l2);
- Node* temp2 = m.Int32Constant(2);
- var1.Bind(temp2);
- CHECK_EQ(var1.value(), temp2);
- m.Goto(&merge);
- m.Bind(&end);
- CHECK(var1.value() != temp);
- CHECK(var1.value() != nullptr);
-}
-
-TEST(VariableMergeSwitch) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
- CodeStubAssembler::Label l1(&m), l2(&m), default_label(&m);
- CodeStubAssembler::Label* labels[] = {&l1, &l2};
- int32_t values[] = {1, 2};
- Node* temp = m.Int32Constant(0);
- var1.Bind(temp);
- m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
- m.Bind(&l1);
- DCHECK_EQ(temp, var1.value());
- m.Return(temp);
- m.Bind(&l2);
- DCHECK_EQ(temp, var1.value());
- m.Return(temp);
- m.Bind(&default_label);
- DCHECK_EQ(temp, var1.value());
- m.Return(temp);
-}
+typedef compiler::CodeAssemblerTesterImpl<CodeStubAssembler>
+ CodeStubAssemblerTester;
TEST(FixedArrayAccessSmiIndex) {
Isolate* isolate(CcTest::InitIsolateOnce());
@@ -301,16 +58,12 @@ TEST(LoadInstanceType) {
Handle<Smi>::cast(result.ToHandleChecked())->value());
}
-namespace {
-
-class TestBitField : public BitField<unsigned, 3, 3> {};
-
-} // namespace
-
TEST(BitFieldDecode) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
+
+ class TestBitField : public BitField<unsigned, 3, 3> {};
m.Return(m.SmiTag(m.BitFieldDecode<TestBitField>(m.Int32Constant(0x2f))));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
@@ -321,103 +74,31 @@ TEST(BitFieldDecode) {
CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
-namespace {
-
-Handle<JSFunction> CreateFunctionFromCode(int parameter_count_with_receiver,
- Handle<Code> code) {
- Isolate* isolate = code->GetIsolate();
- Handle<String> name = isolate->factory()->InternalizeUtf8String("test");
- Handle<JSFunction> function =
- isolate->factory()->NewFunctionWithoutPrototype(name, code);
- function->shared()->set_internal_formal_parameter_count(
- parameter_count_with_receiver - 1); // Implicit undefined receiver.
- return function;
-}
-
-} // namespace
-
TEST(JSFunction) {
const int kNumParams = 3; // Receiver, left, right.
Isolate* isolate(CcTest::InitIsolateOnce());
CodeStubAssemblerTester m(isolate, kNumParams);
- m.Return(m.SmiTag(m.Int32Add(m.SmiToWord32(m.Parameter(1)),
- m.SmiToWord32(m.Parameter(2)))));
- Handle<Code> code = m.GenerateCode();
- Handle<JSFunction> function = CreateFunctionFromCode(kNumParams, code);
- Handle<Object> args[] = {Handle<Smi>(Smi::FromInt(23), isolate),
- Handle<Smi>(Smi::FromInt(34), isolate)};
- MaybeHandle<Object> result =
- Execution::Call(isolate, function, isolate->factory()->undefined_value(),
- arraysize(args), args);
- CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
-}
+ m.Return(m.SmiFromWord32(m.Int32Add(m.SmiToWord32(m.Parameter(1)),
+ m.SmiToWord32(m.Parameter(2)))));
-TEST(SplitEdgeBranchMerge) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- CodeStubAssembler::Label l1(&m), merge(&m);
- m.Branch(m.Int32Constant(1), &l1, &merge);
- m.Bind(&l1);
- m.Goto(&merge);
- m.Bind(&merge);
- USE(m.GenerateCode());
-}
-
-TEST(SplitEdgeSwitchMerge) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- CodeStubAssembler::Label l1(&m), l2(&m), l3(&m), default_label(&m);
- CodeStubAssembler::Label* labels[] = {&l1, &l2};
- int32_t values[] = {1, 2};
- m.Branch(m.Int32Constant(1), &l3, &l1);
- m.Bind(&l3);
- m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
- m.Bind(&l1);
- m.Goto(&l2);
- m.Bind(&l2);
- m.Goto(&default_label);
- m.Bind(&default_label);
- USE(m.GenerateCode());
-}
+ Handle<Code> code = m.GenerateCode();
+ FunctionTester ft(code, kNumParams);
-TEST(TestToConstant) {
- Isolate* isolate(CcTest::InitIsolateOnce());
- VoidDescriptor descriptor(isolate);
- CodeStubAssemblerTester m(isolate, descriptor);
- int32_t value32;
- int64_t value64;
- Node* a = m.Int32Constant(5);
- CHECK(m.ToInt32Constant(a, value32));
- CHECK(m.ToInt64Constant(a, value64));
-
- a = m.Int64Constant(static_cast<int64_t>(1) << 32);
- CHECK(!m.ToInt32Constant(a, value32));
- CHECK(m.ToInt64Constant(a, value64));
-
- a = m.Int64Constant(13);
- CHECK(m.ToInt32Constant(a, value32));
- CHECK(m.ToInt64Constant(a, value64));
-
- a = m.UndefinedConstant();
- CHECK(!m.ToInt32Constant(a, value32));
- CHECK(!m.ToInt64Constant(a, value64));
-
- a = m.UndefinedConstant();
- CHECK(!m.ToInt32Constant(a, value32));
- CHECK(!m.ToInt64Constant(a, value64));
+ MaybeHandle<Object> result = ft.Call(isolate->factory()->undefined_value(),
+ handle(Smi::FromInt(23), isolate),
+ handle(Smi::FromInt(34), isolate));
+ CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(ComputeIntegerHash) {
Isolate* isolate(CcTest::InitIsolateOnce());
- const int param_count = 2;
- CodeStubAssemblerTester m(isolate, param_count);
+ const int kNumParams = 2;
+ CodeStubAssemblerTester m(isolate, kNumParams);
m.Return(m.SmiFromWord32(m.ComputeIntegerHash(
m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1)))));
Handle<Code> code = m.GenerateCode();
- FunctionTester ft(code, param_count);
+ FunctionTester ft(code, kNumParams);
Handle<Smi> hash_seed = isolate->factory()->hash_seed();
@@ -440,8 +121,8 @@ TEST(TryToName) {
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
- const int param_count = 3;
- CodeStubAssemblerTester m(isolate, param_count);
+ const int kNumParams = 3;
+ CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
{
@@ -481,7 +162,7 @@ TEST(TryToName) {
}
Handle<Code> code = m.GenerateCode();
- FunctionTester ft(code, param_count);
+ FunctionTester ft(code, kNumParams);
Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate);
Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate);
@@ -539,8 +220,8 @@ void TestNameDictionaryLookup() {
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
- const int param_count = 4;
- CodeStubAssemblerTester m(isolate, param_count);
+ const int kNumParams = 4;
+ CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kFound, kNotFound };
{
@@ -575,7 +256,7 @@ void TestNameDictionaryLookup() {
}
Handle<Code> code = m.GenerateCode();
- FunctionTester ft(code, param_count);
+ FunctionTester ft(code, kNumParams);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
@@ -643,8 +324,8 @@ void TestNumberDictionaryLookup() {
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
- const int param_count = 4;
- CodeStubAssemblerTester m(isolate, param_count);
+ const int kNumParams = 4;
+ CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kFound, kNotFound };
{
@@ -679,7 +360,7 @@ void TestNumberDictionaryLookup() {
}
Handle<Code> code = m.GenerateCode();
- FunctionTester ft(code, param_count);
+ FunctionTester ft(code, kNumParams);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
@@ -749,8 +430,8 @@ TEST(TryLookupProperty) {
typedef CodeStubAssembler::Label Label;
Isolate* isolate(CcTest::InitIsolateOnce());
- const int param_count = 4;
- CodeStubAssemblerTester m(isolate, param_count);
+ const int kNumParams = 4;
+ CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kFound, kNotFound, kBailout };
{
@@ -789,7 +470,7 @@ TEST(TryLookupProperty) {
}
Handle<Code> code = m.GenerateCode();
- FunctionTester ft(code, param_count);
+ FunctionTester ft(code, kNumParams);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
@@ -896,8 +577,8 @@ TEST(TryLookupElement) {
typedef CodeStubAssembler::Label Label;
Isolate* isolate(CcTest::InitIsolateOnce());
- const int param_count = 4;
- CodeStubAssemblerTester m(isolate, param_count);
+ const int kNumParams = 4;
+ CodeStubAssemblerTester m(isolate, kNumParams);
enum Result { kFound, kNotFound, kBailout };
{
@@ -936,7 +617,7 @@ TEST(TryLookupElement) {
}
Handle<Code> code = m.GenerateCode();
- FunctionTester ft(code, param_count);
+ FunctionTester ft(code, kNumParams);
Factory* factory = isolate->factory();
Handle<Object> smi0(Smi::FromInt(0), isolate);
@@ -1137,8 +818,8 @@ namespace {
void TestStubCacheOffsetCalculation(StubCache::Table table,
Code::Kind handler_kind) {
Isolate* isolate(CcTest::InitIsolateOnce());
- const int param_count = 2;
- CodeStubAssemblerTester m(isolate, param_count);
+ const int kNumParams = 2;
+ CodeStubAssemblerTester m(isolate, kNumParams);
Code::Flags code_flags =
Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(handler_kind));
@@ -1157,7 +838,7 @@ void TestStubCacheOffsetCalculation(StubCache::Table table,
}
Handle<Code> code = m.GenerateCode();
- FunctionTester ft(code, param_count);
+ FunctionTester ft(code, kNumParams);
Factory* factory = isolate->factory();
Handle<Name> names[] = {
@@ -1244,8 +925,8 @@ TEST(TryProbeStubCache) {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
- const int param_count = 3;
- CodeStubAssemblerTester m(isolate, param_count);
+ const int kNumParams = 3;
+ CodeStubAssemblerTester m(isolate, kNumParams);
Code::Flags flags_to_query =
Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::LOAD_IC));
@@ -1281,7 +962,7 @@ TEST(TryProbeStubCache) {
}
Handle<Code> code = m.GenerateCode();
- FunctionTester ft(code, param_count);
+ FunctionTester ft(code, kNumParams);
std::vector<Handle<Name>> names;
std::vector<Handle<JSObject>> receivers;
« no previous file with comments | « test/cctest/compiler/test-code-assembler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698