1 /*
2 * Copyright (C) 2021 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 <elf.h>
18 #include <stdint.h>
19
20 #include <gtest/gtest.h>
21
22 #include <memory>
23 #include <string>
24 #include <vector>
25
26 #include <unwindstack/Arch.h>
27 #include <unwindstack/Elf.h>
28 #include <unwindstack/Memory.h>
29
30 #include "GlobalDebugImpl.h"
31
32 namespace unwindstack {
33
TEST(GlobalDebugImplTest,strip_address_tag_non_arm64)34 TEST(GlobalDebugImplTest, strip_address_tag_non_arm64) {
35 std::shared_ptr<Memory> memory;
36 std::vector<std::string> libs;
37 GlobalDebugImpl<Elf, uint64_t, Uint64_P> debug(ARCH_X86_64, memory, libs, nullptr);
38
39 EXPECT_EQ(0UL, debug.StripAddressTag(0));
40 EXPECT_EQ(0x1234567812345678UL, debug.StripAddressTag(0x1234567812345678UL));
41 }
42
TEST(GlobalDebugImplTest,strip_address_tag_arm64)43 TEST(GlobalDebugImplTest, strip_address_tag_arm64) {
44 std::shared_ptr<Memory> memory;
45 std::vector<std::string> libs;
46 GlobalDebugImpl<Elf, uint64_t, Uint64_P> debug(ARCH_ARM64, memory, libs, nullptr);
47
48 EXPECT_EQ(0UL, debug.StripAddressTag(0));
49 EXPECT_EQ(0x34567812345678UL, debug.StripAddressTag(0x1234567812345678UL));
50
51 // Verify value is sign-extended.
52 EXPECT_EQ(0xfff4567812345678UL, debug.StripAddressTag(0x00f4567812345678UL));
53 }
54
55 } // namespace unwindstack
56