diff options
author | Lang Hames <lhames@gmail.com> | 2016-04-18 01:06:49 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-04-18 01:06:49 +0000 |
commit | 236cea74dfda56dc62f847c3f416b9a2c212485d (patch) | |
tree | ca33ca7845a4d70ef0f2d8587bbfc3e13073204f /llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp | |
parent | c4d56970dc74e4b7c26f6597ea38289051d9b545 (diff) | |
download | bcm5719-llvm-236cea74dfda56dc62f847c3f416b9a2c212485d.tar.gz bcm5719-llvm-236cea74dfda56dc62f847c3f416b9a2c212485d.zip |
[ORC] Generalize the ORC RPC utils to support RPC function return values and
asynchronous call/handle. Also updates the ORC remote JIT API to use the new
scheme.
The previous version of the RPC tools only supported void functions, and
required the user to manually call a paired function to return results. This
patch replaces the Procedure typedef (which only supported void functions) with
the Function typedef which supports return values, e.g.:
Function<FooId, int32_t(std::string)> Foo;
The RPC primitives and channel operations are also expanded. RPC channels must
support four new operations: startSendMessage, endSendMessage,
startRecieveMessage and endRecieveMessage, to handle channel locking. In
addition, serialization support for tuples to RPCChannels is added to enable
multiple return values.
The RPC primitives are expanded from callAppend, call, expect and handle, to:
appendCallAsync - Make an asynchronous call to the given function.
callAsync - The same as appendCallAsync, but calls send on the channel when
done.
callSTHandling - Blocking call for single-threaded code. Wraps a call to
callAsync then waits on the result, using a user-supplied
handler to handle any callbacks from the remote.
callST - The same as callSTHandling, except that it doesn't handle
callbacks - it expects the result to be the first return.
expect and handle - as before.
handleResponse - Handle a response from the remote.
waitForResult - Wait for the response with the given sequence number to arrive.
llvm-svn: 266581
Diffstat (limited to 'llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp')
-rw-r--r-- | llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp | 103 |
1 files changed, 76 insertions, 27 deletions
diff --git a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp index 3b01c3828b6..77632e35eb1 100644 --- a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp @@ -44,26 +44,25 @@ private: class DummyRPC : public testing::Test, public RPC<QueueChannel> { public: - typedef Procedure<1, void(bool)> Proc1; - typedef Procedure<2, void(int8_t, uint8_t, int16_t, uint16_t, - int32_t, uint32_t, int64_t, uint64_t, - bool, std::string, std::vector<int>)> AllTheTypes; + typedef Function<2, void(bool)> BasicVoid; + typedef Function<3, int32_t(bool)> BasicInt; + typedef Function<4, void(int8_t, uint8_t, int16_t, uint16_t, + int32_t, uint32_t, int64_t, uint64_t, + bool, std::string, std::vector<int>)> AllTheTypes; }; -TEST_F(DummyRPC, TestBasic) { +TEST_F(DummyRPC, TestAsyncBasicVoid) { std::queue<char> Queue; QueueChannel C(Queue); - { - // Make a call to Proc1. - auto EC = call<Proc1>(C, true); - EXPECT_FALSE(EC) << "Simple call over queue failed"; - } + // Make an async call. + auto ResOrErr = callAsync<BasicVoid>(C, true); + EXPECT_TRUE(!!ResOrErr) << "Simple call over queue failed"; { // Expect a call to Proc1. - auto EC = expect<Proc1>(C, + auto EC = expect<BasicVoid>(C, [&](bool &B) { EXPECT_EQ(B, true) << "Bool serialization broken"; @@ -71,31 +70,71 @@ TEST_F(DummyRPC, TestBasic) { }); EXPECT_FALSE(EC) << "Simple expect over queue failed"; } + + { + // Wait for the result. + auto EC = waitForResult(C, ResOrErr->second, handleNone); + EXPECT_FALSE(EC) << "Could not read result."; + } + + // Verify that the function returned ok. + auto Val = ResOrErr->first.get(); + EXPECT_TRUE(Val) << "Remote void function failed to execute."; } -TEST_F(DummyRPC, TestSerialization) { +TEST_F(DummyRPC, TestAsyncBasicInt) { std::queue<char> Queue; QueueChannel C(Queue); + // Make an async call. + auto ResOrErr = callAsync<BasicInt>(C, false); + EXPECT_TRUE(!!ResOrErr) << "Simple call over queue failed"; + { - // Make a call to Proc1. - std::vector<int> v({42, 7}); - auto EC = call<AllTheTypes>(C, - -101, - 250, - -10000, - 10000, - -1000000000, - 1000000000, - -10000000000, - 10000000000, - true, - "foo", - v); - EXPECT_FALSE(EC) << "Big (serialization test) call over queue failed"; + // Expect a call to Proc1. + auto EC = expect<BasicInt>(C, + [&](bool &B) { + EXPECT_EQ(B, false) + << "Bool serialization broken"; + return 42; + }); + EXPECT_FALSE(EC) << "Simple expect over queue failed"; } { + // Wait for the result. + auto EC = waitForResult(C, ResOrErr->second, handleNone); + EXPECT_FALSE(EC) << "Could not read result."; + } + + // Verify that the function returned ok. + auto Val = ResOrErr->first.get(); + EXPECT_TRUE(!!Val) << "Remote int function failed to execute."; + EXPECT_EQ(*Val, 42) << "Remote int function return wrong value."; +} + +TEST_F(DummyRPC, TestSerialization) { + std::queue<char> Queue; + QueueChannel C(Queue); + + // Make a call to Proc1. + std::vector<int> v({42, 7}); + auto ResOrErr = callAsync<AllTheTypes>(C, + -101, + 250, + -10000, + 10000, + -1000000000, + 1000000000, + -10000000000, + 10000000000, + true, + "foo", + v); + EXPECT_TRUE(!!ResOrErr) + << "Big (serialization test) call over queue failed"; + + { // Expect a call to Proc1. auto EC = expect<AllTheTypes>(C, [&](int8_t &s8, @@ -136,4 +175,14 @@ TEST_F(DummyRPC, TestSerialization) { }); EXPECT_FALSE(EC) << "Big (serialization test) call over queue failed"; } + + { + // Wait for the result. + auto EC = waitForResult(C, ResOrErr->second, handleNone); + EXPECT_FALSE(EC) << "Could not read result."; + } + + // Verify that the function returned ok. + auto Val = ResOrErr->first.get(); + EXPECT_TRUE(Val) << "Remote void function failed to execute."; } |