[flang] Update CommandTest for AIX (NFC) (#118403)
[llvm-project.git] / llvm / unittests / ExecutionEngine / Orc / ExecutionSessionWrapperFunctionCallsTest.cpp
bloba25da8a727de549a174f685999884c8c7af22d19
1 //===- ExecutionSessionWrapperFunctionCallsTest.cpp -- Test wrapper calls -===//
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 "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
10 #include "llvm/ExecutionEngine/Orc/Core.h"
11 #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
12 #include "llvm/Support/MSVCErrorWorkarounds.h"
13 #include "llvm/Testing/Support/Error.h"
14 #include "gtest/gtest.h"
16 #include <future>
18 using namespace llvm;
19 using namespace llvm::orc;
20 using namespace llvm::orc::shared;
22 static llvm::orc::shared::CWrapperFunctionResult addWrapper(const char *ArgData,
23 size_t ArgSize) {
24 return WrapperFunction<int32_t(int32_t, int32_t)>::handle(
25 ArgData, ArgSize, [](int32_t X, int32_t Y) { return X + Y; })
26 .release();
29 static void addAsyncWrapper(unique_function<void(int32_t)> SendResult,
30 int32_t X, int32_t Y) {
31 SendResult(X + Y);
34 static llvm::orc::shared::CWrapperFunctionResult
35 voidWrapper(const char *ArgData, size_t ArgSize) {
36 return WrapperFunction<void()>::handle(ArgData, ArgSize, []() {}).release();
39 TEST(ExecutionSessionWrapperFunctionCalls, RunWrapperTemplate) {
40 ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create()));
42 int32_t Result;
43 EXPECT_THAT_ERROR(ES.callSPSWrapper<int32_t(int32_t, int32_t)>(
44 ExecutorAddr::fromPtr(addWrapper), Result, 2, 3),
45 Succeeded());
46 EXPECT_EQ(Result, 5);
47 cantFail(ES.endSession());
50 TEST(ExecutionSessionWrapperFunctionCalls, RunVoidWrapperAsyncTemplate) {
51 ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create()));
53 std::promise<MSVCPError> RP;
54 ES.callSPSWrapperAsync<void()>(ExecutorAddr::fromPtr(voidWrapper),
55 [&](Error SerializationErr) {
56 RP.set_value(std::move(SerializationErr));
57 });
58 Error Err = RP.get_future().get();
59 EXPECT_THAT_ERROR(std::move(Err), Succeeded());
60 cantFail(ES.endSession());
63 TEST(ExecutionSessionWrapperFunctionCalls, RunNonVoidWrapperAsyncTemplate) {
64 ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create()));
66 std::promise<MSVCPExpected<int32_t>> RP;
67 ES.callSPSWrapperAsync<int32_t(int32_t, int32_t)>(
68 ExecutorAddr::fromPtr(addWrapper),
69 [&](Error SerializationErr, int32_t R) {
70 if (SerializationErr)
71 RP.set_value(std::move(SerializationErr));
72 RP.set_value(std::move(R));
74 2, 3);
75 Expected<int32_t> Result = RP.get_future().get();
76 EXPECT_THAT_EXPECTED(Result, HasValue(5));
77 cantFail(ES.endSession());
80 TEST(ExecutionSessionWrapperFunctionCalls, RegisterAsyncHandlerAndRun) {
82 constexpr ExecutorAddr AddAsyncTagAddr(0x01);
84 ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create()));
85 auto &JD = ES.createBareJITDylib("JD");
87 auto AddAsyncTag = ES.intern("addAsync_tag");
88 cantFail(JD.define(absoluteSymbols(
89 {{AddAsyncTag, {AddAsyncTagAddr, JITSymbolFlags::Exported}}})));
91 ExecutionSession::JITDispatchHandlerAssociationMap Associations;
93 Associations[AddAsyncTag] =
94 ES.wrapAsyncWithSPS<int32_t(int32_t, int32_t)>(addAsyncWrapper);
96 cantFail(ES.registerJITDispatchHandlers(JD, std::move(Associations)));
98 std::promise<int32_t> RP;
99 auto RF = RP.get_future();
101 using ArgSerialization = SPSArgList<int32_t, int32_t>;
102 size_t ArgBufferSize = ArgSerialization::size(1, 2);
103 auto ArgBuffer = WrapperFunctionResult::allocate(ArgBufferSize);
104 SPSOutputBuffer OB(ArgBuffer.data(), ArgBuffer.size());
105 EXPECT_TRUE(ArgSerialization::serialize(OB, 1, 2));
107 ES.runJITDispatchHandler(
108 [&](WrapperFunctionResult ResultBuffer) {
109 int32_t Result;
110 SPSInputBuffer IB(ResultBuffer.data(), ResultBuffer.size());
111 EXPECT_TRUE(SPSArgList<int32_t>::deserialize(IB, Result));
112 RP.set_value(Result);
114 AddAsyncTagAddr, ArrayRef<char>(ArgBuffer.data(), ArgBuffer.size()));
116 EXPECT_EQ(RF.get(), (int32_t)3);
118 cantFail(ES.endSession());