File: EPCGenericMemoryAccessTest.cpp

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (99 lines) | stat: -rw-r--r-- 3,619 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//===- EPCGenericMemoryAccessTest.cpp -- Tests for EPCGenericMemoryAccess -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "OrcTestCommon.h"

#include "llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h"
#include "llvm/Testing/Support/Error.h"

using namespace llvm;
using namespace llvm::orc;
using namespace llvm::orc::shared;

namespace {

template <typename WriteT, typename SPSWriteT>
llvm::orc::shared::CWrapperFunctionResult testWriteUInts(const char *ArgData,
                                                         size_t ArgSize) {
  return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
             ArgData, ArgSize,
             [](std::vector<WriteT> Ws) {
               for (auto &W : Ws)
                 *W.Addr.template toPtr<decltype(W.Value) *>() = W.Value;
             })
      .release();
}

llvm::orc::shared::CWrapperFunctionResult testWriteBuffers(const char *ArgData,
                                                           size_t ArgSize) {
  return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(
             ArgData, ArgSize,
             [](std::vector<tpctypes::BufferWrite> Ws) {
               for (auto &W : Ws)
                 memcpy(W.Addr.template toPtr<char *>(), W.Buffer.data(),
                        W.Buffer.size());
             })
      .release();
}

TEST(EPCGenericMemoryAccessTest, MemWrites) {
  auto SelfEPC = cantFail(SelfExecutorProcessControl::Create());

  EPCGenericMemoryAccess::FuncAddrs FAs;
  FAs.WriteUInt8s = ExecutorAddr::fromPtr(
      &testWriteUInts<tpctypes::UInt8Write, SPSMemoryAccessUInt8Write>);
  FAs.WriteUInt16s = ExecutorAddr::fromPtr(
      &testWriteUInts<tpctypes::UInt16Write, SPSMemoryAccessUInt16Write>);
  FAs.WriteUInt32s = ExecutorAddr::fromPtr(
      &testWriteUInts<tpctypes::UInt32Write, SPSMemoryAccessUInt32Write>);
  FAs.WriteUInt64s = ExecutorAddr::fromPtr(
      &testWriteUInts<tpctypes::UInt64Write, SPSMemoryAccessUInt64Write>);
  FAs.WriteBuffers = ExecutorAddr::fromPtr(&testWriteBuffers);

  auto MemAccess = std::make_unique<EPCGenericMemoryAccess>(*SelfEPC, FAs);

  uint8_t Test_UInt8_1 = 0;
  uint8_t Test_UInt8_2 = 0;
  uint16_t Test_UInt16 = 0;
  uint32_t Test_UInt32 = 0;
  uint64_t Test_UInt64 = 0;
  char Test_Buffer[21];

  auto Err1 =
      MemAccess->writeUInt8s({{ExecutorAddr::fromPtr(&Test_UInt8_1), 1},
                              {ExecutorAddr::fromPtr(&Test_UInt8_2), 0xFE}});

  EXPECT_THAT_ERROR(std::move(Err1), Succeeded());
  EXPECT_EQ(Test_UInt8_1, 1U);
  EXPECT_EQ(Test_UInt8_2, 0xFE);

  auto Err2 =
      MemAccess->writeUInt16s({{ExecutorAddr::fromPtr(&Test_UInt16), 1}});
  EXPECT_THAT_ERROR(std::move(Err2), Succeeded());
  EXPECT_EQ(Test_UInt16, 1U);

  auto Err3 =
      MemAccess->writeUInt32s({{ExecutorAddr::fromPtr(&Test_UInt32), 1}});
  EXPECT_THAT_ERROR(std::move(Err3), Succeeded());
  EXPECT_EQ(Test_UInt32, 1U);

  auto Err4 =
      MemAccess->writeUInt64s({{ExecutorAddr::fromPtr(&Test_UInt64), 1}});
  EXPECT_THAT_ERROR(std::move(Err4), Succeeded());
  EXPECT_EQ(Test_UInt64, 1U);

  StringRef TestMsg("test-message");
  auto Err5 =
      MemAccess->writeBuffers({{ExecutorAddr::fromPtr(&Test_Buffer), TestMsg}});
  EXPECT_THAT_ERROR(std::move(Err5), Succeeded());
  EXPECT_EQ(StringRef(Test_Buffer, TestMsg.size()), TestMsg);

  cantFail(SelfEPC->disconnect());
}

} // namespace