1 /*
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
24 #include <unwindstack/DwarfError.h>
25 #include <unwindstack/DwarfMemory.h>
26 #include <unwindstack/Log.h>
27 #include <unwindstack/Regs.h>
28
29 #include "DwarfOp.h"
30
31 #include "MemoryFake.h"
32
33 namespace unwindstack {
34
35 template <typename TypeParam>
36 class DwarfOpLogTest : public ::testing::Test {
37 protected:
SetUp()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(), ®ular_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 };
51 TYPED_TEST_SUITE_P(DwarfOpLogTest);
52
TYPED_TEST_P(DwarfOpLogTest,multiple_ops)53 TYPED_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
68 REGISTER_TYPED_TEST_SUITE_P(DwarfOpLogTest, multiple_ops);
69
70 typedef ::testing::Types<uint32_t, uint64_t> DwarfOpLogTestTypes;
71 INSTANTIATE_TYPED_TEST_SUITE_P(Libunwindstack, DwarfOpLogTest, DwarfOpLogTestTypes);
72
73 } // namespace unwindstack
74