Skip to content

Commit

Permalink
Convert everything to new encode API
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Apr 4, 2017
1 parent 83f7b95 commit eb0e34f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
61 changes: 37 additions & 24 deletions test/core/transport/chttp2/hpack_encoder_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ 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, int eof,
size_t expect_window_used, const char *expected,
size_t nheaders, ...) {
static void verify(grpc_exec_ctx *exec_ctx, 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;
grpc_slice merged;
grpc_slice expect = parse_hexstring(expected);
Expand Down Expand Up @@ -103,8 +103,14 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof,

grpc_transport_one_way_stats stats;
memset(&stats, 0, sizeof(stats));
grpc_chttp2_encode_header(exec_ctx, &g_compressor, 0xdeadbeef, &b, eof, 16384,
&stats, &output);
grpc_encode_header_options hopt = {
.stream_id = 0xdeadbeef,
.is_eof = eof,
.use_true_binary_metadata = false,
.max_frame_size = 16384,
.stats = &stats,
};
grpc_chttp2_encode_header(exec_ctx, &g_compressor, &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);
Expand All @@ -127,25 +133,28 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof,
static void test_basic_headers(grpc_exec_ctx *exec_ctx) {
int i;

verify(exec_ctx, 0, 0, 0, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a");
verify(exec_ctx, 0, 0, 0, "000001 0104 deadbeef be", 1, "a", "a");
verify(exec_ctx, 0, 0, 0, "000001 0104 deadbeef be", 1, "a", "a");
verify(exec_ctx, 0, 0, 0, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a",
"b", "c");
verify(exec_ctx, 0, 0, 0, "000002 0104 deadbeef bf be", 2, "a", "a", "b",
"c");
verify(exec_ctx, 0, 0, 0, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d");
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");

/* flush out what's there to make a few values look very popular */
for (i = 0; i < 350; i++) {
verify(exec_ctx, 0, 0, 0, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b",
"c", "a", "d");
verify(exec_ctx, 0, false, false, 0, "000003 0104 deadbeef c0 bf be", 3,
"a", "a", "b", "c", "a", "d");
}

verify(exec_ctx, 0, 0, 0, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a",
"k", "v");
verify(exec_ctx, 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, 0, 0, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v");
verify(exec_ctx, 0, false, false, 0, "000004 0104 deadbeef 0f 2f 0176", 1,
"a", "v");
}

static void encode_int_to_str(int i, char *p) {
Expand Down Expand Up @@ -179,17 +188,17 @@ static void test_decode_table_overflow(grpc_exec_ctx *exec_ctx) {
}

if (i > 0) {
verify(exec_ctx, 0, 0, 0, expect, 2, "aa", "ba", key, value);
verify(exec_ctx, 0, false, false, 0, expect, 2, "aa", "ba", key, value);
} else {
verify(exec_ctx, 0, 0, 0, expect, 1, key, value);
verify(exec_ctx, 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, 0, 0, "000007 0104 deadbeef 40 026161 026261", 1, "aa",
"ba");
verify(exec_ctx, 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,
Expand All @@ -214,8 +223,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_chttp2_encode_header(exec_ctx, &g_compressor, 0xdeadbeef, &b, 0, 16384,
&stats, &output);
grpc_encode_header_options hopt = {.stream_id = 0xdeadbeef,
.is_eof = false,
.use_true_binary_metadata = false,
.max_frame_size = 16384,
.stats = &stats};
grpc_chttp2_encode_header(exec_ctx, &g_compressor, &b, &hopt, &output);
grpc_slice_buffer_destroy_internal(exec_ctx, &output);
grpc_metadata_batch_destroy(exec_ctx, &b);

Expand Down
11 changes: 8 additions & 3 deletions test/cpp/microbenchmarks/bm_chttp2_hpack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State &state) {
grpc_slice_buffer outbuf;
grpc_slice_buffer_init(&outbuf);
while (state.KeepRunning()) {
uint32_t stream_id = static_cast<uint32_t>(state.iterations());
grpc_chttp2_encode_header(&exec_ctx, &c, stream_id, &b, state.range(0),
state.range(1), &stats, &outbuf);
grpc_encode_header_options hopt = {
static_cast<uint32_t>(state.iterations()),
state.range(0) != 0,
false,
(size_t)state.range(1),
&stats,
};
grpc_chttp2_encode_header(&exec_ctx, &c, &b, &hopt, &outbuf);
if (!logged_representative_output) {
logged_representative_output = true;
for (size_t i = 0; i < outbuf.count; i++) {
Expand Down

0 comments on commit eb0e34f

Please sign in to comment.