Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
Show First 20 Lines • Show All 277 Lines • ▼ Show 20 Lines | TEST(DummyRPC, TestAsyncVoidBoolHandler) { | ||||
DummyRPCEndpoint Client(*Channels.first); | DummyRPCEndpoint Client(*Channels.first); | ||||
DummyRPCEndpoint Server(*Channels.second); | DummyRPCEndpoint Server(*Channels.second); | ||||
std::thread ServerThread([&]() { | std::thread ServerThread([&]() { | ||||
Server.addAsyncHandler<DummyRPCAPI::VoidBool>( | Server.addAsyncHandler<DummyRPCAPI::VoidBool>( | ||||
[](std::function<Error(Error)> SendResult, | [](std::function<Error(Error)> SendResult, | ||||
bool B) { | bool B) { | ||||
EXPECT_EQ(B, true) << "Server void(bool) receieved unexpected result"; | EXPECT_EQ(B, true) << "Server void(bool) receieved unexpected result"; | ||||
cantFail(SendResult(Error::success())); | llvm_cantFail(SendResult(Error::success())); | ||||
return Error::success(); | return Error::success(); | ||||
}); | }); | ||||
{ | { | ||||
// Poke the server to handle the negotiate call. | // Poke the server to handle the negotiate call. | ||||
auto Err = Server.handleOne(); | auto Err = Server.handleOne(); | ||||
EXPECT_FALSE(!!Err) << "Server failed to handle call to negotiate"; | EXPECT_FALSE(!!Err) << "Server failed to handle call to negotiate"; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | TEST(DummyRPC, ReturnErrorSuccess) { | ||||
std::thread ServerThread([&]() { | std::thread ServerThread([&]() { | ||||
Server.addHandler<DummyRPCAPI::ErrorFunc>( | Server.addHandler<DummyRPCAPI::ErrorFunc>( | ||||
[]() { | []() { | ||||
return Error::success(); | return Error::success(); | ||||
}); | }); | ||||
// Handle the negotiate plus one call. | // Handle the negotiate plus one call. | ||||
for (unsigned I = 0; I != 2; ++I) | for (unsigned I = 0; I != 2; ++I) | ||||
cantFail(Server.handleOne()); | llvm_cantFail(Server.handleOne()); | ||||
}); | }); | ||||
cantFail(Client.callAsync<DummyRPCAPI::ErrorFunc>( | llvm_cantFail(Client.callAsync<DummyRPCAPI::ErrorFunc>( | ||||
[&](Error Err) { | [&](Error Err) { | ||||
EXPECT_FALSE(!!Err) << "Expected success value"; | EXPECT_FALSE(!!Err) << "Expected success value"; | ||||
return Error::success(); | return Error::success(); | ||||
})); | })); | ||||
cantFail(Client.handleOne()); | llvm_cantFail(Client.handleOne()); | ||||
ServerThread.join(); | ServerThread.join(); | ||||
} | } | ||||
TEST(DummyRPC, ReturnErrorFailure) { | TEST(DummyRPC, ReturnErrorFailure) { | ||||
registerDummyErrorSerialization<QueueChannel>(); | registerDummyErrorSerialization<QueueChannel>(); | ||||
auto Channels = createPairedQueueChannels(); | auto Channels = createPairedQueueChannels(); | ||||
DummyRPCEndpoint Client(*Channels.first); | DummyRPCEndpoint Client(*Channels.first); | ||||
DummyRPCEndpoint Server(*Channels.second); | DummyRPCEndpoint Server(*Channels.second); | ||||
std::thread ServerThread([&]() { | std::thread ServerThread([&]() { | ||||
Server.addHandler<DummyRPCAPI::ErrorFunc>( | Server.addHandler<DummyRPCAPI::ErrorFunc>( | ||||
[]() { | []() { | ||||
return make_error<DummyError>(42); | return make_error<DummyError>(42); | ||||
}); | }); | ||||
// Handle the negotiate plus one call. | // Handle the negotiate plus one call. | ||||
for (unsigned I = 0; I != 2; ++I) | for (unsigned I = 0; I != 2; ++I) | ||||
cantFail(Server.handleOne()); | llvm_cantFail(Server.handleOne()); | ||||
}); | }); | ||||
cantFail(Client.callAsync<DummyRPCAPI::ErrorFunc>( | llvm_cantFail(Client.callAsync<DummyRPCAPI::ErrorFunc>( | ||||
[&](Error Err) { | [&](Error Err) { | ||||
EXPECT_TRUE(Err.isA<DummyError>()) | EXPECT_TRUE(Err.isA<DummyError>()) | ||||
<< "Incorrect error type"; | << "Incorrect error type"; | ||||
return handleErrors( | return handleErrors( | ||||
std::move(Err), | std::move(Err), | ||||
[](const DummyError &DE) { | [](const DummyError &DE) { | ||||
EXPECT_EQ(DE.getValue(), 42ULL) | EXPECT_EQ(DE.getValue(), 42ULL) | ||||
<< "Incorrect DummyError serialization"; | << "Incorrect DummyError serialization"; | ||||
}); | }); | ||||
})); | })); | ||||
cantFail(Client.handleOne()); | llvm_cantFail(Client.handleOne()); | ||||
ServerThread.join(); | ServerThread.join(); | ||||
} | } | ||||
TEST(DummyRPC, ReturnExpectedSuccess) { | TEST(DummyRPC, ReturnExpectedSuccess) { | ||||
registerDummyErrorSerialization<QueueChannel>(); | registerDummyErrorSerialization<QueueChannel>(); | ||||
auto Channels = createPairedQueueChannels(); | auto Channels = createPairedQueueChannels(); | ||||
DummyRPCEndpoint Client(*Channels.first); | DummyRPCEndpoint Client(*Channels.first); | ||||
DummyRPCEndpoint Server(*Channels.second); | DummyRPCEndpoint Server(*Channels.second); | ||||
std::thread ServerThread([&]() { | std::thread ServerThread([&]() { | ||||
Server.addHandler<DummyRPCAPI::ExpectedFunc>( | Server.addHandler<DummyRPCAPI::ExpectedFunc>( | ||||
[]() -> uint32_t { | []() -> uint32_t { | ||||
return 42; | return 42; | ||||
}); | }); | ||||
// Handle the negotiate plus one call. | // Handle the negotiate plus one call. | ||||
for (unsigned I = 0; I != 2; ++I) | for (unsigned I = 0; I != 2; ++I) | ||||
cantFail(Server.handleOne()); | llvm_cantFail(Server.handleOne()); | ||||
}); | }); | ||||
cantFail(Client.callAsync<DummyRPCAPI::ExpectedFunc>( | llvm_cantFail(Client.callAsync<DummyRPCAPI::ExpectedFunc>( | ||||
[&](Expected<uint32_t> ValOrErr) { | [&](Expected<uint32_t> ValOrErr) { | ||||
EXPECT_TRUE(!!ValOrErr) | EXPECT_TRUE(!!ValOrErr) | ||||
<< "Expected success value"; | << "Expected success value"; | ||||
EXPECT_EQ(*ValOrErr, 42ULL) | EXPECT_EQ(*ValOrErr, 42ULL) | ||||
<< "Incorrect Expected<uint32_t> deserialization"; | << "Incorrect Expected<uint32_t> deserialization"; | ||||
return Error::success(); | return Error::success(); | ||||
})); | })); | ||||
cantFail(Client.handleOne()); | llvm_cantFail(Client.handleOne()); | ||||
ServerThread.join(); | ServerThread.join(); | ||||
} | } | ||||
TEST(DummyRPC, ReturnExpectedFailure) { | TEST(DummyRPC, ReturnExpectedFailure) { | ||||
registerDummyErrorSerialization<QueueChannel>(); | registerDummyErrorSerialization<QueueChannel>(); | ||||
auto Channels = createPairedQueueChannels(); | auto Channels = createPairedQueueChannels(); | ||||
DummyRPCEndpoint Client(*Channels.first); | DummyRPCEndpoint Client(*Channels.first); | ||||
DummyRPCEndpoint Server(*Channels.second); | DummyRPCEndpoint Server(*Channels.second); | ||||
std::thread ServerThread([&]() { | std::thread ServerThread([&]() { | ||||
Server.addHandler<DummyRPCAPI::ExpectedFunc>( | Server.addHandler<DummyRPCAPI::ExpectedFunc>( | ||||
[]() -> Expected<uint32_t> { | []() -> Expected<uint32_t> { | ||||
return make_error<DummyError>(7); | return make_error<DummyError>(7); | ||||
}); | }); | ||||
// Handle the negotiate plus one call. | // Handle the negotiate plus one call. | ||||
for (unsigned I = 0; I != 2; ++I) | for (unsigned I = 0; I != 2; ++I) | ||||
cantFail(Server.handleOne()); | llvm_cantFail(Server.handleOne()); | ||||
}); | }); | ||||
cantFail(Client.callAsync<DummyRPCAPI::ExpectedFunc>( | llvm_cantFail(Client.callAsync<DummyRPCAPI::ExpectedFunc>( | ||||
[&](Expected<uint32_t> ValOrErr) { | [&](Expected<uint32_t> ValOrErr) { | ||||
EXPECT_FALSE(!!ValOrErr) | EXPECT_FALSE(!!ValOrErr) | ||||
<< "Expected failure value"; | << "Expected failure value"; | ||||
auto Err = ValOrErr.takeError(); | auto Err = ValOrErr.takeError(); | ||||
EXPECT_TRUE(Err.isA<DummyError>()) | EXPECT_TRUE(Err.isA<DummyError>()) | ||||
<< "Incorrect error type"; | << "Incorrect error type"; | ||||
return handleErrors( | return handleErrors( | ||||
std::move(Err), | std::move(Err), | ||||
[](const DummyError &DE) { | [](const DummyError &DE) { | ||||
EXPECT_EQ(DE.getValue(), 7ULL) | EXPECT_EQ(DE.getValue(), 7ULL) | ||||
<< "Incorrect DummyError serialization"; | << "Incorrect DummyError serialization"; | ||||
}); | }); | ||||
})); | })); | ||||
cantFail(Client.handleOne()); | llvm_cantFail(Client.handleOne()); | ||||
ServerThread.join(); | ServerThread.join(); | ||||
} | } | ||||
TEST(DummyRPC, TestParallelCallGroup) { | TEST(DummyRPC, TestParallelCallGroup) { | ||||
auto Channels = createPairedQueueChannels(); | auto Channels = createPairedQueueChannels(); | ||||
DummyRPCEndpoint Client(*Channels.first); | DummyRPCEndpoint Client(*Channels.first); | ||||
DummyRPCEndpoint Server(*Channels.second); | DummyRPCEndpoint Server(*Channels.second); | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |