|
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | 9 | #include "lldb/Utility/RegisterValue.h" |
| 10 | +#include "lldb/Utility/DataExtractor.h" |
| 11 | +#include "lldb/lldb-private-types.h" |
10 | 12 | #include "gtest/gtest.h" |
11 | 13 | #include <optional> |
12 | 14 |
|
@@ -54,3 +56,41 @@ TEST(RegisterValueTest, GetScalarValue) { |
54 | 56 | Scalar((APInt(128, 0xffeeddccbbaa9988ull) << 64) | |
55 | 57 | APInt(128, 0x7766554433221100))); |
56 | 58 | } |
| 59 | + |
| 60 | +static const Scalar etalon128(APInt(128, 0xffeeddccbbaa9988ull) << 64 | |
| 61 | + APInt(128, 0x7766554433221100ull)); |
| 62 | + |
| 63 | +void TestSetValueFromData128(void *src, const lldb::ByteOrder endianness) { |
| 64 | + RegisterInfo ri{"uint128_register", |
| 65 | + nullptr, |
| 66 | + 16, |
| 67 | + 0, |
| 68 | + lldb::Encoding::eEncodingUint, |
| 69 | + lldb::Format::eFormatDefault, |
| 70 | + {0, 0, 0, LLDB_INVALID_REGNUM, 0}, |
| 71 | + nullptr, |
| 72 | + nullptr, |
| 73 | + nullptr}; |
| 74 | + DataExtractor src_extractor(src, 16, endianness, 8); |
| 75 | + RegisterValue rv; |
| 76 | + EXPECT_TRUE(rv.SetValueFromData(ri, src_extractor, 0, false).Success()); |
| 77 | + Scalar s; |
| 78 | + EXPECT_TRUE(rv.GetScalarValue(s)); |
| 79 | + EXPECT_EQ(s, etalon128); |
| 80 | +} |
| 81 | + |
| 82 | +// Test that the "RegisterValue::SetValueFromData" method works correctly |
| 83 | +// with 128-bit little-endian data that represents an integer. |
| 84 | +TEST(RegisterValueTest, SetValueFromData_128_le) { |
| 85 | + uint8_t src[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
| 86 | + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; |
| 87 | + TestSetValueFromData128(src, lldb::ByteOrder::eByteOrderLittle); |
| 88 | +} |
| 89 | + |
| 90 | +// Test that the "RegisterValue::SetValueFromData" method works correctly |
| 91 | +// with 128-bit big-endian data that represents an integer. |
| 92 | +TEST(RegisterValueTest, SetValueFromData_128_be) { |
| 93 | + uint8_t src[] = {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, |
| 94 | + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}; |
| 95 | + TestSetValueFromData128(src, lldb::ByteOrder::eByteOrderBig); |
| 96 | +} |
0 commit comments