summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2017-02-14 05:40:01 +0000
committerLang Hames <lhames@gmail.com>2017-02-14 05:40:01 +0000
commitf401077c29aed362d22ec7d27ea35079fa7b854e (patch)
treec27e337ffc1d7c6ab243ffa6af78c859d0d02be2 /llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
parentb61bfbd93aae792229a672e027198390299ed5e7 (diff)
downloadbcm5719-llvm-f401077c29aed362d22ec7d27ea35079fa7b854e.tar.gz
bcm5719-llvm-f401077c29aed362d22ec7d27ea35079fa7b854e.zip
[Orc][RPC] Remove lanch policies in favor of async handlers.
Launch policies provided a mechanism for running RPC handlers on a background thread (unblocking the main RPC receiver thread). Async handlers generalize this by passing the responder function (the function that sends the RPC return value) as an argument to the handler. The handler can optionally do its work on a background thread (the same way launch policies do), but can also (a) can inspect the call arguments before deciding to run the work on a different thread, or (b) can use the responder in a subsequent RPC call (e.g. in the handler of a callAsync), allowing the handler to call back to the originator (or to a 3rd party) without blocking the listener thread, and without launching a new thread. llvm-svn: 295030
Diffstat (limited to 'llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp')
-rw-r--r--llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
index ae2d18e3d75..91cec1c1ede 100644
--- a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
@@ -154,7 +154,7 @@ TEST(DummyRPC, TestFreeFunctionHandler) {
Server.addHandler<DummyRPCAPI::VoidBool>(freeVoidBool);
}
-TEST(DummyRPC, TestAsyncVoidBool) {
+TEST(DummyRPC, TestCallAsyncVoidBool) {
Queue Q1, Q2;
DummyRPCEndpoint Client(Q1, Q2);
DummyRPCEndpoint Server(Q2, Q1);
@@ -198,7 +198,7 @@ TEST(DummyRPC, TestAsyncVoidBool) {
ServerThread.join();
}
-TEST(DummyRPC, TestAsyncIntInt) {
+TEST(DummyRPC, TestCallAsyncIntInt) {
Queue Q1, Q2;
DummyRPCEndpoint Client(Q1, Q2);
DummyRPCEndpoint Server(Q2, Q1);
@@ -243,6 +243,52 @@ TEST(DummyRPC, TestAsyncIntInt) {
ServerThread.join();
}
+TEST(DummyRPC, TestAsyncIntIntHandler) {
+ Queue Q1, Q2;
+ DummyRPCEndpoint Client(Q1, Q2);
+ DummyRPCEndpoint Server(Q2, Q1);
+
+ std::thread ServerThread([&]() {
+ Server.addAsyncHandler<DummyRPCAPI::IntInt>(
+ [](std::function<Error(Expected<int32_t>)> SendResult,
+ int32_t X) {
+ EXPECT_EQ(X, 21) << "Server int(int) receieved unexpected result";
+ return SendResult(2 * X);
+ });
+
+ {
+ // Poke the server to handle the negotiate call.
+ auto Err = Server.handleOne();
+ EXPECT_FALSE(!!Err) << "Server failed to handle call to negotiate";
+ }
+
+ {
+ // Poke the server to handle the VoidBool call.
+ auto Err = Server.handleOne();
+ EXPECT_FALSE(!!Err) << "Server failed to handle call to void(bool)";
+ }
+ });
+
+ {
+ auto Err = Client.callAsync<DummyRPCAPI::IntInt>(
+ [](Expected<int> Result) {
+ EXPECT_TRUE(!!Result) << "Async int(int) response handler failed";
+ EXPECT_EQ(*Result, 42)
+ << "Async int(int) response handler received incorrect result";
+ return Error::success();
+ }, 21);
+ EXPECT_FALSE(!!Err) << "Client.callAsync failed for int(int)";
+ }
+
+ {
+ // Poke the client to process the result.
+ auto Err = Client.handleOne();
+ EXPECT_FALSE(!!Err) << "Client failed to handle response from void(bool)";
+ }
+
+ ServerThread.join();
+}
+
TEST(DummyRPC, TestSerialization) {
Queue Q1, Q2;
DummyRPCEndpoint Client(Q1, Q2);
OpenPOWER on IntegriCloud