diff --git a/CMakeLists.txt b/CMakeLists.txt index ff59d481686..3a68c6e09ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -790,7 +790,6 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_c combiner_test) endif() - add_dependencies(buildtests_c compression_test) add_dependencies(buildtests_c connection_refused_test) add_dependencies(buildtests_c cpu_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) @@ -816,7 +815,6 @@ if(gRPC_BUILD_TESTS) 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) add_dependencies(buildtests_c multiple_server_queues_test) add_dependencies(buildtests_c murmur_hash_test) @@ -939,6 +937,7 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx codegen_test_full) add_dependencies(buildtests_cxx codegen_test_minimal) add_dependencies(buildtests_cxx completion_queue_threading_test) + add_dependencies(buildtests_cxx compression_test) add_dependencies(buildtests_cxx concurrent_connectivity_test) add_dependencies(buildtests_cxx connection_prefix_bad_client_test) add_dependencies(buildtests_cxx connectivity_state_test) @@ -1059,6 +1058,7 @@ if(gRPC_BUILD_TESTS) endif() add_dependencies(buildtests_cxx memory_quota_test) add_dependencies(buildtests_cxx message_allocator_end2end_test) + add_dependencies(buildtests_cxx message_compress_test) add_dependencies(buildtests_cxx metadata_map_test) add_dependencies(buildtests_cxx miscompile_with_no_unique_address_test) add_dependencies(buildtests_cxx mock_stream_test) @@ -4509,34 +4509,6 @@ endif() endif() if(gRPC_BUILD_TESTS) -add_executable(compression_test - test/core/compression/args_utils.cc - test/core/compression/compression_test.cc -) - -target_include_directories(compression_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(compression_test - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util -) - - -endif() -if(gRPC_BUILD_TESTS) - add_executable(connection_refused_test test/core/end2end/connection_refused_test.cc test/core/end2end/cq_verifier.cc @@ -4966,33 +4938,6 @@ target_link_libraries(load_file_test ) -endif() -if(gRPC_BUILD_TESTS) - -add_executable(message_compress_test - test/core/compression/message_compress_test.cc -) - -target_include_directories(message_compress_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(message_compress_test - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util -) - - endif() if(gRPC_BUILD_TESTS) @@ -8529,6 +8474,42 @@ target_link_libraries(completion_queue_threading_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(compression_test + test/core/compression/args_utils.cc + test/core/compression/compression_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + +target_include_directories(compression_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(compression_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) @@ -12977,6 +12958,41 @@ target_link_libraries(message_allocator_end2end_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(message_compress_test + test/core/compression/message_compress_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + +target_include_directories(message_compress_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(message_compress_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 2685fe10b1d..eb495fd9339 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -3279,17 +3279,6 @@ targets: - linux - posix - mac -- name: compression_test - build: test - language: c - headers: - - test/core/compression/args_utils.h - src: - - test/core/compression/args_utils.cc - - test/core/compression/compression_test.cc - deps: - - grpc_test_util - uses_polling: false - name: connection_refused_test build: test language: c @@ -3459,15 +3448,6 @@ targets: deps: - grpc_test_util uses_polling: false -- name: message_compress_test - build: test - language: c - headers: [] - src: - - test/core/compression/message_compress_test.cc - deps: - - grpc_test_util - uses_polling: false - name: minimal_stack_is_minimal_test build: test language: c @@ -4919,6 +4899,18 @@ targets: - test/core/surface/completion_queue_threading_test.cc deps: - grpc_test_util +- name: compression_test + gtest: true + build: test + language: c++ + headers: + - test/core/compression/args_utils.h + src: + - test/core/compression/args_utils.cc + - test/core/compression/compression_test.cc + deps: + - grpc_test_util + uses_polling: false - name: concurrent_connectivity_test gtest: true build: test @@ -6813,6 +6805,16 @@ targets: - test/cpp/end2end/test_service_impl.cc deps: - grpc++_test_util +- name: message_compress_test + gtest: true + build: test + language: c++ + headers: [] + src: + - test/core/compression/message_compress_test.cc + deps: + - grpc_test_util + uses_polling: false - name: metadata_map_test gtest: true build: test diff --git a/test/core/compression/BUILD b/test/core/compression/BUILD index 1e77e7050f9..d48b400e6df 100644 --- a/test/core/compression/BUILD +++ b/test/core/compression/BUILD @@ -36,6 +36,7 @@ grpc_cc_library( grpc_cc_test( name = "compression_test", srcs = ["compression_test.cc"], + external_deps = ["gtest"], language = "C++", uses_event_engine = False, uses_polling = False, @@ -76,6 +77,7 @@ grpc_fuzzer( grpc_cc_test( name = "message_compress_test", srcs = ["message_compress_test.cc"], + external_deps = ["gtest"], language = "C++", uses_event_engine = False, uses_polling = False, diff --git a/test/core/compression/compression_test.cc b/test/core/compression/compression_test.cc index 89775ac3ce0..71f29485675 100644 --- a/test/core/compression/compression_test.cc +++ b/test/core/compression/compression_test.cc @@ -19,6 +19,8 @@ #include #include +#include + #include #include #include @@ -30,7 +32,7 @@ #include "test/core/compression/args_utils.h" #include "test/core/util/test_config.h" -static void test_compression_algorithm_parse(void) { +TEST(CompressionTest, CompressionAlgorithmParse) { size_t i; const char* valid_names[] = {"identity", "gzip", "deflate"}; const grpc_compression_algorithm valid_algorithms[] = { @@ -47,8 +49,8 @@ static void test_compression_algorithm_parse(void) { grpc_compression_algorithm algorithm; const int success = grpc_compression_algorithm_parse( grpc_slice_from_static_string(valid_name), &algorithm); - GPR_ASSERT(success != 0); - GPR_ASSERT(algorithm == valid_algorithms[i]); + ASSERT_NE(success, 0); + ASSERT_EQ(algorithm, valid_algorithms[i]); } for (i = 0; i < GPR_ARRAY_SIZE(invalid_names); i++) { @@ -57,12 +59,12 @@ static void test_compression_algorithm_parse(void) { int success; success = grpc_compression_algorithm_parse( grpc_slice_from_static_string(invalid_name), &algorithm); - GPR_ASSERT(success == 0); + ASSERT_EQ(success, 0); /* the value of "algorithm" is undefined upon failure */ } } -static void test_compression_algorithm_name(void) { +TEST(CompressionTest, CompressionAlgorithmName) { int success; const char* name; size_t i; @@ -77,17 +79,17 @@ static void test_compression_algorithm_name(void) { for (i = 0; i < GPR_ARRAY_SIZE(valid_algorithms); i++) { success = grpc_compression_algorithm_name(valid_algorithms[i], &name); - GPR_ASSERT(success != 0); - GPR_ASSERT(strcmp(name, valid_names[i]) == 0); + ASSERT_NE(success, 0); + ASSERT_STREQ(name, valid_names[i]); } success = grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT, &name); - GPR_ASSERT(success == 0); + ASSERT_EQ(success, 0); /* the value of "name" is undefined upon failure */ } -static void test_compression_algorithm_for_level(void) { +TEST(CompressionTest, CompressionAlgorithmForLevel) { gpr_log(GPR_DEBUG, "test_compression_algorithm_for_level"); { @@ -95,21 +97,21 @@ static void test_compression_algorithm_for_level(void) { uint32_t accepted_encodings = 0; grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */ - GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, + accepted_encodings)); } { @@ -118,21 +120,21 @@ static void test_compression_algorithm_for_level(void) { grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */ grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_GZIP); - GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_GZIP == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_GZIP, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_GZIP == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_GZIP, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_GZIP == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_GZIP, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, + accepted_encodings)); } { @@ -141,21 +143,21 @@ static void test_compression_algorithm_for_level(void) { grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */ grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_DEFLATE); - GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_DEFLATE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_DEFLATE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_DEFLATE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, + accepted_encodings)); } { @@ -165,21 +167,21 @@ static void test_compression_algorithm_for_level(void) { grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_GZIP); grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_DEFLATE); - GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_GZIP == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_GZIP, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_DEFLATE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_DEFLATE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, + accepted_encodings)); } { @@ -189,25 +191,25 @@ static void test_compression_algorithm_for_level(void) { grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_GZIP); grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_DEFLATE); - GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_GZIP == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_GZIP, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_DEFLATE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, + accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, - accepted_encodings)); + ASSERT_EQ(GRPC_COMPRESS_DEFLATE, + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, + accepted_encodings)); } } -static void test_compression_enable_disable_algorithm(void) { +TEST(CompressionTest, CompressionEnableDisableAlgorithm) { grpc_compression_options options; grpc_compression_algorithm algorithm; @@ -219,8 +221,8 @@ static void test_compression_enable_disable_algorithm(void) { algorithm = static_cast( static_cast(algorithm) + 1)) { /* all algorithms are enabled by default */ - GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options, - algorithm) != 0); + ASSERT_NE( + grpc_compression_options_is_algorithm_enabled(&options, algorithm), 0); } /* disable one by one */ for (algorithm = GRPC_COMPRESS_NONE; @@ -228,8 +230,8 @@ static void test_compression_enable_disable_algorithm(void) { algorithm = static_cast( static_cast(algorithm) + 1)) { grpc_compression_options_disable_algorithm(&options, algorithm); - GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options, - algorithm) == 0); + ASSERT_EQ( + grpc_compression_options_is_algorithm_enabled(&options, algorithm), 0); } /* re-enable one by one */ for (algorithm = GRPC_COMPRESS_NONE; @@ -237,26 +239,26 @@ static void test_compression_enable_disable_algorithm(void) { algorithm = static_cast( static_cast(algorithm) + 1)) { grpc_compression_options_enable_algorithm(&options, algorithm); - GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options, - algorithm) != 0); + ASSERT_NE( + grpc_compression_options_is_algorithm_enabled(&options, algorithm), 0); } } -static void test_channel_args_set_compression_algorithm(void) { +TEST(CompressionTest, ChannelArgsSetCompressionAlgorithm) { grpc_core::ExecCtx exec_ctx; const grpc_channel_args* ch_args; ch_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, GRPC_COMPRESS_GZIP); - GPR_ASSERT(ch_args->num_args == 1); - GPR_ASSERT(strcmp(ch_args->args[0].key, - GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) == 0); - GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_INTEGER); + ASSERT_EQ(ch_args->num_args, 1); + ASSERT_STREQ(ch_args->args[0].key, + GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM); + ASSERT_EQ(ch_args->args[0].type, GRPC_ARG_INTEGER); grpc_channel_args_destroy(ch_args); } -static void test_channel_args_compression_algorithm_states(void) { +TEST(CompressionTest, ChannelArgsCompressionAlgorithmStates) { grpc_core::ExecCtx exec_ctx; grpc_core::CompressionAlgorithmSet states; @@ -266,40 +268,40 @@ static void test_channel_args_compression_algorithm_states(void) { states = grpc_core::CompressionAlgorithmSet::FromChannelArgs(ch_args); for (size_t i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { - GPR_ASSERT(states.IsSet(static_cast(i))); + ASSERT_TRUE(states.IsSet(static_cast(i))); } /* disable gzip and deflate and stream/gzip */ const grpc_channel_args* ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state(&ch_args, GRPC_COMPRESS_GZIP, 0); - GPR_ASSERT(ch_args == ch_args_wo_gzip); + ASSERT_EQ(ch_args, ch_args_wo_gzip); const grpc_channel_args* ch_args_wo_gzip_deflate = grpc_channel_args_compression_algorithm_set_state( &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); - GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); + ASSERT_EQ(ch_args_wo_gzip, ch_args_wo_gzip_deflate); states = grpc_core::CompressionAlgorithmSet::FromChannelArgs( ch_args_wo_gzip_deflate); for (size_t i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_GZIP || i == GRPC_COMPRESS_DEFLATE) { - GPR_ASSERT(!states.IsSet(static_cast(i))); + ASSERT_FALSE(states.IsSet(static_cast(i))); } else { - GPR_ASSERT(states.IsSet(static_cast(i))); + ASSERT_TRUE(states.IsSet(static_cast(i))); } } /* re-enabled gzip only */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); - GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); + ASSERT_EQ(ch_args_wo_gzip, ch_args_wo_gzip_deflate); states = grpc_core::CompressionAlgorithmSet::FromChannelArgs(ch_args_wo_gzip); for (size_t i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_DEFLATE) { - GPR_ASSERT(!states.IsSet(static_cast(i))); + ASSERT_FALSE(states.IsSet(static_cast(i))); } else { - GPR_ASSERT(states.IsSet(static_cast(i))); + ASSERT_TRUE(states.IsSet(static_cast(i))); } } @@ -308,13 +310,7 @@ static void test_channel_args_compression_algorithm_states(void) { int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); - grpc_init(); - test_compression_algorithm_parse(); - test_compression_algorithm_name(); - test_compression_algorithm_for_level(); - test_compression_enable_disable_algorithm(); - test_channel_args_set_compression_algorithm(); - test_channel_args_compression_algorithm_states(); - grpc_shutdown(); - return 0; + ::testing::InitGoogleTest(&argc, argv); + grpc::testing::TestGrpcScope grpc_scope; + return RUN_ALL_TESTS(); } diff --git a/test/core/compression/message_compress_test.cc b/test/core/compression/message_compress_test.cc index 6901fe1aab9..faf7204c496 100644 --- a/test/core/compression/message_compress_test.cc +++ b/test/core/compression/message_compress_test.cc @@ -21,6 +21,8 @@ #include #include +#include + #include #include #include @@ -52,7 +54,7 @@ static void assert_passthrough(grpc_slice value, int was_compressed; const char* algorithm_name; - GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algorithm_name) != 0); + ASSERT_NE(grpc_compression_algorithm_name(algorithm, &algorithm_name), 0); gpr_log(GPR_INFO, "assert_passthrough: value_length=%" PRIuPTR " value_hash=0x%08x " @@ -74,14 +76,14 @@ static void assert_passthrough(grpc_slice value, grpc_core::ExecCtx exec_ctx; was_compressed = grpc_msg_compress(algorithm, &input, &compressed_raw); } - GPR_ASSERT(input.count > 0); + ASSERT_GT(input.count, 0); switch (compress_result_check) { case SHOULD_NOT_COMPRESS: - GPR_ASSERT(was_compressed == 0); + ASSERT_EQ(was_compressed, 0); break; case SHOULD_COMPRESS: - GPR_ASSERT(was_compressed == 1); + ASSERT_EQ(was_compressed, 1); break; case MAYBE_COMPRESSES: /* no check */ @@ -92,12 +94,12 @@ static void assert_passthrough(grpc_slice value, { grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(grpc_msg_decompress( + ASSERT_TRUE(grpc_msg_decompress( was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, &output)); } final = grpc_slice_merge(output.slices, output.count); - GPR_ASSERT(grpc_slice_eq(value, final)); + ASSERT_TRUE(grpc_slice_eq(value, final)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&compressed); @@ -141,7 +143,7 @@ static grpc_slice create_test_value(test_value id) { return grpc_slice_from_copied_string("bad value"); } -static void test_tiny_data_compress(void) { +TEST(MessageCompressTest, TinyDataCompress) { grpc_slice_buffer input; grpc_slice_buffer output; @@ -152,17 +154,16 @@ static void test_tiny_data_compress(void) { for (int i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_NONE) continue; grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(0 == - grpc_msg_compress(static_cast(i), - &input, &output)); - GPR_ASSERT(1 == output.count); + ASSERT_EQ(0, grpc_msg_compress(static_cast(i), + &input, &output)); + ASSERT_EQ(1, output.count); } grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); } -static void test_bad_decompression_data_crc(void) { +TEST(MessageCompressTest, BadDecompressionDataCrc) { grpc_slice_buffer input; grpc_slice_buffer corrupted; grpc_slice_buffer output; @@ -178,20 +179,20 @@ static void test_bad_decompression_data_crc(void) { /* compress it */ grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &corrupted); /* corrupt the output by smashing the CRC */ - GPR_ASSERT(corrupted.count > 1); - GPR_ASSERT(GRPC_SLICE_LENGTH(corrupted.slices[1]) > 8); + ASSERT_GT(corrupted.count, 1); + ASSERT_GT(GRPC_SLICE_LENGTH(corrupted.slices[1]), 8); idx = GRPC_SLICE_LENGTH(corrupted.slices[1]) - 8; memcpy(GRPC_SLICE_START_PTR(corrupted.slices[1]) + idx, &bad, 4); /* try (and fail) to decompress the corrupted compresed buffer */ - GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_GZIP, &corrupted, &output)); + ASSERT_EQ(0, grpc_msg_decompress(GRPC_COMPRESS_GZIP, &corrupted, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&corrupted); grpc_slice_buffer_destroy(&output); } -static void test_bad_decompression_data_missing_trailer(void) { +TEST(MessageCompressTest, BadDecompressionDataMissingTrailer) { grpc_slice_buffer input; grpc_slice_buffer decompressed; grpc_slice_buffer garbage; @@ -206,12 +207,11 @@ static void test_bad_decompression_data_missing_trailer(void) { grpc_core::ExecCtx exec_ctx; /* compress it */ grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &decompressed); - GPR_ASSERT(decompressed.length > 8); + ASSERT_GT(decompressed.length, 8); /* Remove the footer from the decompressed message */ grpc_slice_buffer_trim_end(&decompressed, 8, &garbage); /* try (and fail) to decompress the compressed buffer without the footer */ - GPR_ASSERT(0 == - grpc_msg_decompress(GRPC_COMPRESS_GZIP, &decompressed, &output)); + ASSERT_EQ(0, grpc_msg_decompress(GRPC_COMPRESS_GZIP, &decompressed, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&decompressed); @@ -219,7 +219,7 @@ static void test_bad_decompression_data_missing_trailer(void) { grpc_slice_buffer_destroy(&output); } -static void test_bad_decompression_data_trailing_garbage(void) { +TEST(MessageCompressTest, BadDecompressionDataTrailingGarbage) { grpc_slice_buffer input; grpc_slice_buffer output; @@ -232,13 +232,13 @@ static void test_bad_decompression_data_trailing_garbage(void) { /* try (and fail) to decompress the invalid compresed buffer */ grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); + ASSERT_EQ(0, grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); } -static void test_bad_decompression_data_stream(void) { +TEST(MessageCompressTest, BadDecompressionDataStream) { grpc_slice_buffer input; grpc_slice_buffer output; @@ -249,13 +249,13 @@ static void test_bad_decompression_data_stream(void) { /* try (and fail) to decompress the invalid compresed buffer */ grpc_core::ExecCtx exec_ctx; - GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); + ASSERT_EQ(0, grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); } -static void test_bad_compression_algorithm(void) { +TEST(MessageCompressTest, BadCompressionAlgorithm) { grpc_slice_buffer input; grpc_slice_buffer output; int was_compressed; @@ -268,18 +268,18 @@ static void test_bad_compression_algorithm(void) { grpc_core::ExecCtx exec_ctx; was_compressed = grpc_msg_compress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); - GPR_ASSERT(0 == was_compressed); + ASSERT_EQ(0, was_compressed); was_compressed = grpc_msg_compress(static_cast( GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); - GPR_ASSERT(0 == was_compressed); + ASSERT_EQ(0, was_compressed); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); } -static void test_bad_decompression_algorithm(void) { +TEST(MessageCompressTest, BadDecompressionAlgorithm) { grpc_slice_buffer input; grpc_slice_buffer output; int was_decompressed; @@ -292,29 +292,29 @@ static void test_bad_decompression_algorithm(void) { grpc_core::ExecCtx exec_ctx; was_decompressed = grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); - GPR_ASSERT(0 == was_decompressed); + ASSERT_EQ(0, was_decompressed); was_decompressed = grpc_msg_decompress(static_cast( GRPC_COMPRESS_ALGORITHMS_COUNT + 123), &input, &output); - GPR_ASSERT(0 == was_decompressed); + ASSERT_EQ(0, was_decompressed); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&output); } int main(int argc, char** argv) { + grpc::testing::TestEnvironment env(&argc, argv); + ::testing::InitGoogleTest(&argc, argv); + grpc::testing::TestGrpcScope grpc_scope; + unsigned i, j, k, m; grpc_slice_split_mode uncompressed_split_modes[] = { GRPC_SLICE_SPLIT_IDENTITY, GRPC_SLICE_SPLIT_ONE_BYTE}; grpc_slice_split_mode compressed_split_modes[] = {GRPC_SLICE_SPLIT_MERGE_ALL, GRPC_SLICE_SPLIT_IDENTITY, GRPC_SLICE_SPLIT_ONE_BYTE}; - - grpc::testing::TestEnvironment env(&argc, argv); - grpc_init(); - for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { for (j = 0; j < GPR_ARRAY_SIZE(uncompressed_split_modes); j++) { for (k = 0; k < GPR_ARRAY_SIZE(compressed_split_modes); k++) { @@ -332,14 +332,5 @@ int main(int argc, char** argv) { } } - test_tiny_data_compress(); - test_bad_decompression_data_crc(); - test_bad_decompression_data_missing_trailer(); - test_bad_decompression_data_stream(); - test_bad_decompression_data_trailing_garbage(); - test_bad_compression_algorithm(); - test_bad_decompression_algorithm(); - grpc_shutdown(); - - return 0; + return RUN_ALL_TESTS(); } diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index e69cc6e2e90..3c82f47a1ac 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -187,30 +187,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": "compression_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, { "args": [], "benchmark": false, @@ -561,30 +537,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": "message_compress_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, { "args": [], "benchmark": false, @@ -2673,6 +2625,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": "compression_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false, @@ -4831,6 +4807,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": "message_compress_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false,