diff options
author | Lang Hames <lhames@gmail.com> | 2016-12-25 21:55:05 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-12-25 21:55:05 +0000 |
commit | c9d0ff13024bc0aa896fdb2cab6051cedc1e0ae3 (patch) | |
tree | 9d5b5857e2bc38f1845627a939a7afa46c3d95bf /llvm/unittests/ExecutionEngine | |
parent | 993f2032789cabd5df00d75940454c6799bb0291 (diff) | |
download | bcm5719-llvm-c9d0ff13024bc0aa896fdb2cab6051cedc1e0ae3.tar.gz bcm5719-llvm-c9d0ff13024bc0aa896fdb2cab6051cedc1e0ae3.zip |
[Orc][RPC] Add a ParallelCallGroup utility for dispatching and waiting on
multiple asynchronous RPC calls.
ParallelCallGroup allows multiple asynchronous calls to be dispatched,
and provides a wait method that blocks until all asynchronous calls have
been executed on the remote and all return value handlers run on the
local machine.
This will allow, for example, the JIT client to issue memory allocation calls
for all sections in parallel, then block until all memory has been allocated
on the remote and the allocated addresses registered with the client, at which
point the JIT client can proceed to applying relocations.
llvm-svn: 290523
Diffstat (limited to 'llvm/unittests/ExecutionEngine')
-rw-r--r-- | llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp index f9b65a99505..381fd103042 100644 --- a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp @@ -386,3 +386,74 @@ TEST(DummyRPC, TestWithAltCustomType) { ServerThread.join(); } + +TEST(DummyRPC, TestParallelCallGroup) { + Queue Q1, Q2; + DummyRPCEndpoint Client(Q1, Q2); + DummyRPCEndpoint Server(Q2, Q1); + + std::thread ServerThread([&]() { + Server.addHandler<DummyRPCAPI::IntInt>( + [](int X) -> int { + return 2 * X; + }); + + // Handle the negotiate, plus three calls. + for (unsigned I = 0; I != 4; ++I) { + auto Err = Server.handleOne(); + EXPECT_FALSE(!!Err) << "Server failed to handle call to int(int)"; + } + }); + + { + int A, B, C; + ParallelCallGroup<DummyRPCEndpoint> PCG(Client); + + { + auto Err = PCG.appendCall<DummyRPCAPI::IntInt>( + [&A](Expected<int> Result) { + EXPECT_TRUE(!!Result) << "Async int(int) response handler failed"; + A = *Result; + return Error::success(); + }, 1); + EXPECT_FALSE(!!Err) << "First parallel call failed for int(int)"; + } + + { + auto Err = PCG.appendCall<DummyRPCAPI::IntInt>( + [&B](Expected<int> Result) { + EXPECT_TRUE(!!Result) << "Async int(int) response handler failed"; + B = *Result; + return Error::success(); + }, 2); + EXPECT_FALSE(!!Err) << "Second parallel call failed for int(int)"; + } + + { + auto Err = PCG.appendCall<DummyRPCAPI::IntInt>( + [&C](Expected<int> Result) { + EXPECT_TRUE(!!Result) << "Async int(int) response handler failed"; + C = *Result; + return Error::success(); + }, 3); + EXPECT_FALSE(!!Err) << "Third parallel call failed for int(int)"; + } + + // Handle the three int(int) results. + for (unsigned I = 0; I != 3; ++I) { + auto Err = Client.handleOne(); + EXPECT_FALSE(!!Err) << "Client failed to handle response from void(bool)"; + } + + { + auto Err = PCG.wait(); + EXPECT_FALSE(!!Err) << "Third parallel call failed for int(int)"; + } + + EXPECT_EQ(A, 2) << "First parallel call returned bogus result"; + EXPECT_EQ(B, 4) << "Second parallel call returned bogus result"; + EXPECT_EQ(C, 6) << "Third parallel call returned bogus result"; + } + + ServerThread.join(); +} |