diff options
author | Alistair Veitch <aveitch@google.com> | 2016-02-02 09:43:02 -0800 |
---|---|---|
committer | Alistair Veitch <aveitch@google.com> | 2016-02-02 09:43:02 -0800 |
commit | 75d5c0f024438944425cf1bd3163b07c6f6e55b5 (patch) | |
tree | 8130c65c6e654bc42187342cb3d8004379422dfa /test/core | |
parent | 7c43f4909242b62881389c7d4cfc9541c70151b6 (diff) |
post merge
Diffstat (limited to 'test/core')
29 files changed, 302 insertions, 222 deletions
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c index 832570a81d..1a2ca6f0c0 100644 --- a/test/core/bad_client/bad_client.c +++ b/test/core/bad_client/bad_client.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -60,7 +60,7 @@ static void thd_func(void *arg) { gpr_event_set(&a->done_thd, (void *)1); } -static void done_write(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void done_write(grpc_exec_ctx *exec_ctx, void *arg, bool success) { thd_args *a = arg; gpr_event_set(&a->done_write, (void *)1); } diff --git a/test/core/census/tag_set_test.c b/test/core/census/context_test.c index 1056e98d55..63e7103ddc 100644 --- a/test/core/census/tag_set_test.c +++ b/test/core/census/context_test.c @@ -31,7 +31,7 @@ * */ -// Test census_tag_set functions, including encoding/decoding +// Test census_context functions, including encoding/decoding #include <grpc/census.h> #include <grpc/support/log.h> @@ -46,7 +46,7 @@ static uint8_t one_byte_val = 7; static uint32_t four_byte_val = 0x12345678; static uint64_t eight_byte_val = 0x1234567890abcdef; -// A set of tags Used to create a basic tag_set for testing. Each tag has a +// A set of tags Used to create a basic context for testing. Each tag has a // unique set of flags. Note that replace_add_delete_test() relies on specific // offsets into this array - if you add or delete entries, you will also need // to change the test. @@ -65,7 +65,7 @@ static census_tag basic_tags[BASIC_TAG_COUNT] = { /* 7 */ {"k7", (char *)&four_byte_val, 4, CENSUS_TAG_PROPAGATE | CENSUS_TAG_STATS | CENSUS_TAG_BINARY}}; -// Set of tags used to modify the basic tag_set. Note that +// Set of tags used to modify the basic context. Note that // replace_add_delete_test() relies on specific offsets into this array - if // you add or delete entries, you will also need to change the test. Other // tests that rely on specific instances have XXX_XXX_OFFSET definitions (also @@ -99,35 +99,34 @@ static bool compare_tag(const census_tag *t1, const census_tag *t2) { t1->flags == t2->flags); } -// Utility function to validate a tag exists in tag set. -static bool validate_tag(const census_tag_set *cts, const census_tag *tag) { +// Utility function to validate a tag exists in context. +static bool validate_tag(const census_context *context, const census_tag *tag) { census_tag tag2; - if (census_tag_set_get_tag_by_key(cts, tag->key, &tag2) != 1) return false; + if (census_context_get_tag(context, tag->key, &tag2) != 1) return false; return compare_tag(tag, &tag2); } -// Create an empty tag_set. +// Create an empty context. static void empty_test(void) { - struct census_tag_set *cts = census_tag_set_create(NULL, NULL, 0, NULL); - GPR_ASSERT(cts != NULL); - const census_tag_set_create_status *status = - census_tag_set_get_create_status(cts); - census_tag_set_create_status expected = {0, 0, 0, 0, 0, 0, 0, 0}; + struct census_context *context = census_context_create(NULL, NULL, 0, NULL); + GPR_ASSERT(context != NULL); + const census_context_status *status = census_context_get_status(context); + census_context_status expected = {0, 0, 0, 0, 0, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag_set_destroy(cts); + census_context_destroy(context); } -// Test create and iteration over basic tag set. +// Test create and iteration over basic context. static void basic_test(void) { - const census_tag_set_create_status *status; - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, &status); - census_tag_set_create_status expected = {2, 2, 4, 0, 8, 0, 0, 0}; + const census_context_status *status; + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, &status); + census_context_status expected = {2, 2, 4, 0, 8, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag_set_iterator it; - census_tag_set_initialize_iterator(cts, &it); + census_context_iterator it; + census_context_initialize_iterator(context, &it); census_tag tag; - while (census_tag_set_next_tag(&it, &tag)) { + while (census_context_next_tag(&it, &tag)) { // can't rely on tag return order: make sure it matches exactly one. int matches = 0; for (int i = 0; i < BASIC_TAG_COUNT; i++) { @@ -135,29 +134,28 @@ static void basic_test(void) { } GPR_ASSERT(matches == 1); } - census_tag_set_destroy(cts); + census_context_destroy(context); } -// Test that census_tag_set_get_tag_by_key(). +// Test census_context_get_tag(). static void lookup_by_key_test(void) { - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); census_tag tag; for (int i = 0; i < BASIC_TAG_COUNT; i++) { - GPR_ASSERT(census_tag_set_get_tag_by_key(cts, basic_tags[i].key, &tag) == - 1); + GPR_ASSERT(census_context_get_tag(context, basic_tags[i].key, &tag) == 1); GPR_ASSERT(compare_tag(&tag, &basic_tags[i])); } // non-existent keys - GPR_ASSERT(census_tag_set_get_tag_by_key(cts, "key", &tag) == 0); - GPR_ASSERT(census_tag_set_get_tag_by_key(cts, "key01", &tag) == 0); - GPR_ASSERT(census_tag_set_get_tag_by_key(cts, "k9", &tag) == 0); - GPR_ASSERT(census_tag_set_get_tag_by_key(cts, "random", &tag) == 0); - GPR_ASSERT(census_tag_set_get_tag_by_key(cts, "", &tag) == 0); - census_tag_set_destroy(cts); + GPR_ASSERT(census_context_get_tag(context, "key", &tag) == 0); + GPR_ASSERT(census_context_get_tag(context, "key01", &tag) == 0); + GPR_ASSERT(census_context_get_tag(context, "k9", &tag) == 0); + GPR_ASSERT(census_context_get_tag(context, "random", &tag) == 0); + GPR_ASSERT(census_context_get_tag(context, "", &tag) == 0); + census_context_destroy(context); } -// Try creating tag set with invalid entries. +// Try creating context with invalid entries. static void invalid_test(void) { char key[300]; memset(key, 'k', 299); @@ -168,155 +166,156 @@ static void invalid_test(void) { // long keys, short value. Key lengths (including terminator) should be // <= 255 (CENSUS_MAX_TAG_KV_LEN) GPR_ASSERT(strlen(key) == 299); - const census_tag_set_create_status *status; - struct census_tag_set *cts = census_tag_set_create(NULL, &tag, 1, &status); - census_tag_set_create_status expected = {0, 0, 0, 0, 0, 0, 1, 0}; + const census_context_status *status; + struct census_context *context = + census_context_create(NULL, &tag, 1, &status); + census_context_status expected = {0, 0, 0, 0, 0, 0, 1, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag_set_destroy(cts); + census_context_destroy(context); key[CENSUS_MAX_TAG_KV_LEN] = 0; GPR_ASSERT(strlen(key) == CENSUS_MAX_TAG_KV_LEN); - cts = census_tag_set_create(NULL, &tag, 1, &status); + context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag_set_destroy(cts); + census_context_destroy(context); key[CENSUS_MAX_TAG_KV_LEN - 1] = 0; GPR_ASSERT(strlen(key) == CENSUS_MAX_TAG_KV_LEN - 1); - cts = census_tag_set_create(NULL, &tag, 1, &status); - census_tag_set_create_status expected2 = {0, 0, 1, 0, 1, 0, 0, 0}; + context = census_context_create(NULL, &tag, 1, &status); + census_context_status expected2 = {0, 0, 1, 0, 1, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected2, sizeof(expected2)) == 0); - census_tag_set_destroy(cts); + census_context_destroy(context); // now try with long values tag.value_len = 300; - cts = census_tag_set_create(NULL, &tag, 1, &status); + context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag_set_destroy(cts); + census_context_destroy(context); tag.value_len = CENSUS_MAX_TAG_KV_LEN + 1; - cts = census_tag_set_create(NULL, &tag, 1, &status); + context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag_set_destroy(cts); + census_context_destroy(context); tag.value_len = CENSUS_MAX_TAG_KV_LEN; - cts = census_tag_set_create(NULL, &tag, 1, &status); + context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected2, sizeof(expected2)) == 0); - census_tag_set_destroy(cts); + census_context_destroy(context); // 0 length key. key[0] = 0; - cts = census_tag_set_create(NULL, &tag, 1, &status); + context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag_set_destroy(cts); + census_context_destroy(context); } -// Make a copy of a tag set +// Make a copy of a context static void copy_test(void) { - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_tag_set_create_status *status; - struct census_tag_set *cts2 = census_tag_set_create(cts, NULL, 0, &status); - census_tag_set_create_status expected = {2, 2, 4, 0, 0, 0, 0, 0}; + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); + const census_context_status *status; + struct census_context *context2 = + census_context_create(context, NULL, 0, &status); + census_context_status expected = {2, 2, 4, 0, 0, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); for (int i = 0; i < BASIC_TAG_COUNT; i++) { census_tag tag; - GPR_ASSERT(census_tag_set_get_tag_by_key(cts2, basic_tags[i].key, &tag) == - 1); + GPR_ASSERT(census_context_get_tag(context2, basic_tags[i].key, &tag) == 1); GPR_ASSERT(compare_tag(&tag, &basic_tags[i])); } - census_tag_set_destroy(cts); - census_tag_set_destroy(cts2); + census_context_destroy(context); + census_context_destroy(context2); } // replace a single tag value static void replace_value_test(void) { - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_tag_set_create_status *status; - struct census_tag_set *cts2 = census_tag_set_create( - cts, modify_tags + REPLACE_VALUE_OFFSET, 1, &status); - census_tag_set_create_status expected = {2, 2, 4, 0, 0, 1, 0, 0}; + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); + const census_context_status *status; + struct census_context *context2 = census_context_create( + context, modify_tags + REPLACE_VALUE_OFFSET, 1, &status); + census_context_status expected = {2, 2, 4, 0, 0, 1, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_tag tag; - GPR_ASSERT(census_tag_set_get_tag_by_key( - cts2, modify_tags[REPLACE_VALUE_OFFSET].key, &tag) == 1); + GPR_ASSERT(census_context_get_tag( + context2, modify_tags[REPLACE_VALUE_OFFSET].key, &tag) == 1); GPR_ASSERT(compare_tag(&tag, &modify_tags[REPLACE_VALUE_OFFSET])); - census_tag_set_destroy(cts); - census_tag_set_destroy(cts2); + census_context_destroy(context); + census_context_destroy(context2); } // replace a single tags flags static void replace_flags_test(void) { - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_tag_set_create_status *status; - struct census_tag_set *cts2 = - census_tag_set_create(cts, modify_tags + REPLACE_FLAG_OFFSET, 1, &status); - census_tag_set_create_status expected = {1, 2, 5, 0, 0, 1, 0, 0}; + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); + const census_context_status *status; + struct census_context *context2 = census_context_create( + context, modify_tags + REPLACE_FLAG_OFFSET, 1, &status); + census_context_status expected = {1, 2, 5, 0, 0, 1, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_tag tag; - GPR_ASSERT(census_tag_set_get_tag_by_key( - cts2, modify_tags[REPLACE_FLAG_OFFSET].key, &tag) == 1); + GPR_ASSERT(census_context_get_tag( + context2, modify_tags[REPLACE_FLAG_OFFSET].key, &tag) == 1); GPR_ASSERT(compare_tag(&tag, &modify_tags[REPLACE_FLAG_OFFSET])); - census_tag_set_destroy(cts); - census_tag_set_destroy(cts2); + census_context_destroy(context); + census_context_destroy(context2); } // delete a single tag. static void delete_tag_test(void) { - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_tag_set_create_status *status; - struct census_tag_set *cts2 = - census_tag_set_create(cts, modify_tags + DELETE_TAG_OFFSET, 1, &status); - census_tag_set_create_status expected = {2, 1, 4, 1, 0, 0, 0, 0}; + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); + const census_context_status *status; + struct census_context *context2 = census_context_create( + context, modify_tags + DELETE_TAG_OFFSET, 1, &status); + census_context_status expected = {2, 1, 4, 1, 0, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_tag tag; - GPR_ASSERT(census_tag_set_get_tag_by_key( - cts2, modify_tags[DELETE_TAG_OFFSET].key, &tag) == 0); - census_tag_set_destroy(cts); - census_tag_set_destroy(cts2); + GPR_ASSERT(census_context_get_tag( + context2, modify_tags[DELETE_TAG_OFFSET].key, &tag) == 0); + census_context_destroy(context); + census_context_destroy(context2); } // add a single new tag. static void add_tag_test(void) { - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_tag_set_create_status *status; - struct census_tag_set *cts2 = - census_tag_set_create(cts, modify_tags + ADD_TAG_OFFSET, 1, &status); - census_tag_set_create_status expected = {2, 2, 5, 0, 1, 0, 0, 0}; + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); + const census_context_status *status; + struct census_context *context2 = + census_context_create(context, modify_tags + ADD_TAG_OFFSET, 1, &status); + census_context_status expected = {2, 2, 5, 0, 1, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_tag tag; - GPR_ASSERT(census_tag_set_get_tag_by_key( - cts2, modify_tags[ADD_TAG_OFFSET].key, &tag) == 1); + GPR_ASSERT(census_context_get_tag(context2, modify_tags[ADD_TAG_OFFSET].key, + &tag) == 1); GPR_ASSERT(compare_tag(&tag, &modify_tags[ADD_TAG_OFFSET])); - census_tag_set_destroy(cts); - census_tag_set_destroy(cts2); + census_context_destroy(context); + census_context_destroy(context2); } // test many changes at once. static void replace_add_delete_test(void) { - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_tag_set_create_status *status; - struct census_tag_set *cts2 = - census_tag_set_create(cts, modify_tags, MODIFY_TAG_COUNT, &status); - census_tag_set_create_status expected = {2, 1, 6, 2, 3, 4, 0, 2}; + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); + const census_context_status *status; + struct census_context *context2 = + census_context_create(context, modify_tags, MODIFY_TAG_COUNT, &status); + census_context_status expected = {2, 1, 6, 2, 3, 4, 0, 2}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - // validate tag set contents. Use specific indices into the two arrays + // validate context contents. Use specific indices into the two arrays // holding tag values. - GPR_ASSERT(validate_tag(cts2, &basic_tags[3])); - GPR_ASSERT(validate_tag(cts2, &basic_tags[4])); - GPR_ASSERT(validate_tag(cts2, &modify_tags[0])); - GPR_ASSERT(validate_tag(cts2, &modify_tags[1])); - GPR_ASSERT(validate_tag(cts2, &modify_tags[6])); - GPR_ASSERT(validate_tag(cts2, &modify_tags[7])); - GPR_ASSERT(validate_tag(cts2, &modify_tags[8])); - GPR_ASSERT(validate_tag(cts2, &modify_tags[9])); - GPR_ASSERT(validate_tag(cts2, &modify_tags[10])); - GPR_ASSERT(!validate_tag(cts2, &basic_tags[0])); - GPR_ASSERT(!validate_tag(cts2, &basic_tags[1])); - GPR_ASSERT(!validate_tag(cts2, &basic_tags[2])); - GPR_ASSERT(!validate_tag(cts2, &basic_tags[5])); - GPR_ASSERT(!validate_tag(cts2, &basic_tags[6])); - GPR_ASSERT(!validate_tag(cts2, &basic_tags[7])); - census_tag_set_destroy(cts); - census_tag_set_destroy(cts2); + GPR_ASSERT(validate_tag(context2, &basic_tags[3])); + GPR_ASSERT(validate_tag(context2, &basic_tags[4])); + GPR_ASSERT(validate_tag(context2, &modify_tags[0])); + GPR_ASSERT(validate_tag(context2, &modify_tags[1])); + GPR_ASSERT(validate_tag(context2, &modify_tags[6])); + GPR_ASSERT(validate_tag(context2, &modify_tags[7])); + GPR_ASSERT(validate_tag(context2, &modify_tags[8])); + GPR_ASSERT(validate_tag(context2, &modify_tags[9])); + GPR_ASSERT(validate_tag(context2, &modify_tags[10])); + GPR_ASSERT(!validate_tag(context2, &basic_tags[0])); + GPR_ASSERT(!validate_tag(context2, &basic_tags[1])); + GPR_ASSERT(!validate_tag(context2, &basic_tags[2])); + GPR_ASSERT(!validate_tag(context2, &basic_tags[5])); + GPR_ASSERT(!validate_tag(context2, &basic_tags[6])); + GPR_ASSERT(!validate_tag(context2, &basic_tags[7])); + census_context_destroy(context); + census_context_destroy(context2); } #define BUF_SIZE 200 @@ -324,38 +323,37 @@ static void replace_add_delete_test(void) { // test encode/decode. static void encode_decode_test(void) { char buffer[BUF_SIZE]; - struct census_tag_set *cts = - census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); + struct census_context *context = + census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); size_t print_bsize; size_t bin_bsize; // Test with too small a buffer - GPR_ASSERT(census_tag_set_encode(cts, buffer, 2, &print_bsize, &bin_bsize) == - NULL); - char *b_buffer = - census_tag_set_encode(cts, buffer, BUF_SIZE, &print_bsize, &bin_bsize); + GPR_ASSERT(census_context_encode(context, buffer, 2, &print_bsize, + &bin_bsize) == NULL); + char *b_buffer = census_context_encode(context, buffer, BUF_SIZE, + &print_bsize, &bin_bsize); GPR_ASSERT(b_buffer != NULL && print_bsize > 0 && bin_bsize > 0 && print_bsize + bin_bsize <= BUF_SIZE && b_buffer == buffer + print_bsize); - census_tag_set *cts2 = - census_tag_set_decode(buffer, print_bsize, b_buffer, bin_bsize); - GPR_ASSERT(cts2 != NULL); - const census_tag_set_create_status *status = - census_tag_set_get_create_status(cts2); - census_tag_set_create_status expected = {2, 2, 0, 0, 0, 0, 0, 0}; + census_context *context2 = + census_context_decode(buffer, print_bsize, b_buffer, bin_bsize); + GPR_ASSERT(context2 != NULL); + const census_context_status *status = census_context_get_status(context2); + census_context_status expected = {2, 2, 0, 0, 0, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); for (int i = 0; i < BASIC_TAG_COUNT; i++) { census_tag tag; if (CENSUS_TAG_IS_PROPAGATED(basic_tags[i].flags)) { - GPR_ASSERT(census_tag_set_get_tag_by_key(cts2, basic_tags[i].key, &tag) == + GPR_ASSERT(census_context_get_tag(context2, basic_tags[i].key, &tag) == 1); GPR_ASSERT(compare_tag(&tag, &basic_tags[i])); } else { - GPR_ASSERT(census_tag_set_get_tag_by_key(cts2, basic_tags[i].key, &tag) == + GPR_ASSERT(census_context_get_tag(context2, basic_tags[i].key, &tag) == 0); } } - census_tag_set_destroy(cts2); - census_tag_set_destroy(cts); + census_context_destroy(context2); + census_context_destroy(context); } int main(int argc, char *argv[]) { diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index f1bb37c0bf..e19e9a57ae 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -81,12 +81,12 @@ static char *get_peer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { return gpr_strdup("peer"); } -static void free_channel(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void free_channel(grpc_exec_ctx *exec_ctx, void *arg, bool success) { grpc_channel_stack_destroy(exec_ctx, arg); gpr_free(arg); } -static void free_call(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void free_call(grpc_exec_ctx *exec_ctx, void *arg, bool success) { grpc_call_stack_destroy(exec_ctx, arg); gpr_free(arg); } diff --git a/test/core/client_config/set_initial_connect_string_test.c b/test/core/client_config/set_initial_connect_string_test.c index 33cab715b2..bcd1f26123 100644 --- a/test/core/client_config/set_initial_connect_string_test.c +++ b/test/core/client_config/set_initial_connect_string_test.c @@ -64,7 +64,7 @@ static int server_port; static struct rpc_state state; static grpc_closure on_read; -static void handle_read(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void handle_read(grpc_exec_ctx *exec_ctx, void *arg, bool success) { GPR_ASSERT(success); gpr_slice_buffer_move_into(&state.temp_incoming_buffer, &state.incoming_buffer); diff --git a/test/core/end2end/fixtures/h2_uchannel.c b/test/core/end2end/fixtures/h2_uchannel.c index 9b622e80d6..5ab64f9800 100644 --- a/test/core/end2end/fixtures/h2_uchannel.c +++ b/test/core/end2end/fixtures/h2_uchannel.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -81,7 +81,7 @@ static void connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *con) { } } -static void connected(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void connected(grpc_exec_ctx *exec_ctx, void *arg, bool success) { connector *c = arg; grpc_closure *notify; grpc_endpoint *tcp = c->tcp; @@ -240,7 +240,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_micro_fullstack( grpc_connectivity_state g_state = GRPC_CHANNEL_IDLE; grpc_pollset_set g_interested_parties; -static void state_changed(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void state_changed(grpc_exec_ctx *exec_ctx, void *arg, bool success) { if (g_state != GRPC_CHANNEL_READY) { grpc_subchannel_notify_on_state_change( exec_ctx, arg, &g_interested_parties, &g_state, @@ -248,7 +248,7 @@ static void state_changed(grpc_exec_ctx *exec_ctx, void *arg, int success) { } } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *arg, bool success) { grpc_pollset_destroy(arg); } diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c index 612388c61d..651ef1fa3b 100644 --- a/test/core/httpcli/httpcli_test.c +++ b/test/core/httpcli/httpcli_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -131,7 +131,7 @@ static void test_post(int port) { gpr_free(host); } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/httpcli/httpscli_test.c b/test/core/httpcli/httpscli_test.c index ba5660bd18..db41be17e7 100644 --- a/test/core/httpcli/httpscli_test.c +++ b/test/core/httpcli/httpscli_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -133,7 +133,7 @@ static void test_post(int port) { gpr_free(host); } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/iomgr/endpoint_pair_test.c b/test/core/iomgr/endpoint_pair_test.c index ff590cf2d5..7e266ebfb9 100644 --- a/test/core/iomgr/endpoint_pair_test.c +++ b/test/core/iomgr/endpoint_pair_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -65,7 +65,7 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up}, }; -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index a66fe32fde..1b6a78da9a 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -127,7 +127,7 @@ struct read_and_write_test_state { }; static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx, - void *data, int success) { + void *data, bool success) { struct read_and_write_test_state *state = data; state->bytes_read += count_slices( @@ -145,7 +145,7 @@ static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx, } static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx, - void *data, int success) { + void *data, bool success) { struct read_and_write_test_state *state = data; gpr_slice *slices = NULL; size_t nslices; diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index b186520729..347a86af10 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -118,7 +118,7 @@ typedef struct { /* Called when an upload session can be safely shutdown. Close session FD and start to shutdown listen FD. */ static void session_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ - int success) { + bool success) { session *se = arg; server *sv = se->sv; grpc_fd_orphan(exec_ctx, se->em_fd, NULL, NULL, "a"); @@ -129,7 +129,7 @@ static void session_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ /* Called when data become readable in a session. */ static void session_read_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ - int success) { + bool success) { session *se = arg; int fd = se->em_fd->fd; @@ -187,7 +187,7 @@ static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */, /* Called when a new TCP connection request arrives in the listening port. */ static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/ - int success) { + bool success) { server *sv = arg; int fd; int flags; @@ -301,7 +301,7 @@ static void client_session_shutdown_cb(grpc_exec_ctx *exec_ctx, /* Write as much as possible, then register notify_on_write. */ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ - int success) { + bool success) { client *cl = arg; int fd = cl->em_fd->fd; ssize_t write_once = 0; @@ -399,7 +399,7 @@ static void test_grpc_fd(void) { } typedef struct fd_change_data { - void (*cb_that_ran)(grpc_exec_ctx *exec_ctx, void *, int success); + grpc_iomgr_cb_func cb_that_ran; } fd_change_data; void init_change_data(fd_change_data *fdc) { fdc->cb_that_ran = NULL; } @@ -407,7 +407,7 @@ void init_change_data(fd_change_data *fdc) { fdc->cb_that_ran = NULL; } void destroy_change_data(fd_change_data *fdc) {} static void first_read_callback(grpc_exec_ctx *exec_ctx, - void *arg /* fd_change_data */, int success) { + void *arg /* fd_change_data */, bool success) { fd_change_data *fdc = arg; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -417,7 +417,7 @@ static void first_read_callback(grpc_exec_ctx *exec_ctx, } static void second_read_callback(grpc_exec_ctx *exec_ctx, - void *arg /* fd_change_data */, int success) { + void *arg /* fd_change_data */, bool success) { fd_change_data *fdc = arg; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -510,7 +510,7 @@ static void test_grpc_fd_change(void) { close(sv[1]); } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index 833ceace54..9725d8a3b6 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -63,7 +63,7 @@ static void finish_connection() { gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } -static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, bool success) { GPR_ASSERT(g_connecting != NULL); GPR_ASSERT(success); grpc_endpoint_shutdown(exec_ctx, g_connecting); @@ -72,7 +72,7 @@ static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, int success) { finish_connection(); } -static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, bool success) { GPR_ASSERT(g_connecting == NULL); GPR_ASSERT(!success); finish_connection(); @@ -258,7 +258,7 @@ void test_times_out(void) { } } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index e0136b3cd7..d290c6bc3a 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -138,7 +138,7 @@ static size_t count_slices(gpr_slice *slices, size_t nslices, return num_bytes; } -static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, int success) { +static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) { struct read_socket_state *state = (struct read_socket_state *)user_data; size_t read_bytes; int current_data; @@ -280,7 +280,7 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, } static void write_done(grpc_exec_ctx *exec_ctx, - void *user_data /* write_socket_state */, int success) { + void *user_data /* write_socket_state */, bool success) { struct write_socket_state *state = (struct write_socket_state *)user_data; gpr_log(GPR_INFO, "Write done callback called"); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -383,7 +383,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_exec_ctx_finish(&exec_ctx); } -void on_fd_released(grpc_exec_ctx *exec_ctx, void *arg, int success) { +void on_fd_released(grpc_exec_ctx *exec_ctx, void *arg, bool success) { int *done = arg; *done = 1; grpc_pollset_kick(&g_pollset, NULL); @@ -503,7 +503,7 @@ static grpc_endpoint_test_config configs[] = { {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, }; -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index f7097ac904..272d97bfcb 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -86,7 +86,7 @@ static void on_connect_result_set(on_connect_result *result, } static void server_weak_ref_shutdown(grpc_exec_ctx *exec_ctx, void *arg, - int success) { + bool success) { server_weak_ref *weak_ref = arg; weak_ref->server = NULL; } @@ -303,7 +303,7 @@ static void test_connect(unsigned n) { grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c index 63014c3939..15de87c5a1 100644 --- a/test/core/iomgr/timer_list_test.c +++ b/test/core/iomgr/timer_list_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,7 @@ static int cb_called[MAX_CB][2]; -static void cb(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void cb(grpc_exec_ctx *exec_ctx, void *arg, bool success) { cb_called[(intptr_t)arg][success]++; } diff --git a/test/core/iomgr/workqueue_test.c b/test/core/iomgr/workqueue_test.c index d1f9dabc57..500170b542 100644 --- a/test/core/iomgr/workqueue_test.c +++ b/test/core/iomgr/workqueue_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ static grpc_pollset g_pollset; -static void must_succeed(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void must_succeed(grpc_exec_ctx *exec_ctx, void *p, bool success) { GPR_ASSERT(success == 1); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); *(int *)p = 1; @@ -90,7 +90,7 @@ static void test_flush(void) { grpc_pollset_worker worker; grpc_closure_init(&c, must_succeed, &done); - grpc_exec_ctx_enqueue(&exec_ctx, &c, 1); + grpc_exec_ctx_enqueue(&exec_ctx, &c, true, NULL); grpc_workqueue_flush(&exec_ctx, wq); grpc_workqueue_add_to_pollset(&exec_ctx, wq, &g_pollset); @@ -106,7 +106,7 @@ static void test_flush(void) { grpc_exec_ctx_finish(&exec_ctx); } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/security/create_jwt.c b/test/core/security/create_jwt.c index b02469fb35..237dc9aa3e 100644 --- a/test/core/security/create_jwt.c +++ b/test/core/security/create_jwt.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -62,7 +62,7 @@ void create_jwt(const char *json_key_file_path, const char *service_url, } jwt = grpc_jwt_encode_and_sign( &key, service_url == NULL ? GRPC_JWT_OAUTH2_AUDIENCE : service_url, - grpc_max_auth_token_lifetime, scope); + grpc_max_auth_token_lifetime(), scope); grpc_auth_json_key_destruct(&key); if (jwt == NULL) { fprintf(stderr, "Could not create JWT.\n"); diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index a32ddd2ec7..8a210bb3c3 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -734,7 +734,7 @@ static void validate_jwt_encode_and_sign_params( "777-abaslkan11hlb6nmim3bpspl31ud@developer." "gserviceaccount.com") == 0); if (scope != NULL) GPR_ASSERT(strcmp(scope, test_scope) == 0); - GPR_ASSERT(!gpr_time_cmp(token_lifetime, grpc_max_auth_token_lifetime)); + GPR_ASSERT(!gpr_time_cmp(token_lifetime, grpc_max_auth_token_lifetime())); } static char *encode_and_sign_jwt_success(const grpc_auth_json_key *json_key, @@ -794,7 +794,7 @@ static void test_jwt_creds_success(void) { NULL}; grpc_call_credentials *jwt_creds = grpc_service_account_jwt_access_credentials_create( - json_key_string, grpc_max_auth_token_lifetime, NULL); + json_key_string, grpc_max_auth_token_lifetime(), NULL); /* First request: jwt_encode_and_sign should be called. */ grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); @@ -832,7 +832,7 @@ static void test_jwt_creds_signing_failure(void) { NULL}; grpc_call_credentials *jwt_creds = grpc_service_account_jwt_access_credentials_create( - json_key_string, grpc_max_auth_token_lifetime, NULL); + json_key_string, grpc_max_auth_token_lifetime(), NULL); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure); grpc_call_credentials_get_request_metadata( diff --git a/test/core/security/json_token_test.c b/test/core/security/json_token_test.c index 740fd018b6..7c01a9ce5c 100644 --- a/test/core/security/json_token_test.c +++ b/test/core/security/json_token_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -330,7 +330,7 @@ static void check_jwt_claim(grpc_json *claim, const char *expected_audience, issue_time.tv_sec = strtol(iat->value, NULL, 10); parsed_lifetime = gpr_time_sub(expiration, issue_time); - GPR_ASSERT(parsed_lifetime.tv_sec == grpc_max_auth_token_lifetime.tv_sec); + GPR_ASSERT(parsed_lifetime.tv_sec == grpc_max_auth_token_lifetime().tv_sec); } static void check_jwt_signature(const char *b64_signature, RSA *rsa_key, @@ -361,12 +361,12 @@ static void check_jwt_signature(const char *b64_signature, RSA *rsa_key, static char *service_account_creds_jwt_encode_and_sign( const grpc_auth_json_key *key) { return grpc_jwt_encode_and_sign(key, GRPC_JWT_OAUTH2_AUDIENCE, - grpc_max_auth_token_lifetime, test_scope); + grpc_max_auth_token_lifetime(), test_scope); } static char *jwt_creds_jwt_encode_and_sign(const grpc_auth_json_key *key) { return grpc_jwt_encode_and_sign(key, test_service_url, - grpc_max_auth_token_lifetime, NULL); + grpc_max_auth_token_lifetime(), NULL); } static void service_account_creds_check_jwt_claim(grpc_json *claim) { diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c index fb62bf4134..55ac31e62c 100644 --- a/test/core/security/oauth2_utils.c +++ b/test/core/security/oauth2_utils.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -73,7 +73,7 @@ static void on_oauth2_response(grpc_exec_ctx *exec_ctx, void *user_data, gpr_mu_unlock(GRPC_POLLSET_MU(&request->pollset)); } -static void do_nothing(grpc_exec_ctx *exec_ctx, void *unused, int success) {} +static void do_nothing(grpc_exec_ctx *exec_ctx, void *unused, bool success) {} char *grpc_test_fetch_oauth2_token_with_credentials( grpc_call_credentials *creds) { diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c index 240c4596b4..fb4bd30e2d 100644 --- a/test/core/security/secure_endpoint_test.c +++ b/test/core/security/secure_endpoint_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -138,7 +138,7 @@ static grpc_endpoint_test_config configs[] = { secure_endpoint_create_fixture_tcp_socketpair_leftover, clean_up}, }; -static void inc_call_ctr(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void inc_call_ctr(grpc_exec_ctx *exec_ctx, void *arg, bool success) { ++*(int *)arg; } @@ -171,7 +171,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { clean_up(); } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) { +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { grpc_pollset_destroy(p); } diff --git a/test/core/security/security_connector_test.c b/test/core/security/security_connector_test.c index 0dcffa40ce..ee5435f01d 100644 --- a/test/core/security/security_connector_test.c +++ b/test/core/security/security_connector_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,6 +36,9 @@ #include "src/core/security/security_connector.h" #include "src/core/security/security_context.h" +#include "src/core/support/env.h" +#include "src/core/support/file.h" +#include "src/core/support/string.h" #include "src/core/tsi/ssl_transport_security.h" #include "src/core/tsi/transport_security.h" #include "test/core/util/test_config.h" @@ -44,6 +47,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include <grpc/support/string_util.h> #include <grpc/support/useful.h> static int check_transport_security_type(const grpc_auth_context *ctx) { @@ -297,7 +301,66 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context( GRPC_AUTH_CONTEXT_UNREF(ctx, "test"); } -/* TODO(jboeuf): Unit-test tsi_shallow_peer_from_auth_context. */ +static const char *roots_for_override_api = "roots for override api"; + +static grpc_ssl_roots_override_result override_roots_success( + char **pem_root_certs) { + *pem_root_certs = gpr_strdup(roots_for_override_api); + return GRPC_SSL_ROOTS_OVERRIDE_OK; +} + +static grpc_ssl_roots_override_result override_roots_permanent_failure( + char **pem_root_certs) { + return GRPC_SSL_ROOTS_OVERRIDE_FAIL_PERMANENTLY; +} + +static void test_default_ssl_roots(void) { + const char *roots_for_env_var = "roots for env var"; + + char *roots_env_var_file_path; + FILE *roots_env_var_file = + gpr_tmpfile("test_roots_for_env_var", &roots_env_var_file_path); + fwrite(roots_for_env_var, 1, strlen(roots_for_env_var), roots_env_var_file); + fclose(roots_env_var_file); + + /* First let's get the root through the override: set the env to an invalid + value. */ + gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, ""); + grpc_set_ssl_roots_override_callback(override_roots_success); + gpr_slice roots = grpc_get_default_ssl_roots_for_testing(); + char *roots_contents = gpr_dump_slice(roots, GPR_DUMP_ASCII); + gpr_slice_unref(roots); + GPR_ASSERT(strcmp(roots_contents, roots_for_override_api) == 0); + gpr_free(roots_contents); + + /* Now let's set the env var: We should get the contents pointed value + instead. */ + gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_env_var_file_path); + roots = grpc_get_default_ssl_roots_for_testing(); + roots_contents = gpr_dump_slice(roots, GPR_DUMP_ASCII); + gpr_slice_unref(roots); + GPR_ASSERT(strcmp(roots_contents, roots_for_env_var) == 0); + gpr_free(roots_contents); + + /* Now reset the env var. We should fall back to the value overridden using + the api. */ + gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, ""); + roots = grpc_get_default_ssl_roots_for_testing(); + roots_contents = gpr_dump_slice(roots, GPR_DUMP_ASCII); + gpr_slice_unref(roots); + GPR_ASSERT(strcmp(roots_contents, roots_for_override_api) == 0); + gpr_free(roots_contents); + + /* Now setup a permanent failure for the overridden roots and we should get + an empty slice. */ + grpc_set_ssl_roots_override_callback(override_roots_permanent_failure); + roots = grpc_get_default_ssl_roots_for_testing(); + GPR_ASSERT(GPR_SLICE_IS_EMPTY(roots)); + + /* Cleanup. */ + remove(roots_env_var_file_path); + gpr_free(roots_env_var_file_path); +} int main(int argc, char **argv) { grpc_test_init(argc, argv); @@ -308,6 +371,7 @@ int main(int argc, char **argv) { test_cn_and_one_san_ssl_peer_to_auth_context(); test_cn_and_multiple_sans_ssl_peer_to_auth_context(); test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context(); + test_default_ssl_roots(); grpc_shutdown(); return 0; diff --git a/test/core/support/alloc_test.c b/test/core/support/alloc_test.c index a7051a46a1..6bdba8c390 100644 --- a/test/core/support/alloc_test.c +++ b/test/core/support/alloc_test.c @@ -39,7 +39,9 @@ static void *fake_malloc(size_t size) { return (void *)size; } static void *fake_realloc(void *addr, size_t size) { return (void *)size; } -static void fake_free(void *addr) { *((intptr_t *)addr) = 0xdeadd00d; } +static void fake_free(void *addr) { + *((intptr_t *)addr) = (intptr_t)0xdeadd00d; +} static void test_custom_allocs() { const gpr_allocation_functions default_fns = gpr_get_allocation_functions(); @@ -52,7 +54,7 @@ static void test_custom_allocs() { GPR_ASSERT((void *)(size_t)0xcafed00d == gpr_realloc(0, 0xcafed00d)); gpr_free(&addr_to_free); - GPR_ASSERT(addr_to_free == 0xdeadd00d); + GPR_ASSERT(addr_to_free == (intptr_t)0xdeadd00d); /* Restore and check we don't get funky values and that we don't leak */ gpr_set_allocation_functions(default_fns); diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c index e03cce1322..79e53cb422 100644 --- a/test/core/surface/lame_client_test.c +++ b/test/core/surface/lame_client_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,13 +47,13 @@ grpc_closure transport_op_cb; static void *tag(intptr_t x) { return (void *)x; } -void verify_connectivity(grpc_exec_ctx *exec_ctx, void *arg, int success) { +void verify_connectivity(grpc_exec_ctx *exec_ctx, void *arg, bool success) { grpc_transport_op *op = arg; GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE == *op->connectivity_state); GPR_ASSERT(success); } -void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) {} +void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, bool success) {} void test_transport_op(grpc_channel *channel) { grpc_transport_op op; diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index 1e1524d098..579faa4441 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -37,6 +37,21 @@ #include <grpc/compression.h> #include <grpc/grpc.h> #include <grpc/grpc_security.h> +#include <grpc/impl/codegen/alloc.h> +#include <grpc/impl/codegen/atm.h> +#include <grpc/impl/codegen/byte_buffer.h> +#include <grpc/impl/codegen/compression_types.h> +#include <grpc/impl/codegen/connectivity_state.h> +#include <grpc/impl/codegen/grpc_types.h> +#include <grpc/impl/codegen/log.h> +#include <grpc/impl/codegen/port_platform.h> +#include <grpc/impl/codegen/propagation_bits.h> +#include <grpc/impl/codegen/slice.h> +#include <grpc/impl/codegen/slice_buffer.h> +#include <grpc/impl/codegen/status.h> +#include <grpc/impl/codegen/sync.h> +#include <grpc/impl/codegen/sync_generic.h> +#include <grpc/impl/codegen/time.h> #include <grpc/status.h> #include <grpc/support/alloc.h> #include <grpc/support/atm.h> diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index 39f4174eec..3c5f2e4e31 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -236,7 +236,7 @@ static void test_find(void) { /* overflow the string buffer, check find still works */ for (i = 0; i < 10000; i++) { - gpr_ltoa(i, buffer); + int64_ttoa(i, buffer); elem = grpc_mdelem_from_strings("test", buffer); GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem)); GRPC_MDELEM_UNREF(elem); @@ -256,7 +256,7 @@ static void test_find(void) { for (i = 0; i < tbl.num_ents; i++) { uint32_t expect = 9999 - i; - gpr_ltoa(expect, buffer); + int64_ttoa(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/connectivity_state_test.c b/test/core/transport/connectivity_state_test.c index 34ab45d260..4b2d0aa44a 100644 --- a/test/core/transport/connectivity_state_test.c +++ b/test/core/transport/connectivity_state_test.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,13 +43,13 @@ int g_counter; -static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, bool success) { GPR_ASSERT(success); GPR_ASSERT(arg == THE_ARG); g_counter++; } -static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, int success) { +static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, bool success) { GPR_ASSERT(!success); GPR_ASSERT(arg == THE_ARG); g_counter++; diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index 732a51c5cb..4b31f810e5 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,11 +37,12 @@ #include "test/core/util/port.h" +#include <errno.h> +#include <math.h> #include <netinet/in.h> -#include <sys/socket.h> #include <stdio.h> -#include <errno.h> #include <string.h> +#include <sys/socket.h> #include <unistd.h> #include <grpc/grpc.h> @@ -73,7 +74,7 @@ typedef struct freereq { } freereq; static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p, - int success) { + bool success) { grpc_pollset_destroy(p); grpc_shutdown(); } @@ -229,10 +230,10 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, grpc_httpcli_request req; memset(&req, 0, sizeof(req)); GPR_ASSERT(pr->retries < 10); + sleep(1 + (unsigned)(pow(1.3, pr->retries) * rand() / RAND_MAX)); pr->retries++; req.host = pr->server; req.path = "/get"; - sleep(1); grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server, pr); diff --git a/test/core/util/port_windows.c b/test/core/util/port_windows.c index 60ad9b4f2a..85d7c0ce07 100644 --- a/test/core/util/port_windows.c +++ b/test/core/util/port_windows.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -152,7 +152,7 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, } static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p, - int success) { + bool success) { grpc_pollset_destroy(p); grpc_shutdown(); } diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c index aaba7be356..66470c0288 100644 --- a/test/core/util/test_tcp_server.c +++ b/test/core/util/test_tcp_server.c @@ -46,7 +46,7 @@ #include "test/core/util/port.h" static void on_server_destroyed(grpc_exec_ctx *exec_ctx, void *data, - int success) { + bool success) { test_tcp_server *server = data; server->shutdown = 1; } @@ -97,7 +97,7 @@ void test_tcp_server_poll(test_tcp_server *server, int seconds) { grpc_exec_ctx_finish(&exec_ctx); } -static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) {} +static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, bool success) {} void test_tcp_server_destroy(test_tcp_server *server) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |