summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp')
-rw-r--r--llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp71
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();
+}
OpenPOWER on IntegriCloud