diff options
author | yang-g <yangg@google.com> | 2015-12-02 13:23:33 -0800 |
---|---|---|
committer | yang-g <yangg@google.com> | 2015-12-02 13:23:33 -0800 |
commit | d88e1d8f4e42764e17aa2bed3a85b39f68673c03 (patch) | |
tree | 57cf6860d1c67257ccedc8b762f744e9e4df4a69 /test/core/transport | |
parent | 768999d0a351e2fd0a691d6391ff767228135123 (diff) | |
parent | 9fac2afdafe1355b02a355b06955b21d2a2cd004 (diff) |
merge with head and resolve conflict
Diffstat (limited to 'test/core/transport')
-rw-r--r-- | test/core/transport/chttp2/hpack_encoder_test.c | 9 | ||||
-rw-r--r-- | test/core/transport/chttp2/hpack_parser_test.c | 21 | ||||
-rw-r--r-- | test/core/transport/chttp2/hpack_table_test.c | 50 | ||||
-rw-r--r-- | test/core/transport/metadata_test.c | 105 |
4 files changed, 83 insertions, 102 deletions
diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c index 6553e0da20..64ea1e3f14 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.c +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -46,7 +46,6 @@ #define TEST(x) run_test(x, #x) -grpc_mdctx *g_mdctx; grpc_chttp2_hpack_compressor g_compressor; int g_failure = 0; @@ -76,7 +75,7 @@ static void verify(size_t window_available, int eof, size_t expect_window_used, e[i - 1].next = &e[i]; e[i].prev = &e[i - 1]; } - e[i].md = grpc_mdelem_from_strings(g_mdctx, key, value); + e[i].md = grpc_mdelem_from_strings(key, value); } e[0].prev = NULL; e[nheaders - 1].next = NULL; @@ -181,18 +180,18 @@ static void test_decode_table_overflow(void) { static void run_test(void (*test)(), const char *name) { gpr_log(GPR_INFO, "RUN TEST: %s", name); - g_mdctx = grpc_mdctx_create_with_seed(0); - grpc_chttp2_hpack_compressor_init(&g_compressor, g_mdctx); + grpc_chttp2_hpack_compressor_init(&g_compressor); test(); grpc_chttp2_hpack_compressor_destroy(&g_compressor); - grpc_mdctx_unref(g_mdctx); } int main(int argc, char **argv) { size_t i; grpc_test_init(argc, argv); + grpc_init(); TEST(test_basic_headers); TEST(test_decode_table_overflow); + grpc_shutdown(); for (i = 0; i < num_to_delete; i++) { gpr_free(to_delete[i]); } diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index 3a313375a4..4456e197af 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -35,6 +35,7 @@ #include <stdarg.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/slice.h> @@ -90,9 +91,8 @@ static void test_vector(grpc_chttp2_hpack_parser *parser, static void test_vectors(grpc_slice_split_mode mode) { grpc_chttp2_hpack_parser parser; - grpc_mdctx *mdctx = grpc_mdctx_create(); - grpc_chttp2_hpack_parser_init(&parser, mdctx); + grpc_chttp2_hpack_parser_init(&parser); /* D.2.1 */ test_vector(&parser, mode, "400a 6375 7374 6f6d 2d6b 6579 0d63 7573" @@ -110,7 +110,7 @@ static void test_vectors(grpc_slice_split_mode mode) { test_vector(&parser, mode, "82", ":method", "GET", NULL); grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&parser, mdctx); + grpc_chttp2_hpack_parser_init(&parser); /* D.3.1 */ test_vector(&parser, mode, "8286 8441 0f77 7777 2e65 7861 6d70 6c65" @@ -130,7 +130,7 @@ static void test_vectors(grpc_slice_split_mode mode) { NULL); grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&parser, mdctx); + grpc_chttp2_hpack_parser_init(&parser); /* D.4.1 */ test_vector(&parser, mode, "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4" @@ -150,8 +150,9 @@ static void test_vectors(grpc_slice_split_mode mode) { NULL); grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&parser, mdctx); - parser.table.max_bytes = 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" @@ -183,8 +184,9 @@ static void test_vectors(grpc_slice_split_mode mode) { "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); grpc_chttp2_hpack_parser_destroy(&parser); - grpc_chttp2_hpack_parser_init(&parser, mdctx); - parser.table.max_bytes = 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" @@ -212,12 +214,13 @@ static void test_vectors(grpc_slice_split_mode mode) { "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL); grpc_chttp2_hpack_parser_destroy(&parser); - grpc_mdctx_unref(mdctx); } int main(int argc, char **argv) { grpc_test_init(argc, argv); + grpc_init(); test_vectors(GRPC_SLICE_SPLIT_MERGE_ALL); test_vectors(GRPC_SLICE_SPLIT_ONE_BYTE); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index aa3e273a6c..fde352433b 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -36,10 +36,12 @@ #include <string.h> #include <stdio.h> -#include "src/core/support/string.h" +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> + +#include "src/core/support/string.h" #include "test/core/util/test_config.h" #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) @@ -58,10 +60,8 @@ static void assert_index(const grpc_chttp2_hptbl *tbl, gpr_uint32 idx, static void test_static_lookup(void) { grpc_chttp2_hptbl tbl; - grpc_mdctx *mdctx; - mdctx = grpc_mdctx_create(); - grpc_chttp2_hptbl_init(&tbl, mdctx); + grpc_chttp2_hptbl_init(&tbl); LOG_TEST("test_static_lookup"); assert_index(&tbl, 1, ":authority", ""); @@ -127,7 +127,6 @@ static void test_static_lookup(void) { assert_index(&tbl, 61, "www-authenticate", ""); grpc_chttp2_hptbl_destroy(&tbl); - grpc_mdctx_unref(mdctx); } static void test_many_additions(void) { @@ -135,17 +134,18 @@ static void test_many_additions(void) { int i; char *key; char *value; - grpc_mdctx *mdctx; LOG_TEST("test_many_additions"); - mdctx = grpc_mdctx_create(); - grpc_chttp2_hptbl_init(&tbl, mdctx); + grpc_chttp2_hptbl_init(&tbl); for (i = 0; i < 1000000; i++) { + grpc_mdelem *elem; gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&value, "VALUE:%d", i); - grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, key, value)); + elem = grpc_mdelem_from_strings(key, value); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem)); + GRPC_MDELEM_UNREF(elem); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); gpr_free(key); gpr_free(value); @@ -159,13 +159,12 @@ static void test_many_additions(void) { } grpc_chttp2_hptbl_destroy(&tbl); - grpc_mdctx_unref(mdctx); } static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl *tbl, const char *key, const char *value) { - grpc_mdelem *md = grpc_mdelem_from_strings(tbl->mdctx, key, value); + grpc_mdelem *md = grpc_mdelem_from_strings(key, value); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); GRPC_MDELEM_UNREF(md); return r; @@ -173,18 +172,23 @@ static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl *tbl, static void test_find(void) { grpc_chttp2_hptbl tbl; - int i; + gpr_uint32 i; char buffer[32]; - grpc_mdctx *mdctx; + grpc_mdelem *elem; grpc_chttp2_hptbl_find_result r; LOG_TEST("test_find"); - mdctx = grpc_mdctx_create(); - grpc_chttp2_hptbl_init(&tbl, mdctx); - grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "abc", "xyz")); - grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "abc", "123")); - grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "x", "1")); + grpc_chttp2_hptbl_init(&tbl); + elem = grpc_mdelem_from_strings("abc", "xyz"); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem)); + GRPC_MDELEM_UNREF(elem); + elem = grpc_mdelem_from_strings("abc", "123"); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem)); + GRPC_MDELEM_UNREF(elem); + elem = grpc_mdelem_from_strings("x", "1"); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem)); + GRPC_MDELEM_UNREF(elem); r = find_simple(&tbl, "abc", "123"); GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY); @@ -233,8 +237,9 @@ static void test_find(void) { /* overflow the string buffer, check find still works */ for (i = 0; i < 10000; i++) { gpr_ltoa(i, buffer); - grpc_chttp2_hptbl_add(&tbl, - grpc_mdelem_from_strings(mdctx, "test", buffer)); + elem = grpc_mdelem_from_strings("test", buffer); + GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem)); + GRPC_MDELEM_UNREF(elem); } r = find_simple(&tbl, "abc", "123"); @@ -250,7 +255,7 @@ static void test_find(void) { GPR_ASSERT(r.has_value == 1); for (i = 0; i < tbl.num_ents; i++) { - int expect = 9999 - i; + gpr_uint32 expect = 9999 - i; gpr_ltoa(expect, buffer); r = find_simple(&tbl, "test", buffer); @@ -263,13 +268,14 @@ static void test_find(void) { GPR_ASSERT(r.has_value == 0); grpc_chttp2_hptbl_destroy(&tbl); - grpc_mdctx_unref(mdctx); } int main(int argc, char **argv) { grpc_test_init(argc, argv); + grpc_init(); test_static_lookup(); test_many_additions(); test_find(); + grpc_shutdown(); return 0; } diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index 080e86cb63..9c1eae9552 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -35,11 +35,13 @@ #include <stdio.h> -#include "src/core/support/string.h" -#include "src/core/transport/chttp2/bin_encoder.h" +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> + +#include "src/core/support/string.h" +#include "src/core/transport/chttp2/bin_encoder.h" #include "test/core/util/test_config.h" #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) @@ -48,44 +50,39 @@ #define MANY 10000 static void test_no_op(void) { - grpc_mdctx *ctx; - LOG_TEST("test_no_op"); - - ctx = grpc_mdctx_create(); - grpc_mdctx_unref(ctx); + grpc_init(); + grpc_shutdown(); } static void test_create_string(void) { - grpc_mdctx *ctx; grpc_mdstr *s1, *s2, *s3; LOG_TEST("test_create_string"); - ctx = grpc_mdctx_create(); - s1 = grpc_mdstr_from_string(ctx, "hello"); - s2 = grpc_mdstr_from_string(ctx, "hello"); - s3 = grpc_mdstr_from_string(ctx, "very much not hello"); + grpc_init(); + s1 = grpc_mdstr_from_string("hello"); + s2 = grpc_mdstr_from_string("hello"); + s3 = grpc_mdstr_from_string("very much not hello"); GPR_ASSERT(s1 == s2); GPR_ASSERT(s3 != s1); GPR_ASSERT(gpr_slice_str_cmp(s1->slice, "hello") == 0); GPR_ASSERT(gpr_slice_str_cmp(s3->slice, "very much not hello") == 0); GRPC_MDSTR_UNREF(s1); GRPC_MDSTR_UNREF(s2); - grpc_mdctx_unref(ctx); GRPC_MDSTR_UNREF(s3); + grpc_shutdown(); } static void test_create_metadata(void) { - grpc_mdctx *ctx; grpc_mdelem *m1, *m2, *m3; LOG_TEST("test_create_metadata"); - ctx = grpc_mdctx_create(); - m1 = grpc_mdelem_from_strings(ctx, "a", "b"); - m2 = grpc_mdelem_from_strings(ctx, "a", "b"); - m3 = grpc_mdelem_from_strings(ctx, "a", "c"); + grpc_init(); + m1 = grpc_mdelem_from_strings("a", "b"); + m2 = grpc_mdelem_from_strings("a", "b"); + m3 = grpc_mdelem_from_strings("a", "c"); GPR_ASSERT(m1 == m2); GPR_ASSERT(m3 != m1); GPR_ASSERT(m3->key == m1->key); @@ -96,32 +93,25 @@ static void test_create_metadata(void) { GRPC_MDELEM_UNREF(m1); GRPC_MDELEM_UNREF(m2); GRPC_MDELEM_UNREF(m3); - grpc_mdctx_unref(ctx); + grpc_shutdown(); } static void test_create_many_ephemeral_metadata(void) { - grpc_mdctx *ctx; char buffer[GPR_LTOA_MIN_BUFSIZE]; long i; - size_t mdtab_capacity_before; LOG_TEST("test_create_many_ephemeral_metadata"); - ctx = grpc_mdctx_create(); - mdtab_capacity_before = grpc_mdctx_get_mdtab_capacity_test_only(ctx); + grpc_init(); /* add, and immediately delete a bunch of different elements */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - GRPC_MDELEM_UNREF(grpc_mdelem_from_strings(ctx, "a", buffer)); + GRPC_MDELEM_UNREF(grpc_mdelem_from_strings("a", buffer)); } - /* capacity should not grow */ - GPR_ASSERT(mdtab_capacity_before == - grpc_mdctx_get_mdtab_capacity_test_only(ctx)); - grpc_mdctx_unref(ctx); + grpc_shutdown(); } static void test_create_many_persistant_metadata(void) { - grpc_mdctx *ctx; char buffer[GPR_LTOA_MIN_BUFSIZE]; long i; grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY); @@ -129,16 +119,16 @@ static void test_create_many_persistant_metadata(void) { LOG_TEST("test_create_many_persistant_metadata"); - ctx = grpc_mdctx_create(); + grpc_init(); /* add phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - created[i] = grpc_mdelem_from_strings(ctx, "a", buffer); + created[i] = grpc_mdelem_from_strings("a", buffer); } /* verify phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - md = grpc_mdelem_from_strings(ctx, "a", buffer); + md = grpc_mdelem_from_strings("a", buffer); GPR_ASSERT(md == created[i]); GRPC_MDELEM_UNREF(md); } @@ -146,37 +136,22 @@ static void test_create_many_persistant_metadata(void) { for (i = 0; i < MANY; i++) { GRPC_MDELEM_UNREF(created[i]); } - grpc_mdctx_unref(ctx); + grpc_shutdown(); gpr_free(created); } static void test_spin_creating_the_same_thing(void) { - grpc_mdctx *ctx; - LOG_TEST("test_spin_creating_the_same_thing"); - ctx = grpc_mdctx_create(); - GPR_ASSERT(grpc_mdctx_get_mdtab_count_test_only(ctx) == 0); - GPR_ASSERT(grpc_mdctx_get_mdtab_free_test_only(ctx) == 0); - - GRPC_MDELEM_UNREF(grpc_mdelem_from_strings(ctx, "a", "b")); - GPR_ASSERT(grpc_mdctx_get_mdtab_count_test_only(ctx) == 1); - GPR_ASSERT(grpc_mdctx_get_mdtab_free_test_only(ctx) == 1); - - GRPC_MDELEM_UNREF(grpc_mdelem_from_strings(ctx, "a", "b")); - GPR_ASSERT(grpc_mdctx_get_mdtab_count_test_only(ctx) == 1); - GPR_ASSERT(grpc_mdctx_get_mdtab_free_test_only(ctx) == 1); - - GRPC_MDELEM_UNREF(grpc_mdelem_from_strings(ctx, "a", "b")); - GPR_ASSERT(grpc_mdctx_get_mdtab_count_test_only(ctx) == 1); - GPR_ASSERT(grpc_mdctx_get_mdtab_free_test_only(ctx) == 1); - - grpc_mdctx_unref(ctx); + grpc_init(); + GRPC_MDELEM_UNREF(grpc_mdelem_from_strings("a", "b")); + GRPC_MDELEM_UNREF(grpc_mdelem_from_strings("a", "b")); + GRPC_MDELEM_UNREF(grpc_mdelem_from_strings("a", "b")); + grpc_shutdown(); } static void test_things_stick_around(void) { - grpc_mdctx *ctx; size_t i, j; char *buffer; size_t nstrs = 1000; @@ -186,11 +161,11 @@ static void test_things_stick_around(void) { LOG_TEST("test_things_stick_around"); - ctx = grpc_mdctx_create(); + grpc_init(); for (i = 0; i < nstrs; i++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", i); - strs[i] = grpc_mdstr_from_string(ctx, buffer); + strs[i] = grpc_mdstr_from_string(buffer); shuf[i] = i; gpr_free(buffer); } @@ -212,60 +187,58 @@ static void test_things_stick_around(void) { GRPC_MDSTR_UNREF(strs[shuf[i]]); for (j = i + 1; j < nstrs; j++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", shuf[j]); - test = grpc_mdstr_from_string(ctx, buffer); + test = grpc_mdstr_from_string(buffer); GPR_ASSERT(test == strs[shuf[j]]); GRPC_MDSTR_UNREF(test); gpr_free(buffer); } } - grpc_mdctx_unref(ctx); + grpc_shutdown(); gpr_free(strs); gpr_free(shuf); } static void test_slices_work(void) { /* ensure no memory leaks when switching representation from mdstr to slice */ - grpc_mdctx *ctx; grpc_mdstr *str; gpr_slice slice; LOG_TEST("test_slices_work"); - ctx = grpc_mdctx_create(); + grpc_init(); str = grpc_mdstr_from_string( - ctx, "123456789012345678901234567890123456789012345678901234567890"); + "123456789012345678901234567890123456789012345678901234567890"); slice = gpr_slice_ref(str->slice); GRPC_MDSTR_UNREF(str); gpr_slice_unref(slice); str = grpc_mdstr_from_string( - ctx, "123456789012345678901234567890123456789012345678901234567890"); + "123456789012345678901234567890123456789012345678901234567890"); slice = gpr_slice_ref(str->slice); gpr_slice_unref(slice); GRPC_MDSTR_UNREF(str); - grpc_mdctx_unref(ctx); + grpc_shutdown(); } static void test_base64_and_huffman_works(void) { - grpc_mdctx *ctx; grpc_mdstr *str; gpr_slice slice1; gpr_slice slice2; LOG_TEST("test_base64_and_huffman_works"); - ctx = grpc_mdctx_create(); - str = grpc_mdstr_from_string(ctx, "abcdefg"); + grpc_init(); + str = grpc_mdstr_from_string("abcdefg"); slice1 = grpc_mdstr_as_base64_encoded_and_huffman_compressed(str); slice2 = grpc_chttp2_base64_encode_and_huffman_compress(str->slice); GPR_ASSERT(0 == gpr_slice_cmp(slice1, slice2)); gpr_slice_unref(slice2); GRPC_MDSTR_UNREF(str); - grpc_mdctx_unref(ctx); + grpc_shutdown(); } int main(int argc, char **argv) { |