1 //===---- MemoryManagerErrorTests.cpp - Test memory manager error paths ---===// 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 "JITLinkTestUtils.h" 10 #include "llvm/ExecutionEngine/JITLink/MachO_x86_64.h" 11 12 #include "llvm/Testing/Support/Error.h" 13 #include "gtest/gtest.h" 14 15 using namespace llvm; 16 using namespace llvm::orc; 17 using namespace llvm::jitlink; 18 19 TEST(MemoryManagerErrorTest, ErrorOnFirstAllocate) { 20 // Check that we can get addresses for blocks, symbols, and edges. 21 auto G = std::make_unique<LinkGraph>( 22 "foo", std::make_shared<orc::SymbolStringPool>(), 23 Triple("x86_64-apple-darwin"), SubtargetFeatures(), 24 getGenericEdgeKindName); 25 26 ArrayRef<char> Content = "hello, world!"; 27 auto &Sec = 28 G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write); 29 orc::ExecutorAddr B1Addr(0x1000); 30 auto &B = G->createContentBlock(Sec, Content, B1Addr, 8, 0); 31 G->addDefinedSymbol(B, 4, "S", 4, Linkage::Strong, Scope::Default, false, 32 false); 33 34 Error Err = Error::success(); 35 auto Ctx = makeMockContext( 36 JoinErrorsInto(Err), 37 [](MockJITLinkMemoryManager &MemMgr) { 38 MemMgr.Allocate = [](const JITLinkDylib *JD, LinkGraph &G) { 39 return make_error<StringError>("Failed to allocate", 40 inconvertibleErrorCode()); 41 }; 42 }, 43 defaultCtxSetup); 44 45 link_MachO_x86_64(std::move(G), std::move(Ctx)); 46 47 EXPECT_THAT_ERROR(std::move(Err), Failed()); 48 } 49