|
| 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 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "lldb/Core/DumpRegisterInfo.h" |
| 10 | +#include "lldb/Utility/StreamString.h" |
| 11 | +#include "gtest/gtest.h" |
| 12 | + |
| 13 | +using namespace lldb_private; |
| 14 | + |
| 15 | +TEST(DoDumpRegisterInfoTest, MinimumInfo) { |
| 16 | + StreamString strm; |
| 17 | + DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {}); |
| 18 | + ASSERT_EQ(strm.GetString(), " Name: foo\n" |
| 19 | + " Size: 4 bytes (32 bits)"); |
| 20 | +} |
| 21 | + |
| 22 | +TEST(DoDumpRegisterInfoTest, AltName) { |
| 23 | + StreamString strm; |
| 24 | + DoDumpRegisterInfo(strm, "foo", "bar", 4, {}, {}, {}); |
| 25 | + ASSERT_EQ(strm.GetString(), " Name: foo (bar)\n" |
| 26 | + " Size: 4 bytes (32 bits)"); |
| 27 | +} |
| 28 | + |
| 29 | +TEST(DoDumpRegisterInfoTest, Invalidates) { |
| 30 | + StreamString strm; |
| 31 | + DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2"}, {}, {}); |
| 32 | + ASSERT_EQ(strm.GetString(), " Name: foo\n" |
| 33 | + " Size: 4 bytes (32 bits)\n" |
| 34 | + "Invalidates: foo2"); |
| 35 | + |
| 36 | + strm.Clear(); |
| 37 | + DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {}); |
| 38 | + ASSERT_EQ(strm.GetString(), " Name: foo\n" |
| 39 | + " Size: 4 bytes (32 bits)\n" |
| 40 | + "Invalidates: foo2, foo3, foo4"); |
| 41 | +} |
| 42 | + |
| 43 | +TEST(DoDumpRegisterInfoTest, ReadFrom) { |
| 44 | + StreamString strm; |
| 45 | + DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1"}, {}); |
| 46 | + ASSERT_EQ(strm.GetString(), " Name: foo\n" |
| 47 | + " Size: 4 bytes (32 bits)\n" |
| 48 | + " Read from: foo1"); |
| 49 | + |
| 50 | + strm.Clear(); |
| 51 | + DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {}); |
| 52 | + ASSERT_EQ(strm.GetString(), " Name: foo\n" |
| 53 | + " Size: 4 bytes (32 bits)\n" |
| 54 | + " Read from: foo1, foo2, foo3"); |
| 55 | +} |
| 56 | + |
| 57 | +TEST(DoDumpRegisterInfoTest, InSets) { |
| 58 | + StreamString strm; |
| 59 | + DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {{"set1", 101}}); |
| 60 | + ASSERT_EQ(strm.GetString(), " Name: foo\n" |
| 61 | + " Size: 4 bytes (32 bits)\n" |
| 62 | + " In sets: set1 (index 101)"); |
| 63 | + |
| 64 | + strm.Clear(); |
| 65 | + DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, |
| 66 | + {{"set1", 0}, {"set2", 1}, {"set3", 2}}); |
| 67 | + ASSERT_EQ(strm.GetString(), |
| 68 | + " Name: foo\n" |
| 69 | + " Size: 4 bytes (32 bits)\n" |
| 70 | + " In sets: set1 (index 0), set2 (index 1), set3 (index 2)"); |
| 71 | +} |
| 72 | + |
| 73 | +TEST(DoDumpRegisterInfoTest, MaxInfo) { |
| 74 | + StreamString strm; |
| 75 | + DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3"}, |
| 76 | + {"foo3", "foo4"}, {{"set1", 1}, {"set2", 2}}); |
| 77 | + ASSERT_EQ(strm.GetString(), " Name: foo\n" |
| 78 | + " Size: 4 bytes (32 bits)\n" |
| 79 | + "Invalidates: foo2, foo3\n" |
| 80 | + " Read from: foo3, foo4\n" |
| 81 | + " In sets: set1 (index 1), set2 (index 2)"); |
| 82 | +} |
0 commit comments