gtestify test/core/gprpp (#30197)

* fix

* gtestify test/core/gprpp

* Update by review
pull/30201/head
Esun Kim 3 years ago committed by GitHub
parent 98b1a7710e
commit dfe6a8b903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 272
      CMakeLists.txt
  2. 92
      build_autogenerated.yaml
  3. 4
      test/core/gprpp/BUILD
  4. 37
      test/core/gprpp/fork_test.cc
  5. 27
      test/core/gprpp/host_port_test.cc
  6. 22
      test/core/gprpp/mpscq_test.cc
  7. 16
      test/core/gprpp/thd_test.cc
  8. 184
      tools/run_tests/generated/tests.json

272
CMakeLists.txt generated

@ -815,23 +815,16 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c fling_test)
endif()
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c fork_test)
endif()
add_dependencies(buildtests_c format_request_test)
add_dependencies(buildtests_c goaway_server_test)
add_dependencies(buildtests_c grpc_ipv6_loopback_available_test)
add_dependencies(buildtests_c histogram_test)
add_dependencies(buildtests_c host_port_test)
add_dependencies(buildtests_c hpack_encoder_test)
add_dependencies(buildtests_c inproc_callback_test)
add_dependencies(buildtests_c invalid_call_argument_test)
add_dependencies(buildtests_c load_file_test)
add_dependencies(buildtests_c message_compress_test)
add_dependencies(buildtests_c minimal_stack_is_minimal_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c mpscq_test)
endif()
add_dependencies(buildtests_c multiple_server_queues_test)
add_dependencies(buildtests_c murmur_hash_test)
add_dependencies(buildtests_c no_server_test)
@ -866,7 +859,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_c test_core_iomgr_time_averaged_stats_test)
add_dependencies(buildtests_c test_core_iomgr_timer_heap_test)
add_dependencies(buildtests_c test_core_iomgr_timer_list_test)
add_dependencies(buildtests_c thd_test)
add_dependencies(buildtests_c varint_test)
add_custom_target(buildtests_cxx)
@ -990,6 +982,9 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx flaky_network_test)
add_dependencies(buildtests_cxx flow_control_test)
add_dependencies(buildtests_cxx for_each_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx fork_test)
endif()
add_dependencies(buildtests_cxx frame_handler_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx fuzzing_event_engine_test)
@ -1028,6 +1023,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx head_of_line_blocking_bad_client_test)
add_dependencies(buildtests_cxx headers_bad_client_test)
add_dependencies(buildtests_cxx health_service_end2end_test)
add_dependencies(buildtests_cxx host_port_test)
add_dependencies(buildtests_cxx hpack_parser_table_test)
add_dependencies(buildtests_cxx hpack_parser_test)
add_dependencies(buildtests_cxx http2_client)
@ -1070,6 +1066,9 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx miscompile_with_no_unique_address_test)
add_dependencies(buildtests_cxx mock_stream_test)
add_dependencies(buildtests_cxx mock_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx mpscq_test)
endif()
add_dependencies(buildtests_cxx nonblocking_test)
add_dependencies(buildtests_cxx num_external_connectivity_watchers_test)
add_dependencies(buildtests_cxx observable_test)
@ -1181,6 +1180,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx test_cpp_server_credentials_test)
add_dependencies(buildtests_cxx test_cpp_util_slice_test)
add_dependencies(buildtests_cxx test_cpp_util_time_test)
add_dependencies(buildtests_cxx thd_test)
add_dependencies(buildtests_cxx thread_manager_test)
add_dependencies(buildtests_cxx thread_quota_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
@ -4928,35 +4928,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
)
endif()
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(fork_test
test/core/gprpp/fork_test.cc
)
target_include_directories(fork_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(fork_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
endif()
if(gRPC_BUILD_TESTS)
@ -5071,33 +5042,6 @@ target_link_libraries(histogram_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(host_port_test
test/core/gprpp/host_port_test.cc
)
target_include_directories(host_port_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(host_port_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -5261,35 +5205,6 @@ target_link_libraries(minimal_stack_is_minimal_test
)
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(mpscq_test
test/core/gprpp/mpscq_test.cc
)
target_include_directories(mpscq_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(mpscq_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
endif()
if(gRPC_BUILD_TESTS)
@ -5908,33 +5823,6 @@ target_link_libraries(test_core_iomgr_timer_list_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(thd_test
test/core/gprpp/thd_test.cc
)
target_include_directories(thd_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(thd_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -10269,6 +10157,43 @@ target_link_libraries(for_each_test
)
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(fork_test
test/core/gprpp/fork_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(fork_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(fork_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
endif()
if(gRPC_BUILD_TESTS)
@ -11690,6 +11615,41 @@ target_link_libraries(health_service_end2end_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(host_port_test
test/core/gprpp/host_port_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(host_port_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(host_port_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -13215,6 +13175,43 @@ target_link_libraries(mock_test
)
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(mpscq_test
test/core/gprpp/mpscq_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(mpscq_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(mpscq_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
endif()
if(gRPC_BUILD_TESTS)
@ -17173,6 +17170,41 @@ target_link_libraries(test_cpp_util_time_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(thd_test
test/core/gprpp/thd_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(thd_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(thd_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)

@ -3442,19 +3442,6 @@ targets:
- linux
- posix
- mac
- name: fork_test
build: test
language: c
headers: []
src:
- test/core/gprpp/fork_test.cc
deps:
- grpc_test_util
platforms:
- linux
- posix
- mac
uses_polling: false
- name: format_request_test
build: test
language: c
@ -3495,15 +3482,6 @@ targets:
deps:
- grpc_test_util
uses_polling: false
- name: host_port_test
build: test
language: c
headers: []
src:
- test/core/gprpp/host_port_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: hpack_encoder_test
build: test
language: c
@ -3559,19 +3537,6 @@ targets:
deps:
- grpc_test_util
uses_polling: false
- name: mpscq_test
build: test
language: c
headers: []
src:
- test/core/gprpp/mpscq_test.cc
deps:
- grpc_test_util
platforms:
- linux
- posix
- mac
uses_polling: false
- name: multiple_server_queues_test
build: test
language: c
@ -3810,15 +3775,6 @@ targets:
deps:
- grpc_test_util
uses_polling: false
- name: thd_test
build: test
language: c
headers: []
src:
- test/core/gprpp/thd_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: varint_test
build: test
language: c
@ -5770,6 +5726,20 @@ targets:
- gpr
- upb
uses_polling: false
- name: fork_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/gprpp/fork_test.cc
deps:
- grpc_test_util
platforms:
- linux
- posix
- mac
uses_polling: false
- name: frame_handler_test
gtest: true
build: test
@ -6203,6 +6173,16 @@ targets:
- test/cpp/end2end/test_service_impl.cc
deps:
- grpc++_test_util
- name: host_port_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/gprpp/host_port_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: hpack_parser_table_test
gtest: true
build: test
@ -6897,6 +6877,20 @@ targets:
deps:
- grpc++_test
- grpc++_test_util
- name: mpscq_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/gprpp/mpscq_test.cc
deps:
- grpc_test_util
platforms:
- linux
- posix
- mac
uses_polling: false
- name: nonblocking_test
gtest: true
build: test
@ -8736,6 +8730,16 @@ targets:
deps:
- grpc++_test_util
uses_polling: false
- name: thd_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/gprpp/thd_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: thread_manager_test
gtest: true
build: test

@ -43,6 +43,7 @@ grpc_cc_test(
grpc_cc_test(
name = "fork_test",
srcs = ["fork_test.cc"],
external_deps = ["gtest"],
language = "C++",
tags = ["no_windows"],
uses_event_engine = True, # engines should behave appropriately on Fork
@ -142,6 +143,7 @@ grpc_cc_test(
grpc_cc_test(
name = "host_port_test",
srcs = ["host_port_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_event_engine = False,
uses_polling = False,
@ -155,6 +157,7 @@ grpc_cc_test(
name = "mpscq_test",
srcs = ["mpscq_test.cc"],
exec_properties = LARGE_MACHINE,
external_deps = ["gtest"],
language = "C++",
tags = ["no_windows"], # LARGE_MACHINE is not configured for windows RBE
uses_event_engine = False,
@ -222,6 +225,7 @@ grpc_cc_test(
grpc_cc_test(
name = "thd_test",
srcs = ["thd_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_event_engine = False,
uses_polling = False,

@ -18,27 +18,29 @@
#include "src/core/lib/gprpp/fork.h"
#include <gtest/gtest.h>
#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
static void test_init() {
GPR_ASSERT(!grpc_core::Fork::Enabled());
TEST(ForkTest, Init) {
ASSERT_FALSE(grpc_core::Fork::Enabled());
// Default fork support (disabled)
grpc_core::Fork::GlobalInit();
GPR_ASSERT(!grpc_core::Fork::Enabled());
ASSERT_FALSE(grpc_core::Fork::Enabled());
grpc_core::Fork::GlobalShutdown();
// Explicitly disabled fork support
grpc_core::Fork::Enable(false);
grpc_core::Fork::GlobalInit();
GPR_ASSERT(!grpc_core::Fork::Enabled());
ASSERT_FALSE(grpc_core::Fork::Enabled());
grpc_core::Fork::GlobalShutdown();
// Explicitly enabled fork support
grpc_core::Fork::Enable(true);
grpc_core::Fork::GlobalInit();
GPR_ASSERT(grpc_core::Fork::Enabled());
ASSERT_TRUE(grpc_core::Fork::Enabled());
grpc_core::Fork::GlobalShutdown();
}
@ -56,7 +58,7 @@ static void sleeping_thd(void* arg) {
gpr_time_from_millis(sleep_ms, GPR_TIMESPAN)));
}
static void test_thd_count() {
TEST(ForkTest, ThdCount) {
// Test no active threads
grpc_core::Fork::Enable(true);
grpc_core::Fork::GlobalInit();
@ -83,7 +85,7 @@ static void test_thd_count() {
for (auto& thd : thds) {
thd.Join();
}
GPR_ASSERT(gpr_time_similar(end_time, est_end_time, tolerance));
ASSERT_TRUE(gpr_time_similar(end_time, est_end_time, tolerance));
grpc_core::Fork::GlobalShutdown();
}
@ -93,23 +95,23 @@ static void exec_ctx_thread(void* arg) {
*exec_ctx_created = true;
}
static void test_exec_count() {
TEST(ForkTest, ExecCount) {
grpc_core::Fork::Enable(true);
grpc_core::Fork::GlobalInit();
grpc_core::Fork::IncExecCtxCount();
GPR_ASSERT(grpc_core::Fork::BlockExecCtx());
ASSERT_TRUE(grpc_core::Fork::BlockExecCtx());
grpc_core::Fork::DecExecCtxCount();
grpc_core::Fork::AllowExecCtx();
grpc_core::Fork::IncExecCtxCount();
grpc_core::Fork::IncExecCtxCount();
GPR_ASSERT(!grpc_core::Fork::BlockExecCtx());
ASSERT_FALSE(grpc_core::Fork::BlockExecCtx());
grpc_core::Fork::DecExecCtxCount();
grpc_core::Fork::DecExecCtxCount();
grpc_core::Fork::IncExecCtxCount();
GPR_ASSERT(grpc_core::Fork::BlockExecCtx());
ASSERT_TRUE(grpc_core::Fork::BlockExecCtx());
grpc_core::Fork::DecExecCtxCount();
grpc_core::Fork::AllowExecCtx();
@ -118,22 +120,19 @@ static void test_exec_count() {
grpc_core::Thread thd =
grpc_core::Thread("grpc_fork_test", exec_ctx_thread, &exec_ctx_created);
grpc_core::Fork::IncExecCtxCount();
GPR_ASSERT(grpc_core::Fork::BlockExecCtx());
ASSERT_TRUE(grpc_core::Fork::BlockExecCtx());
grpc_core::Fork::DecExecCtxCount();
thd.Start();
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(1, GPR_TIMESPAN)));
GPR_ASSERT(!exec_ctx_created);
ASSERT_FALSE(exec_ctx_created);
grpc_core::Fork::AllowExecCtx();
thd.Join(); // This ensure that the call got un-blocked
grpc_core::Fork::GlobalShutdown();
}
int main(int argc, char* argv[]) {
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
test_init();
test_thd_count();
test_exec_count();
return 0;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -20,6 +20,8 @@
#include <string.h>
#include <gtest/gtest.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -28,10 +30,10 @@
static void join_host_port_expect(const char* host, int port,
const char* expected) {
std::string actual = grpc_core::JoinHostPort(host, port);
GPR_ASSERT(actual == expected);
ASSERT_EQ(actual, expected);
}
static void test_join_host_port(void) {
TEST(HostPortTest, JoinHostPort) {
join_host_port_expect("foo", 101, "foo:101");
join_host_port_expect("", 102, ":102");
join_host_port_expect("1::2", 103, "[1::2]:103");
@ -39,7 +41,7 @@ static void test_join_host_port(void) {
}
/* Garbage in, garbage out. */
static void test_join_host_port_garbage(void) {
TEST(HostPortTest, JoinHostPortGarbage) {
join_host_port_expect("[foo]", 105, "[foo]:105");
join_host_port_expect("[::", 106, "[:::106");
join_host_port_expect("::]", 107, "[::]]:107");
@ -51,12 +53,12 @@ static void split_host_port_expect(const char* name, const char* host,
std::string actual_port;
const bool actual_ret =
grpc_core::SplitHostPort(name, &actual_host, &actual_port);
GPR_ASSERT(actual_ret == ret);
GPR_ASSERT(actual_host == (host == nullptr ? "" : host));
GPR_ASSERT(actual_port == (port == nullptr ? "" : port));
ASSERT_EQ(actual_ret, ret);
ASSERT_EQ(actual_host, (host == nullptr ? "" : host));
ASSERT_EQ(actual_port, (port == nullptr ? "" : port));
}
static void test_split_host_port() {
TEST(HostPortTest, SplitHostPort) {
split_host_port_expect("", "", nullptr, true);
split_host_port_expect("[a:b]", "a:b", nullptr, true);
split_host_port_expect("1.2.3.4", "1.2.3.4", nullptr, true);
@ -68,18 +70,13 @@ static void test_split_host_port() {
split_host_port_expect(":30", "", "30", true);
}
static void test_split_host_port_invalid() {
TEST(HostPortTest, SplitHostPortInvalid) {
split_host_port_expect("[a:b", nullptr, nullptr, false);
split_host_port_expect("[a:b]30", nullptr, nullptr, false);
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
test_join_host_port();
test_join_host_port_garbage();
test_split_host_port();
test_split_host_port_invalid();
return 0;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -21,6 +21,8 @@
#include <inttypes.h>
#include <stdlib.h>
#include <gtest/gtest.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
@ -44,7 +46,7 @@ static test_node* new_node(size_t i, size_t* ctr) {
return n;
}
static void test_serial(void) {
TEST(MpscqTest, Serial) {
gpr_log(GPR_DEBUG, "test_serial");
MultiProducerSingleConsumerQueue q;
for (size_t i = 0; i < 10000000; i++) {
@ -52,8 +54,8 @@ static void test_serial(void) {
}
for (size_t i = 0; i < 10000000; i++) {
test_node* n = reinterpret_cast<test_node*>(q.Pop());
GPR_ASSERT(n);
GPR_ASSERT(n->i == i);
ASSERT_NE(n, nullptr);
ASSERT_EQ(n->i, i);
delete n;
}
}
@ -74,7 +76,7 @@ static void test_thread(void* args) {
}
}
static void test_mt(void) {
TEST(MpscqTest, Mt) {
gpr_log(GPR_DEBUG, "test_mt");
gpr_event start;
gpr_event_init(&start);
@ -97,7 +99,7 @@ static void test_mt(void) {
spins++;
}
test_node* tn = reinterpret_cast<test_node*>(n);
GPR_ASSERT(*tn->ctr == tn->i - 1);
ASSERT_EQ(*tn->ctr, tn->i - 1);
*tn->ctr = tn->i;
if (tn->i == THREAD_ITERATIONS) num_done++;
delete tn;
@ -133,7 +135,7 @@ static void pull_thread(void* arg) {
pa->spins++;
}
test_node* tn = reinterpret_cast<test_node*>(n);
GPR_ASSERT(*tn->ctr == tn->i - 1);
ASSERT_EQ(*tn->ctr, tn->i - 1);
*tn->ctr = tn->i;
if (tn->i == THREAD_ITERATIONS) pa->num_done++;
delete tn;
@ -141,7 +143,7 @@ static void pull_thread(void* arg) {
}
}
static void test_mt_multipop(void) {
TEST(MpscqTest, MtMultipop) {
gpr_log(GPR_DEBUG, "test_mt_multipop");
gpr_event start;
gpr_event_init(&start);
@ -181,8 +183,6 @@ static void test_mt_multipop(void) {
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
test_serial();
test_mt();
test_mt_multipop();
return 0;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -23,6 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <gtest/gtest.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
@ -70,7 +72,7 @@ static void test1(void) {
for (auto& th : thds) {
th.Join();
}
GPR_ASSERT(t.n == 0);
ASSERT_EQ(t.n, 0);
gpr_mu_destroy(&t.mu);
gpr_cv_destroy(&t.done_cv);
}
@ -83,7 +85,7 @@ static void test2(void) {
for (auto& th : thds) {
bool ok;
th = grpc_core::Thread("grpc_thread_body2_test", &thd_body2, nullptr, &ok);
GPR_ASSERT(ok);
ASSERT_TRUE(ok);
th.Start();
}
for (auto& th : thds) {
@ -93,9 +95,13 @@ static void test2(void) {
/* ------------------------------------------------- */
int main(int argc, char* argv[]) {
grpc::testing::TestEnvironment env(&argc, argv);
TEST(ThdTest, MainTest) {
test1();
test2();
return 0;
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -537,28 +537,6 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "fork_test",
"platforms": [
"linux",
"mac",
"posix"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -655,30 +633,6 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "host_port_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -823,28 +777,6 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "mpscq_test",
"platforms": [
"linux",
"mac",
"posix"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -1363,30 +1295,6 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "thd_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -3649,6 +3557,28 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "fork_test",
"platforms": [
"linux",
"mac",
"posix"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -4261,6 +4191,30 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "host_port_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -5045,6 +4999,28 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "mpscq_test",
"platforms": [
"linux",
"mac",
"posix"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -7063,6 +7039,30 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "thd_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save