1 //===- EPCGenericMemoryAccessTest.cpp -- Tests for EPCGenericMemoryAccess -===//
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 "OrcTestCommon.h"
11 #include "llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h"
12 #include "llvm/Testing/Support/Error.h"
15 using namespace llvm::orc
;
16 using namespace llvm::orc::shared
;
20 template <typename WriteT
, typename SPSWriteT
>
21 llvm::orc::shared::CWrapperFunctionResult
testWriteUInts(const char *ArgData
,
23 return WrapperFunction
<void(SPSSequence
<SPSWriteT
>)>::handle(
25 [](std::vector
<WriteT
> Ws
) {
27 *W
.Addr
.template toPtr
<decltype(W
.Value
) *>() = W
.Value
;
32 llvm::orc::shared::CWrapperFunctionResult
testWriteBuffers(const char *ArgData
,
34 return WrapperFunction
<void(SPSSequence
<SPSMemoryAccessBufferWrite
>)>::handle(
36 [](std::vector
<tpctypes::BufferWrite
> Ws
) {
38 memcpy(W
.Addr
.template toPtr
<char *>(), W
.Buffer
.data(),
44 llvm::orc::shared::CWrapperFunctionResult
testWritePointers(const char *ArgData
,
46 return WrapperFunction
<void(SPSSequence
<SPSMemoryAccessPointerWrite
>)>::
47 handle(ArgData
, ArgSize
,
48 [](std::vector
<tpctypes::PointerWrite
> Ws
) {
50 *W
.Addr
.template toPtr
<uint64_t *>() = W
.Value
.getValue();
55 TEST(EPCGenericMemoryAccessTest
, MemWrites
) {
56 auto SelfEPC
= cantFail(SelfExecutorProcessControl::Create());
58 EPCGenericMemoryAccess::FuncAddrs FAs
;
59 FAs
.WriteUInt8s
= ExecutorAddr::fromPtr(
60 &testWriteUInts
<tpctypes::UInt8Write
, SPSMemoryAccessUInt8Write
>);
61 FAs
.WriteUInt16s
= ExecutorAddr::fromPtr(
62 &testWriteUInts
<tpctypes::UInt16Write
, SPSMemoryAccessUInt16Write
>);
63 FAs
.WriteUInt32s
= ExecutorAddr::fromPtr(
64 &testWriteUInts
<tpctypes::UInt32Write
, SPSMemoryAccessUInt32Write
>);
65 FAs
.WriteUInt64s
= ExecutorAddr::fromPtr(
66 &testWriteUInts
<tpctypes::UInt64Write
, SPSMemoryAccessUInt64Write
>);
67 FAs
.WriteBuffers
= ExecutorAddr::fromPtr(&testWriteBuffers
);
68 FAs
.WritePointers
= ExecutorAddr::fromPtr(&testWritePointers
);
70 auto MemAccess
= std::make_unique
<EPCGenericMemoryAccess
>(*SelfEPC
, FAs
);
72 uint8_t Test_UInt8_1
= 0;
73 uint8_t Test_UInt8_2
= 0;
74 uint16_t Test_UInt16
= 0;
75 uint32_t Test_UInt32
= 0;
76 uint64_t Test_UInt64
= 0;
77 uint64_t Test_Pointer
= 0;
81 MemAccess
->writeUInt8s({{ExecutorAddr::fromPtr(&Test_UInt8_1
), 1},
82 {ExecutorAddr::fromPtr(&Test_UInt8_2
), 0xFE}});
84 EXPECT_THAT_ERROR(std::move(Err1
), Succeeded());
85 EXPECT_EQ(Test_UInt8_1
, 1U);
86 EXPECT_EQ(Test_UInt8_2
, 0xFE);
89 MemAccess
->writeUInt16s({{ExecutorAddr::fromPtr(&Test_UInt16
), 1}});
90 EXPECT_THAT_ERROR(std::move(Err2
), Succeeded());
91 EXPECT_EQ(Test_UInt16
, 1U);
94 MemAccess
->writeUInt32s({{ExecutorAddr::fromPtr(&Test_UInt32
), 1}});
95 EXPECT_THAT_ERROR(std::move(Err3
), Succeeded());
96 EXPECT_EQ(Test_UInt32
, 1U);
99 MemAccess
->writeUInt64s({{ExecutorAddr::fromPtr(&Test_UInt64
), 1}});
100 EXPECT_THAT_ERROR(std::move(Err4
), Succeeded());
101 EXPECT_EQ(Test_UInt64
, 1U);
103 StringRef
TestMsg("test-message");
105 MemAccess
->writeBuffers({{ExecutorAddr::fromPtr(&Test_Buffer
), TestMsg
}});
106 EXPECT_THAT_ERROR(std::move(Err5
), Succeeded());
107 EXPECT_EQ(StringRef(Test_Buffer
, TestMsg
.size()), TestMsg
);
109 auto Err6
= MemAccess
->writePointers(
110 {{ExecutorAddr::fromPtr(&Test_Pointer
), ExecutorAddr(1U)}});
111 EXPECT_THAT_ERROR(std::move(Err6
), Succeeded());
112 EXPECT_EQ(Test_Pointer
, 1U);
114 cantFail(SelfEPC
->disconnect());