1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dex_instruction-inl.h"
#include "gtest/gtest.h"
namespace art {
TEST(StaticGetters, PropertiesOfNopTest) {
Instruction::Code nop = Instruction::NOP;
EXPECT_STREQ("nop", Instruction::Name(nop));
EXPECT_EQ(Instruction::k10x, Instruction::FormatOf(nop));
EXPECT_EQ(Instruction::kIndexNone, Instruction::IndexTypeOf(nop));
EXPECT_EQ(Instruction::kContinue, Instruction::FlagsOf(nop));
EXPECT_EQ(Instruction::kVerifyNone, Instruction::VerifyFlagsOf(nop));
}
static void Build45cc(uint8_t num_args, uint16_t method_idx, uint16_t proto_idx,
uint16_t arg_regs, uint16_t* out) {
// A = num argument registers
// B = method_idx
// C - G = argument registers
// H = proto_idx
//
// op = 0xFA
//
// format:
// AG op BBBB FEDC HHHH
out[0] = 0;
out[0] |= (num_args << 12);
out[0] |= 0x00FA;
out[1] = method_idx;
out[2] = arg_regs;
out[3] = proto_idx;
}
static void Build4rcc(uint16_t num_args, uint16_t method_idx, uint16_t proto_idx,
uint16_t arg_regs_start, uint16_t* out) {
// A = num argument registers
// B = method_idx
// C = first argument register
// H = proto_idx
//
// op = 0xFB
//
// format:
// AA op BBBB CCCC HHHH
out[0] = 0;
out[0] |= (num_args << 8);
out[0] |= 0x00FB;
out[1] = method_idx;
out[2] = arg_regs_start;
out[3] = proto_idx;
}
TEST(Instruction, PropertiesOf45cc) {
uint16_t instruction[4];
Build45cc(4u /* num_vregs */, 16u /* method_idx */, 32u /* proto_idx */,
0xcafe /* arg_regs */, instruction);
const Instruction* ins = Instruction::At(instruction);
ASSERT_EQ(4u, ins->SizeInCodeUnits());
ASSERT_TRUE(ins->HasVRegA());
ASSERT_EQ(4, ins->VRegA());
ASSERT_EQ(4u, ins->VRegA_45cc());
ASSERT_EQ(4u, ins->VRegA_45cc(instruction[0]));
ASSERT_TRUE(ins->HasVRegB());
ASSERT_EQ(16, ins->VRegB());
ASSERT_EQ(16u, ins->VRegB_45cc());
ASSERT_TRUE(ins->HasVRegC());
ASSERT_EQ(0xe, ins->VRegC());
ASSERT_EQ(0xe, ins->VRegC_45cc());
ASSERT_TRUE(ins->HasVRegH());
ASSERT_EQ(32, ins->VRegH());
ASSERT_EQ(32, ins->VRegH_45cc());
ASSERT_TRUE(ins->HasVarArgs());
uint32_t arg_regs[Instruction::kMaxVarArgRegs];
ins->GetVarArgs(arg_regs);
ASSERT_EQ(0xeu, arg_regs[0]);
ASSERT_EQ(0xfu, arg_regs[1]);
ASSERT_EQ(0xau, arg_regs[2]);
ASSERT_EQ(0xcu, arg_regs[3]);
}
TEST(Instruction, PropertiesOf4rcc) {
uint16_t instruction[4];
Build4rcc(4u /* num_vregs */, 16u /* method_idx */, 32u /* proto_idx */,
0xcafe /* arg_regs */, instruction);
const Instruction* ins = Instruction::At(instruction);
ASSERT_EQ(4u, ins->SizeInCodeUnits());
ASSERT_TRUE(ins->HasVRegA());
ASSERT_EQ(4, ins->VRegA());
ASSERT_EQ(4u, ins->VRegA_4rcc());
ASSERT_EQ(4u, ins->VRegA_4rcc(instruction[0]));
ASSERT_TRUE(ins->HasVRegB());
ASSERT_EQ(16, ins->VRegB());
ASSERT_EQ(16u, ins->VRegB_4rcc());
ASSERT_TRUE(ins->HasVRegC());
ASSERT_EQ(0xcafe, ins->VRegC());
ASSERT_EQ(0xcafe, ins->VRegC_4rcc());
ASSERT_TRUE(ins->HasVRegH());
ASSERT_EQ(32, ins->VRegH());
ASSERT_EQ(32, ins->VRegH_4rcc());
ASSERT_FALSE(ins->HasVarArgs());
}
} // namespace art
|