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