blob: f4ade5d3fcaba2926d1c2519fb14a9f1f46c3fd8 [file] [log] [blame]
Christopher Ferris55d22ef2017-04-04 10:41:31 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdint.h>
18
19#include <ios>
20#include <vector>
21
22#include <gtest/gtest.h>
23
Christopher Ferris2fcf4cf2018-01-23 17:52:23 -080024#include <unwindstack/DwarfError.h>
Christopher Ferrisd226a512017-07-14 10:37:19 -070025#include <unwindstack/DwarfMemory.h>
26#include <unwindstack/Log.h>
27#include <unwindstack/Regs.h>
28
Christopher Ferris55d22ef2017-04-04 10:41:31 -070029#include "DwarfOp.h"
Christopher Ferris55d22ef2017-04-04 10:41:31 -070030
31#include "MemoryFake.h"
32
Christopher Ferrisd226a512017-07-14 10:37:19 -070033namespace unwindstack {
34
Christopher Ferris55d22ef2017-04-04 10:41:31 -070035template <typename TypeParam>
36class DwarfOpLogTest : public ::testing::Test {
37 protected:
38 void SetUp() override {
39 op_memory_.Clear();
40 regular_memory_.Clear();
41 mem_.reset(new DwarfMemory(&op_memory_));
42 op_.reset(new DwarfOp<TypeParam>(mem_.get(), &regular_memory_));
43 }
44
45 MemoryFake op_memory_;
46 MemoryFake regular_memory_;
47
48 std::unique_ptr<DwarfMemory> mem_;
49 std::unique_ptr<DwarfOp<TypeParam>> op_;
50};
Christopher Ferris7e21eba2019-06-20 16:16:42 -070051TYPED_TEST_SUITE_P(DwarfOpLogTest);
Christopher Ferris55d22ef2017-04-04 10:41:31 -070052
53TYPED_TEST_P(DwarfOpLogTest, multiple_ops) {
54 // Multi operation opcodes.
55 std::vector<uint8_t> opcode_buffer = {
56 0x0a, 0x20, 0x10, 0x08, 0x03, 0x12, 0x27,
57 };
58 this->op_memory_.SetMemory(0, opcode_buffer);
59
60 std::vector<std::string> lines;
61 this->op_->GetLogInfo(0, opcode_buffer.size(), &lines);
62 std::vector<std::string> expected{
63 "DW_OP_const2u 4128", "Raw Data: 0x0a 0x20 0x10", "DW_OP_const1u 3", "Raw Data: 0x08 0x03",
64 "DW_OP_dup", "Raw Data: 0x12", "DW_OP_xor", "Raw Data: 0x27"};
65 ASSERT_EQ(expected, lines);
66}
67
Christopher Ferris7e21eba2019-06-20 16:16:42 -070068REGISTER_TYPED_TEST_SUITE_P(DwarfOpLogTest, multiple_ops);
Christopher Ferris55d22ef2017-04-04 10:41:31 -070069
70typedef ::testing::Types<uint32_t, uint64_t> DwarfOpLogTestTypes;
Christopher Ferris7e21eba2019-06-20 16:16:42 -070071INSTANTIATE_TYPED_TEST_SUITE_P(, DwarfOpLogTest, DwarfOpLogTestTypes);
Christopher Ferrisd226a512017-07-14 10:37:19 -070072
73} // namespace unwindstack