diff options
author | 2017-10-13 16:07:13 -0700 | |
---|---|---|
committer | 2017-10-18 17:12:19 -0700 | |
commit | 0ee7574732a06e8cace4e099a678f4bd5dbff679 (patch) | |
tree | e43d5de442fdcc3d39cd5af687f319fa39612d3f /test/core/transport/chttp2 | |
parent | 6bf5f833efe2cb9e2ecc14358dd9699cd5d05263 (diff) |
Removing instances of exec_ctx being passed around in functions in
src/core. exec_ctx is now a thread_local pointer of type ExecCtx instead of
grpc_exec_ctx which is initialized whenever ExecCtx is instantiated. ExecCtx
also keeps track of the previous exec_ctx so that nesting of exec_ctx is
allowed. This means that there is only one exec_ctx being used at any
time. Also, grpc_exec_ctx_finish is called in the destructor of the
object, and the previous exec_ctx is restored to avoid breaking current
functionality. The code still explicitly calls grpc_exec_ctx_finish
because removing all such instances causes the code to break.
Diffstat (limited to 'test/core/transport/chttp2')
-rw-r--r-- | test/core/transport/chttp2/bin_decoder_test.c | 102 | ||||
-rw-r--r-- | test/core/transport/chttp2/bin_decoder_test.cc | 135 | ||||
-rw-r--r-- | test/core/transport/chttp2/hpack_encoder_test.c | 82 | ||||
-rw-r--r-- | test/core/transport/chttp2/hpack_parser_fuzzer_test.c | 14 | ||||
-rw-r--r-- | test/core/transport/chttp2/hpack_parser_test.c | 42 | ||||
-rw-r--r-- | test/core/transport/chttp2/hpack_table_test.c | 75 |
6 files changed, 281 insertions, 169 deletions
diff --git a/test/core/transport/chttp2/bin_decoder_test.c b/test/core/transport/chttp2/bin_decoder_test.c index 775161ec91..824b756398 100644 --- a/test/core/transport/chttp2/bin_decoder_test.c +++ b/test/core/transport/chttp2/bin_decoder_test.c @@ -29,8 +29,8 @@ static int all_ok = 1; -static void expect_slice_eq(grpc_exec_ctx *exec_ctx, grpc_slice expected, - grpc_slice slice, char *debug, int line) { +static void expect_slice_eq(grpc_slice expected, grpc_slice slice, char *debug, + int line) { if (!grpc_slice_eq(slice, expected)) { char *hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -40,104 +40,94 @@ static void expect_slice_eq(grpc_exec_ctx *exec_ctx, grpc_slice expected, gpr_free(he); all_ok = 0; } - grpc_slice_unref_internal(exec_ctx, expected); - grpc_slice_unref_internal(exec_ctx, slice); + grpc_slice_unref_internal(expected); + grpc_slice_unref_internal(slice); } -static grpc_slice base64_encode(grpc_exec_ctx *exec_ctx, const char *s) { +static grpc_slice base64_encode(const char *s) { grpc_slice ss = grpc_slice_from_copied_string(s); grpc_slice out = grpc_chttp2_base64_encode(ss); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice_unref_internal(ss); return out; } -static grpc_slice base64_decode(grpc_exec_ctx *exec_ctx, const char *s) { +static grpc_slice base64_decode(const char *s) { grpc_slice ss = grpc_slice_from_copied_string(s); - grpc_slice out = grpc_chttp2_base64_decode(exec_ctx, ss); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice out = grpc_chttp2_base64_decode(ss); + grpc_slice_unref_internal(ss); return out; } -static grpc_slice base64_decode_with_length(grpc_exec_ctx *exec_ctx, - const char *s, +static grpc_slice base64_decode_with_length(const char *s, size_t output_length) { grpc_slice ss = grpc_slice_from_copied_string(s); - grpc_slice out = - grpc_chttp2_base64_decode_with_length(exec_ctx, ss, output_length); - grpc_slice_unref_internal(exec_ctx, ss); + grpc_slice out = grpc_chttp2_base64_decode_with_length(ss, output_length); + grpc_slice_unref_internal(ss); return out; } -#define EXPECT_SLICE_EQ(exec_ctx, expected, slice) \ - expect_slice_eq( \ - exec_ctx, grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), \ - slice, #slice, __LINE__); +#define EXPECT_SLICE_EQ(expected, slice) \ + expect_slice_eq( \ + grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), slice, \ + #slice, __LINE__); -#define ENCODE_AND_DECODE(exec_ctx, s) \ - EXPECT_SLICE_EQ(exec_ctx, s, \ - grpc_chttp2_base64_decode_with_length( \ - exec_ctx, base64_encode(exec_ctx, s), strlen(s))); +#define ENCODE_AND_DECODE(s) \ + EXPECT_SLICE_EQ( \ + s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s))); int main(int argc, char **argv) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which takes encoded base64 strings without pad chars, but output length is required. */ /* Base64 test vectors from RFC 4648 */ - ENCODE_AND_DECODE(&exec_ctx, ""); - ENCODE_AND_DECODE(&exec_ctx, "f"); - ENCODE_AND_DECODE(&exec_ctx, "foo"); - ENCODE_AND_DECODE(&exec_ctx, "fo"); - ENCODE_AND_DECODE(&exec_ctx, "foob"); - ENCODE_AND_DECODE(&exec_ctx, "fooba"); - ENCODE_AND_DECODE(&exec_ctx, "foobar"); + ENCODE_AND_DECODE(""); + ENCODE_AND_DECODE("f"); + ENCODE_AND_DECODE("foo"); + ENCODE_AND_DECODE("fo"); + ENCODE_AND_DECODE("foob"); + ENCODE_AND_DECODE("fooba"); + ENCODE_AND_DECODE("foobar"); - ENCODE_AND_DECODE(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5"); + ENCODE_AND_DECODE("\xc0\xc1\xc2\xc3\xc4\xc5"); /* Base64 test vectors from RFC 4648, with pad chars */ /* BASE64("") = "" */ - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "")); + EXPECT_SLICE_EQ("", base64_decode("")); /* BASE64("f") = "Zg==" */ - EXPECT_SLICE_EQ(&exec_ctx, "f", base64_decode(&exec_ctx, "Zg==")); + EXPECT_SLICE_EQ("f", base64_decode("Zg==")); /* BASE64("fo") = "Zm8=" */ - EXPECT_SLICE_EQ(&exec_ctx, "fo", base64_decode(&exec_ctx, "Zm8=")); + EXPECT_SLICE_EQ("fo", base64_decode("Zm8=")); /* BASE64("foo") = "Zm9v" */ - EXPECT_SLICE_EQ(&exec_ctx, "foo", base64_decode(&exec_ctx, "Zm9v")); + EXPECT_SLICE_EQ("foo", base64_decode("Zm9v")); /* BASE64("foob") = "Zm9vYg==" */ - EXPECT_SLICE_EQ(&exec_ctx, "foob", base64_decode(&exec_ctx, "Zm9vYg==")); + EXPECT_SLICE_EQ("foob", base64_decode("Zm9vYg==")); /* BASE64("fooba") = "Zm9vYmE=" */ - EXPECT_SLICE_EQ(&exec_ctx, "fooba", base64_decode(&exec_ctx, "Zm9vYmE=")); + EXPECT_SLICE_EQ("fooba", base64_decode("Zm9vYmE=")); /* BASE64("foobar") = "Zm9vYmFy" */ - EXPECT_SLICE_EQ(&exec_ctx, "foobar", base64_decode(&exec_ctx, "Zm9vYmFy")); + EXPECT_SLICE_EQ("foobar", base64_decode("Zm9vYmFy")); - EXPECT_SLICE_EQ(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5", - base64_decode(&exec_ctx, "wMHCw8TF")); + EXPECT_SLICE_EQ("\xc0\xc1\xc2\xc3\xc4\xc5", base64_decode("wMHCw8TF")); // Test illegal input length in grpc_chttp2_base64_decode - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "a")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "ab")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "abc")); + EXPECT_SLICE_EQ("", base64_decode("a")); + EXPECT_SLICE_EQ("", base64_decode("ab")); + EXPECT_SLICE_EQ("", base64_decode("abc")); // Test illegal charactors in grpc_chttp2_base64_decode - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "Zm:v")); - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode(&exec_ctx, "Zm=v")); + EXPECT_SLICE_EQ("", base64_decode("Zm:v")); + EXPECT_SLICE_EQ("", base64_decode("Zm=v")); // Test output_length longer than max possible output length in // grpc_chttp2_base64_decode_with_length - EXPECT_SLICE_EQ(&exec_ctx, "", base64_decode_with_length(&exec_ctx, "Zg", 2)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm8", 3)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm9v", 4)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zg", 2)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm8", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm9v", 4)); // Test illegal charactors in grpc_chttp2_base64_decode_with_length - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm:v", 3)); - EXPECT_SLICE_EQ(&exec_ctx, "", - base64_decode_with_length(&exec_ctx, "Zm=v", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3)); - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc new file mode 100644 index 0000000000..d426731dae --- /dev/null +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -0,0 +1,135 @@ +/* + * + * Copyright 2016 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/ext/transport/chttp2/transport/bin_decoder.h" + +#include <string.h> + +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include "src/core/ext/transport/chttp2/transport/bin_encoder.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/lib/support/string.h" + +static int all_ok = 1; + +static void expect_slice_eq(grpc_slice expected, grpc_slice slice, char *debug, + int line) { + if (!grpc_slice_eq(slice, expected)) { + char *hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); + char *he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "FAILED:%d: %s\ngot: %s\nwant: %s", line, debug, hs, + he); + gpr_free(hs); + gpr_free(he); + all_ok = 0; + } + grpc_slice_unref_internal(expected); + grpc_slice_unref_internal(slice); +} + +static grpc_slice base64_encode(const char *s) { + grpc_slice ss = grpc_slice_from_copied_string(s); + grpc_slice out = grpc_chttp2_base64_encode(ss); + grpc_slice_unref_internal(ss); + return out; +} + +static grpc_slice base64_decode(const char *s) { + grpc_slice ss = grpc_slice_from_copied_string(s); + grpc_slice out = grpc_chttp2_base64_decode(ss); + grpc_slice_unref_internal(ss); + return out; +} + +static grpc_slice base64_decode_with_length(const char *s, + size_t output_length) { + grpc_slice ss = grpc_slice_from_copied_string(s); + grpc_slice out = grpc_chttp2_base64_decode_with_length(ss, output_length); + grpc_slice_unref_internal(ss); + return out; +} + +#define EXPECT_SLICE_EQ(expected, slice) \ + expect_slice_eq( \ + exec_ctx, grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), \ + slice, #slice, __LINE__); + +#define ENCODE_AND_DECODE(s) \ + EXPECT_SLICE_EQ(s, grpc_chttp2_base64_decode_with_length( \ + exec_ctx, base64_encode(s), strlen(s))); + +int main(int argc, char **argv) { + ExecCtx _local_exec_ctx; + + /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which + takes encoded base64 strings without pad chars, but output length is + required. */ + /* Base64 test vectors from RFC 4648 */ + ENCODE_AND_DECODE(""); + ENCODE_AND_DECODE("f"); + ENCODE_AND_DECODE("foo"); + ENCODE_AND_DECODE("fo"); + ENCODE_AND_DECODE("foob"); + ENCODE_AND_DECODE("fooba"); + ENCODE_AND_DECODE("foobar"); + + ENCODE_AND_DECODE("\xc0\xc1\xc2\xc3\xc4\xc5"); + + /* Base64 test vectors from RFC 4648, with pad chars */ + /* BASE64("") = "" */ + EXPECT_SLICE_EQ("", base64_decode("")); + /* BASE64("f") = "Zg==" */ + EXPECT_SLICE_EQ("f", base64_decode("Zg==")); + /* BASE64("fo") = "Zm8=" */ + EXPECT_SLICE_EQ("fo", base64_decode("Zm8=")); + /* BASE64("foo") = "Zm9v" */ + EXPECT_SLICE_EQ("foo", base64_decode("Zm9v")); + /* BASE64("foob") = "Zm9vYg==" */ + EXPECT_SLICE_EQ("foob", base64_decode("Zm9vYg==")); + /* BASE64("fooba") = "Zm9vYmE=" */ + EXPECT_SLICE_EQ("fooba", base64_decode("Zm9vYmE=")); + /* BASE64("foobar") = "Zm9vYmFy" */ + EXPECT_SLICE_EQ("foobar", base64_decode("Zm9vYmFy")); + + EXPECT_SLICE_EQ("\xc0\xc1\xc2\xc3\xc4\xc5", base64_decode("wMHCw8TF")); + + // Test illegal input length in grpc_chttp2_base64_decode + EXPECT_SLICE_EQ("", base64_decode("a")); + EXPECT_SLICE_EQ("", base64_decode("ab")); + EXPECT_SLICE_EQ("", base64_decode("abc")); + + // Test illegal charactors in grpc_chttp2_base64_decode + EXPECT_SLICE_EQ("", base64_decode("Zm:v")); + EXPECT_SLICE_EQ("", base64_decode("Zm=v")); + + // Test output_length longer than max possible output length in + // grpc_chttp2_base64_decode_with_length + EXPECT_SLICE_EQ("", base64_decode_with_length("Zg", 2)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm8", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm9v", 4)); + + // Test illegal charactors in grpc_chttp2_base64_decode_with_length + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3)); + EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3)); + + grpc_exec_ctx_finish(); + + return all_ok ? 0 : 1; +} diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c index ed51dd1859..f3690fc410 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.c +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -45,7 +45,7 @@ size_t cap_to_delete = 0; /* verify that the output generated by encoding the stream matches the hexstring passed in */ -static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, bool eof, +static void verify(size_t window_available, bool eof, bool use_true_binary_metadata, size_t expect_window_used, const char *expected, size_t nheaders, ...) { grpc_slice_buffer output; @@ -67,7 +67,7 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, bool eof, e[i].prev = &e[i - 1]; } e[i].md = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + grpc_slice_intern(grpc_slice_from_static_string(key)), grpc_slice_intern(grpc_slice_from_static_string(value))); } e[0].prev = NULL; @@ -95,11 +95,10 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, bool eof, .max_frame_size = 16384, .stats = &stats, }; - grpc_chttp2_encode_header(exec_ctx, &g_compressor, NULL, 0, &b, &hopt, - &output); + grpc_chttp2_encode_header(&g_compressor, NULL, 0, &b, &hopt, &output); merged = grpc_slice_merge(output.slices, output.count); - grpc_slice_buffer_destroy_internal(exec_ctx, &output); - grpc_metadata_batch_destroy(exec_ctx, &b); + grpc_slice_buffer_destroy_internal(&output); + grpc_metadata_batch_destroy(&b); if (!grpc_slice_eq(merged, expect)) { char *expect_str = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -112,35 +111,32 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, bool eof, g_failure = 1; } - grpc_slice_unref_internal(exec_ctx, merged); - grpc_slice_unref_internal(exec_ctx, expect); + grpc_slice_unref_internal(merged); + grpc_slice_unref_internal(expect); } -static void test_basic_headers(grpc_exec_ctx *exec_ctx) { +static void test_basic_headers() { int i; - verify(exec_ctx, 0, false, false, 0, "000005 0104 deadbeef 40 0161 0161", 1, - "a", "a"); - verify(exec_ctx, 0, false, false, 0, "000001 0104 deadbeef be", 1, "a", "a"); - verify(exec_ctx, 0, false, false, 0, "000001 0104 deadbeef be", 1, "a", "a"); - verify(exec_ctx, 0, false, false, 0, "000006 0104 deadbeef be 40 0162 0163", - 2, "a", "a", "b", "c"); - verify(exec_ctx, 0, false, false, 0, "000002 0104 deadbeef bf be", 2, "a", + verify(0, false, false, 0, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); + verify(0, false, false, 0, "000001 0104 deadbeef be", 1, "a", "a"); + verify(0, false, false, 0, "000001 0104 deadbeef be", 1, "a", "a"); + verify(0, false, false, 0, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", "b", "c"); - verify(exec_ctx, 0, false, false, 0, "000004 0104 deadbeef 7f 00 0164", 1, - "a", "d"); + verify(0, false, false, 0, "000002 0104 deadbeef bf be", 2, "a", "a", "b", + "c"); + verify(0, false, false, 0, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); /* flush out what's there to make a few values look very popular */ for (i = 0; i < 350; i++) { - verify(exec_ctx, 0, false, false, 0, "000003 0104 deadbeef c0 bf be", 3, - "a", "a", "b", "c", "a", "d"); + verify(0, false, false, 0, "000003 0104 deadbeef c0 bf be", 3, "a", "a", + "b", "c", "a", "d"); } - verify(exec_ctx, 0, false, false, 0, "000006 0104 deadbeef c0 00 016b 0176", - 2, "a", "a", "k", "v"); + verify(0, false, false, 0, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", + "a", "k", "v"); /* this could be 000004 0104 deadbeef 0f 30 0176 also */ - verify(exec_ctx, 0, false, false, 0, "000004 0104 deadbeef 0f 2f 0176", 1, - "a", "v"); + verify(0, false, false, 0, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); } static void encode_int_to_str(int i, char *p) { @@ -151,7 +147,7 @@ static void encode_int_to_str(int i, char *p) { p[2] = 0; } -static void test_decode_table_overflow(grpc_exec_ctx *exec_ctx) { +static void test_decode_table_overflow() { int i; char key[3], value[3]; char *expect; @@ -174,25 +170,24 @@ static void test_decode_table_overflow(grpc_exec_ctx *exec_ctx) { } if (i > 0) { - verify(exec_ctx, 0, false, false, 0, expect, 2, "aa", "ba", key, value); + verify(0, false, false, 0, expect, 2, "aa", "ba", key, value); } else { - verify(exec_ctx, 0, false, false, 0, expect, 1, key, value); + verify(0, false, false, 0, expect, 1, key, value); } gpr_free(expect); } /* if the above passes, then we must have just knocked this pair out of the decoder stack, and so we'll be forced to re-encode it */ - verify(exec_ctx, 0, false, false, 0, "000007 0104 deadbeef 40 026161 026261", - 1, "aa", "ba"); + verify(0, false, false, 0, "000007 0104 deadbeef 40 026161 026261", 1, "aa", + "ba"); } -static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, - const char *key, +static void verify_table_size_change_match_elem_size(const char *key, const char *value) { grpc_slice_buffer output; grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + grpc_slice_intern(grpc_slice_from_static_string(key)), grpc_slice_intern(grpc_slice_from_static_string(value))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); size_t initial_table_size = g_compressor.table_size; @@ -214,27 +209,26 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, .use_true_binary_metadata = false, .max_frame_size = 16384, .stats = &stats}; - grpc_chttp2_encode_header(exec_ctx, &g_compressor, NULL, 0, &b, &hopt, - &output); - grpc_slice_buffer_destroy_internal(exec_ctx, &output); - grpc_metadata_batch_destroy(exec_ctx, &b); + grpc_chttp2_encode_header(&g_compressor, NULL, 0, &b, &hopt, &output); + grpc_slice_buffer_destroy_internal(&output); + grpc_metadata_batch_destroy(&b); GPR_ASSERT(g_compressor.table_size == elem_size + initial_table_size); gpr_free(e); } -static void test_encode_header_size(grpc_exec_ctx *exec_ctx) { - verify_table_size_change_match_elem_size(exec_ctx, "hello", "world"); - verify_table_size_change_match_elem_size(exec_ctx, "hello-bin", "world"); +static void test_encode_header_size() { + verify_table_size_change_match_elem_size("hello", "world"); + verify_table_size_change_match_elem_size("hello-bin", "world"); } -static void run_test(void (*test)(grpc_exec_ctx *exec_ctx), const char *name) { +static void run_test(void (*test)(), const char *name) { gpr_log(GPR_INFO, "RUN TEST: %s", name); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_chttp2_hpack_compressor_init(&g_compressor); - test(&exec_ctx); - grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &g_compressor); - grpc_exec_ctx_finish(&exec_ctx); + test(); + grpc_chttp2_hpack_compressor_destroy(&g_compressor); + grpc_exec_ctx_finish(); } int main(int argc, char **argv) { diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c index 03834084cb..944f81f7c6 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c @@ -29,9 +29,7 @@ bool squelch = true; bool leak_check = true; -static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem md) { - GRPC_MDELEM_UNREF(exec_ctx, md); -} +static void onhdr(void *ud, grpc_mdelem md) { GRPC_MDELEM_UNREF(md); } static void dont_log(gpr_log_func_args *args) {} int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { @@ -39,13 +37,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (squelch) gpr_set_log_function(dont_log); grpc_init(); grpc_chttp2_hpack_parser parser; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_chttp2_hpack_parser_init(&parser); parser.on_header = onhdr; GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( - &exec_ctx, &parser, grpc_slice_from_static_buffer(data, size))); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); - grpc_exec_ctx_finish(&exec_ctx); + &parser, grpc_slice_from_static_buffer(data, size))); + grpc_chttp2_hpack_parser_destroy(&parser); + grpc_exec_ctx_finish(); grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index 0946c05261..67b527934e 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -30,7 +30,7 @@ typedef struct { va_list args; } test_checker; -static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem md) { +static void onhdr(void *ud, grpc_mdelem md) { const char *ekey, *evalue; test_checker *chk = ud; ekey = va_arg(chk->args, char *); @@ -39,7 +39,7 @@ static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem md) { GPR_ASSERT(evalue); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(md), ekey) == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(md), evalue) == 0); - GRPC_MDELEM_UNREF(exec_ctx, md); + GRPC_MDELEM_UNREF(md); } static void test_vector(grpc_chttp2_hpack_parser *parser, @@ -60,10 +60,10 @@ static void test_vector(grpc_chttp2_hpack_parser *parser, grpc_slice_unref(input); for (i = 0; i < nslices; i++) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(grpc_chttp2_hpack_parser_parse(&exec_ctx, parser, slices[i]) == + exec_ctx = GRPC_EXEC_CTX_INIT; + GPR_ASSERT(grpc_chttp2_hpack_parser_parse(parser, slices[i]) == GRPC_ERROR_NONE); - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); } for (i = 0; i < nslices; i++) { @@ -78,9 +78,9 @@ static void test_vector(grpc_chttp2_hpack_parser *parser, static void test_vectors(grpc_slice_split_mode mode) { grpc_chttp2_hpack_parser parser; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.2.1 */ test_vector(&parser, mode, "400a 6375 7374 6f6d 2d6b 6579 0d63 7573" @@ -96,9 +96,9 @@ static void test_vectors(grpc_slice_split_mode mode) { "password", "secret", NULL); /* D.2.4 */ test_vector(&parser, mode, "82", ":method", "GET", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.3.1 */ test_vector(&parser, mode, "8286 8441 0f77 7777 2e65 7861 6d70 6c65" @@ -116,9 +116,9 @@ static void test_vectors(grpc_slice_split_mode mode) { ":method", "GET", ":scheme", "https", ":path", "/index.html", ":authority", "www.example.com", "custom-key", "custom-value", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_init(&parser); /* D.4.1 */ test_vector(&parser, mode, "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4" @@ -136,11 +136,11 @@ static void test_vectors(grpc_slice_split_mode mode) { ":method", "GET", ":scheme", "https", ":path", "/index.html", ":authority", "www.example.com", "custom-key", "custom-value", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); - grpc_chttp2_hptbl_set_max_bytes(&exec_ctx, &parser.table, 256); - grpc_chttp2_hptbl_set_current_table_size(&exec_ctx, &parser.table, 256); + grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256); + grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256); /* D.5.1 */ test_vector(&parser, mode, "4803 3330 3258 0770 7269 7661 7465 611d" @@ -170,11 +170,11 @@ static void test_vectors(grpc_slice_split_mode mode) { "https://www.example.com", "content-encoding", "gzip", "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); - grpc_chttp2_hptbl_set_max_bytes(&exec_ctx, &parser.table, 256); - grpc_chttp2_hptbl_set_current_table_size(&exec_ctx, &parser.table, 256); + grpc_chttp2_hpack_parser_init(&parser); + grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256); + grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256); /* D.6.1 */ test_vector(&parser, mode, "4882 6402 5885 aec3 771a 4b61 96d0 7abe" @@ -201,9 +201,9 @@ static void test_vectors(grpc_slice_split_mode mode) { "https://www.example.com", "content-encoding", "gzip", "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); + grpc_chttp2_hpack_parser_destroy(&parser); - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); } int main(int argc, char **argv) { diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index 430ece33c7..cbb6b1d7a3 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -44,10 +44,10 @@ static void assert_index(const grpc_chttp2_hptbl *tbl, uint32_t idx, } static void test_static_lookup(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hptbl tbl; - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); + grpc_chttp2_hptbl_init(&tbl); LOG_TEST("test_static_lookup"); assert_index(&tbl, 1, ":authority", ""); @@ -112,8 +112,8 @@ static void test_static_lookup(void) { assert_index(&tbl, 60, "via", ""); assert_index(&tbl, 61, "www-authenticate", ""); - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); + grpc_exec_ctx_finish(); } static void test_many_additions(void) { @@ -124,18 +124,17 @@ static void test_many_additions(void) { LOG_TEST("test_many_additions"); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); + exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_chttp2_hptbl_init(&tbl); for (i = 0; i < 100000; i++) { grpc_mdelem elem; gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&value, "VALUE:%d", i); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); gpr_free(key); gpr_free(value); @@ -148,25 +147,24 @@ static void test_many_additions(void) { } } - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); + grpc_exec_ctx_finish(); } static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl *tbl, const char *key, const char *value) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem md = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_mdelem md = grpc_mdelem_from_slices( + grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); - GRPC_MDELEM_UNREF(&exec_ctx, md); - grpc_exec_ctx_finish(&exec_ctx); + GRPC_MDELEM_UNREF(md); + grpc_exec_ctx_finish(); return r; } static void test_find(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hptbl tbl; uint32_t i; char buffer[32]; @@ -175,21 +173,19 @@ static void test_find(void) { LOG_TEST("test_find"); - grpc_chttp2_hptbl_init(&exec_ctx, &tbl); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("xyz")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("123")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("x"), + grpc_chttp2_hptbl_init(&tbl); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("xyz")); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("123")); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("x"), grpc_slice_from_static_string("1")); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); r = find_simple(&tbl, "abc", "123"); GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY); @@ -238,11 +234,10 @@ static void test_find(void) { /* overflow the string buffer, check find still works */ for (i = 0; i < 10000; i++) { int64_ttoa(i, buffer); - elem = grpc_mdelem_from_slices(&exec_ctx, - grpc_slice_from_static_string("test"), + elem = grpc_mdelem_from_slices(grpc_slice_from_static_string("test"), grpc_slice_from_copied_string(buffer)); - GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); - GRPC_MDELEM_UNREF(&exec_ctx, elem); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE); + GRPC_MDELEM_UNREF(elem); } r = find_simple(&tbl, "abc", "123"); @@ -270,8 +265,8 @@ static void test_find(void) { GPR_ASSERT(r.index != 0); GPR_ASSERT(r.has_value == 0); - grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hptbl_destroy(&tbl); + grpc_exec_ctx_finish(); } int main(int argc, char **argv) { |