aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-10-17 15:06:16 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-10-17 15:06:16 -0700
commit1bc3f8a9fc69860cfb98ed55e17b5a31e08f24f9 (patch)
treefd75bc3ecec2ec903846ba28420a46c7fa9278f4 /test/core
parent8223f4172f0a5739813fe6bb82863e68a2f588c9 (diff)
parent342d2a4c9a757b0eeed9bdbd1105aeed94c7512b (diff)
Merge github.com:grpc/grpc into epexinf
Diffstat (limited to 'test/core')
-rw-r--r--test/core/transport/chttp2/hpack_encoder_test.c99
-rw-r--r--test/core/transport/metadata_test.c4
2 files changed, 67 insertions, 36 deletions
diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c
index ed51dd1859..a2af83b6cb 100644
--- a/test/core/transport/chttp2/hpack_encoder_test.c
+++ b/test/core/transport/chttp2/hpack_encoder_test.c
@@ -43,10 +43,15 @@ void **to_delete = NULL;
size_t num_to_delete = 0;
size_t cap_to_delete = 0;
+typedef struct {
+ bool eof;
+ bool use_true_binary_metadata;
+ bool only_intern_key;
+} verify_params;
+
/* 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,
- bool use_true_binary_metadata, size_t expect_window_used,
+static void verify(grpc_exec_ctx *exec_ctx, const verify_params params,
const char *expected, size_t nheaders, ...) {
grpc_slice_buffer output;
grpc_slice merged;
@@ -66,9 +71,13 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, bool eof,
e[i - 1].next = &e[i];
e[i].prev = &e[i - 1];
}
+ grpc_slice value_slice = grpc_slice_from_static_string(value);
+ if (!params.only_intern_key) {
+ 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)),
- grpc_slice_intern(grpc_slice_from_static_string(value)));
+ value_slice);
}
e[0].prev = NULL;
e[nheaders - 1].next = NULL;
@@ -90,8 +99,8 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, bool eof,
memset(&stats, 0, sizeof(stats));
grpc_encode_header_options hopt = {
.stream_id = 0xdeadbeef,
- .is_eof = eof,
- .use_true_binary_metadata = use_true_binary_metadata,
+ .is_eof = params.eof,
+ .use_true_binary_metadata = params.use_true_binary_metadata,
.max_frame_size = 16384,
.stats = &stats,
};
@@ -119,28 +128,27 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, bool eof,
static void test_basic_headers(grpc_exec_ctx *exec_ctx) {
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",
- "a", "b", "c");
- verify(exec_ctx, 0, false, false, 0, "000004 0104 deadbeef 7f 00 0164", 1,
- "a", "d");
+ verify_params params = {
+ .eof = false, .use_true_binary_metadata = false, .only_intern_key = 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");
/* 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(exec_ctx, params, "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(exec_ctx, 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, 0, false, false, 0, "000004 0104 deadbeef 0f 2f 0176", 1,
- "a", "v");
+ verify(exec_ctx, params, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v");
}
static void encode_int_to_str(int i, char *p) {
@@ -156,6 +164,10 @@ static void test_decode_table_overflow(grpc_exec_ctx *exec_ctx) {
char key[3], value[3];
char *expect;
+ verify_params params = {
+ .eof = false, .use_true_binary_metadata = false, .only_intern_key = false,
+ };
+
for (i = 0; i < 114; i++) {
encode_int_to_str(i, key);
encode_int_to_str(i + 1, value);
@@ -174,27 +186,28 @@ 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(exec_ctx, params, expect, 2, "aa", "ba", key, value);
} else {
- verify(exec_ctx, 0, false, false, 0, expect, 1, key, value);
+ verify(exec_ctx, 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, 0, false, false, 0, "000007 0104 deadbeef 40 026161 026261",
- 1, "aa", "ba");
+ verify(exec_ctx, 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,
- const char *value) {
+ 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(value)));
- size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem);
+ size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, use_true_binary);
size_t initial_table_size = g_compressor.table_size;
grpc_linked_mdelem *e = gpr_malloc(sizeof(*e));
grpc_metadata_batch b;
@@ -209,11 +222,12 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx,
grpc_transport_one_way_stats stats;
memset(&stats, 0, sizeof(stats));
- grpc_encode_header_options hopt = {.stream_id = 0xdeadbeef,
- .is_eof = false,
- .use_true_binary_metadata = false,
- .max_frame_size = 16384,
- .stats = &stats};
+ grpc_encode_header_options hopt = {
+ .stream_id = 0xdeadbeef,
+ .is_eof = false,
+ .use_true_binary_metadata = use_true_binary,
+ .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);
@@ -224,8 +238,24 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx,
}
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");
+ 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",
+ "I_am_true_binary_value", true);
+}
+
+static void test_interned_key_indexed(grpc_exec_ctx *exec_ctx) {
+ int i;
+ verify_params params = {
+ .eof = false, .use_true_binary_metadata = false, .only_intern_key = true,
+ };
+ verify(exec_ctx, 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");
+ }
}
static void run_test(void (*test)(grpc_exec_ctx *exec_ctx), const char *name) {
@@ -245,6 +275,7 @@ int main(int argc, char **argv) {
TEST(test_basic_headers);
TEST(test_decode_table_overflow);
TEST(test_encode_header_size);
+ TEST(test_interned_key_indexed);
grpc_shutdown();
for (i = 0; i < num_to_delete; i++) {
gpr_free(to_delete[i]);
diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c
index cb06fce30b..f7124d29a7 100644
--- a/test/core/transport/metadata_test.c
+++ b/test/core/transport/metadata_test.c
@@ -302,7 +302,7 @@ static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key,
grpc_mdelem elem = grpc_mdelem_from_slices(
exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key),
maybe_intern(grpc_slice_from_static_string(value), intern_value));
- size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem);
+ size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, false);
size_t expected_size = 32 + strlen(key) + strlen(value);
GPR_ASSERT(expected_size == elem_size);
GRPC_MDELEM_UNREF(exec_ctx, elem);
@@ -316,7 +316,7 @@ static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key,
maybe_intern(grpc_slice_from_static_buffer(value, value_len),
intern_value));
GPR_ASSERT(grpc_is_binary_header(GRPC_MDKEY(elem)));
- size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem);
+ size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem, false);
grpc_slice value_slice =
grpc_slice_from_copied_buffer((const char *)value, value_len);
grpc_slice base64_encoded = grpc_chttp2_base64_encode(value_slice);