diff options
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/channel/channel_args_test.c | 30 | ||||
-rw-r--r-- | test/core/compression/BUILD | 12 | ||||
-rw-r--r-- | test/core/compression/algorithm_test.c | 25 | ||||
-rw-r--r-- | test/core/compression/compression_test.c | 202 | ||||
-rw-r--r-- | test/core/compression/message_compress_test.c | 45 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_compress.c | 4 | ||||
-rw-r--r-- | test/core/end2end/fuzzers/hpack.dictionary | 3 | ||||
-rw-r--r-- | test/core/end2end/tests/compressed_payload.c | 38 | ||||
-rw-r--r-- | test/core/end2end/tests/stream_compression_compressed_payload.c | 107 | ||||
-rw-r--r-- | test/core/end2end/tests/stream_compression_payload.c | 10 | ||||
-rw-r--r-- | test/core/end2end/tests/stream_compression_ping_pong_streaming.c | 10 | ||||
-rw-r--r-- | test/core/end2end/tests/workaround_cronet_compression.c | 13 | ||||
-rw-r--r-- | test/core/slice/slice_string_helpers_test.c | 67 | ||||
-rw-r--r-- | test/core/surface/byte_buffer_reader_test.c | 12 | ||||
-rw-r--r-- | test/core/surface/public_headers_must_be_c89.c | 8 |
15 files changed, 406 insertions, 180 deletions
diff --git a/test/core/channel/channel_args_test.c b/test/core/channel/channel_args_test.c index deaf2933ec..f356c5b0a5 100644 --- a/test/core/channel/channel_args_test.c +++ b/test/core/channel/channel_args_test.c @@ -63,8 +63,8 @@ static void test_set_compression_algorithm(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_args *ch_args; - ch_args = - grpc_channel_args_set_compression_algorithm(NULL, GRPC_COMPRESS_GZIP); + ch_args = grpc_channel_args_set_compression_algorithm( + NULL, GRPC_COMPRESS_MESSAGE_GZIP); GPR_ASSERT(ch_args->num_args == 1); GPR_ASSERT(strcmp(ch_args->args[0].key, GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) == 0); @@ -76,7 +76,8 @@ static void test_set_compression_algorithm(void) { static void test_compression_algorithm_states(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate; + grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate, + *ch_args_wo_gzip_deflate_gzip; unsigned states_bitset; size_t i; @@ -89,33 +90,40 @@ static void test_compression_algorithm_states(void) { GPR_ASSERT(GPR_BITGET(states_bitset, i)); } - /* disable gzip and deflate */ + /* disable message/gzip and message/deflate and stream/gzip */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args, GRPC_COMPRESS_GZIP, 0); + &exec_ctx, &ch_args, GRPC_COMPRESS_MESSAGE_GZIP, 0); GPR_ASSERT(ch_args == ch_args_wo_gzip); ch_args_wo_gzip_deflate = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); + &exec_ctx, &ch_args_wo_gzip, GRPC_COMPRESS_MESSAGE_DEFLATE, 0); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); + ch_args_wo_gzip_deflate_gzip = + grpc_channel_args_compression_algorithm_set_state( + &exec_ctx, &ch_args_wo_gzip_deflate, GRPC_COMPRESS_STREAM_GZIP, 0); + GPR_ASSERT(ch_args_wo_gzip_deflate == ch_args_wo_gzip_deflate_gzip); states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( ch_args_wo_gzip_deflate); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { - if (i == GRPC_COMPRESS_GZIP || i == GRPC_COMPRESS_DEFLATE) { + if (i == GRPC_COMPRESS_MESSAGE_GZIP || i == GRPC_COMPRESS_MESSAGE_DEFLATE || + i == GRPC_COMPRESS_STREAM_GZIP) { GPR_ASSERT(GPR_BITGET(states_bitset, i) == 0); } else { GPR_ASSERT(GPR_BITGET(states_bitset, i) != 0); } } - /* re-enabled gzip only */ + /* re-enabled message/gzip and stream/gzip only */ ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( - &exec_ctx, &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); - GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); + &exec_ctx, &ch_args_wo_gzip_deflate_gzip, GRPC_COMPRESS_MESSAGE_GZIP, 1); + ch_args_wo_gzip = grpc_channel_args_compression_algorithm_set_state( + &exec_ctx, &ch_args_wo_gzip, GRPC_COMPRESS_STREAM_GZIP, 1); + GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate_gzip); states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( ch_args_wo_gzip); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { - if (i == GRPC_COMPRESS_DEFLATE) { + if (i == GRPC_COMPRESS_MESSAGE_DEFLATE) { GPR_ASSERT(GPR_BITGET(states_bitset, i) == 0); } else { GPR_ASSERT(GPR_BITGET(states_bitset, i) != 0); diff --git a/test/core/compression/BUILD b/test/core/compression/BUILD index 1ab6e35f0d..dbeb89a59f 100644 --- a/test/core/compression/BUILD +++ b/test/core/compression/BUILD @@ -53,3 +53,15 @@ grpc_cc_test( "//test/core/util:grpc_test_util", ], ) + +grpc_cc_test( + name = "stream_compress_test", + srcs = ["stream_compression_test.c"], + language = "C", + deps = [ + "//:gpr", + "//:grpc", + "//test/core/util:gpr_test_util", + "//test/core/util:grpc_test_util", + ], +) diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c index a11e6e90ac..d637e2c0c2 100644 --- a/test/core/compression/algorithm_test.c +++ b/test/core/compression/algorithm_test.c @@ -29,6 +29,8 @@ #include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" +const uint32_t message_prefix_length = 8; +const uint32_t stream_prefix_length = 7; static void test_algorithm_mesh(void) { int i; @@ -48,9 +50,26 @@ static void test_algorithm_mesh(void) { mdstr = grpc_slice_from_copied_string(name); GPR_ASSERT(grpc_slice_eq(mdstr, grpc_compression_algorithm_slice(parsed))); GPR_ASSERT(parsed == grpc_compression_algorithm_from_slice(mdstr)); - mdelem = grpc_compression_encoding_mdelem(parsed); - GPR_ASSERT(grpc_slice_eq(GRPC_MDVALUE(mdelem), mdstr)); - GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); + if (parsed == 0) { + continue; + } else if (grpc_compression_algorithm_is_message(parsed)) { + mdelem = grpc_message_compression_encoding_mdelem( + grpc_compression_algorithm_to_message_compression_algorithm(parsed)); + grpc_slice value = GRPC_MDVALUE(mdelem); + GPR_ASSERT(0 == memcmp(&name[message_prefix_length], + GRPC_SLICE_START_PTR(value), + GRPC_SLICE_LENGTH(value))); + GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); + } else { + mdelem = grpc_stream_compression_encoding_mdelem( + grpc_compression_algorithm_to_stream_compression_algorithm(parsed)); + grpc_slice value = GRPC_MDVALUE(mdelem); + GPR_ASSERT(0 == memcmp(&name[stream_prefix_length], + GRPC_SLICE_START_PTR(value), + GRPC_SLICE_LENGTH(value))); + GPR_ASSERT( + grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_CONTENT_ENCODING)); + } grpc_slice_unref_internal(&exec_ctx, mdstr); GRPC_MDELEM_UNREF(&exec_ctx, mdelem); grpc_exec_ctx_finish(&exec_ctx); diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c index 326a800300..fb5876a57a 100644 --- a/test/core/compression/compression_test.c +++ b/test/core/compression/compression_test.c @@ -28,9 +28,11 @@ static void test_compression_algorithm_parse(void) { size_t i; - const char *valid_names[] = {"identity", "gzip", "deflate"}; + const char *valid_names[] = {"identity", "message/gzip", "message/deflate", + "stream/gzip"}; const grpc_compression_algorithm valid_algorithms[] = { - GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_DEFLATE}; + GRPC_COMPRESS_NONE, GRPC_COMPRESS_MESSAGE_GZIP, + GRPC_COMPRESS_MESSAGE_DEFLATE, GRPC_COMPRESS_STREAM_GZIP}; const char *invalid_names[] = {"gzip2", "foo", "", "2gzip"}; gpr_log(GPR_DEBUG, "test_compression_algorithm_parse"); @@ -59,9 +61,11 @@ static void test_compression_algorithm_name(void) { int success; const char *name; size_t i; - const char *valid_names[] = {"identity", "gzip", "deflate"}; + const char *valid_names[] = {"identity", "message/gzip", "message/deflate", + "stream/gzip"}; const grpc_compression_algorithm valid_algorithms[] = { - GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_DEFLATE}; + GRPC_COMPRESS_NONE, GRPC_COMPRESS_MESSAGE_GZIP, + GRPC_COMPRESS_MESSAGE_DEFLATE, GRPC_COMPRESS_STREAM_GZIP}; gpr_log(GPR_DEBUG, "test_compression_algorithm_name"); @@ -90,86 +94,206 @@ static void test_compression_algorithm_for_level(void) { accepted_encodings)); GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW, - accepted_encodings)); + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_LOW, accepted_encodings)); GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, - accepted_encodings)); + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_MED, accepted_encodings)); GPR_ASSERT(GRPC_COMPRESS_NONE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, - accepted_encodings)); + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_HIGH, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_MED, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_HIGH, accepted_encodings)); } { /* accept only gzip */ uint32_t accepted_encodings = 0; GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */ - GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP); + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_MESSAGE_GZIP); GPR_ASSERT(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)); + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_LOW, accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_GZIP == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, - accepted_encodings)); + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_MED, accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_GZIP == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, - accepted_encodings)); + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_HIGH, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_MED, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_HIGH, accepted_encodings)); } { /* accept only deflate */ uint32_t accepted_encodings = 0; GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */ - GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE); + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_MESSAGE_DEFLATE); GPR_ASSERT(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)); + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_DEFLATE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_LOW, accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, - accepted_encodings)); + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_DEFLATE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_MED, accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH, - accepted_encodings)); + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_DEFLATE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_HIGH, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_MED, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_HIGH, accepted_encodings)); } { /* accept gzip and deflate */ uint32_t accepted_encodings = 0; GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */ - GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP); - GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE); + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_MESSAGE_GZIP); + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_MESSAGE_DEFLATE); GPR_ASSERT(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)); + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_DEFLATE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_MED, accepted_encodings)); - GPR_ASSERT(GRPC_COMPRESS_DEFLATE == - grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED, + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_DEFLATE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_HIGH, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_MED, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_HIGH, accepted_encodings)); + } + + { + /* accept stream gzip */ + uint32_t accepted_encodings = 0; + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */ + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_STREAM_GZIP); + + GPR_ASSERT(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_HIGH, + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_MED, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_HIGH, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_STREAM_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_STREAM_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_MED, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_STREAM_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_HIGH, accepted_encodings)); + } + + { + /* accept all algorithms */ + uint32_t accepted_encodings = 0; + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */ + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_MESSAGE_GZIP); + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_MESSAGE_DEFLATE); + GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_STREAM_GZIP); + + GPR_ASSERT(GRPC_COMPRESS_NONE == + grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_DEFLATE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_MED, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_MESSAGE_DEFLATE == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_MESSAGE_HIGH, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_STREAM_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_LOW, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_STREAM_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_MED, accepted_encodings)); + + GPR_ASSERT(GRPC_COMPRESS_STREAM_GZIP == + grpc_compression_algorithm_for_level( + GRPC_COMPRESS_LEVEL_STREAM_HIGH, accepted_encodings)); } } diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c index f7f4893dee..015664d281 100644 --- a/test/core/compression/message_compress_test.c +++ b/test/core/compression/message_compress_test.c @@ -39,7 +39,7 @@ typedef enum { } compressability; static void assert_passthrough(grpc_slice value, - grpc_compression_algorithm algorithm, + grpc_message_compression_algorithm algorithm, grpc_slice_split_mode uncompressed_split_mode, grpc_slice_split_mode compressed_split_mode, compressability compress_result_check) { @@ -51,7 +51,8 @@ static void assert_passthrough(grpc_slice value, int was_compressed; const char *algorithm_name; - GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algorithm_name) != 0); + GPR_ASSERT( + grpc_message_compression_algorithm_name(algorithm, &algorithm_name) != 0); gpr_log( GPR_INFO, "assert_passthrough: value_length=%" PRIuPTR " value_hash=0x%08x " @@ -93,8 +94,8 @@ static void assert_passthrough(grpc_slice value, { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(grpc_msg_decompress( - &exec_ctx, was_compressed ? algorithm : GRPC_COMPRESS_NONE, &compressed, - &output)); + &exec_ctx, was_compressed ? algorithm : GRPC_MESSAGE_COMPRESS_NONE, + &compressed, &output)); grpc_exec_ctx_finish(&exec_ctx); } @@ -115,8 +116,8 @@ static grpc_slice repeated(char c, size_t length) { } static compressability get_compressability( - test_value id, grpc_compression_algorithm algorithm) { - if (algorithm == GRPC_COMPRESS_NONE) return SHOULD_NOT_COMPRESS; + test_value id, grpc_message_compression_algorithm algorithm) { + if (algorithm == GRPC_MESSAGE_COMPRESS_NONE) return SHOULD_NOT_COMPRESS; switch (id) { case ONE_A: return SHOULD_NOT_COMPRESS; @@ -148,14 +149,14 @@ static grpc_slice create_test_value(test_value id) { static void test_tiny_data_compress(void) { grpc_slice_buffer input; grpc_slice_buffer output; - grpc_compression_algorithm i; + grpc_message_compression_algorithm i; grpc_slice_buffer_init(&input); grpc_slice_buffer_init(&output); grpc_slice_buffer_add(&input, create_test_value(ONE_A)); - for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { - if (i == GRPC_COMPRESS_NONE) continue; + for (i = 0; i < GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT; i++) { + if (i == GRPC_MESSAGE_COMPRESS_NONE) continue; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(0 == grpc_msg_compress(&exec_ctx, i, &input, &output)); grpc_exec_ctx_finish(&exec_ctx); @@ -180,7 +181,7 @@ static void test_bad_decompression_data_crc(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* compress it */ - grpc_msg_compress(&exec_ctx, GRPC_COMPRESS_GZIP, &input, &corrupted); + grpc_msg_compress(&exec_ctx, GRPC_MESSAGE_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); @@ -188,8 +189,8 @@ static void test_bad_decompression_data_crc(void) { 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(&exec_ctx, GRPC_COMPRESS_GZIP, &corrupted, - &output)); + GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_MESSAGE_COMPRESS_GZIP, + &corrupted, &output)); grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); @@ -210,8 +211,8 @@ static void test_bad_decompression_data_trailing_garbage(void) { /* try (and fail) to decompress the invalid compresed buffer */ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_DEFLATE, &input, - &output)); + GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_MESSAGE_COMPRESS_DEFLATE, + &input, &output)); grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); @@ -229,8 +230,8 @@ static void test_bad_decompression_data_stream(void) { /* try (and fail) to decompress the invalid compresed buffer */ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_COMPRESS_DEFLATE, &input, - &output)); + GPR_ASSERT(0 == grpc_msg_decompress(&exec_ctx, GRPC_MESSAGE_COMPRESS_DEFLATE, + &input, &output)); grpc_exec_ctx_finish(&exec_ctx); grpc_slice_buffer_destroy(&input); @@ -248,12 +249,12 @@ static void test_bad_compression_algorithm(void) { &input, grpc_slice_from_copied_string("Never gonna give you up")); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - was_compressed = grpc_msg_compress(&exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT, - &input, &output); + was_compressed = grpc_msg_compress( + &exec_ctx, GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_compressed); was_compressed = grpc_msg_compress( - &exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT + 123, &input, &output); + &exec_ctx, GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT + 123, &input, &output); GPR_ASSERT(0 == was_compressed); grpc_exec_ctx_finish(&exec_ctx); @@ -273,11 +274,11 @@ static void test_bad_decompression_algorithm(void) { "I'm not really compressed but it doesn't matter")); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; was_decompressed = grpc_msg_decompress( - &exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output); + &exec_ctx, GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT, &input, &output); GPR_ASSERT(0 == was_decompressed); was_decompressed = grpc_msg_decompress( - &exec_ctx, GRPC_COMPRESS_ALGORITHMS_COUNT + 123, &input, &output); + &exec_ctx, GRPC_MESSAGE_COMPRESS_ALGORITHMS_COUNT + 123, &input, &output); GPR_ASSERT(0 == was_decompressed); grpc_exec_ctx_finish(&exec_ctx); @@ -296,7 +297,7 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); - for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { + for (i = 0; i < GRPC_MESSAGE_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++) { for (m = 0; m < TEST_VALUE_COUNT; m++) { diff --git a/test/core/end2end/fixtures/h2_compress.c b/test/core/end2end/fixtures/h2_compress.c index 9866dea7eb..0f4621ae34 100644 --- a/test/core/end2end/fixtures/h2_compress.c +++ b/test/core/end2end/fixtures/h2_compress.c @@ -69,7 +69,7 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture *f, grpc_exec_ctx_finish(&exec_ctx); } ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( - client_args, GRPC_COMPRESS_GZIP); + client_args, GRPC_COMPRESS_MESSAGE_GZIP); f->client = grpc_insecure_channel_create(ffd->localaddr, ffd->client_args_compression, NULL); } @@ -83,7 +83,7 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f, grpc_exec_ctx_finish(&exec_ctx); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( - server_args, GRPC_COMPRESS_GZIP); + server_args, GRPC_COMPRESS_MESSAGE_GZIP); if (f->server) { grpc_server_destroy(f->server); } diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index 7c77512aa9..a87e49ee52 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -28,6 +28,9 @@ "\x1Egrpc.max_request_message_bytes" "\x1Fgrpc.max_response_message_bytes" "$/grpc.lb.v1.LoadBalancer/BalanceLoad" +"\x0Fmessage/deflate" +"\x0Cmessage/gzip" +"\x0Bstream/gzip" "\x010" "\x011" "\x012" diff --git a/test/core/end2end/tests/compressed_payload.c b/test/core/end2end/tests/compressed_payload.c index ba03773036..5c5aa820f7 100644 --- a/test/core/end2end/tests/compressed_payload.c +++ b/test/core/end2end/tests/compressed_payload.c @@ -385,9 +385,9 @@ static void request_with_payload_template( GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), GRPC_COMPRESS_NONE) != 0); GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), - GRPC_COMPRESS_DEFLATE) != 0); + GRPC_COMPRESS_MESSAGE_DEFLATE) != 0); GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), - GRPC_COMPRESS_GZIP) != 0); + GRPC_COMPRESS_MESSAGE_GZIP) != 0); memset(ops, 0, sizeof(ops)); op = ops; @@ -550,8 +550,9 @@ static void test_invoke_request_with_exceptionally_uncompressed_payload( grpc_end2end_test_config config) { request_with_payload_template( config, "test_invoke_request_with_exceptionally_uncompressed_payload", - GRPC_WRITE_NO_COMPRESS, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, - GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, NULL, false, + GRPC_WRITE_NO_COMPRESS, GRPC_COMPRESS_MESSAGE_GZIP, + GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_NONE, + GRPC_COMPRESS_MESSAGE_GZIP, NULL, false, /* ignored */ GRPC_COMPRESS_LEVEL_NONE, false); } @@ -568,18 +569,18 @@ static void test_invoke_request_with_compressed_payload( grpc_end2end_test_config config) { request_with_payload_template( config, "test_invoke_request_with_compressed_payload", 0, - GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, - GRPC_COMPRESS_GZIP, NULL, false, /* ignored */ GRPC_COMPRESS_LEVEL_NONE, - false); + GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_MESSAGE_GZIP, + GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_MESSAGE_GZIP, NULL, false, + /* ignored */ GRPC_COMPRESS_LEVEL_NONE, false); } static void test_invoke_request_with_send_message_before_initial_metadata( grpc_end2end_test_config config) { request_with_payload_template( config, "test_invoke_request_with_compressed_payload", 0, - GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, - GRPC_COMPRESS_GZIP, NULL, false, /* ignored */ GRPC_COMPRESS_LEVEL_NONE, - true); + GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_MESSAGE_GZIP, + GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_MESSAGE_GZIP, NULL, false, + /* ignored */ GRPC_COMPRESS_LEVEL_NONE, true); } static void test_invoke_request_with_server_level( @@ -587,7 +588,7 @@ static void test_invoke_request_with_server_level( request_with_payload_template( config, "test_invoke_request_with_server_level", 0, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE /* ignored */, - NULL, true, GRPC_COMPRESS_LEVEL_HIGH, false); + NULL, true, GRPC_COMPRESS_LEVEL_MESSAGE_HIGH, false); } static void test_invoke_request_with_compressed_payload_md_override( @@ -596,7 +597,8 @@ static void test_invoke_request_with_compressed_payload_md_override( grpc_metadata identity_compression_override; gzip_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; - gzip_compression_override.value = grpc_slice_from_static_string("gzip"); + gzip_compression_override.value = + grpc_slice_from_static_string("message/gzip"); memset(&gzip_compression_override.internal_data, 0, sizeof(gzip_compression_override.internal_data)); @@ -609,21 +611,22 @@ static void test_invoke_request_with_compressed_payload_md_override( /* Channel default NONE (aka IDENTITY), call override to GZIP */ request_with_payload_template( config, "test_invoke_request_with_compressed_payload_md_override_1", 0, - GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, + GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_NONE, &gzip_compression_override, false, /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false); /* Channel default DEFLATE, call override to GZIP */ request_with_payload_template( config, "test_invoke_request_with_compressed_payload_md_override_2", 0, - GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, - GRPC_COMPRESS_NONE, &gzip_compression_override, false, + GRPC_COMPRESS_MESSAGE_DEFLATE, GRPC_COMPRESS_NONE, + GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_NONE, + &gzip_compression_override, false, /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false); /* Channel default DEFLATE, call override to NONE (aka IDENTITY) */ request_with_payload_template( config, "test_invoke_request_with_compressed_payload_md_override_3", 0, - GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, + GRPC_COMPRESS_MESSAGE_DEFLATE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, &identity_compression_override, false, /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false); } @@ -632,7 +635,8 @@ static void test_invoke_request_with_disabled_algorithm( grpc_end2end_test_config config) { request_for_disabled_algorithm( config, "test_invoke_request_with_disabled_algorithm", 0, - GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_STATUS_UNIMPLEMENTED, NULL); + GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_MESSAGE_GZIP, + GRPC_STATUS_UNIMPLEMENTED, NULL); } void compressed_payload(grpc_end2end_test_config config) { diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.c b/test/core/end2end/tests/stream_compression_compressed_payload.c index 8b47741cd4..4c6a9cb852 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.c +++ b/test/core/end2end/tests/stream_compression_compressed_payload.c @@ -95,8 +95,8 @@ static void end_test(grpc_end2end_test_fixture *f) { static void request_for_disabled_algorithm( grpc_end2end_test_config config, const char *test_name, uint32_t send_flags_bitmask, - grpc_stream_compression_algorithm algorithm_to_disable, - grpc_stream_compression_algorithm requested_client_compression_algorithm, + grpc_compression_algorithm algorithm_to_disable, + grpc_compression_algorithm requested_client_compression_algorithm, grpc_status_code expected_error, grpc_metadata *client_metadata) { grpc_call *c; grpc_call *s; @@ -124,13 +124,13 @@ static void request_for_disabled_algorithm( request_payload_slice = grpc_slice_from_copied_string(str); request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - client_args = grpc_channel_args_set_stream_compression_algorithm( + client_args = grpc_channel_args_set_compression_algorithm( NULL, requested_client_compression_algorithm); - server_args = grpc_channel_args_set_stream_compression_algorithm( - NULL, GRPC_STREAM_COMPRESS_NONE); + server_args = + grpc_channel_args_set_compression_algorithm(NULL, GRPC_COMPRESS_NONE); { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - server_args = grpc_channel_args_stream_compression_algorithm_set_state( + server_args = grpc_channel_args_compression_algorithm_set_state( &exec_ctx, &server_args, algorithm_to_disable, false); grpc_exec_ctx_finish(&exec_ctx); } @@ -230,11 +230,10 @@ static void request_for_disabled_algorithm( GPR_ASSERT(status == expected_error); const char *algo_name = NULL; - GPR_ASSERT( - grpc_stream_compression_algorithm_name(algorithm_to_disable, &algo_name)); + GPR_ASSERT(grpc_compression_algorithm_name(algorithm_to_disable, &algo_name)); char *expected_details = NULL; - gpr_asprintf(&expected_details, - "Stream compression algorithm '%s' is disabled.", algo_name); + gpr_asprintf(&expected_details, "Compression algorithm '%s' is disabled.", + algo_name); /* and we expect a specific reason for it */ GPR_ASSERT(0 == grpc_slice_str_cmp(details, expected_details)); gpr_free(expected_details); @@ -271,14 +270,12 @@ static void request_for_disabled_algorithm( static void request_with_payload_template( grpc_end2end_test_config config, const char *test_name, uint32_t client_send_flags_bitmask, - grpc_stream_compression_algorithm - default_client_channel_compression_algorithm, - grpc_stream_compression_algorithm - default_server_channel_compression_algorithm, - grpc_stream_compression_algorithm expected_client_compression_algorithm, - grpc_stream_compression_algorithm expected_server_compression_algorithm, + grpc_compression_algorithm default_client_channel_compression_algorithm, + grpc_compression_algorithm default_server_channel_compression_algorithm, + grpc_compression_algorithm expected_client_compression_algorithm, + grpc_compression_algorithm expected_server_compression_algorithm, grpc_metadata *client_init_metadata, bool set_server_level, - grpc_stream_compression_level server_compression_level, + grpc_compression_level server_compression_level, bool send_message_before_initial_metadata, bool set_default_server_message_compression_algorithm, grpc_compression_algorithm default_server_message_compression_algorithm) { @@ -316,13 +313,13 @@ static void request_with_payload_template( grpc_slice response_payload_slice = grpc_slice_from_copied_string(response_str); - client_args = grpc_channel_args_set_stream_compression_algorithm( + client_args = grpc_channel_args_set_compression_algorithm( NULL, default_client_channel_compression_algorithm); if (set_default_server_message_compression_algorithm) { server_args = grpc_channel_args_set_compression_algorithm( NULL, default_server_message_compression_algorithm); } else { - server_args = grpc_channel_args_set_stream_compression_algorithm( + server_args = grpc_channel_args_set_compression_algorithm( NULL, default_server_channel_compression_algorithm); } @@ -395,26 +392,21 @@ static void request_with_payload_template( GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), GRPC_COMPRESS_NONE) != 0); GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), - GRPC_COMPRESS_DEFLATE) != 0); + GRPC_COMPRESS_MESSAGE_DEFLATE) != 0); + GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), + GRPC_COMPRESS_MESSAGE_GZIP) != 0); GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), - GRPC_COMPRESS_GZIP) != 0); - GPR_ASSERT( - GPR_BITCOUNT(grpc_call_test_only_get_stream_encodings_accepted_by_peer( - s)) == GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT); - GPR_ASSERT( - GPR_BITGET(grpc_call_test_only_get_stream_encodings_accepted_by_peer(s), - GRPC_STREAM_COMPRESS_NONE) != 0); - GPR_ASSERT( - GPR_BITGET(grpc_call_test_only_get_stream_encodings_accepted_by_peer(s), - GRPC_STREAM_COMPRESS_GZIP) != 0); + GRPC_COMPRESS_STREAM_GZIP) != 0); + GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer( + s)) == GRPC_COMPRESS_ALGORITHMS_COUNT); memset(ops, 0, sizeof(ops)); op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; if (set_server_level) { - op->data.send_initial_metadata.maybe_stream_compression_level.is_set = true; - op->data.send_initial_metadata.maybe_stream_compression_level.level = + op->data.send_initial_metadata.maybe_compression_level.is_set = true; + op->data.send_initial_metadata.maybe_compression_level.level = server_compression_level; } op->flags = 0; @@ -558,29 +550,28 @@ static void test_invoke_request_with_compressed_payload( grpc_end2end_test_config config) { request_with_payload_template( config, "test_invoke_request_with_compressed_payload", 0, - GRPC_STREAM_COMPRESS_GZIP, GRPC_STREAM_COMPRESS_GZIP, - GRPC_STREAM_COMPRESS_GZIP, GRPC_STREAM_COMPRESS_GZIP, NULL, + GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP, + GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP, NULL, false, /* ignored */ - GRPC_STREAM_COMPRESS_LEVEL_NONE, false, false, GRPC_COMPRESS_NONE); + GRPC_COMPRESS_LEVEL_NONE, false, false, GRPC_COMPRESS_NONE); } static void test_invoke_request_with_send_message_before_initial_metadata( grpc_end2end_test_config config) { request_with_payload_template( config, "test_invoke_request_with_send_message_before_initial_metadata", - 0, GRPC_STREAM_COMPRESS_GZIP, GRPC_STREAM_COMPRESS_GZIP, - GRPC_STREAM_COMPRESS_GZIP, GRPC_STREAM_COMPRESS_GZIP, NULL, + 0, GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP, + GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP, NULL, false, /* ignored */ - GRPC_STREAM_COMPRESS_LEVEL_NONE, true, false, GRPC_COMPRESS_NONE); + GRPC_COMPRESS_LEVEL_NONE, true, false, GRPC_COMPRESS_NONE); } static void test_invoke_request_with_server_level( grpc_end2end_test_config config) { request_with_payload_template( - config, "test_invoke_request_with_server_level", 0, - GRPC_STREAM_COMPRESS_NONE, GRPC_STREAM_COMPRESS_NONE, - GRPC_STREAM_COMPRESS_NONE, GRPC_STREAM_COMPRESS_GZIP, - /* ignored */ NULL, true, GRPC_STREAM_COMPRESS_LEVEL_HIGH, false, false, + config, "test_invoke_request_with_server_level", 0, GRPC_COMPRESS_NONE, + GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_STREAM_GZIP, + /* ignored */ NULL, true, GRPC_COMPRESS_LEVEL_STREAM_HIGH, false, false, GRPC_COMPRESS_NONE); } @@ -591,7 +582,8 @@ static void test_invoke_request_with_compressed_payload_md_override( gzip_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_STREAM_ENCODING_REQUEST; - gzip_compression_override.value = grpc_slice_from_static_string("gzip"); + gzip_compression_override.value = + grpc_slice_from_static_string("stream/gzip"); memset(&gzip_compression_override.internal_data, 0, sizeof(gzip_compression_override.internal_data)); @@ -605,40 +597,35 @@ static void test_invoke_request_with_compressed_payload_md_override( /* Channel default NONE (aka IDENTITY), call override to stream GZIP */ request_with_payload_template( config, "test_invoke_request_with_compressed_payload_md_override_1", 0, - GRPC_STREAM_COMPRESS_NONE, GRPC_STREAM_COMPRESS_NONE, - GRPC_STREAM_COMPRESS_GZIP, GRPC_STREAM_COMPRESS_NONE, - &gzip_compression_override, false, - /*ignored*/ GRPC_STREAM_COMPRESS_LEVEL_NONE, false, false, - GRPC_COMPRESS_NONE); + GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_STREAM_GZIP, + GRPC_COMPRESS_NONE, &gzip_compression_override, false, + /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false, false, GRPC_COMPRESS_NONE); /* Channel default stream GZIP, call override to NONE (aka IDENTITY) */ request_with_payload_template( config, "test_invoke_request_with_compressed_payload_md_override_3", 0, - GRPC_STREAM_COMPRESS_GZIP, GRPC_STREAM_COMPRESS_NONE, - GRPC_STREAM_COMPRESS_NONE, GRPC_STREAM_COMPRESS_NONE, - &identity_compression_override, false, - /*ignored*/ GRPC_STREAM_COMPRESS_LEVEL_NONE, false, false, - GRPC_COMPRESS_NONE); + GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, + GRPC_COMPRESS_NONE, &identity_compression_override, false, + /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false, false, GRPC_COMPRESS_NONE); } static void test_invoke_request_with_disabled_algorithm( grpc_end2end_test_config config) { request_for_disabled_algorithm( config, "test_invoke_request_with_disabled_algorithm", 0, - GRPC_STREAM_COMPRESS_GZIP, GRPC_STREAM_COMPRESS_GZIP, + GRPC_COMPRESS_STREAM_GZIP, GRPC_COMPRESS_STREAM_GZIP, GRPC_STATUS_UNIMPLEMENTED, NULL); } static void test_stream_compression_override_message_compression( grpc_end2end_test_config config) { - grpc_stream_compression_level level = GRPC_STREAM_COMPRESS_LEVEL_MED; + grpc_compression_level level = GRPC_COMPRESS_LEVEL_STREAM_MED; request_with_payload_template( config, "test_stream_compression_override_message_compression", 0, - GRPC_STREAM_COMPRESS_NONE, GRPC_STREAM_COMPRESS_NONE, - GRPC_STREAM_COMPRESS_NONE, - grpc_stream_compression_algorithm_for_level( - level, (1u << GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) - 1), - /* ignored */ NULL, true, level, false, true, GRPC_COMPRESS_GZIP); + GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, + grpc_compression_algorithm_for_level( + level, (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1), + /* ignored */ NULL, true, level, false, true, GRPC_COMPRESS_MESSAGE_GZIP); } void stream_compression_compressed_payload(grpc_end2end_test_config config) { diff --git a/test/core/end2end/tests/stream_compression_payload.c b/test/core/end2end/tests/stream_compression_payload.c index e47d2aa93c..6b5b6d4fb5 100644 --- a/test/core/end2end/tests/stream_compression_payload.c +++ b/test/core/end2end/tests/stream_compression_payload.c @@ -265,12 +265,10 @@ static void request_response_with_payload(grpc_end2end_test_config config, payload and status. */ static void test_invoke_request_response_with_payload( grpc_end2end_test_config config) { - grpc_channel_args *client_args = - grpc_channel_args_set_stream_compression_algorithm( - NULL, GRPC_STREAM_COMPRESS_GZIP); - grpc_channel_args *server_args = - grpc_channel_args_set_stream_compression_algorithm( - NULL, GRPC_STREAM_COMPRESS_GZIP); + grpc_channel_args *client_args = grpc_channel_args_set_compression_algorithm( + NULL, GRPC_COMPRESS_STREAM_GZIP); + grpc_channel_args *server_args = grpc_channel_args_set_compression_algorithm( + NULL, GRPC_COMPRESS_STREAM_GZIP); grpc_end2end_test_fixture f = begin_test(config, "test_invoke_request_response_with_payload", client_args, server_args); diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.c b/test/core/end2end/tests/stream_compression_ping_pong_streaming.c index 4c1a34cc64..4dd35680d7 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.c +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.c @@ -90,12 +90,10 @@ static void end_test(grpc_end2end_test_fixture *f) { /* Client pings and server pongs. Repeat messages rounds before finishing. */ static void test_pingpong_streaming(grpc_end2end_test_config config, int messages) { - grpc_channel_args *client_args = - grpc_channel_args_set_stream_compression_algorithm( - NULL, GRPC_STREAM_COMPRESS_GZIP); - grpc_channel_args *server_args = - grpc_channel_args_set_stream_compression_algorithm( - NULL, GRPC_STREAM_COMPRESS_GZIP); + grpc_channel_args *client_args = grpc_channel_args_set_compression_algorithm( + NULL, GRPC_COMPRESS_STREAM_GZIP); + grpc_channel_args *server_args = grpc_channel_args_set_compression_algorithm( + NULL, GRPC_COMPRESS_STREAM_GZIP); grpc_end2end_test_fixture f = begin_test(config, "test_pingpong_streaming", client_args, server_args); grpc_call *c; diff --git a/test/core/end2end/tests/workaround_cronet_compression.c b/test/core/end2end/tests/workaround_cronet_compression.c index 44e8e04643..4ca018cf50 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.c +++ b/test/core/end2end/tests/workaround_cronet_compression.c @@ -208,9 +208,9 @@ static void request_with_payload_template( GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), GRPC_COMPRESS_NONE) != 0); GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), - GRPC_COMPRESS_DEFLATE) != 0); + GRPC_COMPRESS_MESSAGE_DEFLATE) != 0); GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), - GRPC_COMPRESS_GZIP) != 0); + GRPC_COMPRESS_MESSAGE_GZIP) != 0); memset(ops, 0, sizeof(ops)); op = ops; @@ -365,13 +365,13 @@ typedef struct workaround_cronet_compression_config { } workaround_cronet_compression_config; static workaround_cronet_compression_config workaround_configs[] = { - {NULL, GRPC_COMPRESS_GZIP}, + {NULL, GRPC_COMPRESS_MESSAGE_GZIP}, {"grpc-objc/1.3.0-dev grpc-c/3.0.0-dev (ios; cronet_http; gentle)", GRPC_COMPRESS_NONE}, {"grpc-objc/1.3.0-dev grpc-c/3.0.0-dev (ios; chttp2; gentle)", - GRPC_COMPRESS_GZIP}, + GRPC_COMPRESS_MESSAGE_GZIP}, {"grpc-objc/1.4.0 grpc-c/3.0.0-dev (ios; cronet_http; gentle)", - GRPC_COMPRESS_GZIP}}; + GRPC_COMPRESS_MESSAGE_GZIP}}; static const size_t workaround_configs_num = sizeof(workaround_configs) / sizeof(*workaround_configs); @@ -380,7 +380,8 @@ static void test_workaround_cronet_compression( for (uint32_t i = 0; i < workaround_configs_num; i++) { request_with_payload_template( config, "test_invoke_request_with_compressed_payload", 0, - GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, + GRPC_COMPRESS_MESSAGE_GZIP, GRPC_COMPRESS_MESSAGE_GZIP, + GRPC_COMPRESS_MESSAGE_GZIP, workaround_configs[i].expected_algorithm_from_server, NULL, false, /* ignored */ GRPC_COMPRESS_LEVEL_NONE, workaround_configs[i].user_agent_override); diff --git a/test/core/slice/slice_string_helpers_test.c b/test/core/slice/slice_string_helpers_test.c index 504acf8f84..48f3701c0a 100644 --- a/test/core/slice/slice_string_helpers_test.c +++ b/test/core/slice/slice_string_helpers_test.c @@ -127,9 +127,76 @@ static void test_strsplit(void) { gpr_free(parts); } +static void test_strsplit_nospace(void) { + grpc_slice_buffer *parts; + grpc_slice str; + + LOG_TEST_NAME("test_strsplit_nospace"); + + parts = gpr_malloc(sizeof(grpc_slice_buffer)); + grpc_slice_buffer_init(parts); + + str = grpc_slice_from_copied_string("one ,two, three , four"); + grpc_slice_split_without_space(str, ",", parts); + GPR_ASSERT(4 == parts->count); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[0], "one")); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[1], "two")); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[2], "three")); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[3], "four")); + grpc_slice_buffer_reset_and_unref(parts); + grpc_slice_unref(str); + + /* separator not present in string */ + str = grpc_slice_from_copied_string("one two three four "); + grpc_slice_split_without_space(str, ",", parts); + GPR_ASSERT(1 == parts->count); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[0], "one two three four")); + grpc_slice_buffer_reset_and_unref(parts); + grpc_slice_unref(str); + + /* separator at the end */ + str = grpc_slice_from_copied_string("foo,"); + grpc_slice_split_without_space(str, ",", parts); + GPR_ASSERT(2 == parts->count); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[0], "foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[1], "")); + grpc_slice_buffer_reset_and_unref(parts); + grpc_slice_unref(str); + + /* separator at the beginning */ + str = grpc_slice_from_copied_string(" , foo"); + grpc_slice_split_without_space(str, ",", parts); + GPR_ASSERT(2 == parts->count); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[0], "")); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[1], "foo")); + grpc_slice_buffer_reset_and_unref(parts); + grpc_slice_unref(str); + + /* standalone separator */ + str = grpc_slice_from_copied_string(", "); + grpc_slice_split_without_space(str, ", ", parts); + GPR_ASSERT(2 == parts->count); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[0], "")); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[1], "")); + grpc_slice_buffer_reset_and_unref(parts); + grpc_slice_unref(str); + + /* empty input */ + str = grpc_slice_from_copied_string(""); + grpc_slice_split_without_space(str, ",", parts); + GPR_ASSERT(1 == parts->count); + GPR_ASSERT(0 == grpc_slice_str_cmp(parts->slices[0], "")); + grpc_slice_buffer_reset_and_unref(parts); + grpc_slice_unref(str); + + grpc_slice_buffer_destroy(parts); + gpr_free(parts); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_dump_slice(); test_strsplit(); + test_strsplit_nospace(); return 0; } diff --git a/test/core/surface/byte_buffer_reader_test.c b/test/core/surface/byte_buffer_reader_test.c index a6b4c86abc..40bb4a2913 100644 --- a/test/core/surface/byte_buffer_reader_test.c +++ b/test/core/surface/byte_buffer_reader_test.c @@ -109,7 +109,7 @@ static void test_read_corrupted_slice(void) { LOG_TEST("test_read_corrupted_slice"); slice = grpc_slice_from_copied_string("test"); buffer = grpc_raw_byte_buffer_create(&slice, 1); - buffer->data.raw.compression = GRPC_COMPRESS_GZIP; /* lies! */ + buffer->data.raw.compression = GRPC_COMPRESS_MESSAGE_GZIP; /* lies! */ grpc_slice_unref(slice); GPR_ASSERT(!grpc_byte_buffer_reader_init(&reader, buffer)); grpc_byte_buffer_destroy(buffer); @@ -133,8 +133,10 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, grpc_slice_buffer_add(&sliceb_in, input_slice); /* takes ownership */ { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT( - grpc_msg_compress(&exec_ctx, algorithm, &sliceb_in, &sliceb_out)); + GPR_ASSERT(grpc_msg_compress( + &exec_ctx, + grpc_compression_algorithm_to_message_compression_algorithm(algorithm), + &sliceb_in, &sliceb_out)); grpc_exec_ctx_finish(&exec_ctx); } @@ -160,13 +162,13 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, static void test_read_gzip_compressed_slice(void) { const size_t INPUT_SIZE = 2048; LOG_TEST("test_read_gzip_compressed_slice"); - read_compressed_slice(GRPC_COMPRESS_GZIP, INPUT_SIZE); + read_compressed_slice(GRPC_COMPRESS_MESSAGE_GZIP, INPUT_SIZE); } static void test_read_deflate_compressed_slice(void) { const size_t INPUT_SIZE = 2048; LOG_TEST("test_read_deflate_compressed_slice"); - read_compressed_slice(GRPC_COMPRESS_DEFLATE, INPUT_SIZE); + read_compressed_slice(GRPC_COMPRESS_MESSAGE_DEFLATE, INPUT_SIZE); } static void test_byte_buffer_from_reader(void) { diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index db9f902dbf..7d6a11b1fb 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -20,6 +20,7 @@ #include <grpc/byte_buffer_reader.h> #include <grpc/census.h> #include <grpc/compression.h> +#include <grpc/compression_ruby.h> #include <grpc/grpc.h> #include <grpc/grpc_security.h> #include <grpc/grpc_security_constants.h> @@ -67,16 +68,17 @@ int main(int argc, char **argv) { if(argc == 12345678) { + printf("%lx", (unsigned long) grpc_compression_algorithm_is_message); + printf("%lx", (unsigned long) grpc_compression_algorithm_is_stream); printf("%lx", (unsigned long) grpc_compression_algorithm_parse); printf("%lx", (unsigned long) grpc_compression_algorithm_name); - printf("%lx", (unsigned long) grpc_stream_compression_algorithm_name); printf("%lx", (unsigned long) grpc_compression_algorithm_for_level); - printf("%lx", (unsigned long) grpc_stream_compression_algorithm_for_level); printf("%lx", (unsigned long) grpc_compression_options_init); printf("%lx", (unsigned long) grpc_compression_options_enable_algorithm); printf("%lx", (unsigned long) grpc_compression_options_disable_algorithm); printf("%lx", (unsigned long) grpc_compression_options_is_algorithm_enabled); - printf("%lx", (unsigned long) grpc_compression_options_is_stream_compression_algorithm_enabled); + printf("%lx", (unsigned long) grpc_compression_algorithm_parse_ruby); + printf("%lx", (unsigned long) grpc_compression_algorithm_name_ruby); printf("%lx", (unsigned long) grpc_metadata_array_init); printf("%lx", (unsigned long) grpc_metadata_array_destroy); printf("%lx", (unsigned long) grpc_call_details_init); |