From 4f734f254e5575f41758cdc313bae6a56925bbf4 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Fri, 11 Nov 2016 19:46:46 +0000 Subject: [ORC] Revert r286620 while I investigate a bot failure. llvm-svn: 286621 --- .../unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp | 236 ++++++++------------- 1 file changed, 86 insertions(+), 150 deletions(-) (limited to 'llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp') diff --git a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp index 4d703c78a0e..259a75a203f 100644 --- a/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ExecutionEngine/Orc/RawByteChannel.h" +#include "llvm/ExecutionEngine/Orc/RPCByteChannel.h" #include "llvm/ExecutionEngine/Orc/RPCUtils.h" #include "gtest/gtest.h" @@ -15,7 +15,7 @@ using namespace llvm; using namespace llvm::orc; -using namespace llvm::orc::rpc; +using namespace llvm::orc::remote; class Queue : public std::queue { public: @@ -25,7 +25,7 @@ private: std::mutex Lock; }; -class QueueChannel : public RawByteChannel { +class QueueChannel : public RPCByteChannel { public: QueueChannel(Queue &InQueue, Queue &OutQueue) : InQueue(InQueue), OutQueue(OutQueue) {} @@ -61,190 +61,126 @@ private: Queue &OutQueue; }; -class DummyRPCAPI { +class DummyRPC : public testing::Test, public RPC { public: - - class VoidBool : public Function { - public: - static const char* getName() { return "VoidBool"; } - }; - - class IntInt : public Function { - public: - static const char* getName() { return "IntInt"; } - }; - - class AllTheTypes - : public Function)> { - public: - static const char* getName() { return "AllTheTypes"; } + enum FuncId : uint32_t { + VoidBoolId = RPCFunctionIdTraits::FirstValidId, + IntIntId, + AllTheTypesId }; -}; -class DummyRPCEndpoint : public DummyRPCAPI, - public SingleThreadedRPC { -public: - DummyRPCEndpoint(Queue &Q1, Queue &Q2) - : SingleThreadedRPC(C, true), C(Q1, Q2) {} -private: - QueueChannel C; + typedef Function VoidBool; + typedef Function IntInt; + typedef Function)> + AllTheTypes; }; -TEST(DummyRPC, TestAsyncVoidBool) { +TEST_F(DummyRPC, TestAsyncVoidBool) { Queue Q1, Q2; - DummyRPCEndpoint Client(Q1, Q2); - DummyRPCEndpoint Server(Q2, Q1); + QueueChannel C1(Q1, Q2); + QueueChannel C2(Q2, Q1); - std::thread ServerThread([&]() { - Server.addHandler( - [](bool B) { - EXPECT_EQ(B, true) - << "Server void(bool) received unexpected result"; - }); - - { - // 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)"; - } - }); + // Make an async call. + auto ResOrErr = callNBWithSeq(C1, true); + EXPECT_TRUE(!!ResOrErr) << "Simple call over queue failed"; { - // Make an async call. - auto Err = Client.callAsync( - [](Error Err) { - EXPECT_FALSE(!!Err) << "Async void(bool) response handler failed"; - return Error::success(); - }, true); - EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(bool)"; + // Expect a call to Proc1. + auto EC = expect(C2, [&](bool &B) { + EXPECT_EQ(B, true) << "Bool serialization broken"; + return Error::success(); + }); + EXPECT_FALSE(EC) << "Simple expect over queue failed"; } { - // Poke the client to process the result of the void(bool) call. - auto Err = Client.handleOne(); - EXPECT_FALSE(!!Err) << "Client failed to handle response from void(bool)"; + // Wait for the result. + auto EC = waitForResult(C1, ResOrErr->second, handleNone); + EXPECT_FALSE(EC) << "Could not read result."; } - ServerThread.join(); + // Verify that the function returned ok. + auto Err = ResOrErr->first.get(); + EXPECT_FALSE(!!Err) << "Remote void function failed to execute."; } -TEST(DummyRPC, TestAsyncIntInt) { +TEST_F(DummyRPC, TestAsyncIntInt) { Queue Q1, Q2; - DummyRPCEndpoint Client(Q1, Q2); - DummyRPCEndpoint Server(Q2, Q1); - - std::thread ServerThread([&]() { - Server.addHandler( - [](int X) -> int { - EXPECT_EQ(X, 21) << "Server int(int) receieved unexpected result"; - return 2 * X; - }); + QueueChannel C1(Q1, Q2); + QueueChannel C2(Q2, Q1); - { - // 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 int(int) call. - auto Err = Server.handleOne(); - EXPECT_FALSE(!!Err) << "Server failed to handle call to int(int)"; - } - }); + // Make an async call. + auto ResOrErr = callNBWithSeq(C1, 21); + EXPECT_TRUE(!!ResOrErr) << "Simple call over queue failed"; { - auto Err = Client.callAsync( - [](Expected 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)"; + // Expect a call to Proc1. + auto EC = expect(C2, [&](int32_t I) -> Expected { + EXPECT_EQ(I, 21) << "Bool serialization broken"; + return 2 * I; + }); + EXPECT_FALSE(EC) << "Simple expect over queue failed"; } { - // Poke the client to process the result. - auto Err = Client.handleOne(); - EXPECT_FALSE(!!Err) << "Client failed to handle response from void(bool)"; + // Wait for the result. + auto EC = waitForResult(C1, ResOrErr->second, handleNone); + EXPECT_FALSE(EC) << "Could not read result."; } - ServerThread.join(); + // 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(DummyRPC, TestSerialization) { +TEST_F(DummyRPC, TestSerialization) { Queue Q1, Q2; - DummyRPCEndpoint Client(Q1, Q2); - DummyRPCEndpoint Server(Q2, Q1); - - std::thread ServerThread([&]() { - Server.addHandler( - [&](int8_t S8, uint8_t U8, int16_t S16, uint16_t U16, - int32_t S32, uint32_t U32, int64_t S64, uint64_t U64, - bool B, std::string S, std::vector V) { - - EXPECT_EQ(S8, -101) << "int8_t serialization broken"; - EXPECT_EQ(U8, 250) << "uint8_t serialization broken"; - EXPECT_EQ(S16, -10000) << "int16_t serialization broken"; - EXPECT_EQ(U16, 10000) << "uint16_t serialization broken"; - EXPECT_EQ(S32, -1000000000) << "int32_t serialization broken"; - EXPECT_EQ(U32, 1000000000ULL) << "uint32_t serialization broken"; - EXPECT_EQ(S64, -10000000000) << "int64_t serialization broken"; - EXPECT_EQ(U64, 10000000000ULL) << "uint64_t serialization broken"; - EXPECT_EQ(B, true) << "bool serialization broken"; - EXPECT_EQ(S, "foo") << "std::string serialization broken"; - EXPECT_EQ(V, std::vector({42, 7})) - << "std::vector serialization broken"; - return Error::success(); - }); - - { - // 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 AllTheTypes call. - auto Err = Server.handleOne(); - EXPECT_FALSE(!!Err) << "Server failed to handle call to void(bool)"; - } - }); + QueueChannel C1(Q1, Q2); + QueueChannel C2(Q2, Q1); + // Make a call to Proc1. + std::vector v({42, 7}); + auto ResOrErr = callNBWithSeq( + C1, -101, 250, -10000, 10000, -1000000000, 1000000000, -10000000000, + 10000000000, true, "foo", v); + EXPECT_TRUE(!!ResOrErr) << "Big (serialization test) call over queue failed"; { - // Make an async call. - std::vector v({42, 7}); - auto Err = Client.callAsync( - [](Error Err) { - EXPECT_FALSE(!!Err) << "Async AllTheTypes response handler failed"; + // Expect a call to Proc1. + auto EC = expect( + C2, [&](int8_t &s8, uint8_t &u8, int16_t &s16, uint16_t &u16, + int32_t &s32, uint32_t &u32, int64_t &s64, uint64_t &u64, + bool &b, std::string &s, std::vector &v) { + + EXPECT_EQ(s8, -101) << "int8_t serialization broken"; + EXPECT_EQ(u8, 250) << "uint8_t serialization broken"; + EXPECT_EQ(s16, -10000) << "int16_t serialization broken"; + EXPECT_EQ(u16, 10000) << "uint16_t serialization broken"; + EXPECT_EQ(s32, -1000000000) << "int32_t serialization broken"; + EXPECT_EQ(u32, 1000000000ULL) << "uint32_t serialization broken"; + EXPECT_EQ(s64, -10000000000) << "int64_t serialization broken"; + EXPECT_EQ(u64, 10000000000ULL) << "uint64_t serialization broken"; + EXPECT_EQ(b, true) << "bool serialization broken"; + EXPECT_EQ(s, "foo") << "std::string serialization broken"; + EXPECT_EQ(v, std::vector({42, 7})) + << "std::vector serialization broken"; return Error::success(); - }, - static_cast(-101), static_cast(250), - static_cast(-10000), static_cast(10000), - static_cast(-1000000000), static_cast(1000000000), - static_cast(-10000000000), static_cast(10000000000), - true, std::string("foo"), v); - EXPECT_FALSE(!!Err) << "Client.callAsync failed for AllTheTypes"; + }); + EXPECT_FALSE(EC) << "Big (serialization test) call over queue failed"; } { - // Poke the client to process the result of the AllTheTypes call. - auto Err = Client.handleOne(); - EXPECT_FALSE(!!Err) << "Client failed to handle response from AllTheTypes"; + // Wait for the result. + auto EC = waitForResult(C1, ResOrErr->second, handleNone); + EXPECT_FALSE(EC) << "Could not read result."; } - ServerThread.join(); + // Verify that the function returned ok. + auto Err = ResOrErr->first.get(); + EXPECT_FALSE(!!Err) << "Remote void function failed to execute."; } // Test the synchronous call API. -- cgit v1.2.3