From 81fc8c9c336fab7a71b448f748a32d680301277c Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Tue, 28 Nov 2017 13:23:36 -0800 Subject: Fix tests to call grpc_init and grpc_shutdown before using exec_ctx --- test/core/transport/byte_stream_test.cc | 3 + test/core/transport/chttp2/bin_decoder_test.cc | 110 +++++++++++---------- test/core/transport/chttp2/bin_encoder_test.cc | 3 + .../transport/chttp2/hpack_parser_fuzzer_test.cc | 15 +-- test/core/transport/chttp2/varint_test.cc | 3 + test/core/transport/connectivity_state_test.cc | 2 + test/core/transport/metadata_test.cc | 2 + test/core/transport/stream_owned_slice_test.cc | 3 + 8 files changed, 81 insertions(+), 60 deletions(-) (limited to 'test/core/transport') diff --git a/test/core/transport/byte_stream_test.cc b/test/core/transport/byte_stream_test.cc index 593c2ae141..a0dbc79158 100644 --- a/test/core/transport/byte_stream_test.cc +++ b/test/core/transport/byte_stream_test.cc @@ -18,6 +18,7 @@ #include "src/core/lib/transport/byte_stream.h" +#include #include #include #include @@ -253,11 +254,13 @@ static void test_caching_byte_stream_shared_cache(void) { } int main(int argc, char** argv) { + grpc_init(); grpc_test_init(argc, argv); test_slice_buffer_stream_basic(); test_slice_buffer_stream_shutdown(); test_caching_byte_stream_basic(); test_caching_byte_stream_reset(); test_caching_byte_stream_shared_cache(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc index 897d3008b9..4b65d7d3ca 100644 --- a/test/core/transport/chttp2/bin_decoder_test.cc +++ b/test/core/transport/chttp2/bin_decoder_test.cc @@ -20,6 +20,7 @@ #include +#include #include #include #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" @@ -76,58 +77,61 @@ static grpc_slice base64_decode_with_length(const char* s, s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s))); int main(int argc, char** argv) { - grpc_core::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_init(); + { + grpc_core::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_shutdown(); return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/bin_encoder_test.cc b/test/core/transport/chttp2/bin_encoder_test.cc index 78b8808c41..44f5de8a50 100644 --- a/test/core/transport/chttp2/bin_encoder_test.cc +++ b/test/core/transport/chttp2/bin_encoder_test.cc @@ -99,6 +99,8 @@ static void expect_binary_header(const char* hdr, int binary) { } int main(int argc, char** argv) { + grpc_init(); + /* Base64 test vectors from RFC 4648, with padding removed */ /* BASE64("") = "" */ EXPECT_SLICE_EQ("", B64("")); @@ -169,5 +171,6 @@ int main(int argc, char** argv) { expect_binary_header("foo-bar", 0); expect_binary_header("-bin", 0); + grpc_shutdown(); return all_ok ? 0 : 1; } diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc index 0dfd5ecc2d..dcec8b2230 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc @@ -37,13 +37,14 @@ extern "C" 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_core::ExecCtx _local_exec_ctx; - grpc_chttp2_hpack_parser_init(&parser); - parser.on_header = onhdr; - GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( - &parser, grpc_slice_from_static_buffer(data, size))); - grpc_chttp2_hpack_parser_destroy(&parser); - + { + grpc_core::ExecCtx _local_exec_ctx; + grpc_chttp2_hpack_parser_init(&parser); + parser.on_header = onhdr; + GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( + &parser, grpc_slice_from_static_buffer(data, size))); + grpc_chttp2_hpack_parser_destroy(&parser); + } grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/varint_test.cc b/test/core/transport/chttp2/varint_test.cc index 413b461b3a..36760d0c72 100644 --- a/test/core/transport/chttp2/varint_test.cc +++ b/test/core/transport/chttp2/varint_test.cc @@ -18,6 +18,7 @@ #include "src/core/ext/transport/chttp2/transport/varint.h" +#include #include #include @@ -44,11 +45,13 @@ static void test_varint(uint32_t value, uint32_t prefix_bits, uint8_t prefix_or, int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); TEST_VARINT(0, 1, 0, "\x00"); TEST_VARINT(128, 1, 0, "\x7f\x01"); TEST_VARINT(16384, 1, 0, "\x7f\x81\x7f"); TEST_VARINT(2097152, 1, 0, "\x7f\x81\xff\x7f"); TEST_VARINT(268435456, 1, 0, "\x7f\x81\xff\xff\x7f"); TEST_VARINT(0xffffffff, 1, 0, "\x7f\x80\xff\xff\xff\x0f"); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 99bd0fc65f..e1bc0c4eb7 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -134,11 +134,13 @@ static void test_subscribe_with_failure_then_destroy(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); grpc_core::testing::grpc_tracer_enable_flag(&grpc_connectivity_state_trace); test_connectivity_state_name(); test_check(); test_subscribe_then_unsubscribe(); test_subscribe_then_destroy(); test_subscribe_with_failure_then_destroy(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index e5bdc5901d..70d557b128 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -369,6 +369,7 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_no_op(); for (int k = 0; k <= 1; k++) { for (int v = 0; v <= 1; v++) { @@ -383,5 +384,6 @@ int main(int argc, char** argv) { test_create_many_persistant_metadata(); test_things_stick_around(); test_user_data_works(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/stream_owned_slice_test.cc b/test/core/transport/stream_owned_slice_test.cc index d25d83c2c6..7831f67a04 100644 --- a/test/core/transport/stream_owned_slice_test.cc +++ b/test/core/transport/stream_owned_slice_test.cc @@ -20,12 +20,14 @@ #include "test/core/util/test_config.h" +#include #include static void do_nothing(void* arg, grpc_error* error) {} int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); uint8_t buffer[] = "abc123"; grpc_stream_refcount r; @@ -39,5 +41,6 @@ int main(int argc, char** argv) { grpc_slice_unref(slice); GPR_ASSERT(r.refs.count == 1); + grpc_shutdown(); return 0; } -- cgit v1.2.3