[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Core / DumpRegisterInfoTest.cpp
blob0d3ff8f542595f2aad3ffc008a3c3465e1d6959f
1 //===-- DumpRegisterInfoTest.cpp ------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/DumpRegisterInfo.h"
10 #include "lldb/Target/RegisterFlags.h"
11 #include "lldb/Utility/StreamString.h"
12 #include "gtest/gtest.h"
14 using namespace lldb_private;
16 TEST(DoDumpRegisterInfoTest, MinimumInfo) {
17 StreamString strm;
18 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {}, nullptr, 0);
19 ASSERT_EQ(strm.GetString(), " Name: foo\n"
20 " Size: 4 bytes (32 bits)");
23 TEST(DoDumpRegisterInfoTest, AltName) {
24 StreamString strm;
25 DoDumpRegisterInfo(strm, "foo", "bar", 4, {}, {}, {}, nullptr, 0);
26 ASSERT_EQ(strm.GetString(), " Name: foo (bar)\n"
27 " Size: 4 bytes (32 bits)");
30 TEST(DoDumpRegisterInfoTest, Invalidates) {
31 StreamString strm;
32 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2"}, {}, {}, nullptr, 0);
33 ASSERT_EQ(strm.GetString(), " Name: foo\n"
34 " Size: 4 bytes (32 bits)\n"
35 "Invalidates: foo2");
37 strm.Clear();
38 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {},
39 nullptr, 0);
40 ASSERT_EQ(strm.GetString(), " Name: foo\n"
41 " Size: 4 bytes (32 bits)\n"
42 "Invalidates: foo2, foo3, foo4");
45 TEST(DoDumpRegisterInfoTest, ReadFrom) {
46 StreamString strm;
47 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1"}, {}, nullptr, 0);
48 ASSERT_EQ(strm.GetString(), " Name: foo\n"
49 " Size: 4 bytes (32 bits)\n"
50 " Read from: foo1");
52 strm.Clear();
53 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {},
54 nullptr, 0);
55 ASSERT_EQ(strm.GetString(), " Name: foo\n"
56 " Size: 4 bytes (32 bits)\n"
57 " Read from: foo1, foo2, foo3");
60 TEST(DoDumpRegisterInfoTest, InSets) {
61 StreamString strm;
62 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {{"set1", 101}}, nullptr,
63 0);
64 ASSERT_EQ(strm.GetString(), " Name: foo\n"
65 " Size: 4 bytes (32 bits)\n"
66 " In sets: set1 (index 101)");
68 strm.Clear();
69 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {},
70 {{"set1", 0}, {"set2", 1}, {"set3", 2}}, nullptr, 0);
71 ASSERT_EQ(strm.GetString(),
72 " Name: foo\n"
73 " Size: 4 bytes (32 bits)\n"
74 " In sets: set1 (index 0), set2 (index 1), set3 (index 2)");
77 TEST(DoDumpRegisterInfoTest, MaxInfo) {
78 StreamString strm;
79 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3"},
80 {"foo3", "foo4"}, {{"set1", 1}, {"set2", 2}}, nullptr, 0);
81 ASSERT_EQ(strm.GetString(), " Name: foo\n"
82 " Size: 4 bytes (32 bits)\n"
83 "Invalidates: foo2, foo3\n"
84 " Read from: foo3, foo4\n"
85 " In sets: set1 (index 1), set2 (index 2)");
88 TEST(DoDumpRegisterInfoTest, FieldsTable) {
89 // This is thoroughly tested in RegisterFlags itself, only checking the
90 // integration here.
91 StreamString strm;
92 RegisterFlags flags(
93 "", 4,
94 {RegisterFlags::Field("A", 24, 31), RegisterFlags::Field("B", 16, 23),
95 RegisterFlags::Field("C", 8, 15), RegisterFlags::Field("D", 0, 7)});
97 DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {}, &flags, 100);
98 ASSERT_EQ(strm.GetString(), " Name: foo\n"
99 " Size: 4 bytes (32 bits)\n"
100 "\n"
101 "| 31-24 | 23-16 | 15-8 | 7-0 |\n"
102 "|-------|-------|------|-----|\n"
103 "| A | B | C | D |");