Merge branch 'test-printf' into bprintf

pull/188/head
Craig Tiller 10 years ago
commit 9dd49e664c
  1. 9
      test/core/channel/metadata_buffer_test.c
  2. 125
      test/core/end2end/cq_verifier.c
  3. 6
      test/core/end2end/tests/census_simple_request.c
  4. 6
      test/core/end2end/tests/simple_request.c
  5. 6
      test/core/security/credentials_test.c
  6. 7
      test/core/statistics/hash_table_test.c
  7. 21
      test/core/transport/chttp2/hpack_table_test.c
  8. 17
      test/core/transport/chttp2/stream_encoder_test.c
  9. 19
      test/core/transport/chttp2/timeout_encoding_test.c
  10. 19
      test/core/transport/metadata_test.c

@ -32,6 +32,7 @@
*/ */
#include "src/core/channel/metadata_buffer.h" #include "src/core/channel/metadata_buffer.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
@ -42,12 +43,12 @@
/* construct a buffer with some prefix followed by an integer converted to /* construct a buffer with some prefix followed by an integer converted to
a string */ a string */
static gpr_slice construct_buffer(size_t prefix_length, size_t index) { static gpr_slice construct_buffer(size_t prefix_length, size_t index) {
gpr_slice buffer = gpr_slice_malloc(prefix_length + 32); gpr_slice buffer = gpr_slice_malloc(prefix_length + GPR_LTOA_MIN_BUFSIZE);
memset(GPR_SLICE_START_PTR(buffer), 'a', prefix_length); memset(GPR_SLICE_START_PTR(buffer), 'a', prefix_length);
GPR_SLICE_SET_LENGTH( GPR_SLICE_SET_LENGTH(
buffer, prefix_length + buffer,
sprintf((char *)GPR_SLICE_START_PTR(buffer) + prefix_length, prefix_length +
"%d", (int)index)); gpr_ltoa(index, (char *)GPR_SLICE_START_PTR(buffer) + prefix_length));
return buffer; return buffer;
} }

@ -231,100 +231,92 @@ static void verify_matches(expectation *e, grpc_event *ev) {
} }
} }
static char *metadata_expectation_string(metadata *md) { static void metadata_expectation(gpr_strvec *buf, metadata *md) {
size_t len;
size_t i; size_t i;
char *out; char *tmp;
char *p;
if (!md) {
if (!md) return gpr_strdup("nil"); gpr_strvec_add(buf, gpr_strdup("nil"));
} else {
for (len = 0, i = 0; i < md->count; i++) { for (i = 0; i < md->count; i++) {
len += strlen(md->keys[i]); gpr_asprintf(&tmp, "%c%s:%s", i ? ',' : '{', md->keys[i], md->values[i]);
len += strlen(md->values[i]); gpr_strvec_add(buf, tmp);
} }
len += 3 + md->count; gpr_strvec_add(buf, gpr_strdup("}"));
p = out = gpr_malloc(len);
*p++ = '{';
for (i = 0; i < md->count; i++) {
if (i) *p++ = ',';
p += sprintf(p, "%s:%s", md->keys[i], md->values[i]);
} }
*p++ = '}';
*p++ = 0;
return out;
} }
static size_t expectation_to_string(char *out, expectation *e) { static void expectation_to_strvec(gpr_strvec *buf, expectation *e) {
gpr_timespec timeout; gpr_timespec timeout;
char *str = NULL; char *tmp;
size_t len;
switch (e->type) { switch (e->type) {
case GRPC_FINISH_ACCEPTED: case GRPC_FINISH_ACCEPTED:
return sprintf(out, "GRPC_FINISH_ACCEPTED result=%d", gpr_asprintf(&tmp, "GRPC_FINISH_ACCEPTED result=%d",
e->data.finish_accepted); e->data.finish_accepted);
gpr_strvec_add(buf, tmp);
break;
case GRPC_WRITE_ACCEPTED: case GRPC_WRITE_ACCEPTED:
return sprintf(out, "GRPC_WRITE_ACCEPTED result=%d", gpr_asprintf(&tmp, "GRPC_WRITE_ACCEPTED result=%d",
e->data.write_accepted); e->data.write_accepted);
gpr_strvec_add(buf, tmp);
break;
case GRPC_INVOKE_ACCEPTED: case GRPC_INVOKE_ACCEPTED:
return sprintf(out, "GRPC_INVOKE_ACCEPTED"); gpr_strvec_add(buf, gpr_strdup("GRPC_INVOKE_ACCEPTED"));
break;
case GRPC_SERVER_RPC_NEW: case GRPC_SERVER_RPC_NEW:
timeout = gpr_time_sub(e->data.server_rpc_new.deadline, gpr_now()); timeout = gpr_time_sub(e->data.server_rpc_new.deadline, gpr_now());
return sprintf(out, "GRPC_SERVER_RPC_NEW method=%s host=%s timeout=%fsec", gpr_asprintf(&tmp, "GRPC_SERVER_RPC_NEW method=%s host=%s timeout=%fsec",
e->data.server_rpc_new.method, e->data.server_rpc_new.host, e->data.server_rpc_new.method, e->data.server_rpc_new.host,
timeout.tv_sec + 1e-9 * timeout.tv_nsec); timeout.tv_sec + 1e-9 * timeout.tv_nsec);
gpr_strvec_add(buf, tmp);
break;
case GRPC_CLIENT_METADATA_READ: case GRPC_CLIENT_METADATA_READ:
str = metadata_expectation_string(e->data.client_metadata_read); gpr_strvec_add(buf, gpr_strdup("GRPC_CLIENT_METADATA_READ "));
len = sprintf(out, "GRPC_CLIENT_METADATA_READ %s", str); metadata_expectation(buf, e->data.client_metadata_read);
gpr_free(str); break;
return len;
case GRPC_FINISHED: case GRPC_FINISHED:
str = metadata_expectation_string(e->data.finished.metadata); gpr_asprintf(&tmp, "GRPC_FINISHED status=%d details=%s ",
len = sprintf(out, "GRPC_FINISHED status=%d details=%s %s", e->data.finished.status, e->data.finished.details);
e->data.finished.status, e->data.finished.details, str); gpr_strvec_add(buf, tmp);
gpr_free(str); metadata_expectation(buf, e->data.finished.metadata);
return len; break;
case GRPC_READ: case GRPC_READ:
if (e->data.read) { gpr_strvec_add(buf, gpr_strdup("GRPC_READ data="));
str = gpr_strvec_add(buf, gpr_hexdump((char *)GPR_SLICE_START_PTR(*e->data.read),
gpr_hexdump((char *)GPR_SLICE_START_PTR(*e->data.read), GPR_SLICE_LENGTH(*e->data.read), GPR_HEXDUMP_PLAINTEXT));
GPR_SLICE_LENGTH(*e->data.read), GPR_HEXDUMP_PLAINTEXT); break;
}
len = sprintf(out, "GRPC_READ data=%s", str);
gpr_free(str);
return len;
case GRPC_SERVER_SHUTDOWN: case GRPC_SERVER_SHUTDOWN:
return sprintf(out, "GRPC_SERVER_SHUTDOWN"); gpr_strvec_add(buf, gpr_strdup("GRPC_SERVER_SHUTDOWN"));
break;
case GRPC_COMPLETION_DO_NOT_USE: case GRPC_COMPLETION_DO_NOT_USE:
case GRPC_QUEUE_SHUTDOWN: case GRPC_QUEUE_SHUTDOWN:
gpr_log(GPR_ERROR, "not implemented"); gpr_log(GPR_ERROR, "not implemented");
abort(); abort();
break; break;
} }
return 0;
} }
static char *expectations_to_string(cq_verifier *v) { static void expectations_to_strvec(gpr_strvec *buf, cq_verifier *v) {
/* allocate a large buffer: we're about to crash anyway */ /* allocate a large buffer: we're about to crash anyway */
char *buffer = gpr_malloc(32 * 1024 * 1024);
char *p = buffer;
expectation *e; expectation *e;
for (e = v->expect.next; e != &v->expect; e = e->next) { for (e = v->expect.next; e != &v->expect; e = e->next) {
p += expectation_to_string(p, e); expectation_to_strvec(buf, e);
*p++ = '\n'; gpr_strvec_add(buf, gpr_strdup("\n"));
} }
*p = 0;
return buffer;
} }
static void fail_no_event_received(cq_verifier *v) { static void fail_no_event_received(cq_verifier *v) {
char *expectations = expectations_to_string(v); gpr_strvec buf;
gpr_log(GPR_ERROR, "no event received, but expected:\n%s", expectations); char *msg;
gpr_free(expectations); gpr_strvec_init(&buf);
gpr_strvec_add(&buf, gpr_strdup("no event received, but expected:\n"));
expectations_to_strvec(&buf, v);
msg = gpr_strvec_flatten(&buf, NULL);
gpr_log(GPR_ERROR, "%s", msg);
gpr_strvec_destroy(&buf);
gpr_free(msg);
abort(); abort();
} }
@ -333,9 +325,10 @@ void cq_verify(cq_verifier *v) {
gpr_time_add(gpr_now(), gpr_time_from_micros(10 * GPR_US_PER_SEC)); gpr_time_add(gpr_now(), gpr_time_from_micros(10 * GPR_US_PER_SEC));
grpc_event *ev; grpc_event *ev;
expectation *e; expectation *e;
char *s;
gpr_strvec have_tags;
char have_tags[512] = {0}; gpr_strvec_init(&have_tags);
char *phave = have_tags;
while (v->expect.next != &v->expect) { while (v->expect.next != &v->expect) {
ev = grpc_completion_queue_next(v->cq, deadline); ev = grpc_completion_queue_next(v->cq, deadline);
@ -344,7 +337,8 @@ void cq_verify(cq_verifier *v) {
} }
for (e = v->expect.next; e != &v->expect; e = e->next) { for (e = v->expect.next; e != &v->expect; e = e->next) {
phave += sprintf(phave, " %p", e->tag); gpr_asprintf(&s, " %p", e->tag);
gpr_strvec_add(&have_tags, s);
if (e->tag == ev->tag) { if (e->tag == ev->tag) {
verify_matches(e, ev); verify_matches(e, ev);
e->next->prev = e->prev; e->next->prev = e->prev;
@ -354,15 +348,20 @@ void cq_verify(cq_verifier *v) {
} }
} }
if (e == &v->expect) { if (e == &v->expect) {
char *s = grpc_event_string(ev); s = grpc_event_string(ev);
gpr_log(GPR_ERROR, "event not found: %s", s); gpr_log(GPR_ERROR, "event not found: %s", s);
gpr_log(GPR_ERROR, "have tags:%s", have_tags);
gpr_free(s); gpr_free(s);
s = gpr_strvec_flatten(&have_tags, NULL);
gpr_log(GPR_ERROR, "have tags:%s", s);
gpr_free(s);
gpr_strvec_destroy(&have_tags);
abort(); abort();
} }
grpc_event_finish(ev); grpc_event_finish(ev);
} }
gpr_strvec_destroy(&have_tags);
} }
void cq_verify_empty(cq_verifier *v) { void cq_verify_empty(cq_verifier *v) {

@ -37,6 +37,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "src/core/support/string.h"
#include <grpc/byte_buffer.h> #include <grpc/byte_buffer.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
@ -145,7 +146,7 @@ static void test_body(grpc_end2end_test_fixture f) {
static void test_invoke_request_with_census( static void test_invoke_request_with_census(
grpc_end2end_test_config config, const char *name, grpc_end2end_test_config config, const char *name,
void (*body)(grpc_end2end_test_fixture f)) { void (*body)(grpc_end2end_test_fixture f)) {
char fullname[64]; char *fullname;
grpc_end2end_test_fixture f; grpc_end2end_test_fixture f;
grpc_arg client_arg, server_arg; grpc_arg client_arg, server_arg;
grpc_channel_args client_args, server_args; grpc_channel_args client_args, server_args;
@ -163,11 +164,12 @@ static void test_invoke_request_with_census(
server_args.num_args = 1; server_args.num_args = 1;
server_args.args = &server_arg; server_args.args = &server_arg;
sprintf(fullname, "%s/%s", __FUNCTION__, name); gpr_asprintf(&fullname, "%s/%s", __FUNCTION__, name);
f = begin_test(config, fullname, &client_args, &server_args); f = begin_test(config, fullname, &client_args, &server_args);
body(f); body(f);
end_test(&f); end_test(&f);
config.tear_down_data(&f); config.tear_down_data(&f);
gpr_free(fullname);
} }
void grpc_end2end_tests(grpc_end2end_test_config config) { void grpc_end2end_tests(grpc_end2end_test_config config) {

@ -37,6 +37,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "src/core/support/string.h"
#include <grpc/byte_buffer.h> #include <grpc/byte_buffer.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
@ -198,15 +199,16 @@ static void simple_request_body2(grpc_end2end_test_fixture f) {
static void test_invoke_simple_request( static void test_invoke_simple_request(
grpc_end2end_test_config config, const char *name, grpc_end2end_test_config config, const char *name,
void (*body)(grpc_end2end_test_fixture f)) { void (*body)(grpc_end2end_test_fixture f)) {
char fullname[64]; char *fullname;
grpc_end2end_test_fixture f; grpc_end2end_test_fixture f;
sprintf(fullname, "%s/%s", __FUNCTION__, name); gpr_asprintf(&fullname, "%s/%s", __FUNCTION__, name);
f = begin_test(config, fullname, NULL, NULL); f = begin_test(config, fullname, NULL, NULL);
body(f); body(f);
end_test(&f); end_test(&f);
config.tear_down_data(&f); config.tear_down_data(&f);
gpr_free(fullname);
} }
static void test_invoke_10_simple_requests(grpc_end2end_test_config config) { static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {

@ -498,10 +498,8 @@ static void validate_service_account_http_request(
char *expected_body = NULL; char *expected_body = NULL;
GPR_ASSERT(body != NULL); GPR_ASSERT(body != NULL);
GPR_ASSERT(body_size != 0); GPR_ASSERT(body_size != 0);
expected_body = gpr_malloc(strlen(expected_service_account_http_body_prefix) + gpr_asprintf(&expected_body, "%s%s",
strlen(test_signed_jwt) + 1); expected_service_account_http_body_prefix, test_signed_jwt);
sprintf(expected_body, "%s%s", expected_service_account_http_body_prefix,
test_signed_jwt);
GPR_ASSERT(strlen(expected_body) == body_size); GPR_ASSERT(strlen(expected_body) == body_size);
GPR_ASSERT(!memcmp(expected_body, body, body_size)); GPR_ASSERT(!memcmp(expected_body, body, body_size));
gpr_free(expected_body); gpr_free(expected_body);

@ -38,6 +38,7 @@
#include "src/core/statistics/hash_table.h" #include "src/core/statistics/hash_table.h"
#include "src/core/support/murmur_hash.h" #include "src/core/support/murmur_hash.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
@ -187,15 +188,15 @@ static void test_insertion_and_deletion_with_high_collision_rate(void) {
census_ht_option opt = {CENSUS_HT_POINTER, 13, &force_collision, census_ht_option opt = {CENSUS_HT_POINTER, 13, &force_collision,
&cmp_str_keys, NULL, NULL}; &cmp_str_keys, NULL, NULL};
census_ht* ht = census_ht_create(&opt); census_ht* ht = census_ht_create(&opt);
char key_str[1000][10]; char key_str[1000][GPR_LTOA_MIN_BUFSIZE];
gpr_uint64 val = 0; gpr_uint64 val = 0;
int i = 0; int i = 0;
for (i = 0; i < 1000; i++) { for (i = 0; i < 1000; i++) {
census_ht_key key; census_ht_key key;
key.ptr = key_str[i]; key.ptr = key_str[i];
sprintf(key_str[i], "%d", i); gpr_ltoa(i, key_str[i]);
census_ht_insert(ht, key, (void*)(&val)); census_ht_insert(ht, key, (void*)(&val));
printf("%d\n", i); gpr_log(GPR_INFO, "%d\n", i);
GPR_ASSERT(census_ht_get_size(ht) == (i + 1)); GPR_ASSERT(census_ht_get_size(ht) == (i + 1));
} }
for (i = 0; i < 1000; i++) { for (i = 0; i < 1000; i++) {

@ -36,6 +36,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
@ -131,8 +132,8 @@ static void test_static_lookup(void) {
static void test_many_additions(void) { static void test_many_additions(void) {
grpc_chttp2_hptbl tbl; grpc_chttp2_hptbl tbl;
int i; int i;
char key[32]; char *key;
char value[32]; char *value;
grpc_mdctx *mdctx; grpc_mdctx *mdctx;
LOG_TEST(); LOG_TEST();
@ -141,14 +142,18 @@ static void test_many_additions(void) {
grpc_chttp2_hptbl_init(&tbl, mdctx); grpc_chttp2_hptbl_init(&tbl, mdctx);
for (i = 0; i < 1000000; i++) { for (i = 0; i < 1000000; i++) {
sprintf(key, "K:%d", i); gpr_asprintf(&key, "K:%d", i);
sprintf(value, "VALUE:%d", i); gpr_asprintf(&value, "VALUE:%d", i);
grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, key, value)); grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, key, value));
assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value);
gpr_free(key);
gpr_free(value);
if (i) { if (i) {
sprintf(key, "K:%d", i - 1); gpr_asprintf(&key, "K:%d", i - 1);
sprintf(value, "VALUE:%d", i - 1); gpr_asprintf(&value, "VALUE:%d", i - 1);
assert_index(&tbl, 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); 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 */ /* overflow the string buffer, check find still works */
for (i = 0; i < 10000; i++) { for (i = 0; i < 10000; i++) {
sprintf(buffer, "%d", i); gpr_ltoa(i, buffer);
grpc_chttp2_hptbl_add(&tbl, grpc_chttp2_hptbl_add(&tbl,
grpc_mdelem_from_strings(mdctx, "test", buffer)); grpc_mdelem_from_strings(mdctx, "test", buffer));
} }
@ -245,7 +250,7 @@ static void test_find(void) {
for (i = 0; i < tbl.num_ents; i++) { for (i = 0; i < tbl.num_ents; i++) {
int expect = 9999 - i; int expect = 9999 - i;
sprintf(buffer, "%d", expect); gpr_ltoa(expect, buffer);
r = find_simple(&tbl, "test", buffer); r = find_simple(&tbl, "test", buffer);
GPR_ASSERT(r.index == i + 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY); GPR_ASSERT(r.index == i + 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY);

@ -186,7 +186,7 @@ static void encode_int_to_str(int i, char *p) {
static void test_decode_table_overflow(void) { static void test_decode_table_overflow(void) {
int i; int i;
char key[3], value[3]; char key[3], value[3];
char expect[128]; char *expect;
for (i = 0; i < 114; i++) { for (i = 0; i < 114; i++) {
if (i > 0) { if (i > 0) {
@ -197,18 +197,21 @@ static void test_decode_table_overflow(void) {
encode_int_to_str(i + 1, value); encode_int_to_str(i + 1, value);
if (i + 61 >= 127) { if (i + 61 >= 127) {
sprintf(expect, "000009 0104 deadbeef ff%02x 40 02%02x%02x 02%02x%02x", gpr_asprintf(&expect,
i + 61 - 127, key[0], key[1], value[0], value[1]); "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) { } else if (i > 0) {
sprintf(expect, "000008 0104 deadbeef %02x 40 02%02x%02x 02%02x%02x", gpr_asprintf(&expect,
0x80 + 61 + i, key[0], key[1], value[0], value[1]); "000008 0104 deadbeef %02x 40 02%02x%02x 02%02x%02x",
0x80 + 61 + i, key[0], key[1], value[0], value[1]);
} else { } else {
sprintf(expect, "000007 0104 deadbeef 40 02%02x%02x 02%02x%02x", key[0], gpr_asprintf(&expect, "000007 0104 deadbeef 40 02%02x%02x 02%02x%02x",
key[1], value[0], value[1]); key[0], key[1], value[0], value[1]);
} }
add_sopb_header(key, value); add_sopb_header(key, value);
verify_sopb(0, 0, 0, expect); verify_sopb(0, 0, 0, expect);
gpr_free(expect);
} }
/* if the above passes, then we must have just knocked this pair out of the /* if the above passes, then we must have just knocked this pair out of the

@ -36,6 +36,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/useful.h> #include <grpc/support/useful.h>
#include "test/core/util/test_config.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, 1234567, 12345678, 123456789, 98765432, 9876543, 987654,
98765, 9876, 987, 98, 9}; 98765, 9876, 987, 98, 9};
int i; int i;
char input[32]; char *input;
for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) { 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])); 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])); 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])); 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])); assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
} }
} }

@ -35,6 +35,7 @@
#include <stdio.h> #include <stdio.h>
#include "src/core/support/string.h"
#include "src/core/transport/chttp2/bin_encoder.h" #include "src/core/transport/chttp2/bin_encoder.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
@ -99,7 +100,7 @@ static void test_create_metadata(void) {
static void test_create_many_ephemeral_metadata(void) { static void test_create_many_ephemeral_metadata(void) {
grpc_mdctx *ctx; grpc_mdctx *ctx;
char buffer[256]; char buffer[GPR_LTOA_MIN_BUFSIZE];
long i; long i;
size_t mdtab_capacity_before; 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); mdtab_capacity_before = grpc_mdctx_get_mdtab_capacity_test_only(ctx);
/* add, and immediately delete a bunch of different elements */ /* add, and immediately delete a bunch of different elements */
for (i = 0; i < MANY; i++) { for (i = 0; i < MANY; i++) {
sprintf(buffer, "%ld", i); gpr_ltoa(i, buffer);
grpc_mdelem_unref(grpc_mdelem_from_strings(ctx, "a", buffer)); grpc_mdelem_unref(grpc_mdelem_from_strings(ctx, "a", buffer));
} }
/* capacity should not grow */ /* capacity should not grow */
@ -120,7 +121,7 @@ static void test_create_many_ephemeral_metadata(void) {
static void test_create_many_persistant_metadata(void) { static void test_create_many_persistant_metadata(void) {
grpc_mdctx *ctx; grpc_mdctx *ctx;
char buffer[256]; char buffer[GPR_LTOA_MIN_BUFSIZE];
long i; long i;
grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY); grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY);
grpc_mdelem *md; grpc_mdelem *md;
@ -130,12 +131,12 @@ static void test_create_many_persistant_metadata(void) {
ctx = grpc_mdctx_create(); ctx = grpc_mdctx_create();
/* add phase */ /* add phase */
for (i = 0; i < MANY; i++) { for (i = 0; i < MANY; i++) {
sprintf(buffer, "%ld", i); gpr_ltoa(i, buffer);
created[i] = grpc_mdelem_from_strings(ctx, "a", buffer); created[i] = grpc_mdelem_from_strings(ctx, "a", buffer);
} }
/* verify phase */ /* verify phase */
for (i = 0; i < MANY; i++) { for (i = 0; i < MANY; i++) {
sprintf(buffer, "%ld", i); gpr_ltoa(i, buffer);
md = grpc_mdelem_from_strings(ctx, "a", buffer); md = grpc_mdelem_from_strings(ctx, "a", buffer);
GPR_ASSERT(md == created[i]); GPR_ASSERT(md == created[i]);
grpc_mdelem_unref(md); grpc_mdelem_unref(md);
@ -176,7 +177,7 @@ static void test_spin_creating_the_same_thing(void) {
static void test_things_stick_around(void) { static void test_things_stick_around(void) {
grpc_mdctx *ctx; grpc_mdctx *ctx;
int i, j; int i, j;
char buffer[64]; char *buffer;
int nstrs = 10000; int nstrs = 10000;
grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs); grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs);
int *shuf = gpr_malloc(sizeof(int) * nstrs); int *shuf = gpr_malloc(sizeof(int) * nstrs);
@ -187,9 +188,10 @@ static void test_things_stick_around(void) {
ctx = grpc_mdctx_create(); ctx = grpc_mdctx_create();
for (i = 0; i < nstrs; i++) { 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); strs[i] = grpc_mdstr_from_string(ctx, buffer);
shuf[i] = i; shuf[i] = i;
gpr_free(buffer);
} }
for (i = 0; i < nstrs; i++) { for (i = 0; i < nstrs; i++) {
@ -208,10 +210,11 @@ static void test_things_stick_around(void) {
for (i = 0; i < nstrs; i++) { for (i = 0; i < nstrs; i++) {
grpc_mdstr_unref(strs[shuf[i]]); grpc_mdstr_unref(strs[shuf[i]]);
for (j = i + 1; j < nstrs; j++) { 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); test = grpc_mdstr_from_string(ctx, buffer);
GPR_ASSERT(test == strs[shuf[j]]); GPR_ASSERT(test == strs[shuf[j]]);
grpc_mdstr_unref(test); grpc_mdstr_unref(test);
gpr_free(buffer);
} }
} }

Loading…
Cancel
Save