aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/transport
diff options
context:
space:
mode:
authorGravatar Yang Gao <yangg@google.com>2015-01-27 11:39:14 -0800
committerGravatar Yang Gao <yangg@google.com>2015-01-27 11:39:14 -0800
commit3ed874c861765726b0a86ff610988f56e00db4a2 (patch)
tree59cd01424e74d37bdcc89d6c2a9bd3341aa3de81 /test/core/transport
parentd785904d0a0bcd1b8c2a7dee7681131e8f9d3417 (diff)
parent9a9f4051203b4e8f38107d08c39b8a586e6a8dc9 (diff)
sync up with master
Diffstat (limited to 'test/core/transport')
-rw-r--r--test/core/transport/chttp2/hpack_table_test.c21
-rw-r--r--test/core/transport/chttp2/stream_encoder_test.c17
-rw-r--r--test/core/transport/chttp2/timeout_encoding_test.c19
-rw-r--r--test/core/transport/metadata_test.c19
4 files changed, 48 insertions, 28 deletions
diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c
index 1576a30c1b..d155dee9dc 100644
--- a/test/core/transport/chttp2/hpack_table_test.c
+++ b/test/core/transport/chttp2/hpack_table_test.c
@@ -36,6 +36,7 @@
#include <string.h>
#include <stdio.h>
+#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
@@ -131,8 +132,8 @@ static void test_static_lookup(void) {
static void test_many_additions(void) {
grpc_chttp2_hptbl tbl;
int i;
- char key[32];
- char value[32];
+ char *key;
+ char *value;
grpc_mdctx *mdctx;
LOG_TEST();
@@ -141,14 +142,18 @@ static void test_many_additions(void) {
grpc_chttp2_hptbl_init(&tbl, mdctx);
for (i = 0; i < 1000000; i++) {
- sprintf(key, "K:%d", i);
- sprintf(value, "VALUE:%d", i);
+ gpr_asprintf(&key, "K:%d", i);
+ gpr_asprintf(&value, "VALUE:%d", i);
grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, key, value));
assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value);
+ gpr_free(key);
+ gpr_free(value);
if (i) {
- sprintf(key, "K:%d", i - 1);
- sprintf(value, "VALUE:%d", i - 1);
+ gpr_asprintf(&key, "K:%d", i - 1);
+ gpr_asprintf(&value, "VALUE:%d", i - 1);
assert_index(&tbl, 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value);
+ gpr_free(key);
+ gpr_free(value);
}
}
@@ -226,7 +231,7 @@ static void test_find(void) {
/* overflow the string buffer, check find still works */
for (i = 0; i < 10000; i++) {
- sprintf(buffer, "%d", i);
+ gpr_ltoa(i, buffer);
grpc_chttp2_hptbl_add(&tbl,
grpc_mdelem_from_strings(mdctx, "test", buffer));
}
@@ -245,7 +250,7 @@ static void test_find(void) {
for (i = 0; i < tbl.num_ents; i++) {
int expect = 9999 - i;
- sprintf(buffer, "%d", expect);
+ gpr_ltoa(expect, buffer);
r = find_simple(&tbl, "test", buffer);
GPR_ASSERT(r.index == i + 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c
index eb0f688f58..5e8ec0a1af 100644
--- a/test/core/transport/chttp2/stream_encoder_test.c
+++ b/test/core/transport/chttp2/stream_encoder_test.c
@@ -186,7 +186,7 @@ static void encode_int_to_str(int i, char *p) {
static void test_decode_table_overflow(void) {
int i;
char key[3], value[3];
- char expect[128];
+ char *expect;
for (i = 0; i < 114; i++) {
if (i > 0) {
@@ -197,18 +197,21 @@ static void test_decode_table_overflow(void) {
encode_int_to_str(i + 1, value);
if (i + 61 >= 127) {
- sprintf(expect, "000009 0104 deadbeef ff%02x 40 02%02x%02x 02%02x%02x",
- i + 61 - 127, key[0], key[1], value[0], value[1]);
+ gpr_asprintf(&expect,
+ "000009 0104 deadbeef ff%02x 40 02%02x%02x 02%02x%02x",
+ i + 61 - 127, key[0], key[1], value[0], value[1]);
} else if (i > 0) {
- sprintf(expect, "000008 0104 deadbeef %02x 40 02%02x%02x 02%02x%02x",
- 0x80 + 61 + i, key[0], key[1], value[0], value[1]);
+ gpr_asprintf(&expect,
+ "000008 0104 deadbeef %02x 40 02%02x%02x 02%02x%02x",
+ 0x80 + 61 + i, key[0], key[1], value[0], value[1]);
} else {
- sprintf(expect, "000007 0104 deadbeef 40 02%02x%02x 02%02x%02x", key[0],
- key[1], value[0], value[1]);
+ gpr_asprintf(&expect, "000007 0104 deadbeef 40 02%02x%02x 02%02x%02x",
+ key[0], key[1], value[0], value[1]);
}
add_sopb_header(key, value);
verify_sopb(0, 0, 0, expect);
+ gpr_free(expect);
}
/* if the above passes, then we must have just knocked this pair out of the
diff --git a/test/core/transport/chttp2/timeout_encoding_test.c b/test/core/transport/chttp2/timeout_encoding_test.c
index ffa0070e34..0ad90dbcef 100644
--- a/test/core/transport/chttp2/timeout_encoding_test.c
+++ b/test/core/transport/chttp2/timeout_encoding_test.c
@@ -36,6 +36,8 @@
#include <stdio.h>
#include <string.h>
+#include "src/core/support/string.h"
+#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/useful.h>
#include "test/core/util/test_config.h"
@@ -93,16 +95,23 @@ void decode_suite(char ext, gpr_timespec (*answer)(long x)) {
1234567, 12345678, 123456789, 98765432, 9876543, 987654,
98765, 9876, 987, 98, 9};
int i;
- char input[32];
+ char *input;
for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) {
- sprintf(input, "%ld%c", test_vals[i], ext);
+ gpr_asprintf(&input, "%ld%c", test_vals[i], ext);
assert_decodes_as(input, answer(test_vals[i]));
- sprintf(input, " %ld%c", test_vals[i], ext);
+ gpr_free(input);
+
+ gpr_asprintf(&input, " %ld%c", test_vals[i], ext);
assert_decodes_as(input, answer(test_vals[i]));
- sprintf(input, "%ld %c", test_vals[i], ext);
+ gpr_free(input);
+
+ gpr_asprintf(&input, "%ld %c", test_vals[i], ext);
assert_decodes_as(input, answer(test_vals[i]));
- sprintf(input, "%ld %c ", test_vals[i], ext);
+ gpr_free(input);
+
+ gpr_asprintf(&input, "%ld %c ", test_vals[i], ext);
assert_decodes_as(input, answer(test_vals[i]));
+ gpr_free(input);
}
}
diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c
index 804096d0e1..b23db894be 100644
--- a/test/core/transport/metadata_test.c
+++ b/test/core/transport/metadata_test.c
@@ -35,6 +35,7 @@
#include <stdio.h>
+#include "src/core/support/string.h"
#include "src/core/transport/chttp2/bin_encoder.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@@ -99,7 +100,7 @@ static void test_create_metadata(void) {
static void test_create_many_ephemeral_metadata(void) {
grpc_mdctx *ctx;
- char buffer[256];
+ char buffer[GPR_LTOA_MIN_BUFSIZE];
long i;
size_t mdtab_capacity_before;
@@ -109,7 +110,7 @@ static void test_create_many_ephemeral_metadata(void) {
mdtab_capacity_before = grpc_mdctx_get_mdtab_capacity_test_only(ctx);
/* add, and immediately delete a bunch of different elements */
for (i = 0; i < MANY; i++) {
- sprintf(buffer, "%ld", i);
+ gpr_ltoa(i, buffer);
grpc_mdelem_unref(grpc_mdelem_from_strings(ctx, "a", buffer));
}
/* capacity should not grow */
@@ -120,7 +121,7 @@ static void test_create_many_ephemeral_metadata(void) {
static void test_create_many_persistant_metadata(void) {
grpc_mdctx *ctx;
- char buffer[256];
+ char buffer[GPR_LTOA_MIN_BUFSIZE];
long i;
grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY);
grpc_mdelem *md;
@@ -130,12 +131,12 @@ static void test_create_many_persistant_metadata(void) {
ctx = grpc_mdctx_create();
/* add phase */
for (i = 0; i < MANY; i++) {
- sprintf(buffer, "%ld", i);
+ gpr_ltoa(i, buffer);
created[i] = grpc_mdelem_from_strings(ctx, "a", buffer);
}
/* verify phase */
for (i = 0; i < MANY; i++) {
- sprintf(buffer, "%ld", i);
+ gpr_ltoa(i, buffer);
md = grpc_mdelem_from_strings(ctx, "a", buffer);
GPR_ASSERT(md == created[i]);
grpc_mdelem_unref(md);
@@ -176,7 +177,7 @@ static void test_spin_creating_the_same_thing(void) {
static void test_things_stick_around(void) {
grpc_mdctx *ctx;
int i, j;
- char buffer[64];
+ char *buffer;
int nstrs = 10000;
grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs);
int *shuf = gpr_malloc(sizeof(int) * nstrs);
@@ -187,9 +188,10 @@ static void test_things_stick_around(void) {
ctx = grpc_mdctx_create();
for (i = 0; i < nstrs; i++) {
- sprintf(buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", i);
+ gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", i);
strs[i] = grpc_mdstr_from_string(ctx, buffer);
shuf[i] = i;
+ gpr_free(buffer);
}
for (i = 0; i < nstrs; i++) {
@@ -208,10 +210,11 @@ static void test_things_stick_around(void) {
for (i = 0; i < nstrs; i++) {
grpc_mdstr_unref(strs[shuf[i]]);
for (j = i + 1; j < nstrs; j++) {
- sprintf(buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", shuf[j]);
+ gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", shuf[j]);
test = grpc_mdstr_from_string(ctx, buffer);
GPR_ASSERT(test == strs[shuf[j]]);
grpc_mdstr_unref(test);
+ gpr_free(buffer);
}
}