|
|
|
@ -25,6 +25,7 @@ |
|
|
|
|
|
|
|
|
|
#include "absl/status/statusor.h" |
|
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
|
#include "absl/strings/str_split.h" |
|
|
|
|
#include "absl/strings/string_view.h" |
|
|
|
|
#include "gtest/gtest.h" |
|
|
|
|
|
|
|
|
@ -375,12 +376,7 @@ void WaitAndShutdown(server* sv, client* cl) { |
|
|
|
|
gpr_mu_unlock(&g_mu); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string TestScenarioName( |
|
|
|
|
const ::testing::TestParamInfo<std::string>& info) { |
|
|
|
|
return info.param; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class EventPollerTest : public ::testing::TestWithParam<std::string> { |
|
|
|
|
class EventPollerTest : public ::testing::Test { |
|
|
|
|
void SetUp() override { |
|
|
|
|
engine_ = |
|
|
|
|
std::make_unique<grpc_event_engine::experimental::PosixEventEngine>(); |
|
|
|
@ -389,10 +385,9 @@ class EventPollerTest : public ::testing::TestWithParam<std::string> { |
|
|
|
|
std::make_unique<grpc_event_engine::posix_engine::TestScheduler>( |
|
|
|
|
engine_.get()); |
|
|
|
|
EXPECT_NE(scheduler_, nullptr); |
|
|
|
|
GPR_GLOBAL_CONFIG_SET(grpc_poll_strategy, GetParam().c_str()); |
|
|
|
|
g_event_poller = GetDefaultPoller(scheduler_.get()); |
|
|
|
|
if (g_event_poller != nullptr) { |
|
|
|
|
EXPECT_EQ(g_event_poller->Name(), GetParam()); |
|
|
|
|
gpr_log(GPR_INFO, "Using poller: %s", g_event_poller->Name().c_str()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -413,7 +408,7 @@ class EventPollerTest : public ::testing::TestWithParam<std::string> { |
|
|
|
|
// Test grpc_fd. Start an upload server and client, upload a stream of bytes
|
|
|
|
|
// from the client to the server, and verify that the total number of sent
|
|
|
|
|
// bytes is equal to the total number of received bytes.
|
|
|
|
|
TEST_P(EventPollerTest, TestEventPollerHandle) { |
|
|
|
|
TEST_F(EventPollerTest, TestEventPollerHandle) { |
|
|
|
|
server sv; |
|
|
|
|
client cl; |
|
|
|
|
int port; |
|
|
|
@ -455,7 +450,7 @@ void SecondReadCallback(FdChangeData* fdc, absl::Status /*status*/) { |
|
|
|
|
// Note that we have two different but almost identical callbacks above -- the
|
|
|
|
|
// point is to have two different function pointers and two different data
|
|
|
|
|
// pointers and make sure that changing both really works.
|
|
|
|
|
TEST_P(EventPollerTest, TestEventPollerHandleChange) { |
|
|
|
|
TEST_F(EventPollerTest, TestEventPollerHandleChange) { |
|
|
|
|
EventHandle* em_fd; |
|
|
|
|
FdChangeData a, b; |
|
|
|
|
int flags; |
|
|
|
@ -692,7 +687,7 @@ class Worker : public grpc_core::DualRefCounted<Worker> { |
|
|
|
|
// immediately and schedule the wait for the next read event. A new read event
|
|
|
|
|
// is also generated for each fd in parallel after the previous one is
|
|
|
|
|
// processed.
|
|
|
|
|
TEST_P(EventPollerTest, TestMultipleHandles) { |
|
|
|
|
TEST_F(EventPollerTest, TestMultipleHandles) { |
|
|
|
|
static constexpr int kNumHandles = 100; |
|
|
|
|
static constexpr int kNumWakeupsPerHandle = 100; |
|
|
|
|
if (g_event_poller == nullptr) { |
|
|
|
@ -704,11 +699,6 @@ TEST_P(EventPollerTest, TestMultipleHandles) { |
|
|
|
|
worker->Wait(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(PosixEventPoller, EventPollerTest, |
|
|
|
|
::testing::ValuesIn({std::string("epoll1"), |
|
|
|
|
std::string("poll")}), |
|
|
|
|
&TestScenarioName); |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace posix_engine
|
|
|
|
|
} // namespace grpc_event_engine
|
|
|
|
@ -716,6 +706,14 @@ INSTANTIATE_TEST_SUITE_P(PosixEventPoller, EventPollerTest, |
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
::testing::InitGoogleTest(&argc, argv); |
|
|
|
|
gpr_mu_init(&g_mu); |
|
|
|
|
grpc_core::UniquePtr<char> poll_strategy = |
|
|
|
|
GPR_GLOBAL_CONFIG_GET(grpc_poll_strategy); |
|
|
|
|
GPR_GLOBAL_CONFIG_GET(grpc_poll_strategy); |
|
|
|
|
auto strings = absl::StrSplit(poll_strategy.get(), ','); |
|
|
|
|
if (std::find(strings.begin(), strings.end(), "none") != strings.end()) { |
|
|
|
|
// Skip the test entirely if poll strategy is none.
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
return RUN_ALL_TESTS(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|