[AArch64] Fix SDNode type mismatches between *.td files and ISel (#116523)
[llvm-project.git] / lldb / unittests / Core / DumpRegisterInfoTest.cpp
blob593170c2822abf768063e3aa257466c06cffe838
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 |");
106 TEST(DoDumpRegisterInfoTest, Enumerators) {
107 StreamString strm;
109 FieldEnum enum_one("enum_one", {{0, "an_enumerator"}});
110 FieldEnum enum_two("enum_two",
111 {{1, "another_enumerator"}, {2, "another_enumerator_2"}});
113 RegisterFlags flags("", 4,
114 {RegisterFlags::Field("A", 24, 31, &enum_one),
115 RegisterFlags::Field("B", 16, 23),
116 RegisterFlags::Field("C", 8, 15, &enum_two)});
118 DoDumpRegisterInfo(strm, "abc", nullptr, 4, {}, {}, {}, &flags, 100);
119 ASSERT_EQ(strm.GetString(),
120 " Name: abc\n"
121 " Size: 4 bytes (32 bits)\n"
122 "\n"
123 "| 31-24 | 23-16 | 15-8 | 7-0 |\n"
124 "|-------|-------|------|-----|\n"
125 "| A | B | C | |\n"
126 "\n"
127 "A: 0 = an_enumerator\n"
128 "\n"
129 "C: 1 = another_enumerator, 2 = another_enumerator_2");