1b3c0055cSLang Hames //===---- MemoryManagerErrorTests.cpp - Test memory manager error paths ---===// 2b3c0055cSLang Hames // 3b3c0055cSLang Hames // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4b3c0055cSLang Hames // See https://llvm.org/LICENSE.txt for license information. 5b3c0055cSLang Hames // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b3c0055cSLang Hames // 7b3c0055cSLang Hames //===----------------------------------------------------------------------===// 8b3c0055cSLang Hames 96128ff66SLang Hames #include "JITLinkTestUtils.h" 10b3c0055cSLang Hames #include "llvm/ExecutionEngine/JITLink/MachO_x86_64.h" 11b3c0055cSLang Hames 12b3c0055cSLang Hames #include "llvm/Testing/Support/Error.h" 13b3c0055cSLang Hames #include "gtest/gtest.h" 14b3c0055cSLang Hames 15b3c0055cSLang Hames using namespace llvm; 16b3c0055cSLang Hames using namespace llvm::orc; 17b3c0055cSLang Hames using namespace llvm::jitlink; 18b3c0055cSLang Hames 19b3c0055cSLang Hames TEST(MemoryManagerErrorTest, ErrorOnFirstAllocate) { 20b3c0055cSLang Hames // Check that we can get addresses for blocks, symbols, and edges. 212ccf7ed2SJared Wyles auto G = std::make_unique<LinkGraph>( 222ccf7ed2SJared Wyles "foo", std::make_shared<orc::SymbolStringPool>(), 23*4eaff6c5SLang Hames Triple("x86_64-apple-darwin"), SubtargetFeatures(), 244a0ccfa8SKazu Hirata getGenericEdgeKindName); 25b3c0055cSLang Hames 26b3c0055cSLang Hames ArrayRef<char> Content = "hello, world!"; 27b3c0055cSLang Hames auto &Sec = 28b3c0055cSLang Hames G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write); 29b3c0055cSLang Hames orc::ExecutorAddr B1Addr(0x1000); 30b3c0055cSLang Hames auto &B = G->createContentBlock(Sec, Content, B1Addr, 8, 0); 31b3c0055cSLang Hames G->addDefinedSymbol(B, 4, "S", 4, Linkage::Strong, Scope::Default, false, 32b3c0055cSLang Hames false); 33b3c0055cSLang Hames 34b3c0055cSLang Hames Error Err = Error::success(); 35b3c0055cSLang Hames auto Ctx = makeMockContext( 36b3c0055cSLang Hames JoinErrorsInto(Err), 37b3c0055cSLang Hames [](MockJITLinkMemoryManager &MemMgr) { 38b3c0055cSLang Hames MemMgr.Allocate = [](const JITLinkDylib *JD, LinkGraph &G) { 39b3c0055cSLang Hames return make_error<StringError>("Failed to allocate", 40b3c0055cSLang Hames inconvertibleErrorCode()); 41b3c0055cSLang Hames }; 42b3c0055cSLang Hames }, 43b3c0055cSLang Hames defaultCtxSetup); 44b3c0055cSLang Hames 45b3c0055cSLang Hames link_MachO_x86_64(std::move(G), std::move(Ctx)); 46b3c0055cSLang Hames 47b3c0055cSLang Hames EXPECT_THAT_ERROR(std::move(Err), Failed()); 48b3c0055cSLang Hames } 49