[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / unittests / ExecutionEngine / Orc / EPCGenericMemoryAccessTest.cpp
blobf5209d66fc1d23e74367b61b94a92fc8b9fe6288
1 //===- EPCGenericMemoryAccessTest.cpp -- Tests for EPCGenericMemoryAccess -===//
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 //===----------------------------------------------------------------------===//
9 #include "OrcTestCommon.h"
11 #include "llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h"
12 #include "llvm/Testing/Support/Error.h"
14 using namespace llvm;
15 using namespace llvm::orc;
16 using namespace llvm::orc::shared;
18 namespace {
20 template <typename WriteT, typename SPSWriteT>
21 llvm::orc::shared::detail::CWrapperFunctionResult
22 testWriteUInts(const char *ArgData, size_t ArgSize) {
23 return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
24 ArgData, ArgSize,
25 [](std::vector<WriteT> Ws) {
26 for (auto &W : Ws)
27 *jitTargetAddressToPointer<decltype(W.Value) *>(W.Address) =
28 W.Value;
30 .release();
33 llvm::orc::shared::detail::CWrapperFunctionResult
34 testWriteBuffers(const char *ArgData, size_t ArgSize) {
35 return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(
36 ArgData, ArgSize,
37 [](std::vector<tpctypes::BufferWrite> Ws) {
38 for (auto &W : Ws)
39 memcpy(jitTargetAddressToPointer<char *>(W.Address),
40 W.Buffer.data(), W.Buffer.size());
42 .release();
45 TEST(EPCGenericMemoryAccessTest, MemWrites) {
46 auto SelfEPC = cantFail(SelfExecutorProcessControl::Create());
48 EPCGenericMemoryAccess::FuncAddrs FAs;
49 FAs.WriteUInt8s = ExecutorAddress::fromPtr(
50 &testWriteUInts<tpctypes::UInt8Write, SPSMemoryAccessUInt8Write>);
51 FAs.WriteUInt16s = ExecutorAddress::fromPtr(
52 &testWriteUInts<tpctypes::UInt16Write, SPSMemoryAccessUInt16Write>);
53 FAs.WriteUInt32s = ExecutorAddress::fromPtr(
54 &testWriteUInts<tpctypes::UInt32Write, SPSMemoryAccessUInt32Write>);
55 FAs.WriteUInt64s = ExecutorAddress::fromPtr(
56 &testWriteUInts<tpctypes::UInt64Write, SPSMemoryAccessUInt64Write>);
57 FAs.WriteBuffers = ExecutorAddress::fromPtr(&testWriteBuffers);
59 auto MemAccess = std::make_unique<EPCGenericMemoryAccess>(*SelfEPC, FAs);
61 uint8_t Test_UInt8_1 = 0;
62 uint8_t Test_UInt8_2 = 0;
63 uint16_t Test_UInt16 = 0;
64 uint32_t Test_UInt32 = 0;
65 uint64_t Test_UInt64 = 0;
66 char Test_Buffer[21];
68 auto Err1 = MemAccess->writeUInt8s(
69 {{pointerToJITTargetAddress(&Test_UInt8_1), 1},
70 {pointerToJITTargetAddress(&Test_UInt8_2), 0xFE}});
72 EXPECT_THAT_ERROR(std::move(Err1), Succeeded());
73 EXPECT_EQ(Test_UInt8_1, 1U);
74 EXPECT_EQ(Test_UInt8_2, 0xFE);
76 auto Err2 =
77 MemAccess->writeUInt16s({{pointerToJITTargetAddress(&Test_UInt16), 1}});
78 EXPECT_THAT_ERROR(std::move(Err2), Succeeded());
79 EXPECT_EQ(Test_UInt16, 1U);
81 auto Err3 =
82 MemAccess->writeUInt32s({{pointerToJITTargetAddress(&Test_UInt32), 1}});
83 EXPECT_THAT_ERROR(std::move(Err3), Succeeded());
84 EXPECT_EQ(Test_UInt32, 1U);
86 auto Err4 =
87 MemAccess->writeUInt64s({{pointerToJITTargetAddress(&Test_UInt64), 1}});
88 EXPECT_THAT_ERROR(std::move(Err4), Succeeded());
89 EXPECT_EQ(Test_UInt64, 1U);
91 StringRef TestMsg("test-message");
92 auto Err5 = MemAccess->writeBuffers(
93 {{pointerToJITTargetAddress(&Test_Buffer), TestMsg}});
94 EXPECT_THAT_ERROR(std::move(Err5), Succeeded());
95 EXPECT_EQ(StringRef(Test_Buffer, TestMsg.size()), TestMsg);
98 } // namespace