aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/transport/chttp2
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-12-06 09:47:54 -0800
committerGravatar GitHub <noreply@github.com>2017-12-06 09:47:54 -0800
commit8cf1470a51ea276ca84825e7495d4ee24743540d (patch)
tree72385cc865094115bc08cb813201d48cb09840bb /test/core/transport/chttp2
parent1d4e99508409be052bd129ba507bae1fbe7eb7fa (diff)
Revert "Revert "All instances of exec_ctx being passed around in src/core removed""
Diffstat (limited to 'test/core/transport/chttp2')
-rw-r--r--test/core/transport/chttp2/bin_decoder_test.cc158
-rw-r--r--test/core/transport/chttp2/bin_encoder_test.cc3
-rw-r--r--test/core/transport/chttp2/hpack_encoder_test.cc91
-rw-r--r--test/core/transport/chttp2/hpack_parser_fuzzer_test.cc19
-rw-r--r--test/core/transport/chttp2/hpack_parser_test.cc41
-rw-r--r--test/core/transport/chttp2/hpack_table_test.cc72
-rw-r--r--test/core/transport/chttp2/settings_timeout_test.cc55
-rw-r--r--test/core/transport/chttp2/varint_test.cc3
8 files changed, 208 insertions, 234 deletions
diff --git a/test/core/transport/chttp2/bin_decoder_test.cc b/test/core/transport/chttp2/bin_decoder_test.cc
index a29ec8a13f..6d70a4261b 100644
--- a/test/core/transport/chttp2/bin_decoder_test.cc
+++ b/test/core/transport/chttp2/bin_decoder_test.cc
@@ -20,6 +20,7 @@
#include <string.h>
+#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/bin_encoder.h"
@@ -29,8 +30,8 @@
static int all_ok = 1;
-static void expect_slice_eq(grpc_exec_ctx* exec_ctx, grpc_slice expected,
- grpc_slice slice, const char* debug, int line) {
+static void expect_slice_eq(grpc_slice expected, grpc_slice slice,
+ const 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 +41,97 @@ 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(&exec_ctx, "\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, ""));
- /* BASE64("f") = "Zg==" */
- EXPECT_SLICE_EQ(&exec_ctx, "f", base64_decode(&exec_ctx, "Zg=="));
- /* BASE64("fo") = "Zm8=" */
- EXPECT_SLICE_EQ(&exec_ctx, "fo", base64_decode(&exec_ctx, "Zm8="));
- /* BASE64("foo") = "Zm9v" */
- EXPECT_SLICE_EQ(&exec_ctx, "foo", base64_decode(&exec_ctx, "Zm9v"));
- /* BASE64("foob") = "Zm9vYg==" */
- EXPECT_SLICE_EQ(&exec_ctx, "foob", base64_decode(&exec_ctx, "Zm9vYg=="));
- /* BASE64("fooba") = "Zm9vYmE=" */
- EXPECT_SLICE_EQ(&exec_ctx, "fooba", base64_decode(&exec_ctx, "Zm9vYmE="));
- /* BASE64("foobar") = "Zm9vYmFy" */
- EXPECT_SLICE_EQ(&exec_ctx, "foobar", base64_decode(&exec_ctx, "Zm9vYmFy"));
-
- EXPECT_SLICE_EQ(&exec_ctx, "\xc0\xc1\xc2\xc3\xc4\xc5",
- base64_decode(&exec_ctx, "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"));
-
- // 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"));
-
- // 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));
-
- // 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));
-
- grpc_exec_ctx_finish(&exec_ctx);
-
+ grpc_init();
+ {
+ grpc_core::ExecCtx 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_encoder_test.cc b/test/core/transport/chttp2/hpack_encoder_test.cc
index 2d18b72504..d2dbd4a798 100644
--- a/test/core/transport/chttp2/hpack_encoder_test.cc
+++ b/test/core/transport/chttp2/hpack_encoder_test.cc
@@ -51,8 +51,8 @@ typedef struct {
/* verify that the output generated by encoding the stream matches the
hexstring passed in */
-static void verify(grpc_exec_ctx* exec_ctx, const verify_params params,
- const char* expected, size_t nheaders, ...) {
+static void verify(const verify_params params, const char* expected,
+ size_t nheaders, ...) {
grpc_slice_buffer output;
grpc_slice merged;
grpc_slice expect = parse_hexstring(expected);
@@ -77,8 +77,7 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params,
value_slice = grpc_slice_intern(value_slice);
}
e[i].md = grpc_mdelem_from_slices(
- exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)),
- value_slice);
+ grpc_slice_intern(grpc_slice_from_static_string(key)), value_slice);
}
e[0].prev = nullptr;
e[nheaders - 1].next = nullptr;
@@ -106,11 +105,10 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params,
16384, /* max_frame_size */
&stats /* stats */
};
- grpc_chttp2_encode_header(exec_ctx, &g_compressor, nullptr, 0, &b, &hopt,
- &output);
+ grpc_chttp2_encode_header(&g_compressor, nullptr, 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);
@@ -123,11 +121,11 @@ static void verify(grpc_exec_ctx* exec_ctx, const verify_params params,
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_params params = {
@@ -135,24 +133,22 @@ static void test_basic_headers(grpc_exec_ctx* exec_ctx) {
false,
false,
};
- verify(exec_ctx, params, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a");
- verify(exec_ctx, params, "000001 0104 deadbeef be", 1, "a", "a");
- verify(exec_ctx, params, "000001 0104 deadbeef be", 1, "a", "a");
- verify(exec_ctx, params, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a",
- "b", "c");
- verify(exec_ctx, params, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c");
- verify(exec_ctx, params, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d");
+ verify(params, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a");
+ verify(params, "000001 0104 deadbeef be", 1, "a", "a");
+ verify(params, "000001 0104 deadbeef be", 1, "a", "a");
+ verify(params, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", "b", "c");
+ verify(params, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c");
+ verify(params, "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, params, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b",
- "c", "a", "d");
+ verify(params, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", "c", "a",
+ "d");
}
- verify(exec_ctx, params, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a",
- "k", "v");
+ verify(params, "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, params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v");
+ verify(params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v");
}
static void encode_int_to_str(int i, char* p) {
@@ -163,7 +159,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;
@@ -192,26 +188,24 @@ static void test_decode_table_overflow(grpc_exec_ctx* exec_ctx) {
}
if (i > 0) {
- verify(exec_ctx, params, expect, 2, "aa", "ba", key, value);
+ verify(params, expect, 2, "aa", "ba", key, value);
} else {
- verify(exec_ctx, params, expect, 1, key, value);
+ verify(params, 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, params, "000007 0104 deadbeef 40 026161 026261", 1, "aa",
- "ba");
+ verify(params, "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,
bool use_true_binary) {
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, use_true_binary);
size_t initial_table_size = g_compressor.table_size;
@@ -235,41 +229,38 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx* exec_ctx,
use_true_binary, /* use_true_binary_metadata */
16384, /* max_frame_size */
&stats /* stats */};
- grpc_chttp2_encode_header(exec_ctx, &g_compressor, nullptr, 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, nullptr, 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", false);
- verify_table_size_change_match_elem_size(exec_ctx, "hello-bin", "world",
- false);
- verify_table_size_change_match_elem_size(exec_ctx, "true-binary-bin",
+static void test_encode_header_size() {
+ verify_table_size_change_match_elem_size("hello", "world", false);
+ verify_table_size_change_match_elem_size("hello-bin", "world", false);
+ verify_table_size_change_match_elem_size("true-binary-bin",
"I_am_true_binary_value", true);
}
-static void test_interned_key_indexed(grpc_exec_ctx* exec_ctx) {
+static void test_interned_key_indexed() {
int i;
verify_params params = {false, false, true};
- verify(exec_ctx, params, "000009 0104 deadbeef 40 0161 0162 0f2f 0163", 2,
- "a", "b", "a", "c");
+ verify(params, "000009 0104 deadbeef 40 0161 0162 0f2f 0163", 2, "a", "b",
+ "a", "c");
for (i = 0; i < 10; i++) {
- verify(exec_ctx, params, "000008 0104 deadbeef 0f2f 0162 0f2f 0163", 2, "a",
- "b", "a", "c");
+ verify(params, "000008 0104 deadbeef 0f2f 0162 0f2f 0163", 2, "a", "b", "a",
+ "c");
}
}
-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_core::ExecCtx exec_ctx;
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);
}
int main(int argc, char** argv) {
diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc
index 942f25e0b7..9a195daee0 100644
--- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc
+++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.cc
@@ -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) {}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
@@ -39,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_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_chttp2_hpack_parser_init(&exec_ctx, &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);
+ {
+ grpc_core::ExecCtx 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/hpack_parser_test.cc b/test/core/transport/chttp2/hpack_parser_test.cc
index 82fb20aced..9d3456a873 100644
--- a/test/core/transport/chttp2/hpack_parser_test.cc
+++ b/test/core/transport/chttp2/hpack_parser_test.cc
@@ -32,7 +32,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 = static_cast<test_checker*>(ud);
ekey = va_arg(chk->args, char*);
@@ -41,7 +41,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,
@@ -62,10 +62,9 @@ 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]) ==
+ grpc_core::ExecCtx exec_ctx;
+ GPR_ASSERT(grpc_chttp2_hpack_parser_parse(parser, slices[i]) ==
GRPC_ERROR_NONE);
- grpc_exec_ctx_finish(&exec_ctx);
}
for (i = 0; i < nslices; i++) {
@@ -80,9 +79,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;
+ grpc_core::ExecCtx exec_ctx;
- 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"
@@ -98,9 +97,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"
@@ -118,9 +117,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"
@@ -138,11 +137,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"
@@ -172,11 +171,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"
@@ -203,9 +202,7 @@ 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_exec_ctx_finish(&exec_ctx);
+ grpc_chttp2_hpack_parser_destroy(&parser);
}
int main(int argc, char** argv) {
diff --git a/test/core/transport/chttp2/hpack_table_test.cc b/test/core/transport/chttp2/hpack_table_test.cc
index ff7c2de538..3f3cb2ee9d 100644
--- a/test/core/transport/chttp2/hpack_table_test.cc
+++ b/test/core/transport/chttp2/hpack_table_test.cc
@@ -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;
+ grpc_core::ExecCtx exec_ctx;
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,7 @@ 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);
}
static void test_many_additions(void) {
@@ -124,18 +123,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);
+ grpc_core::ExecCtx exec_ctx;
+ 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 +146,23 @@ static void test_many_additions(void) {
}
}
- grpc_chttp2_hptbl_destroy(&exec_ctx, &tbl);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_chttp2_hptbl_destroy(&tbl);
}
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));
+ grpc_core::ExecCtx exec_ctx;
+ 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);
+
return r;
}
static void test_find(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_chttp2_hptbl tbl;
uint32_t i;
char buffer[32];
@@ -175,21 +171,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 +232,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 +263,7 @@ 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);
}
int main(int argc, char** argv) {
diff --git a/test/core/transport/chttp2/settings_timeout_test.cc b/test/core/transport/chttp2/settings_timeout_test.cc
index 670eae1f79..08473c72b6 100644
--- a/test/core/transport/chttp2/settings_timeout_test.cc
+++ b/test/core/transport/chttp2/settings_timeout_test.cc
@@ -97,7 +97,7 @@ class Client {
: server_address_(server_address) {}
void Connect() {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_resolved_addresses* server_addresses = nullptr;
grpc_error* error =
grpc_blocking_resolve_address(server_address_, "80", &server_addresses);
@@ -106,56 +106,53 @@ class Client {
pollset_ = (grpc_pollset*)gpr_zalloc(grpc_pollset_size());
grpc_pollset_init(pollset_, &mu_);
grpc_pollset_set* pollset_set = grpc_pollset_set_create();
- grpc_pollset_set_add_pollset(&exec_ctx, pollset_set, pollset_);
+ grpc_pollset_set_add_pollset(pollset_set, pollset_);
EventState state;
- grpc_tcp_client_connect(&exec_ctx, state.closure(), &endpoint_, pollset_set,
+ grpc_tcp_client_connect(state.closure(), &endpoint_, pollset_set,
nullptr /* channel_args */, server_addresses->addrs,
1000);
ASSERT_TRUE(PollUntilDone(
- &exec_ctx, &state,
+ &state,
grpc_timespec_to_millis_round_up(gpr_inf_future(GPR_CLOCK_MONOTONIC))));
ASSERT_EQ(GRPC_ERROR_NONE, state.error());
- grpc_pollset_set_destroy(&exec_ctx, pollset_set);
- grpc_endpoint_add_to_pollset(&exec_ctx, endpoint_, pollset_);
+ grpc_pollset_set_destroy(pollset_set);
+ grpc_endpoint_add_to_pollset(endpoint_, pollset_);
grpc_resolved_addresses_destroy(server_addresses);
- grpc_exec_ctx_finish(&exec_ctx);
}
// Reads until an error is returned.
// Returns true if an error was encountered before the deadline.
bool ReadUntilError() {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_slice_buffer read_buffer;
grpc_slice_buffer_init(&read_buffer);
bool retval = true;
// Use a deadline of 3 seconds, which is a lot more than we should
// need for a 1-second timeout, but this helps avoid flakes.
- grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 3000;
+ grpc_millis deadline = grpc_core::ExecCtx::Get()->Now() + 3000;
while (true) {
EventState state;
- grpc_endpoint_read(&exec_ctx, endpoint_, &read_buffer, state.closure());
- if (!PollUntilDone(&exec_ctx, &state, deadline)) {
+ grpc_endpoint_read(endpoint_, &read_buffer, state.closure());
+ if (!PollUntilDone(&state, deadline)) {
retval = false;
break;
}
if (state.error() != GRPC_ERROR_NONE) break;
gpr_log(GPR_INFO, "client read %" PRIuPTR " bytes", read_buffer.length);
- grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &read_buffer);
+ grpc_slice_buffer_reset_and_unref_internal(&read_buffer);
}
- grpc_endpoint_shutdown(&exec_ctx, endpoint_,
+ grpc_endpoint_shutdown(endpoint_,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("shutdown"));
- grpc_slice_buffer_destroy_internal(&exec_ctx, &read_buffer);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_slice_buffer_destroy_internal(&read_buffer);
return retval;
}
void Shutdown() {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_endpoint_destroy(&exec_ctx, endpoint_);
- grpc_pollset_shutdown(&exec_ctx, pollset_,
+ grpc_core::ExecCtx exec_ctx;
+ grpc_endpoint_destroy(endpoint_);
+ grpc_pollset_shutdown(pollset_,
GRPC_CLOSURE_CREATE(&Client::PollsetDestroy, pollset_,
grpc_schedule_on_exec_ctx));
- grpc_exec_ctx_finish(&exec_ctx);
}
private:
@@ -177,8 +174,7 @@ class Client {
grpc_error* error() const { return error_; }
private:
- static void OnEventDone(grpc_exec_ctx* exec_ctx, void* arg,
- grpc_error* error) {
+ static void OnEventDone(void* arg, grpc_error* error) {
gpr_log(GPR_INFO, "OnEventDone(): %s", grpc_error_string(error));
EventState* state = (EventState*)arg;
state->error_ = GRPC_ERROR_REF(error);
@@ -191,24 +187,23 @@ class Client {
};
// Returns true if done, or false if deadline exceeded.
- bool PollUntilDone(grpc_exec_ctx* exec_ctx, EventState* state,
- grpc_millis deadline) {
+ bool PollUntilDone(EventState* state, grpc_millis deadline) {
while (true) {
grpc_pollset_worker* worker = nullptr;
gpr_mu_lock(mu_);
- GRPC_LOG_IF_ERROR("grpc_pollset_work",
- grpc_pollset_work(exec_ctx, pollset_, &worker,
- grpc_exec_ctx_now(exec_ctx) + 1000));
+ GRPC_LOG_IF_ERROR(
+ "grpc_pollset_work",
+ grpc_pollset_work(pollset_, &worker,
+ grpc_core::ExecCtx::Get()->Now() + 1000));
gpr_mu_unlock(mu_);
if (state != nullptr && state->done()) return true;
- if (grpc_exec_ctx_now(exec_ctx) >= deadline) return false;
+ if (grpc_core::ExecCtx::Get()->Now() >= deadline) return false;
}
}
- static void PollsetDestroy(grpc_exec_ctx* exec_ctx, void* arg,
- grpc_error* error) {
+ static void PollsetDestroy(void* arg, grpc_error* error) {
grpc_pollset* pollset = (grpc_pollset*)arg;
- grpc_pollset_destroy(exec_ctx, pollset);
+ grpc_pollset_destroy(pollset);
gpr_free(pollset);
}
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 <grpc/grpc.h>
#include <grpc/slice.h>
#include <grpc/support/log.h>
@@ -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;
}