gtestify test/core/util (#30195)

* Gtestify cmdline_test

* gtestify histogram_test

* Fix
pull/30274/head
Esun Kim 2 years ago committed by GitHub
parent 17d37ac9cf
commit c0ec55d2f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 128
      CMakeLists.txt
  2. 38
      build_autogenerated.yaml
  3. 2
      test/core/util/BUILD
  4. 176
      test/core/util/cmdline_test.cc
  5. 81
      test/core/util/histogram_test.cc
  6. 96
      tools/run_tests/generated/tests.json

128
CMakeLists.txt generated

@ -790,7 +790,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_c bin_encoder_test)
add_dependencies(buildtests_c buffer_list_test)
add_dependencies(buildtests_c c_slice_buffer_test)
add_dependencies(buildtests_c cmdline_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c combiner_test)
endif()
@ -817,7 +816,6 @@ if(gRPC_BUILD_TESTS)
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 hpack_encoder_test)
add_dependencies(buildtests_c inproc_callback_test)
add_dependencies(buildtests_c invalid_call_argument_test)
@ -940,6 +938,7 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx client_ssl_test)
endif()
add_dependencies(buildtests_cxx cmdline_test)
add_dependencies(buildtests_cxx codegen_test_full)
add_dependencies(buildtests_cxx codegen_test_minimal)
add_dependencies(buildtests_cxx completion_queue_threading_test)
@ -1022,6 +1021,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 histogram_test)
add_dependencies(buildtests_cxx host_port_test)
add_dependencies(buildtests_cxx hpack_parser_table_test)
add_dependencies(buildtests_cxx hpack_parser_test)
@ -4554,33 +4554,6 @@ target_link_libraries(c_slice_buffer_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(cmdline_test
test/core/util/cmdline_test.cc
)
target_include_directories(cmdline_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(cmdline_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
@ -4988,33 +4961,6 @@ target_link_libraries(grpc_ipv6_loopback_available_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(histogram_test
test/core/util/histogram_test.cc
)
target_include_directories(histogram_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(histogram_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -8497,6 +8443,41 @@ endif()
endif()
if(gRPC_BUILD_TESTS)
add_executable(cmdline_test
test/core/util/cmdline_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(cmdline_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(cmdline_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(codegen_test_full
test/cpp/codegen/codegen_test_full.cc
third_party/googletest/googletest/src/gtest-all.cc
@ -11596,6 +11577,41 @@ target_link_libraries(health_service_end2end_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(histogram_test
test/core/util/histogram_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(histogram_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(histogram_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)

@ -3291,15 +3291,6 @@ targets:
deps:
- grpc_test_util
uses_polling: false
- name: cmdline_test
build: test
language: c
headers: []
src:
- test/core/util/cmdline_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: combiner_test
build: test
language: c
@ -3464,15 +3455,6 @@ targets:
- test/core/iomgr/grpc_ipv6_loopback_available_test.cc
deps:
- grpc_test_util
- name: histogram_test
build: test
language: c
headers: []
src:
- test/core/util/histogram_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: hpack_encoder_test
build: test
language: c
@ -4916,6 +4898,16 @@ targets:
- linux
- posix
- mac
- name: cmdline_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/util/cmdline_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: codegen_test_full
gtest: true
build: test
@ -6165,6 +6157,16 @@ targets:
- test/cpp/end2end/test_service_impl.cc
deps:
- grpc++_test_util
- name: histogram_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/util/histogram_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: host_port_test
gtest: true
build: test

@ -114,6 +114,7 @@ grpc_cc_library(
grpc_cc_test(
name = "cmdline_test",
srcs = ["cmdline_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_event_engine = False,
uses_polling = False,
@ -143,6 +144,7 @@ grpc_cc_library(
grpc_cc_test(
name = "histogram_test",
srcs = ["histogram_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_event_engine = False,
uses_polling = False,

@ -20,6 +20,8 @@
#include <string.h>
#include <gtest/gtest.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -28,7 +30,7 @@
#define LOG_TEST() gpr_log(GPR_INFO, "test at %s:%d", __FILE__, __LINE__)
static void test_simple_int(void) {
TEST(CmdlineTest, SimpleInt) {
int x = 1;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("-foo"),
@ -38,13 +40,13 @@ static void test_simple_int(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_int(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 1);
ASSERT_EQ(x, 1);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 3);
ASSERT_EQ(x, 3);
gpr_cmdline_destroy(cl);
}
static void test_eq_int(void) {
TEST(CmdlineTest, EqInt) {
int x = 1;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("-foo=3")};
@ -53,13 +55,13 @@ static void test_eq_int(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_int(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 1);
ASSERT_EQ(x, 1);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 3);
ASSERT_EQ(x, 3);
gpr_cmdline_destroy(cl);
}
static void test_2dash_int(void) {
TEST(CmdlineTest, 2DashInt) {
int x = 1;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo"),
@ -69,13 +71,13 @@ static void test_2dash_int(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_int(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 1);
ASSERT_EQ(x, 1);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 3);
ASSERT_EQ(x, 3);
gpr_cmdline_destroy(cl);
}
static void test_2dash_eq_int(void) {
TEST(CmdlineTest, 2DashEqInt) {
int x = 1;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=3")};
@ -84,13 +86,13 @@ static void test_2dash_eq_int(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_int(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 1);
ASSERT_EQ(x, 1);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 3);
ASSERT_EQ(x, 3);
gpr_cmdline_destroy(cl);
}
static void test_simple_string(void) {
TEST(CmdlineTest, SimpleString) {
const char* x = nullptr;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("-foo"),
@ -100,13 +102,13 @@ static void test_simple_string(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_string(cl, "foo", nullptr, &x);
GPR_ASSERT(x == nullptr);
ASSERT_EQ(x, nullptr);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(0 == strcmp(x, "3"));
ASSERT_STREQ(x, "3");
gpr_cmdline_destroy(cl);
}
static void test_eq_string(void) {
TEST(CmdlineTest, EqString) {
const char* x = nullptr;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("-foo=3")};
@ -115,13 +117,13 @@ static void test_eq_string(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_string(cl, "foo", nullptr, &x);
GPR_ASSERT(x == nullptr);
ASSERT_EQ(x, nullptr);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(0 == strcmp(x, "3"));
ASSERT_STREQ(x, "3");
gpr_cmdline_destroy(cl);
}
static void test_2dash_string(void) {
TEST(CmdlineTest, 2DashString) {
const char* x = nullptr;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo"),
@ -131,13 +133,13 @@ static void test_2dash_string(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_string(cl, "foo", nullptr, &x);
GPR_ASSERT(x == nullptr);
ASSERT_EQ(x, nullptr);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(0 == strcmp(x, "3"));
ASSERT_STREQ(x, "3");
gpr_cmdline_destroy(cl);
}
static void test_2dash_eq_string(void) {
TEST(CmdlineTest, 2DashEqString) {
const char* x = nullptr;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=3")};
@ -146,13 +148,13 @@ static void test_2dash_eq_string(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_string(cl, "foo", nullptr, &x);
GPR_ASSERT(x == nullptr);
ASSERT_EQ(x, nullptr);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(0 == strcmp(x, "3"));
ASSERT_STREQ(x, "3");
gpr_cmdline_destroy(cl);
}
static void test_flag_on(void) {
TEST(CmdlineTest, FlagOn) {
int x = 2;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo")};
@ -161,13 +163,13 @@ static void test_flag_on(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_flag(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 2);
ASSERT_EQ(x, 2);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 1);
ASSERT_EQ(x, 1);
gpr_cmdline_destroy(cl);
}
static void test_flag_no(void) {
TEST(CmdlineTest, FlagNo) {
int x = 2;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--no-foo")};
@ -176,13 +178,13 @@ static void test_flag_no(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_flag(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 2);
ASSERT_EQ(x, 2);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 0);
ASSERT_EQ(x, 0);
gpr_cmdline_destroy(cl);
}
static void test_flag_val_1(void) {
TEST(CmdlineTest, FlagVal1) {
int x = 2;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=1")};
@ -191,13 +193,13 @@ static void test_flag_val_1(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_flag(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 2);
ASSERT_EQ(x, 2);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 1);
ASSERT_EQ(x, 1);
gpr_cmdline_destroy(cl);
}
static void test_flag_val_0(void) {
TEST(CmdlineTest, FlagVal0) {
int x = 2;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=0")};
@ -206,13 +208,13 @@ static void test_flag_val_0(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_flag(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 2);
ASSERT_EQ(x, 2);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 0);
ASSERT_EQ(x, 0);
gpr_cmdline_destroy(cl);
}
static void test_flag_val_true(void) {
TEST(CmdlineTest, FlagValTrue) {
int x = 2;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--foo=true")};
@ -221,13 +223,13 @@ static void test_flag_val_true(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_flag(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 2);
ASSERT_EQ(x, 2);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 1);
ASSERT_EQ(x, 1);
gpr_cmdline_destroy(cl);
}
static void test_flag_val_false(void) {
TEST(CmdlineTest, FlagValFalse) {
int x = 2;
gpr_cmdline* cl;
char* args[] = {const_cast<char*>(__FILE__),
@ -237,13 +239,13 @@ static void test_flag_val_false(void) {
cl = gpr_cmdline_create(nullptr);
gpr_cmdline_add_flag(cl, "foo", nullptr, &x);
GPR_ASSERT(x == 2);
ASSERT_EQ(x, 2);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 0);
ASSERT_EQ(x, 0);
gpr_cmdline_destroy(cl);
}
static void test_many(void) {
TEST(CmdlineTest, Many) {
const char* str = nullptr;
int x = 0;
int flag = 2;
@ -260,21 +262,21 @@ static void test_many(void) {
gpr_cmdline_add_int(cl, "x", nullptr, &x);
gpr_cmdline_add_flag(cl, "flag", nullptr, &flag);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(x == 4);
GPR_ASSERT(0 == strcmp(str, "hello"));
GPR_ASSERT(flag == 0);
ASSERT_EQ(x, 4);
ASSERT_STREQ(str, "hello");
ASSERT_EQ(flag, 0);
gpr_cmdline_destroy(cl);
}
static void extra_arg_cb(void* user_data, const char* arg) {
int* count = static_cast<int*>(user_data);
GPR_ASSERT(arg != nullptr);
GPR_ASSERT(strlen(arg) == 1);
GPR_ASSERT(arg[0] == 'a' + *count);
ASSERT_NE(arg, nullptr);
ASSERT_EQ(strlen(arg), 1);
ASSERT_EQ(arg[0], 'a' + *count);
++*count;
}
static void test_extra(void) {
TEST(CmdlineTest, Extra) {
gpr_cmdline* cl;
int count = 0;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("a"),
@ -286,11 +288,11 @@ static void test_extra(void) {
gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb,
&count);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(count == 3);
ASSERT_EQ(count, 3);
gpr_cmdline_destroy(cl);
}
static void test_extra_dashdash(void) {
TEST(CmdlineTest, ExtraDashdash) {
gpr_cmdline* cl;
int count = 0;
char* args[] = {const_cast<char*>(__FILE__), const_cast<char*>("--"),
@ -303,11 +305,11 @@ static void test_extra_dashdash(void) {
gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb,
&count);
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(args), args);
GPR_ASSERT(count == 3);
ASSERT_EQ(count, 3);
gpr_cmdline_destroy(cl);
}
static void test_usage(void) {
TEST(CmdlineTest, Usage) {
gpr_cmdline* cl;
const char* str = nullptr;
@ -324,19 +326,19 @@ static void test_usage(void) {
nullptr);
std::string usage = gpr_cmdline_usage_string(cl, "test");
GPR_ASSERT(usage ==
"Usage: test [--str=string] [--x=int] "
"[--flag|--no-flag] [file...]\n");
ASSERT_EQ(usage,
"Usage: test [--str=string] [--x=int] "
"[--flag|--no-flag] [file...]\n");
usage = gpr_cmdline_usage_string(cl, "/foo/test");
GPR_ASSERT(usage ==
"Usage: test [--str=string] [--x=int] "
"[--flag|--no-flag] [file...]\n");
ASSERT_EQ(usage,
"Usage: test [--str=string] [--x=int] "
"[--flag|--no-flag] [file...]\n");
gpr_cmdline_destroy(cl);
}
static void test_help(void) {
TEST(CmdlineTest, Help) {
gpr_cmdline* cl;
const char* str = nullptr;
@ -355,12 +357,12 @@ static void test_help(void) {
gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb,
nullptr);
GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(help), help));
ASSERT_EQ(0, gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(help), help));
gpr_cmdline_destroy(cl);
}
static void test_badargs1(void) {
TEST(CmdlineTest, Badargs1) {
gpr_cmdline* cl;
const char* str = nullptr;
@ -380,13 +382,13 @@ static void test_badargs1(void) {
gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb,
nullptr);
GPR_ASSERT(0 ==
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_arg_name), bad_arg_name));
ASSERT_EQ(0,
gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_arg_name), bad_arg_name));
gpr_cmdline_destroy(cl);
}
static void test_badargs2(void) {
TEST(CmdlineTest, Badargs2) {
gpr_cmdline* cl;
const char* str = nullptr;
@ -407,13 +409,13 @@ static void test_badargs2(void) {
gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb,
nullptr);
GPR_ASSERT(
0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_int_value), bad_int_value));
ASSERT_EQ(
0, gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_int_value), bad_int_value));
gpr_cmdline_destroy(cl);
}
static void test_badargs3(void) {
TEST(CmdlineTest, Badargs3) {
gpr_cmdline* cl;
const char* str = nullptr;
@ -433,13 +435,13 @@ static void test_badargs3(void) {
gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb,
nullptr);
GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_bool_value),
bad_bool_value));
ASSERT_EQ(
0, gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_bool_value), bad_bool_value));
gpr_cmdline_destroy(cl);
}
static void test_badargs4(void) {
TEST(CmdlineTest, Badargs4) {
gpr_cmdline* cl;
const char* str = nullptr;
@ -459,36 +461,14 @@ static void test_badargs4(void) {
gpr_cmdline_on_extra_arg(cl, "file", "filenames to process", extra_arg_cb,
nullptr);
GPR_ASSERT(0 == gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_bool_value),
bad_bool_value));
ASSERT_EQ(
0, gpr_cmdline_parse(cl, GPR_ARRAY_SIZE(bad_bool_value), bad_bool_value));
gpr_cmdline_destroy(cl);
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
test_simple_int();
test_eq_int();
test_2dash_int();
test_2dash_eq_int();
test_simple_string();
test_eq_string();
test_2dash_string();
test_2dash_eq_string();
test_flag_on();
test_flag_no();
test_flag_val_1();
test_flag_val_0();
test_flag_val_true();
test_flag_val_false();
test_many();
test_extra();
test_extra_dashdash();
test_usage();
test_help();
test_badargs1();
test_badargs2();
test_badargs3();
test_badargs4();
return 0;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -18,11 +18,13 @@
#include "test/core/util/histogram.h"
#include <gtest/gtest.h>
#include <grpc/support/log.h>
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x);
static void test_no_op(void) {
TEST(HistogramTest, NoOp) {
grpc_histogram_destroy(grpc_histogram_create(0.01, 60e9));
}
@ -31,11 +33,11 @@ static void expect_percentile(grpc_histogram* h, double percentile,
double got = grpc_histogram_percentile(h, percentile);
gpr_log(GPR_INFO, "@%f%%, expect %f <= %f <= %f", percentile, min_expect, got,
max_expect);
GPR_ASSERT(min_expect <= got);
GPR_ASSERT(got <= max_expect);
ASSERT_LE(min_expect, got);
ASSERT_LE(got, max_expect);
}
static void test_simple(void) {
TEST(HistogramTest, Simple) {
grpc_histogram* h;
LOG_TEST("test_simple");
@ -47,12 +49,12 @@ static void test_simple(void) {
grpc_histogram_add(h, 11000);
expect_percentile(h, 50, 10001, 10999);
GPR_ASSERT(grpc_histogram_mean(h) == 10500);
ASSERT_EQ(grpc_histogram_mean(h), 10500);
grpc_histogram_destroy(h);
}
static void test_percentile(void) {
TEST(HistogramTest, Percentile) {
grpc_histogram* h;
double last;
double i;
@ -66,14 +68,14 @@ static void test_percentile(void) {
grpc_histogram_add(h, 8);
grpc_histogram_add(h, 4);
GPR_ASSERT(grpc_histogram_count(h) == 4);
GPR_ASSERT(grpc_histogram_minimum(h) == 2.5);
GPR_ASSERT(grpc_histogram_maximum(h) == 8);
GPR_ASSERT(grpc_histogram_sum(h) == 17);
GPR_ASSERT(grpc_histogram_sum_of_squares(h) == 92.5);
GPR_ASSERT(grpc_histogram_mean(h) == 4.25);
GPR_ASSERT(grpc_histogram_variance(h) == 5.0625);
GPR_ASSERT(grpc_histogram_stddev(h) == 2.25);
ASSERT_EQ(grpc_histogram_count(h), 4);
ASSERT_EQ(grpc_histogram_minimum(h), 2.5);
ASSERT_EQ(grpc_histogram_maximum(h), 8);
ASSERT_EQ(grpc_histogram_sum(h), 17);
ASSERT_EQ(grpc_histogram_sum_of_squares(h), 92.5);
ASSERT_EQ(grpc_histogram_mean(h), 4.25);
ASSERT_EQ(grpc_histogram_variance(h), 5.0625);
ASSERT_EQ(grpc_histogram_stddev(h), 2.25);
expect_percentile(h, -10, 2.5, 2.5);
expect_percentile(h, 0, 2.5, 2.5);
@ -90,14 +92,14 @@ static void test_percentile(void) {
last = 0.0;
for (i = 0; i < 100.0; i += 0.01) {
cur = grpc_histogram_percentile(h, i);
GPR_ASSERT(cur >= last);
ASSERT_GE(cur, last);
last = cur;
}
grpc_histogram_destroy(h);
}
static void test_merge(void) {
TEST(HistogramTest, Merge) {
grpc_histogram *h1, *h2;
double last;
double i;
@ -112,42 +114,42 @@ static void test_merge(void) {
grpc_histogram_add(h1, 4);
h2 = grpc_histogram_create(0.01, 1e9);
GPR_ASSERT(grpc_histogram_merge(h1, h2) == 0);
ASSERT_EQ(grpc_histogram_merge(h1, h2), 0);
grpc_histogram_destroy(h2);
h2 = grpc_histogram_create(0.05, 1e10);
GPR_ASSERT(grpc_histogram_merge(h1, h2) == 0);
ASSERT_EQ(grpc_histogram_merge(h1, h2), 0);
grpc_histogram_destroy(h2);
h2 = grpc_histogram_create(0.05, 1e9);
GPR_ASSERT(grpc_histogram_merge(h1, h2) == 1);
GPR_ASSERT(grpc_histogram_count(h1) == 4);
GPR_ASSERT(grpc_histogram_minimum(h1) == 2.5);
GPR_ASSERT(grpc_histogram_maximum(h1) == 8);
GPR_ASSERT(grpc_histogram_sum(h1) == 17);
GPR_ASSERT(grpc_histogram_sum_of_squares(h1) == 92.5);
GPR_ASSERT(grpc_histogram_mean(h1) == 4.25);
GPR_ASSERT(grpc_histogram_variance(h1) == 5.0625);
GPR_ASSERT(grpc_histogram_stddev(h1) == 2.25);
ASSERT_EQ(grpc_histogram_merge(h1, h2), 1);
ASSERT_EQ(grpc_histogram_count(h1), 4);
ASSERT_EQ(grpc_histogram_minimum(h1), 2.5);
ASSERT_EQ(grpc_histogram_maximum(h1), 8);
ASSERT_EQ(grpc_histogram_sum(h1), 17);
ASSERT_EQ(grpc_histogram_sum_of_squares(h1), 92.5);
ASSERT_EQ(grpc_histogram_mean(h1), 4.25);
ASSERT_EQ(grpc_histogram_variance(h1), 5.0625);
ASSERT_EQ(grpc_histogram_stddev(h1), 2.25);
grpc_histogram_destroy(h2);
h2 = grpc_histogram_create(0.05, 1e9);
grpc_histogram_add(h2, 7.0);
grpc_histogram_add(h2, 17.0);
grpc_histogram_add(h2, 1.0);
GPR_ASSERT(grpc_histogram_merge(h1, h2) == 1);
GPR_ASSERT(grpc_histogram_count(h1) == 7);
GPR_ASSERT(grpc_histogram_minimum(h1) == 1.0);
GPR_ASSERT(grpc_histogram_maximum(h1) == 17.0);
GPR_ASSERT(grpc_histogram_sum(h1) == 42.0);
GPR_ASSERT(grpc_histogram_sum_of_squares(h1) == 431.5);
GPR_ASSERT(grpc_histogram_mean(h1) == 6.0);
ASSERT_EQ(grpc_histogram_merge(h1, h2), 1);
ASSERT_EQ(grpc_histogram_count(h1), 7);
ASSERT_EQ(grpc_histogram_minimum(h1), 1.0);
ASSERT_EQ(grpc_histogram_maximum(h1), 17.0);
ASSERT_EQ(grpc_histogram_sum(h1), 42.0);
ASSERT_EQ(grpc_histogram_sum_of_squares(h1), 431.5);
ASSERT_EQ(grpc_histogram_mean(h1), 6.0);
/* test monotonicity */
last = 0.0;
for (i = 0; i < 100.0; i += 0.01) {
cur = grpc_histogram_percentile(h1, i);
GPR_ASSERT(cur >= last);
ASSERT_GE(cur, last);
last = cur;
}
@ -155,10 +157,7 @@ static void test_merge(void) {
grpc_histogram_destroy(h2);
}
int main(void) {
test_no_op();
test_simple();
test_percentile();
test_merge();
return 0;
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -237,30 +237,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": "cmdline_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -585,30 +561,6 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "histogram_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -2721,6 +2673,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": "cmdline_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -4167,6 +4143,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": "histogram_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save