[llvm] [JITLink][AArch32] Unittest for error paths of readAddend functionality (PR #69636)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 12:46:54 PDT 2023
================
@@ -67,6 +68,99 @@ TEST(AArch32_ELF, EdgeKinds) {
}
}
+struct ThumbRelocation {
+ /// Create a read-only reference to a Thumb32 fixup.
+ ThumbRelocation(const char *FixupPtr)
+ : Hi{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr)},
+ Lo{*reinterpret_cast<const support::ulittle16_t *>(FixupPtr + 2)} {}
+
+ const support::ulittle16_t &Hi; // First halfword
+ const support::ulittle16_t &Lo; // Second halfword
+};
+
+struct ArmRelocation {
+
+ ArmRelocation(const char *FixupPtr)
+ : Wd{*reinterpret_cast<const support::ulittle32_t *>(FixupPtr)} {}
+
+ const support::ulittle32_t &Wd;
+};
+
+std::string makeUnexpectedOpcodeError(const LinkGraph &G,
+ const ThumbRelocation &R,
+ Edge::Kind Kind) {
+ return formatv("Invalid opcode [ {0:x4}, {1:x4} ] for relocation: {2}",
+ static_cast<uint16_t>(R.Hi), static_cast<uint16_t>(R.Lo),
+ G.getEdgeKindName(Kind));
+}
+
+std::string makeUnexpectedOpcodeError(const LinkGraph &G,
+ const ArmRelocation &R, Edge::Kind Kind) {
+ return formatv("Invalid opcode {0:x8} for relocation: {1}",
+ static_cast<uint32_t>(R.Wd), G.getEdgeKindName(Kind));
+}
+
+TEST(AArch32_ELF, readAddends) {
+ auto G = std::make_unique<LinkGraph>("foo", Triple("armv7-linux-gnueabi"), 4,
+ llvm::endianness::little,
+ getGenericEdgeKindName);
+
+ ArrayRef<char> Content = "hello, world!";
+ auto &Sec =
+ G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
+ orc::ExecutorAddr B1Addr(0x1000);
+ auto &B = G->createContentBlock(Sec, Content, B1Addr, 4, 0);
+
+ Symbol &TargetSymbol = G->addAnonymousSymbol(B, 0, 4, false, false);
+ Edge InvalidEdge(FirstDataRelocation - 1, 0, TargetSymbol, 0);
+
+ auto ArmCfg = getArmConfigForCPUArch(ARMBuildAttrs::v7);
+
+ auto makeReadAddendError = [](LinkGraph &G, Block &B, Edge &E) {
+ return ("In graph " + G.getName() + ", section " +
+ B.getSection().getName() +
+ " can not read implicit addend for aarch32 edge kind " +
+ G.getEdgeKindName(E.getKind()))
+ .str();
+ };
+
+ EXPECT_THAT_EXPECTED(
+ readAddend(*G, B, InvalidEdge, ArmCfg),
+ FailedWithMessage(makeReadAddendError(*G, B, InvalidEdge)));
----------------
weliveindetail wrote:
Something like this maybe:
```
FailedWithMessage(testing::HasSubstr(
"can not read implicit addend for aarch32 edge kind INVALID RELOCATION"))
```
I found one example here:
https://github.com/llvm/llvm-project/blob/release/17.x/llvm/unittests/DebugInfo/BTF/BTFParserTest.cpp#L216
It could also be `testing::EndsWith()` or I guess any other matcher from gmock:
https://github.com/llvm/llvm-project/blob/release/17.x/third-party/unittest/googlemock/include/gmock/gmock-matchers.h#L3880
https://github.com/llvm/llvm-project/pull/69636
More information about the llvm-commits
mailing list