1 //===---------------- SimpleExecutorMemoryManagerTest.cpp -----------------===//
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 "llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h"
10 #include "llvm/Testing/Support/Error.h"
11 #include "gtest/gtest.h"
17 using namespace llvm::orc
;
18 using namespace llvm::orc::shared
;
19 using namespace llvm::orc::rt_bootstrap
;
23 orc::shared::CWrapperFunctionResult
incrementWrapper(const char *ArgData
,
25 return WrapperFunction
<SPSError(SPSExecutorAddr
)>::handle(
27 [](ExecutorAddr A
) -> Error
{
28 *A
.toPtr
<int *>() += 1;
29 return Error::success();
34 TEST(SimpleExecutorMemoryManagerTest
, AllocFinalizeFree
) {
35 SimpleExecutorMemoryManager MemMgr
;
37 constexpr unsigned AllocSize
= 16384;
38 auto Mem
= MemMgr
.allocate(AllocSize
);
39 EXPECT_THAT_ERROR(Mem
.takeError(), Succeeded());
41 std::string HW
= "Hello, world!";
43 int FinalizeCounter
= 0;
44 int DeallocateCounter
= 0;
46 tpctypes::FinalizeRequest FR
;
47 FR
.Segments
.push_back(
48 tpctypes::SegFinalizeRequest
{tpctypes::WPF_Read
| tpctypes::WPF_Write
,
51 {HW
.data(), HW
.size() + 1}});
54 cantFail(WrapperFunctionCall::Create
<SPSArgList
<SPSExecutorAddr
>>(
55 ExecutorAddr::fromPtr(incrementWrapper
),
56 ExecutorAddr::fromPtr(&FinalizeCounter
))),
58 cantFail(WrapperFunctionCall::Create
<SPSArgList
<SPSExecutorAddr
>>(
59 ExecutorAddr::fromPtr(incrementWrapper
),
60 ExecutorAddr::fromPtr(&DeallocateCounter
)))});
62 EXPECT_EQ(FinalizeCounter
, 0);
63 EXPECT_EQ(DeallocateCounter
, 0);
65 auto FinalizeErr
= MemMgr
.finalize(FR
);
66 EXPECT_THAT_ERROR(std::move(FinalizeErr
), Succeeded());
68 EXPECT_EQ(FinalizeCounter
, 1);
69 EXPECT_EQ(DeallocateCounter
, 0);
71 EXPECT_EQ(HW
, std::string(Mem
->toPtr
<const char *>()));
73 auto DeallocateErr
= MemMgr
.deallocate({*Mem
});
74 EXPECT_THAT_ERROR(std::move(DeallocateErr
), Succeeded());
76 EXPECT_EQ(FinalizeCounter
, 1);
77 EXPECT_EQ(DeallocateCounter
, 1);