diff options
author | Lang Hames <lhames@gmail.com> | 2017-01-08 01:13:47 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2017-01-08 01:13:47 +0000 |
commit | 7f6acd05dc2ed70e7ba7a95ea70c749118e58e8c (patch) | |
tree | 9cd529c9e006f68649fd077c29c5668593e328f1 /llvm/unittests/ExecutionEngine | |
parent | 7b0d145768fe907fd8e46d102cee006f06400430 (diff) | |
download | bcm5719-llvm-7f6acd05dc2ed70e7ba7a95ea70c749118e58e8c.tar.gz bcm5719-llvm-7f6acd05dc2ed70e7ba7a95ea70c749118e58e8c.zip |
[Orc][RPC] Add an APICalls utility for grouping RPC funtions for registration.
APICalls allows groups of functions to be composed into an API that can be
registered as a unit with an RPC endpoint. Doing registration on a-whole API
basis (rather than per-function) allows missing API functions to be detected
early.
APICalls also allows Function membership to be tested at compile-time. This
allows clients to write static assertions that functions to be called are
members of registered APIs.
llvm-svn: 291380
Diffstat (limited to 'llvm/unittests/ExecutionEngine')
-rw-r--r-- | llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp index c2dca225c12..23052dcb70e 100644 --- a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp @@ -108,8 +108,7 @@ namespace rpc { } // end namespace orc } // end namespace llvm -class DummyRPCAPI { -public: +namespace DummyRPCAPI { class VoidBool : public Function<VoidBool, void(bool)> { public: @@ -456,3 +455,52 @@ TEST(DummyRPC, TestParallelCallGroup) { ServerThread.join(); } + +TEST(DummyRPC, TestAPICalls) { + + using DummyCalls1 = APICalls<DummyRPCAPI::VoidBool, DummyRPCAPI::IntInt>; + using DummyCalls2 = APICalls<DummyRPCAPI::AllTheTypes>; + using DummyCalls3 = APICalls<DummyCalls1, DummyRPCAPI::CustomType>; + using DummyCallsAll = APICalls<DummyCalls1, DummyCalls2, DummyRPCAPI::CustomType>; + + static_assert(DummyCalls1::Contains<DummyRPCAPI::VoidBool>::value, + "Contains<Func> template should return true here"); + static_assert(!DummyCalls1::Contains<DummyRPCAPI::CustomType>::value, + "Contains<Func> template should return false here"); + + Queue Q1, Q2; + DummyRPCEndpoint Client(Q1, Q2); + DummyRPCEndpoint Server(Q2, Q1); + + std::thread ServerThread( + [&]() { + Server.addHandler<DummyRPCAPI::VoidBool>([](bool b) { }); + Server.addHandler<DummyRPCAPI::IntInt>([](int x) { return x; }); + Server.addHandler<DummyRPCAPI::CustomType>([](RPCFoo F) {}); + + for (unsigned I = 0; I < 4; ++I) { + auto Err = Server.handleOne(); + (void)!!Err; + } + }); + + { + auto Err = DummyCalls1::negotiate(Client); + EXPECT_FALSE(!!Err) << "DummyCalls1::negotiate failed"; + } + + { + auto Err = DummyCalls3::negotiate(Client); + EXPECT_FALSE(!!Err) << "DummyCalls3::negotiate failed"; + } + + { + auto Err = DummyCallsAll::negotiate(Client); + EXPECT_EQ(errorToErrorCode(std::move(Err)).value(), + static_cast<int>(OrcErrorCode::UnknownRPCFunction)) + << "Uxpected 'UnknownRPCFunction' error for attempted negotiate of " + "unsupported function"; + } + + ServerThread.join(); +} |