CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
139 lines
4.9 KiB
C++
139 lines
4.9 KiB
C++
//===- SharedMemoryMapperTest.cpp -- Tests for SharedMemoryMapper ---------===//
|
|
//
|
|
// 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/Config/llvm-config.h" // for LLVM_ON_UNIX
|
|
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
|
|
#include "llvm/ExecutionEngine/Orc/MemoryMapper.h"
|
|
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
|
|
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
|
#include "llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h"
|
|
#include "llvm/Testing/Support/Error.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::orc;
|
|
using namespace llvm::orc::shared;
|
|
using namespace llvm::orc::rt_bootstrap;
|
|
|
|
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
|
|
|
|
// A basic function to be used as both initializer/deinitializer
|
|
CWrapperFunctionBuffer incrementWrapper(const char *ArgData, size_t ArgSize) {
|
|
return WrapperFunction<SPSError(SPSExecutorAddr)>::handle(
|
|
ArgData, ArgSize,
|
|
[](ExecutorAddr A) -> Error {
|
|
*A.toPtr<int *>() += 1;
|
|
return Error::success();
|
|
})
|
|
.release();
|
|
}
|
|
|
|
TEST(SharedMemoryMapperTest, MemReserveInitializeDeinitializeRelease) {
|
|
// These counters are used to track how many times the initializer and
|
|
// deinitializer functions are called
|
|
int InitializeCounter = 0;
|
|
int DeinitializeCounter = 0;
|
|
|
|
auto SelfEPC = cantFail(SelfExecutorProcessControl::Create());
|
|
|
|
ExecutorSharedMemoryMapperService MapperService;
|
|
|
|
SharedMemoryMapper::SymbolAddrs SAs;
|
|
{
|
|
StringMap<ExecutorAddr> Map;
|
|
MapperService.addBootstrapSymbols(Map);
|
|
SAs.Instance = Map[rt::ExecutorSharedMemoryMapperServiceInstanceName];
|
|
SAs.Reserve = Map[rt::ExecutorSharedMemoryMapperServiceReserveWrapperName];
|
|
SAs.Initialize =
|
|
Map[rt::ExecutorSharedMemoryMapperServiceInitializeWrapperName];
|
|
SAs.Deinitialize =
|
|
Map[rt::ExecutorSharedMemoryMapperServiceDeinitializeWrapperName];
|
|
SAs.Release = Map[rt::ExecutorSharedMemoryMapperServiceReleaseWrapperName];
|
|
}
|
|
|
|
std::string TestString = "Hello, World!";
|
|
|
|
// barrier
|
|
std::promise<void> P;
|
|
auto F = P.get_future();
|
|
|
|
{
|
|
std::unique_ptr<MemoryMapper> Mapper =
|
|
cantFail(SharedMemoryMapper::Create(*SelfEPC, SAs));
|
|
|
|
auto PageSize = Mapper->getPageSize();
|
|
size_t ReqSize = PageSize;
|
|
jitlink::LinkGraph G("G", std::make_shared<SymbolStringPool>(),
|
|
Triple("x86_64-apple-darwin"), SubtargetFeatures(),
|
|
jitlink::getGenericEdgeKindName);
|
|
|
|
Mapper->reserve(ReqSize, [&](Expected<ExecutorAddrRange> Result) {
|
|
EXPECT_THAT_ERROR(Result.takeError(), Succeeded());
|
|
auto Reservation = std::move(*Result);
|
|
{
|
|
char *Addr =
|
|
Mapper->prepare(G, Reservation.Start, TestString.size() + 1);
|
|
std::strcpy(Addr, TestString.c_str());
|
|
}
|
|
MemoryMapper::AllocInfo AI;
|
|
{
|
|
MemoryMapper::AllocInfo::SegInfo SI;
|
|
SI.Offset = 0;
|
|
SI.ContentSize = TestString.size() + 1;
|
|
SI.ZeroFillSize = PageSize - SI.ContentSize;
|
|
SI.AG = MemProt::Read | MemProt::Write;
|
|
|
|
AI.MappingBase = Reservation.Start;
|
|
AI.Segments.push_back(SI);
|
|
AI.Actions.push_back(
|
|
{cantFail(WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddr>>(
|
|
ExecutorAddr::fromPtr(incrementWrapper),
|
|
ExecutorAddr::fromPtr(&InitializeCounter))),
|
|
cantFail(WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddr>>(
|
|
ExecutorAddr::fromPtr(incrementWrapper),
|
|
ExecutorAddr::fromPtr(&DeinitializeCounter)))});
|
|
}
|
|
|
|
EXPECT_EQ(InitializeCounter, 0);
|
|
EXPECT_EQ(DeinitializeCounter, 0);
|
|
|
|
Mapper->initialize(AI, [&, Reservation](Expected<ExecutorAddr> Result) {
|
|
EXPECT_THAT_ERROR(Result.takeError(), Succeeded());
|
|
|
|
EXPECT_EQ(TestString, std::string(static_cast<char *>(
|
|
Reservation.Start.toPtr<char *>())));
|
|
|
|
EXPECT_EQ(InitializeCounter, 1);
|
|
EXPECT_EQ(DeinitializeCounter, 0);
|
|
|
|
Mapper->deinitialize({*Result}, [&, Reservation](Error Err) {
|
|
EXPECT_THAT_ERROR(std::move(Err), Succeeded());
|
|
|
|
EXPECT_EQ(InitializeCounter, 1);
|
|
EXPECT_EQ(DeinitializeCounter, 1);
|
|
|
|
Mapper->release({Reservation.Start}, [&](Error Err) {
|
|
EXPECT_THAT_ERROR(std::move(Err), Succeeded());
|
|
|
|
P.set_value();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
// This will block the test if any of the above callbacks are not executed
|
|
F.wait();
|
|
// Mapper must be destructed before calling shutdown to avoid double free
|
|
}
|
|
|
|
EXPECT_THAT_ERROR(MapperService.shutdown(), Succeeded());
|
|
cantFail(SelfEPC->disconnect());
|
|
}
|
|
|
|
#endif
|