diff options
Diffstat (limited to 'libunwindstack/tests/DwarfOpLogTest.cpp')
-rw-r--r-- | libunwindstack/tests/DwarfOpLogTest.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libunwindstack/tests/DwarfOpLogTest.cpp b/libunwindstack/tests/DwarfOpLogTest.cpp new file mode 100644 index 000000000..d18aad056 --- /dev/null +++ b/libunwindstack/tests/DwarfOpLogTest.cpp | |||
@@ -0,0 +1,68 @@ | |||
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 "DwarfError.h" | ||
25 | #include "DwarfMemory.h" | ||
26 | #include "DwarfOp.h" | ||
27 | #include "Log.h" | ||
28 | #include "Regs.h" | ||
29 | |||
30 | #include "MemoryFake.h" | ||
31 | |||
32 | template <typename TypeParam> | ||
33 | class DwarfOpLogTest : public ::testing::Test { | ||
34 | protected: | ||
35 | void SetUp() override { | ||
36 | op_memory_.Clear(); | ||
37 | regular_memory_.Clear(); | ||
38 | mem_.reset(new DwarfMemory(&op_memory_)); | ||
39 | op_.reset(new DwarfOp<TypeParam>(mem_.get(), ®ular_memory_)); | ||
40 | } | ||
41 | |||
42 | MemoryFake op_memory_; | ||
43 | MemoryFake regular_memory_; | ||
44 | |||
45 | std::unique_ptr<DwarfMemory> mem_; | ||
46 | std::unique_ptr<DwarfOp<TypeParam>> op_; | ||
47 | }; | ||
48 | TYPED_TEST_CASE_P(DwarfOpLogTest); | ||
49 | |||
50 | TYPED_TEST_P(DwarfOpLogTest, multiple_ops) { | ||
51 | // Multi operation opcodes. | ||
52 | std::vector<uint8_t> opcode_buffer = { | ||
53 | 0x0a, 0x20, 0x10, 0x08, 0x03, 0x12, 0x27, | ||
54 | }; | ||
55 | this->op_memory_.SetMemory(0, opcode_buffer); | ||
56 | |||
57 | std::vector<std::string> lines; | ||
58 | this->op_->GetLogInfo(0, opcode_buffer.size(), &lines); | ||
59 | std::vector<std::string> expected{ | ||
60 | "DW_OP_const2u 4128", "Raw Data: 0x0a 0x20 0x10", "DW_OP_const1u 3", "Raw Data: 0x08 0x03", | ||
61 | "DW_OP_dup", "Raw Data: 0x12", "DW_OP_xor", "Raw Data: 0x27"}; | ||
62 | ASSERT_EQ(expected, lines); | ||
63 | } | ||
64 | |||
65 | REGISTER_TYPED_TEST_CASE_P(DwarfOpLogTest, multiple_ops); | ||
66 | |||
67 | typedef ::testing::Types<uint32_t, uint64_t> DwarfOpLogTestTypes; | ||
68 | INSTANTIATE_TYPED_TEST_CASE_P(, DwarfOpLogTest, DwarfOpLogTestTypes); | ||