1 //===-- DumpRegisterInfoTest.cpp ------------------------------------------===//
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
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
) {
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
) {
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
) {
32 DoDumpRegisterInfo(strm
, "foo", nullptr, 4, {"foo2"}, {}, {}, nullptr, 0);
33 ASSERT_EQ(strm
.GetString(), " Name: foo\n"
34 " Size: 4 bytes (32 bits)\n"
38 DoDumpRegisterInfo(strm
, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {},
40 ASSERT_EQ(strm
.GetString(), " Name: foo\n"
41 " Size: 4 bytes (32 bits)\n"
42 "Invalidates: foo2, foo3, foo4");
45 TEST(DoDumpRegisterInfoTest
, ReadFrom
) {
47 DoDumpRegisterInfo(strm
, "foo", nullptr, 4, {}, {"foo1"}, {}, nullptr, 0);
48 ASSERT_EQ(strm
.GetString(), " Name: foo\n"
49 " Size: 4 bytes (32 bits)\n"
53 DoDumpRegisterInfo(strm
, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {},
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
) {
62 DoDumpRegisterInfo(strm
, "foo", nullptr, 4, {}, {}, {{"set1", 101}}, nullptr,
64 ASSERT_EQ(strm
.GetString(), " Name: foo\n"
65 " Size: 4 bytes (32 bits)\n"
66 " In sets: set1 (index 101)");
69 DoDumpRegisterInfo(strm
, "foo", nullptr, 4, {}, {},
70 {{"set1", 0}, {"set2", 1}, {"set3", 2}}, nullptr, 0);
71 ASSERT_EQ(strm
.GetString(),
73 " Size: 4 bytes (32 bits)\n"
74 " In sets: set1 (index 0), set2 (index 1), set3 (index 2)");
77 TEST(DoDumpRegisterInfoTest
, MaxInfo
) {
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
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"
101 "| 31-24 | 23-16 | 15-8 | 7-0 |\n"
102 "|-------|-------|------|-----|\n"
103 "| A | B | C | D |");
106 TEST(DoDumpRegisterInfoTest
, Enumerators
) {
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(),
121 " Size: 4 bytes (32 bits)\n"
123 "| 31-24 | 23-16 | 15-8 | 7-0 |\n"
124 "|-------|-------|------|-----|\n"
127 "A: 0 = an_enumerator\n"
129 "C: 1 = another_enumerator, 2 = another_enumerator_2");