| Index: runtime/vm/stub_code_arm64_test.cc
|
| ===================================================================
|
| --- runtime/vm/stub_code_arm64_test.cc (revision 35189)
|
| +++ runtime/vm/stub_code_arm64_test.cc (working copy)
|
| @@ -5,6 +5,111 @@
|
| #include "vm/globals.h"
|
| #if defined(TARGET_ARCH_ARM64)
|
|
|
| -// TODO(zra): Port these tests.
|
| +#include "vm/isolate.h"
|
| +#include "vm/dart_entry.h"
|
| +#include "vm/native_entry.h"
|
| +#include "vm/native_entry_test.h"
|
| +#include "vm/object.h"
|
| +#include "vm/runtime_entry.h"
|
| +#include "vm/stub_code.h"
|
| +#include "vm/symbols.h"
|
| +#include "vm/unit_test.h"
|
|
|
| +#define __ assembler->
|
| +
|
| +namespace dart {
|
| +
|
| +DECLARE_RUNTIME_ENTRY(TestSmiSub);
|
| +DECLARE_LEAF_RUNTIME_ENTRY(RawObject*, TestLeafSmiAdd, RawObject*, RawObject*);
|
| +
|
| +
|
| +static Function* CreateFunction(const char* name) {
|
| + const String& class_name = String::Handle(Symbols::New("ownerClass"));
|
| + const Script& script = Script::Handle();
|
| + const Class& owner_class =
|
| + Class::Handle(Class::New(class_name, script, Scanner::kNoSourcePos));
|
| + const Library& lib = Library::Handle(Library::New(class_name));
|
| + owner_class.set_library(lib);
|
| + const String& function_name = String::ZoneHandle(Symbols::New(name));
|
| + Function& function = Function::ZoneHandle(
|
| + Function::New(function_name, RawFunction::kRegularFunction,
|
| + true, false, false, false, false, owner_class, 0));
|
| + return &function;
|
| +}
|
| +
|
| +
|
| +// Test calls to stub code which calls into the runtime.
|
| +static void GenerateCallToCallRuntimeStub(Assembler* assembler,
|
| + int value1, int value2) {
|
| + const int argc = 2;
|
| + const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
|
| + const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2));
|
| + const Object& result = Object::ZoneHandle();
|
| + const Context& context = Context::ZoneHandle(Context::New(0, Heap::kOld));
|
| + ASSERT(context.isolate() == Isolate::Current());
|
| + __ EnterDartFrame(0);
|
| + __ LoadObject(CTX, context, PP);
|
| + __ PushObject(result, PP); // Push Null object for return value.
|
| + __ PushObject(smi1, PP); // Push argument 1 smi1.
|
| + __ PushObject(smi2, PP); // Push argument 2 smi2.
|
| + ASSERT(kTestSmiSubRuntimeEntry.argument_count() == argc);
|
| + __ CallRuntime(kTestSmiSubRuntimeEntry, argc); // Call SmiSub runtime func.
|
| + __ add(SP, SP, Operand(argc * kWordSize));
|
| + __ Pop(R0); // Pop return value from return slot.
|
| + __ LeaveDartFrame();
|
| + __ ret();
|
| +}
|
| +
|
| +
|
| +TEST_CASE(CallRuntimeStubCode) {
|
| + extern const Function& RegisterFakeFunction(const char* name,
|
| + const Code& code);
|
| + const int value1 = 10;
|
| + const int value2 = 20;
|
| + const char* kName = "Test_CallRuntimeStubCode";
|
| + Assembler _assembler_;
|
| + GenerateCallToCallRuntimeStub(&_assembler_, value1, value2);
|
| + const Code& code = Code::Handle(Code::FinalizeCode(
|
| + *CreateFunction("Test_CallRuntimeStubCode"), &_assembler_));
|
| + const Function& function = RegisterFakeFunction(kName, code);
|
| + Smi& result = Smi::Handle();
|
| + result ^= DartEntry::InvokeFunction(function, Object::empty_array());
|
| + EXPECT_EQ((value1 - value2), result.Value());
|
| +}
|
| +
|
| +
|
| +// Test calls to stub code which calls into a leaf runtime entry.
|
| +static void GenerateCallToCallLeafRuntimeStub(Assembler* assembler,
|
| + int value1,
|
| + int value2) {
|
| + const Smi& smi1 = Smi::ZoneHandle(Smi::New(value1));
|
| + const Smi& smi2 = Smi::ZoneHandle(Smi::New(value2));
|
| + __ EnterDartFrame(0);
|
| + __ ReserveAlignedFrameSpace(0);
|
| + __ LoadObject(R0, smi1, PP); // Set up argument 1 smi1.
|
| + __ LoadObject(R1, smi2, PP); // Set up argument 2 smi2.
|
| + __ CallRuntime(kTestLeafSmiAddRuntimeEntry, 2); // Call SmiAdd runtime func.
|
| + __ LeaveDartFrame();
|
| + __ ret(); // Return value is in R0.
|
| +}
|
| +
|
| +
|
| +TEST_CASE(CallLeafRuntimeStubCode) {
|
| + extern const Function& RegisterFakeFunction(const char* name,
|
| + const Code& code);
|
| + const int value1 = 10;
|
| + const int value2 = 20;
|
| + const char* kName = "Test_CallLeafRuntimeStubCode";
|
| + Assembler _assembler_;
|
| + GenerateCallToCallLeafRuntimeStub(&_assembler_, value1, value2);
|
| + const Code& code = Code::Handle(Code::FinalizeCode(
|
| + *CreateFunction("Test_CallLeafRuntimeStubCode"), &_assembler_));
|
| + const Function& function = RegisterFakeFunction(kName, code);
|
| + Smi& result = Smi::Handle();
|
| + result ^= DartEntry::InvokeFunction(function, Object::empty_array());
|
| + EXPECT_EQ((value1 + value2), result.Value());
|
| +}
|
| +
|
| +} // namespace dart
|
| +
|
| #endif // defined TARGET_ARCH_ARM64
|
|
|