diff options
author | 2016-03-11 14:47:07 -0800 | |
---|---|---|
committer | 2016-03-11 14:47:07 -0800 | |
commit | 52676ba0c250f55828f9b590c0e215ec18a9344c (patch) | |
tree | 4138d2fda2bac9430632bdb53cbd02e1366291d2 /test | |
parent | 4d52cca1ef29837c7610e31897240b6f4abd6991 (diff) | |
parent | aad4156a0ba79d963bfa3cd37e48a1074f956809 (diff) |
Merge pull request #5694 from nicolasnoble/pre-0.13.1-downmerge
Pre 0.13.1 downmerge
Diffstat (limited to 'test')
78 files changed, 1459 insertions, 848 deletions
diff --git a/test/build/boringssl.c b/test/build/boringssl.c new file mode 100644 index 0000000000..a31d4bf396 --- /dev/null +++ b/test/build/boringssl.c @@ -0,0 +1,51 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// Check that boringssl is going to compile + +#include <stdio.h> +#include <unistd.h> + +// boringssl uses anonymous unions +struct foo { + union { + int a; + int b; + }; +}; + +int main(void) { + const char *close = "this should not shadow"; + printf("%s\n", close); + return 0; +} diff --git a/test/build/shadow.c b/test/build/shadow.c new file mode 100644 index 0000000000..51d4f9e385 --- /dev/null +++ b/test/build/shadow.c @@ -0,0 +1,43 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// Check that boringssl is going to compile + +#include <stdio.h> +#include <unistd.h> + +int main(void) { + const char *close = "this should not shadow"; + printf("%s\n", close); + return 0; +} diff --git a/test/core/bad_ssl/gen_build_yaml.py b/test/core/bad_ssl/gen_build_yaml.py index cc097a8fdf..e2a3febe5d 100755 --- a/test/core/bad_ssl/gen_build_yaml.py +++ b/test/core/bad_ssl/gen_build_yaml.py @@ -52,8 +52,8 @@ def main(): 'name': 'bad_ssl_test_server', 'build': 'private', 'language': 'c', - 'src': ['test/core/bad_ssl/server.c'], - 'headers': ['test/core/bad_ssl/server.h'], + 'src': ['test/core/bad_ssl/server_common.c'], + 'headers': ['test/core/bad_ssl/server_common.h'], 'vs_proj_dir': 'test', 'platforms': ['linux', 'posix', 'mac'], 'deps': [ diff --git a/test/core/bad_ssl/server.c b/test/core/bad_ssl/server_common.c index 6113d364c9..cde844a552 100644 --- a/test/core/bad_ssl/server.c +++ b/test/core/bad_ssl/server_common.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 @@ -35,7 +35,7 @@ #include <grpc/support/log.h> #include <signal.h> -#include "test/core/bad_ssl/server.h" +#include "test/core/bad_ssl/server_common.h" #include "test/core/util/test_config.h" /* Common server implementation details for all servers in servers/. diff --git a/test/core/bad_ssl/server.h b/test/core/bad_ssl/server_common.h index 8ec7755503..2566c25905 100644 --- a/test/core/bad_ssl/server.h +++ b/test/core/bad_ssl/server_common.h @@ -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 diff --git a/test/core/bad_ssl/servers/alpn.c b/test/core/bad_ssl/servers/alpn.c index 7d70690e52..c8cc83b134 100644 --- a/test/core/bad_ssl/servers/alpn.c +++ b/test/core/bad_ssl/servers/alpn.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 @@ -39,7 +39,7 @@ #include <grpc/support/useful.h> #include "src/core/transport/chttp2/alpn.h" -#include "test/core/bad_ssl/server.h" +#include "test/core/bad_ssl/server_common.h" #include "test/core/end2end/data/ssl_test_data.h" /* This test starts a server that is configured to advertise (via alpn and npn) diff --git a/test/core/bad_ssl/servers/cert.c b/test/core/bad_ssl/servers/cert.c index d67a6ca1d4..4edef50b67 100644 --- a/test/core/bad_ssl/servers/cert.c +++ b/test/core/bad_ssl/servers/cert.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 @@ -38,9 +38,9 @@ #include <grpc/support/log.h> #include <grpc/support/useful.h> -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" -#include "test/core/bad_ssl/server.h" +#include "test/core/bad_ssl/server_common.h" #include "test/core/end2end/data/ssl_test_data.h" /* This server will present an untrusted cert to the connecting client, diff --git a/test/core/census/context_test.c b/test/core/census/context_test.c index 63e7103ddc..ad4c337465 100644 --- a/test/core/census/context_test.c +++ b/test/core/census/context_test.c @@ -42,60 +42,48 @@ #include <string.h> #include "test/core/util/test_config.h" -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 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. +// A set of tags Used to create a basic context for testing. 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. #define BASIC_TAG_COUNT 8 static census_tag basic_tags[BASIC_TAG_COUNT] = { - /* 0 */ {"key0", "printable", 10, 0}, - /* 1 */ {"k1", "a", 2, CENSUS_TAG_PROPAGATE}, - /* 2 */ {"k2", "longer printable string", 24, CENSUS_TAG_STATS}, - /* 3 */ {"key_three", (char *)&one_byte_val, 1, CENSUS_TAG_BINARY}, - /* 4 */ {"really_long_key_4", "random", 7, + /* 0 */ {"key0", "tag value", 0}, + /* 1 */ {"k1", "a", CENSUS_TAG_PROPAGATE}, + /* 2 */ {"k2", "a longer tag value supercalifragilisticexpialiadocious", + CENSUS_TAG_STATS}, + /* 3 */ {"key_three", "", 0}, + /* 4 */ {"a_really_really_really_really_long_key_4", "random", CENSUS_TAG_PROPAGATE | CENSUS_TAG_STATS}, - /* 5 */ {"k5", (char *)&four_byte_val, 4, - CENSUS_TAG_PROPAGATE | CENSUS_TAG_BINARY}, - /* 6 */ {"k6", (char *)&eight_byte_val, 8, - CENSUS_TAG_STATS | CENSUS_TAG_BINARY}, - /* 7 */ {"k7", (char *)&four_byte_val, 4, - CENSUS_TAG_PROPAGATE | CENSUS_TAG_STATS | CENSUS_TAG_BINARY}}; + /* 5 */ {"k5", "v5", CENSUS_TAG_PROPAGATE}, + /* 6 */ {"k6", "v6", CENSUS_TAG_STATS}, + /* 7 */ {"k7", "v7", CENSUS_TAG_PROPAGATE | CENSUS_TAG_STATS}}; // 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 // change the defines below if you add/delete entires). -#define MODIFY_TAG_COUNT 11 +#define MODIFY_TAG_COUNT 10 static census_tag modify_tags[MODIFY_TAG_COUNT] = { #define REPLACE_VALUE_OFFSET 0 - /* 0 */ {"key0", "replace printable", 18, 0}, // replaces tag value only + /* 0 */ {"key0", "replace key0", 0}, // replaces tag value only #define ADD_TAG_OFFSET 1 - /* 1 */ {"new_key", "xyzzy", 6, CENSUS_TAG_STATS}, // new tag + /* 1 */ {"new_key", "xyzzy", CENSUS_TAG_STATS}, // new tag #define DELETE_TAG_OFFSET 2 - /* 2 */ {"k5", NULL, 5, - 0}, // should delete tag, despite bogus value length - /* 3 */ {"k6", "foo", 0, 0}, // should delete tag, despite bogus value - /* 4 */ {"k6", "foo", 0, 0}, // try deleting already-deleted tag - /* 5 */ {"non-existent", NULL, 0, 0}, // another non-existent tag -#define REPLACE_FLAG_OFFSET 6 - /* 6 */ {"k1", "a", 2, 0}, // change flags only - /* 7 */ {"k7", "bar", 4, CENSUS_TAG_STATS}, // change flags and value - /* 8 */ {"k2", (char *)&eight_byte_val, 8, - CENSUS_TAG_BINARY | CENSUS_TAG_PROPAGATE}, // more flags change - // non-binary -> binary - /* 9 */ {"k6", "bar", 4, 0}, // add back tag, with different value - /* 10 */ {"foo", "bar", 4, CENSUS_TAG_PROPAGATE}, // another new tag + /* 2 */ {"k5", NULL, 0}, // should delete tag + /* 3 */ {"k5", NULL, 0}, // try deleting already-deleted tag + /* 4 */ {"non-existent", NULL, 0}, // delete non-existent tag +#define REPLACE_FLAG_OFFSET 5 + /* 5 */ {"k1", "a", 0}, // change flags only + /* 6 */ {"k7", "bar", CENSUS_TAG_STATS}, // change flags and value + /* 7 */ {"k2", "", CENSUS_TAG_PROPAGATE}, // more value and flags change + /* 8 */ {"k5", "bar", 0}, // add back tag, with different value + /* 9 */ {"foo", "bar", CENSUS_TAG_PROPAGATE}, // another new tag }; // Utility function to compare tags. Returns true if all fields match. static bool compare_tag(const census_tag *t1, const census_tag *t2) { - return (strcmp(t1->key, t2->key) == 0 && t1->value_len == t2->value_len && - memcmp(t1->value, t2->value, t1->value_len) == 0 && + return (strcmp(t1->key, t2->key) == 0 && strcmp(t1->value, t2->value) == 0 && t1->flags == t2->flags); } @@ -111,7 +99,7 @@ static void empty_test(void) { 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}; + census_context_status expected = {0, 0, 0, 0, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_context_destroy(context); } @@ -121,7 +109,7 @@ static void basic_test(void) { 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}; + census_context_status expected = {4, 4, 0, 8, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_context_iterator it; census_context_initialize_iterator(context, &it); @@ -161,15 +149,18 @@ static void invalid_test(void) { memset(key, 'k', 299); key[299] = 0; char value[300]; - memset(value, 'v', 300); - census_tag tag = {key, value, 3, CENSUS_TAG_BINARY}; + memset(value, 'v', 299); + value[299] = 0; + census_tag tag = {key, value, 0}; // long keys, short value. Key lengths (including terminator) should be // <= 255 (CENSUS_MAX_TAG_KV_LEN) + value[3] = 0; + GPR_ASSERT(strlen(value) == 3); GPR_ASSERT(strlen(key) == 299); 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}; + census_context_status expected = {0, 0, 0, 0, 0, 1, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_context_destroy(context); key[CENSUS_MAX_TAG_KV_LEN] = 0; @@ -180,24 +171,44 @@ static void invalid_test(void) { key[CENSUS_MAX_TAG_KV_LEN - 1] = 0; GPR_ASSERT(strlen(key) == CENSUS_MAX_TAG_KV_LEN - 1); context = census_context_create(NULL, &tag, 1, &status); - census_context_status expected2 = {0, 0, 1, 0, 1, 0, 0, 0}; + census_context_status expected2 = {0, 1, 0, 1, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected2, sizeof(expected2)) == 0); census_context_destroy(context); // now try with long values - tag.value_len = 300; + value[3] = 'v'; + GPR_ASSERT(strlen(value) == 299); context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_context_destroy(context); - tag.value_len = CENSUS_MAX_TAG_KV_LEN + 1; + value[CENSUS_MAX_TAG_KV_LEN] = 0; + GPR_ASSERT(strlen(value) == CENSUS_MAX_TAG_KV_LEN); context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_context_destroy(context); - tag.value_len = CENSUS_MAX_TAG_KV_LEN; + value[CENSUS_MAX_TAG_KV_LEN - 1] = 0; + GPR_ASSERT(strlen(value) == CENSUS_MAX_TAG_KV_LEN - 1); context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected2, sizeof(expected2)) == 0); census_context_destroy(context); // 0 length key. key[0] = 0; + GPR_ASSERT(strlen(key) == 0); + context = census_context_create(NULL, &tag, 1, &status); + GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); + census_context_destroy(context); + // invalid key character + key[0] = 31; // 32 (' ') is the first valid character value + key[1] = 0; + GPR_ASSERT(strlen(key) == 1); + context = census_context_create(NULL, &tag, 1, &status); + GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); + census_context_destroy(context); + // invalid value character + key[0] = ' '; + value[5] = 127; // 127 (DEL) is ('~' + 1) + value[8] = 0; + GPR_ASSERT(strlen(key) == 1); + GPR_ASSERT(strlen(value) == 8); context = census_context_create(NULL, &tag, 1, &status); GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_context_destroy(context); @@ -210,7 +221,7 @@ static void copy_test(void) { 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}; + census_context_status expected = {4, 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; @@ -228,7 +239,7 @@ static void replace_value_test(void) { 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}; + census_context_status expected = {4, 4, 0, 0, 1, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_tag tag; GPR_ASSERT(census_context_get_tag( @@ -245,7 +256,7 @@ static void replace_flags_test(void) { 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}; + census_context_status expected = {3, 5, 0, 0, 1, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_tag tag; GPR_ASSERT(census_context_get_tag( @@ -262,7 +273,7 @@ static void delete_tag_test(void) { 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}; + census_context_status expected = {3, 4, 1, 0, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_tag tag; GPR_ASSERT(census_context_get_tag( @@ -278,7 +289,7 @@ static void add_tag_test(void) { 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}; + census_context_status expected = {4, 5, 0, 1, 0, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); census_tag tag; GPR_ASSERT(census_context_get_tag(context2, modify_tags[ADD_TAG_OFFSET].key, @@ -295,24 +306,24 @@ static void replace_add_delete_test(void) { 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}; + census_context_status expected = {3, 7, 1, 3, 4, 0, 0}; GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); // validate context contents. Use specific indices into the two arrays // holding tag values. GPR_ASSERT(validate_tag(context2, &basic_tags[3])); GPR_ASSERT(validate_tag(context2, &basic_tags[4])); + GPR_ASSERT(validate_tag(context2, &basic_tags[6])); GPR_ASSERT(validate_tag(context2, &modify_tags[0])); GPR_ASSERT(validate_tag(context2, &modify_tags[1])); + GPR_ASSERT(validate_tag(context2, &modify_tags[5])); 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); @@ -325,21 +336,15 @@ static void encode_decode_test(void) { char buffer[BUF_SIZE]; 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_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_context *context2 = - census_context_decode(buffer, print_bsize, b_buffer, bin_bsize); + GPR_ASSERT(census_context_encode(context, buffer, 2) == 0); + // Test with sufficient buffer + size_t buf_used = census_context_encode(context, buffer, BUF_SIZE); + GPR_ASSERT(buf_used != 0); + census_context *context2 = census_context_decode(buffer, buf_used); 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}; + census_context_status expected = {4, 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; 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 bcd1f26123..3cf267fb3b 100644 --- a/test/core/client_config/set_initial_connect_string_test.c +++ b/test/core/client_config/set_initial_connect_string_test.c @@ -85,7 +85,7 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, gpr_slice_buffer_init(&state.incoming_buffer); gpr_slice_buffer_init(&state.temp_incoming_buffer); state.tcp = tcp; - grpc_endpoint_add_to_pollset(exec_ctx, tcp, &server->pollset); + grpc_endpoint_add_to_pollset(exec_ctx, tcp, server->pollset); grpc_endpoint_read(exec_ctx, tcp, &state.temp_incoming_buffer, &on_read); } diff --git a/test/core/end2end/end2end_nosec_tests.c b/test/core/end2end/end2end_nosec_tests.c index 9ff46d62e4..17dc190d14 100644 --- a/test/core/end2end/end2end_nosec_tests.c +++ b/test/core/end2end/end2end_nosec_tests.c @@ -46,9 +46,8 @@ extern void cancel_after_invoke(grpc_end2end_test_config config); extern void cancel_before_invoke(grpc_end2end_test_config config); extern void cancel_in_a_vacuum(grpc_end2end_test_config config); extern void cancel_with_status(grpc_end2end_test_config config); -extern void channel_connectivity(grpc_end2end_test_config config); -extern void channel_ping(grpc_end2end_test_config config); extern void compressed_payload(grpc_end2end_test_config config); +extern void connectivity(grpc_end2end_test_config config); extern void default_host(grpc_end2end_test_config config); extern void disappearing_server(grpc_end2end_test_config config); extern void empty_batch(grpc_end2end_test_config config); @@ -59,10 +58,10 @@ extern void invoke_large_request(grpc_end2end_test_config config); extern void large_metadata(grpc_end2end_test_config config); extern void max_concurrent_streams(grpc_end2end_test_config config); extern void max_message_length(grpc_end2end_test_config config); -extern void metadata(grpc_end2end_test_config config); extern void negative_deadline(grpc_end2end_test_config config); extern void no_op(grpc_end2end_test_config config); extern void payload(grpc_end2end_test_config config); +extern void ping(grpc_end2end_test_config config); extern void ping_pong_streaming(grpc_end2end_test_config config); extern void registered_call(grpc_end2end_test_config config); extern void request_with_flags(grpc_end2end_test_config config); @@ -71,6 +70,7 @@ extern void server_finishes_request(grpc_end2end_test_config config); extern void shutdown_finishes_calls(grpc_end2end_test_config config); extern void shutdown_finishes_tags(grpc_end2end_test_config config); extern void simple_delayed_request(grpc_end2end_test_config config); +extern void simple_metadata(grpc_end2end_test_config config); extern void simple_request(grpc_end2end_test_config config); extern void trailing_metadata(grpc_end2end_test_config config); @@ -87,9 +87,8 @@ void grpc_end2end_tests(int argc, char **argv, cancel_before_invoke(config); cancel_in_a_vacuum(config); cancel_with_status(config); - channel_connectivity(config); - channel_ping(config); compressed_payload(config); + connectivity(config); default_host(config); disappearing_server(config); empty_batch(config); @@ -100,10 +99,10 @@ void grpc_end2end_tests(int argc, char **argv, large_metadata(config); max_concurrent_streams(config); max_message_length(config); - metadata(config); negative_deadline(config); no_op(config); payload(config); + ping(config); ping_pong_streaming(config); registered_call(config); request_with_flags(config); @@ -112,6 +111,7 @@ void grpc_end2end_tests(int argc, char **argv, shutdown_finishes_calls(config); shutdown_finishes_tags(config); simple_delayed_request(config); + simple_metadata(config); simple_request(config); trailing_metadata(config); return; @@ -150,18 +150,14 @@ void grpc_end2end_tests(int argc, char **argv, cancel_with_status(config); continue; } - if (0 == strcmp("channel_connectivity", argv[i])) { - channel_connectivity(config); - continue; - } - if (0 == strcmp("channel_ping", argv[i])) { - channel_ping(config); - continue; - } if (0 == strcmp("compressed_payload", argv[i])) { compressed_payload(config); continue; } + if (0 == strcmp("connectivity", argv[i])) { + connectivity(config); + continue; + } if (0 == strcmp("default_host", argv[i])) { default_host(config); continue; @@ -202,10 +198,6 @@ void grpc_end2end_tests(int argc, char **argv, max_message_length(config); continue; } - if (0 == strcmp("metadata", argv[i])) { - metadata(config); - continue; - } if (0 == strcmp("negative_deadline", argv[i])) { negative_deadline(config); continue; @@ -218,6 +210,10 @@ void grpc_end2end_tests(int argc, char **argv, payload(config); continue; } + if (0 == strcmp("ping", argv[i])) { + ping(config); + continue; + } if (0 == strcmp("ping_pong_streaming", argv[i])) { ping_pong_streaming(config); continue; @@ -250,6 +246,10 @@ void grpc_end2end_tests(int argc, char **argv, simple_delayed_request(config); continue; } + if (0 == strcmp("simple_metadata", argv[i])) { + simple_metadata(config); + continue; + } if (0 == strcmp("simple_request", argv[i])) { simple_request(config); continue; diff --git a/test/core/end2end/end2end_tests.c b/test/core/end2end/end2end_tests.c index 397ff446a9..6f2f5aff78 100644 --- a/test/core/end2end/end2end_tests.c +++ b/test/core/end2end/end2end_tests.c @@ -47,9 +47,8 @@ extern void cancel_after_invoke(grpc_end2end_test_config config); extern void cancel_before_invoke(grpc_end2end_test_config config); extern void cancel_in_a_vacuum(grpc_end2end_test_config config); extern void cancel_with_status(grpc_end2end_test_config config); -extern void channel_connectivity(grpc_end2end_test_config config); -extern void channel_ping(grpc_end2end_test_config config); extern void compressed_payload(grpc_end2end_test_config config); +extern void connectivity(grpc_end2end_test_config config); extern void default_host(grpc_end2end_test_config config); extern void disappearing_server(grpc_end2end_test_config config); extern void empty_batch(grpc_end2end_test_config config); @@ -60,10 +59,10 @@ extern void invoke_large_request(grpc_end2end_test_config config); extern void large_metadata(grpc_end2end_test_config config); extern void max_concurrent_streams(grpc_end2end_test_config config); extern void max_message_length(grpc_end2end_test_config config); -extern void metadata(grpc_end2end_test_config config); extern void negative_deadline(grpc_end2end_test_config config); extern void no_op(grpc_end2end_test_config config); extern void payload(grpc_end2end_test_config config); +extern void ping(grpc_end2end_test_config config); extern void ping_pong_streaming(grpc_end2end_test_config config); extern void registered_call(grpc_end2end_test_config config); extern void request_with_flags(grpc_end2end_test_config config); @@ -72,6 +71,7 @@ extern void server_finishes_request(grpc_end2end_test_config config); extern void shutdown_finishes_calls(grpc_end2end_test_config config); extern void shutdown_finishes_tags(grpc_end2end_test_config config); extern void simple_delayed_request(grpc_end2end_test_config config); +extern void simple_metadata(grpc_end2end_test_config config); extern void simple_request(grpc_end2end_test_config config); extern void trailing_metadata(grpc_end2end_test_config config); @@ -89,9 +89,8 @@ void grpc_end2end_tests(int argc, char **argv, cancel_before_invoke(config); cancel_in_a_vacuum(config); cancel_with_status(config); - channel_connectivity(config); - channel_ping(config); compressed_payload(config); + connectivity(config); default_host(config); disappearing_server(config); empty_batch(config); @@ -102,10 +101,10 @@ void grpc_end2end_tests(int argc, char **argv, large_metadata(config); max_concurrent_streams(config); max_message_length(config); - metadata(config); negative_deadline(config); no_op(config); payload(config); + ping(config); ping_pong_streaming(config); registered_call(config); request_with_flags(config); @@ -114,6 +113,7 @@ void grpc_end2end_tests(int argc, char **argv, shutdown_finishes_calls(config); shutdown_finishes_tags(config); simple_delayed_request(config); + simple_metadata(config); simple_request(config); trailing_metadata(config); return; @@ -156,18 +156,14 @@ void grpc_end2end_tests(int argc, char **argv, cancel_with_status(config); continue; } - if (0 == strcmp("channel_connectivity", argv[i])) { - channel_connectivity(config); - continue; - } - if (0 == strcmp("channel_ping", argv[i])) { - channel_ping(config); - continue; - } if (0 == strcmp("compressed_payload", argv[i])) { compressed_payload(config); continue; } + if (0 == strcmp("connectivity", argv[i])) { + connectivity(config); + continue; + } if (0 == strcmp("default_host", argv[i])) { default_host(config); continue; @@ -208,10 +204,6 @@ void grpc_end2end_tests(int argc, char **argv, max_message_length(config); continue; } - if (0 == strcmp("metadata", argv[i])) { - metadata(config); - continue; - } if (0 == strcmp("negative_deadline", argv[i])) { negative_deadline(config); continue; @@ -224,6 +216,10 @@ void grpc_end2end_tests(int argc, char **argv, payload(config); continue; } + if (0 == strcmp("ping", argv[i])) { + ping(config); + continue; + } if (0 == strcmp("ping_pong_streaming", argv[i])) { ping_pong_streaming(config); continue; @@ -256,6 +252,10 @@ void grpc_end2end_tests(int argc, char **argv, simple_delayed_request(config); continue; } + if (0 == strcmp("simple_metadata", argv[i])) { + simple_metadata(config); + continue; + } if (0 == strcmp("simple_request", argv[i])) { simple_request(config); continue; diff --git a/test/core/end2end/fixtures/h2_full+poll+pipe.c b/test/core/end2end/fixtures/h2_full+poll+pipe.c index d475a7bb55..682598fbe2 100644 --- a/test/core/end2end/fixtures/h2_full+poll+pipe.c +++ b/test/core/end2end/fixtures/h2_full+poll+pipe.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 @@ -35,21 +35,23 @@ #include <string.h> -#include "src/core/channel/client_channel.h" -#include "src/core/channel/connected_channel.h" -#include "src/core/channel/http_server_filter.h" -#include "src/core/surface/channel.h" -#include "src/core/surface/server.h" -#include "src/core/transport/chttp2_transport.h" #include <grpc/support/alloc.h> #include <grpc/support/host_port.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/thd.h> #include <grpc/support/useful.h> + +#include "src/core/channel/client_channel.h" +#include "src/core/channel/connected_channel.h" +#include "src/core/channel/http_server_filter.h" +#include "src/core/iomgr/pollset_posix.h" +#include "src/core/iomgr/wakeup_fd_posix.h" +#include "src/core/surface/channel.h" +#include "src/core/surface/server.h" +#include "src/core/transport/chttp2_transport.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" -#include "src/core/iomgr/wakeup_fd_posix.h" typedef struct fullstack_fixture_data { char *localaddr; diff --git a/test/core/end2end/fixtures/h2_full+poll.c b/test/core/end2end/fixtures/h2_full+poll.c index 3f5e6096f6..5a0b2ef495 100644 --- a/test/core/end2end/fixtures/h2_full+poll.c +++ b/test/core/end2end/fixtures/h2_full+poll.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 @@ -35,18 +35,20 @@ #include <string.h> -#include "src/core/channel/client_channel.h" -#include "src/core/channel/connected_channel.h" -#include "src/core/channel/http_server_filter.h" -#include "src/core/surface/channel.h" -#include "src/core/surface/server.h" -#include "src/core/transport/chttp2_transport.h" #include <grpc/support/alloc.h> #include <grpc/support/host_port.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/thd.h> #include <grpc/support/useful.h> + +#include "src/core/channel/client_channel.h" +#include "src/core/channel/connected_channel.h" +#include "src/core/channel/http_server_filter.h" +#include "src/core/iomgr/pollset_posix.h" +#include "src/core/surface/channel.h" +#include "src/core/surface/server.h" +#include "src/core/transport/chttp2_transport.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/core/end2end/fixtures/h2_ssl+poll.c b/test/core/end2end/fixtures/h2_ssl+poll.c index 614654ed52..66268c77d5 100644 --- a/test/core/end2end/fixtures/h2_ssl+poll.c +++ b/test/core/end2end/fixtures/h2_ssl+poll.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,17 +36,19 @@ #include <stdio.h> #include <string.h> +#include <grpc/support/alloc.h> +#include <grpc/support/host_port.h> +#include <grpc/support/log.h> + #include "src/core/channel/channel_args.h" +#include "src/core/iomgr/pollset_posix.h" #include "src/core/security/credentials.h" #include "src/core/support/env.h" -#include "src/core/support/file.h" +#include "src/core/support/tmpfile.h" #include "src/core/support/string.h" -#include <grpc/support/alloc.h> -#include <grpc/support/host_port.h> -#include <grpc/support/log.h> -#include "test/core/util/test_config.h" -#include "test/core/util/port.h" #include "test/core/end2end/data/ssl_test_data.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" typedef struct fullstack_secure_fixture_data { char *localaddr; diff --git a/test/core/end2end/fixtures/h2_ssl.c b/test/core/end2end/fixtures/h2_ssl.c index 5c63dfb6aa..e21a3477df 100644 --- a/test/core/end2end/fixtures/h2_ssl.c +++ b/test/core/end2end/fixtures/h2_ssl.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,17 +36,18 @@ #include <stdio.h> #include <string.h> +#include <grpc/support/alloc.h> +#include <grpc/support/host_port.h> +#include <grpc/support/log.h> + #include "src/core/channel/channel_args.h" #include "src/core/security/credentials.h" #include "src/core/support/env.h" -#include "src/core/support/file.h" +#include "src/core/support/tmpfile.h" #include "src/core/support/string.h" -#include <grpc/support/alloc.h> -#include <grpc/support/host_port.h> -#include <grpc/support/log.h> -#include "test/core/util/test_config.h" -#include "test/core/util/port.h" #include "test/core/end2end/data/ssl_test_data.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" typedef struct fullstack_secure_fixture_data { char *localaddr; diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.c b/test/core/end2end/fixtures/h2_ssl_proxy.c index a93bd83a1f..6340d3f403 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.c +++ b/test/core/end2end/fixtures/h2_ssl_proxy.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,18 +36,19 @@ #include <stdio.h> #include <string.h> +#include <grpc/support/alloc.h> +#include <grpc/support/host_port.h> +#include <grpc/support/log.h> + #include "src/core/channel/channel_args.h" #include "src/core/security/credentials.h" #include "src/core/support/env.h" -#include "src/core/support/file.h" +#include "src/core/support/tmpfile.h" #include "src/core/support/string.h" -#include <grpc/support/alloc.h> -#include <grpc/support/host_port.h> -#include <grpc/support/log.h> #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/end2end/fixtures/proxy.h" -#include "test/core/util/test_config.h" #include "test/core/util/port.h" +#include "test/core/util/test_config.h" typedef struct fullstack_secure_fixture_data { grpc_end2end_proxy *proxy; diff --git a/test/core/end2end/fixtures/h2_uchannel.c b/test/core/end2end/fixtures/h2_uchannel.c index dbdd3524ed..87bbd64d09 100644 --- a/test/core/end2end/fixtures/h2_uchannel.c +++ b/test/core/end2end/fixtures/h2_uchannel.c @@ -35,6 +35,13 @@ #include <string.h> +#include <grpc/support/alloc.h> +#include <grpc/support/host_port.h> +#include <grpc/support/log.h> +#include <grpc/support/string_util.h> +#include <grpc/support/sync.h> +#include <grpc/support/thd.h> +#include <grpc/support/useful.h> #include "src/core/channel/channel_args.h" #include "src/core/channel/client_channel.h" #include "src/core/channel/client_uchannel.h" @@ -46,13 +53,6 @@ #include "src/core/surface/channel.h" #include "src/core/surface/server.h" #include "src/core/transport/chttp2_transport.h" -#include <grpc/support/alloc.h> -#include <grpc/support/host_port.h> -#include <grpc/support/log.h> -#include <grpc/support/string_util.h> -#include <grpc/support/sync.h> -#include <grpc/support/thd.h> -#include <grpc/support/useful.h> #include "test/core/util/port.h" #include "test/core/util/test_config.h" @@ -238,12 +238,12 @@ static grpc_end2end_test_fixture chttp2_create_fixture_micro_fullstack( } grpc_connectivity_state g_state = GRPC_CHANNEL_IDLE; -grpc_pollset_set g_interested_parties; +grpc_pollset_set *g_interested_parties; 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, + exec_ctx, arg, g_interested_parties, &g_state, grpc_closure_create(state_changed, arg)); } } @@ -253,30 +253,31 @@ static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *arg, bool success) { } static grpc_connected_subchannel *connect_subchannel(grpc_subchannel *c) { - grpc_pollset pollset; + gpr_mu *mu; + grpc_pollset *pollset = gpr_malloc(grpc_pollset_size()); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_pollset_init(&pollset); - grpc_pollset_set_init(&g_interested_parties); - grpc_pollset_set_add_pollset(&exec_ctx, &g_interested_parties, &pollset); - grpc_subchannel_notify_on_state_change(&exec_ctx, c, &g_interested_parties, + grpc_pollset_init(pollset, &mu); + g_interested_parties = grpc_pollset_set_create(); + grpc_pollset_set_add_pollset(&exec_ctx, g_interested_parties, pollset); + grpc_subchannel_notify_on_state_change(&exec_ctx, c, g_interested_parties, &g_state, grpc_closure_create(state_changed, c)); grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&pollset)); + gpr_mu_lock(mu); while (g_state != GRPC_CHANNEL_READY) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &pollset, &worker, - gpr_now(GPR_CLOCK_MONOTONIC), + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)); - gpr_mu_unlock(GRPC_POLLSET_MU(&pollset)); + gpr_mu_unlock(mu); grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&pollset)); + gpr_mu_lock(mu); } - grpc_pollset_shutdown(&exec_ctx, &pollset, - grpc_closure_create(destroy_pollset, &pollset)); - grpc_pollset_set_destroy(&g_interested_parties); - gpr_mu_unlock(GRPC_POLLSET_MU(&pollset)); + grpc_pollset_shutdown(&exec_ctx, pollset, + grpc_closure_create(destroy_pollset, pollset)); + grpc_pollset_set_destroy(g_interested_parties); + gpr_mu_unlock(mu); grpc_exec_ctx_finish(&exec_ctx); + gpr_free(pollset); return grpc_subchannel_get_connected_subchannel(c); } diff --git a/test/core/end2end/fixtures/h2_uds+poll.c b/test/core/end2end/fixtures/h2_uds+poll.c index 155017c887..c3a855ff88 100644 --- a/test/core/end2end/fixtures/h2_uds+poll.c +++ b/test/core/end2end/fixtures/h2_uds+poll.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,13 +37,6 @@ #include <string.h> #include <unistd.h> -#include "src/core/channel/client_channel.h" -#include "src/core/channel/connected_channel.h" -#include "src/core/channel/http_server_filter.h" -#include "src/core/support/string.h" -#include "src/core/surface/channel.h" -#include "src/core/surface/server.h" -#include "src/core/transport/chttp2_transport.h" #include <grpc/support/alloc.h> #include <grpc/support/host_port.h> #include <grpc/support/log.h> @@ -51,6 +44,15 @@ #include <grpc/support/sync.h> #include <grpc/support/thd.h> #include <grpc/support/useful.h> + +#include "src/core/channel/client_channel.h" +#include "src/core/channel/connected_channel.h" +#include "src/core/channel/http_server_filter.h" +#include "src/core/iomgr/pollset_posix.h" +#include "src/core/support/string.h" +#include "src/core/surface/channel.h" +#include "src/core/surface/server.h" +#include "src/core/transport/chttp2_transport.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index f24dbe72cf..4dfafcea24 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -94,9 +94,8 @@ END2END_TESTS = { 'cancel_before_invoke': default_test_options._replace(cpu_cost=LOWCPU), 'cancel_in_a_vacuum': default_test_options._replace(cpu_cost=LOWCPU), 'cancel_with_status': default_test_options._replace(cpu_cost=LOWCPU), - 'channel_connectivity': connectivity_test_options._replace(proxyable=False, cpu_cost=LOWCPU), - 'channel_ping': connectivity_test_options._replace(proxyable=False), 'compressed_payload': default_test_options._replace(proxyable=False, cpu_cost=LOWCPU), + 'connectivity': connectivity_test_options._replace(proxyable=False, cpu_cost=LOWCPU), 'default_host': default_test_options._replace(needs_fullstack=True, needs_dns=True), 'disappearing_server': connectivity_test_options, @@ -109,11 +108,11 @@ END2END_TESTS = { 'large_metadata': default_test_options, 'max_concurrent_streams': default_test_options._replace(proxyable=False), 'max_message_length': default_test_options._replace(cpu_cost=LOWCPU), - 'metadata': default_test_options, 'negative_deadline': default_test_options, 'no_op': default_test_options, 'payload': default_test_options._replace(cpu_cost=LOWCPU), 'ping_pong_streaming': default_test_options, + 'ping': connectivity_test_options._replace(proxyable=False), 'registered_call': default_test_options, 'request_with_flags': default_test_options._replace(proxyable=False), 'request_with_payload': default_test_options, @@ -121,6 +120,7 @@ END2END_TESTS = { 'shutdown_finishes_calls': default_test_options, 'shutdown_finishes_tags': default_test_options, 'simple_delayed_request': connectivity_test_options._replace(cpu_cost=LOWCPU), + 'simple_metadata': default_test_options, 'simple_request': default_test_options, 'trailing_metadata': default_test_options, } diff --git a/test/core/end2end/tests/channel_connectivity.c b/test/core/end2end/tests/connectivity.c index 0e21e65557..975c620731 100644 --- a/test/core/end2end/tests/channel_connectivity.c +++ b/test/core/end2end/tests/connectivity.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 @@ -168,7 +168,7 @@ static void test_connectivity(grpc_end2end_test_config config) { cq_verifier_destroy(cqv); } -void channel_connectivity(grpc_end2end_test_config config) { +void connectivity(grpc_end2end_test_config config) { GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION); test_connectivity(config); } diff --git a/test/core/end2end/tests/channel_ping.c b/test/core/end2end/tests/ping.c index 73fab206fb..f85df63de7 100644 --- a/test/core/end2end/tests/channel_ping.c +++ b/test/core/end2end/tests/ping.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 @@ -91,7 +91,7 @@ static void test_ping(grpc_end2end_test_config config) { cq_verifier_destroy(cqv); } -void channel_ping(grpc_end2end_test_config config) { +void ping(grpc_end2end_test_config config) { GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION); test_ping(config); } diff --git a/test/core/end2end/tests/metadata.c b/test/core/end2end/tests/simple_metadata.c index 5e92091eb7..c5084a560f 100644 --- a/test/core/end2end/tests/metadata.c +++ b/test/core/end2end/tests/simple_metadata.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 @@ -260,6 +260,6 @@ static void test_request_response_with_metadata_and_payload( config.tear_down_data(&f); } -void metadata(grpc_end2end_test_config config) { +void simple_metadata(grpc_end2end_test_config config) { test_request_response_with_metadata_and_payload(config); } diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c index 651ef1fa3b..da1463329d 100644 --- a/test/core/httpcli/httpcli_test.c +++ b/test/core/httpcli/httpcli_test.c @@ -36,18 +36,19 @@ #include <string.h> #include <grpc/grpc.h> -#include "src/core/iomgr/iomgr.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/subprocess.h> #include <grpc/support/sync.h> +#include "src/core/iomgr/iomgr.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" static int g_done = 0; static grpc_httpcli_context g_context; -static grpc_pollset g_pollset; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; static gpr_timespec n_seconds_time(int seconds) { return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(seconds); @@ -63,10 +64,10 @@ static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, GPR_ASSERT(response->status == 200); GPR_ASSERT(response->body_length == strlen(expect)); GPR_ASSERT(0 == memcmp(expect, response->body, response->body_length)); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); g_done = 1; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } static void test_get(int port) { @@ -85,18 +86,18 @@ static void test_get(int port) { req.path = "/get"; req.handshaker = &grpc_httpcli_plaintext; - grpc_httpcli_get(&exec_ctx, &g_context, &g_pollset, &req, n_seconds_time(15), + grpc_httpcli_get(&exec_ctx, &g_context, g_pollset, &req, n_seconds_time(15), on_finish, (void *)42); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (!g_done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), n_seconds_time(20)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); gpr_free(host); } @@ -116,18 +117,18 @@ static void test_post(int port) { req.path = "/post"; req.handshaker = &grpc_httpcli_plaintext; - grpc_httpcli_post(&exec_ctx, &g_context, &g_pollset, &req, "hello", 5, + grpc_httpcli_post(&exec_ctx, &g_context, g_pollset, &req, "hello", 5, n_seconds_time(15), on_finish, (void *)42); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (!g_done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), n_seconds_time(20)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); gpr_free(host); } @@ -175,17 +176,20 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); grpc_httpcli_context_init(&g_context); - grpc_pollset_init(&g_pollset); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); test_get(port); test_post(port); grpc_httpcli_context_destroy(&g_context); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); + gpr_free(g_pollset); + gpr_subprocess_destroy(server); return 0; diff --git a/test/core/httpcli/httpscli_test.c b/test/core/httpcli/httpscli_test.c index db41be17e7..7f765bc614 100644 --- a/test/core/httpcli/httpscli_test.c +++ b/test/core/httpcli/httpscli_test.c @@ -36,18 +36,19 @@ #include <string.h> #include <grpc/grpc.h> -#include "src/core/iomgr/iomgr.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/subprocess.h> #include <grpc/support/sync.h> +#include "src/core/iomgr/iomgr.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" static int g_done = 0; static grpc_httpcli_context g_context; -static grpc_pollset g_pollset; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; static gpr_timespec n_seconds_time(int seconds) { return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(seconds); @@ -63,10 +64,10 @@ static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, GPR_ASSERT(response->status == 200); GPR_ASSERT(response->body_length == strlen(expect)); GPR_ASSERT(0 == memcmp(expect, response->body, response->body_length)); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); g_done = 1; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } static void test_get(int port) { @@ -86,18 +87,18 @@ static void test_get(int port) { req.path = "/get"; req.handshaker = &grpc_httpcli_ssl; - grpc_httpcli_get(&exec_ctx, &g_context, &g_pollset, &req, n_seconds_time(15), + grpc_httpcli_get(&exec_ctx, &g_context, g_pollset, &req, n_seconds_time(15), on_finish, (void *)42); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (!g_done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), n_seconds_time(20)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); gpr_free(host); } @@ -118,18 +119,18 @@ static void test_post(int port) { req.path = "/post"; req.handshaker = &grpc_httpcli_ssl; - grpc_httpcli_post(&exec_ctx, &g_context, &g_pollset, &req, "hello", 5, + grpc_httpcli_post(&exec_ctx, &g_context, g_pollset, &req, "hello", 5, n_seconds_time(15), on_finish, (void *)42); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (!g_done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), n_seconds_time(20)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); gpr_free(host); } @@ -178,17 +179,20 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); grpc_httpcli_context_init(&g_context); - grpc_pollset_init(&g_pollset); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); test_get(port); test_post(port); grpc_httpcli_context_destroy(&g_context); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); + gpr_free(g_pollset); + gpr_subprocess_destroy(server); return 0; diff --git a/test/core/iomgr/endpoint_pair_test.c b/test/core/iomgr/endpoint_pair_test.c index 7e266ebfb9..c3a91088a5 100644 --- a/test/core/iomgr/endpoint_pair_test.c +++ b/test/core/iomgr/endpoint_pair_test.c @@ -39,10 +39,11 @@ #include <grpc/support/time.h> #include <grpc/support/useful.h> #include "src/core/iomgr/endpoint_pair.h" -#include "test/core/util/test_config.h" #include "test/core/iomgr/endpoint_tests.h" +#include "test/core/util/test_config.h" -static grpc_pollset g_pollset; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; static void clean_up(void) {} @@ -54,8 +55,8 @@ static grpc_endpoint_test_fixture create_fixture_endpoint_pair( f.client_ep = p.client; f.server_ep = p.server; - grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, &g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); grpc_exec_ctx_finish(&exec_ctx); return f; @@ -74,12 +75,14 @@ int main(int argc, char **argv) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - grpc_pollset_init(&g_pollset); - grpc_endpoint_tests(configs[0], &g_pollset); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); + gpr_free(g_pollset); return 0; } diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 1b6a78da9a..f689e4ba7f 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -36,8 +36,8 @@ #include <sys/types.h> #include <grpc/support/alloc.h> -#include <grpc/support/slice.h> #include <grpc/support/log.h> +#include <grpc/support/slice.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> #include "test/core/util/test_config.h" @@ -58,6 +58,7 @@ */ +static gpr_mu *g_mu; static grpc_pollset *g_pollset; size_t count_slices(gpr_slice *slices, size_t nslices, int *current_data) { @@ -134,10 +135,10 @@ static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx, state->incoming.slices, state->incoming.count, &state->current_read_data); if (state->bytes_read == state->target_bytes || !success) { gpr_log(GPR_INFO, "Read handler done"); - gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); + gpr_mu_lock(g_mu); state->read_done = 1 + success; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); + gpr_mu_unlock(g_mu); } else if (success) { grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming, &state->done_read); @@ -169,10 +170,10 @@ static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx, } gpr_log(GPR_INFO, "Write handler done"); - gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); + gpr_mu_lock(g_mu); state->write_done = 1 + success; grpc_pollset_kick(g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); + gpr_mu_unlock(g_mu); } /* Do both reading and writing using the grpc_endpoint API. @@ -232,14 +233,14 @@ static void read_and_write_test(grpc_endpoint_test_config config, } grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); + gpr_mu_lock(g_mu); while (!state.read_done || !state.write_done) { - grpc_pollset_worker worker; + grpc_pollset_worker *worker = NULL; GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), deadline) < 0); grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); } - gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); end_test(config); @@ -251,9 +252,10 @@ static void read_and_write_test(grpc_endpoint_test_config config, } void grpc_endpoint_tests(grpc_endpoint_test_config config, - grpc_pollset *pollset) { + grpc_pollset *pollset, gpr_mu *mu) { size_t i; g_pollset = pollset; + g_mu = mu; read_and_write_test(config, 10000000, 100000, 8192, 0); read_and_write_test(config, 1000000, 100000, 1, 0); read_and_write_test(config, 100000000, 100000, 1, 1); diff --git a/test/core/iomgr/endpoint_tests.h b/test/core/iomgr/endpoint_tests.h index 700f854891..8ea47e345c 100644 --- a/test/core/iomgr/endpoint_tests.h +++ b/test/core/iomgr/endpoint_tests.h @@ -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 @@ -53,6 +53,6 @@ struct grpc_endpoint_test_config { }; void grpc_endpoint_tests(grpc_endpoint_test_config config, - grpc_pollset *pollset); + grpc_pollset *pollset, gpr_mu *mu); #endif /* GRPC_TEST_CORE_IOMGR_ENDPOINT_TESTS_H */ diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 347a86af10..99689ebcc3 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -49,9 +49,12 @@ #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/time.h> + +#include "src/core/iomgr/pollset_posix.h" #include "test/core/util/test_config.h" -static grpc_pollset g_pollset; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; /* buffer size used to send and receive data. 1024 is the minimal value to set TCP send and receive buffer. */ @@ -179,10 +182,10 @@ static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */, grpc_fd_orphan(exec_ctx, sv->em_fd, NULL, NULL, "b"); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); sv->done = 1; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } /* Called when a new TCP connection request arrives in the listening port. */ @@ -209,7 +212,7 @@ static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/ se = gpr_malloc(sizeof(*se)); se->sv = sv; se->em_fd = grpc_fd_create(fd, "listener"); - grpc_pollset_add_fd(exec_ctx, &g_pollset, se->em_fd); + grpc_pollset_add_fd(exec_ctx, g_pollset, se->em_fd); se->session_read_closure.cb = session_read_cb; se->session_read_closure.cb_arg = se; grpc_fd_notify_on_read(exec_ctx, se->em_fd, &se->session_read_closure); @@ -238,7 +241,7 @@ static int server_start(grpc_exec_ctx *exec_ctx, server *sv) { GPR_ASSERT(listen(fd, MAX_NUM_FD) == 0); sv->em_fd = grpc_fd_create(fd, "server"); - grpc_pollset_add_fd(exec_ctx, &g_pollset, sv->em_fd); + grpc_pollset_add_fd(exec_ctx, g_pollset, sv->em_fd); /* Register to be interested in reading from listen_fd. */ sv->listen_closure.cb = listen_cb; sv->listen_closure.cb_arg = sv; @@ -249,18 +252,18 @@ static int server_start(grpc_exec_ctx *exec_ctx, server *sv) { /* Wait and shutdown a sever. */ static void server_wait_and_shutdown(server *sv) { - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (!sv->done) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); } /* ===An upload client to test notify_on_write=== */ @@ -296,7 +299,7 @@ static void client_session_shutdown_cb(grpc_exec_ctx *exec_ctx, client *cl = arg; grpc_fd_orphan(exec_ctx, cl->em_fd, NULL, NULL, "c"); cl->done = 1; - grpc_pollset_kick(&g_pollset, NULL); + grpc_pollset_kick(g_pollset, NULL); } /* Write as much as possible, then register notify_on_write. */ @@ -307,9 +310,9 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ ssize_t write_once = 0; if (!success) { - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); client_session_shutdown_cb(exec_ctx, arg, 1); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); return; } @@ -319,7 +322,7 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ } while (write_once > 0); if (errno == EAGAIN) { - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); if (cl->client_write_cnt < CLIENT_TOTAL_WRITE_CNT) { cl->write_closure.cb = client_session_write; cl->write_closure.cb_arg = cl; @@ -328,7 +331,7 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ } else { client_session_shutdown_cb(exec_ctx, arg, 1); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); } else { gpr_log(GPR_ERROR, "unknown errno %s", strerror(errno)); abort(); @@ -357,25 +360,25 @@ static void client_start(grpc_exec_ctx *exec_ctx, client *cl, int port) { } cl->em_fd = grpc_fd_create(fd, "client"); - grpc_pollset_add_fd(exec_ctx, &g_pollset, cl->em_fd); + grpc_pollset_add_fd(exec_ctx, g_pollset, cl->em_fd); client_session_write(exec_ctx, cl, 1); } /* Wait for the signal to shutdown a client. */ static void client_wait_and_shutdown(client *cl) { - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (!cl->done) { - grpc_pollset_worker worker; + grpc_pollset_worker *worker = NULL; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); } /* Test grpc_fd. Start an upload server and client, upload a stream of @@ -410,20 +413,20 @@ static void first_read_callback(grpc_exec_ctx *exec_ctx, void *arg /* fd_change_data */, bool success) { fd_change_data *fdc = arg; - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); fdc->cb_that_ran = first_read_callback; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } static void second_read_callback(grpc_exec_ctx *exec_ctx, void *arg /* fd_change_data */, bool success) { fd_change_data *fdc = arg; - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); fdc->cb_that_ran = second_read_callback; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } /* Test that changing the callback we use for notify_on_read actually works. @@ -456,7 +459,7 @@ static void test_grpc_fd_change(void) { GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0); em_fd = grpc_fd_create(sv[0], "test_grpc_fd_change"); - grpc_pollset_add_fd(&exec_ctx, &g_pollset, em_fd); + grpc_pollset_add_fd(&exec_ctx, g_pollset, em_fd); /* Register the first callback, then make its FD readable */ grpc_fd_notify_on_read(&exec_ctx, em_fd, &first_closure); @@ -465,18 +468,18 @@ static void test_grpc_fd_change(void) { GPR_ASSERT(result == 1); /* And now wait for it to run. */ - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (a.cb_that_ran == NULL) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } GPR_ASSERT(a.cb_that_ran == first_read_callback); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); /* And drain the socket so we can generate a new read edge */ result = read(sv[0], &data, 1); @@ -489,19 +492,19 @@ static void test_grpc_fd_change(void) { result = write(sv[1], &data, 1); GPR_ASSERT(result == 1); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (b.cb_that_ran == NULL) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } /* Except now we verify that second_read_callback ran instead */ GPR_ASSERT(b.cb_that_ran == second_read_callback); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_fd_orphan(&exec_ctx, em_fd, NULL, NULL, "d"); grpc_exec_ctx_finish(&exec_ctx); @@ -519,12 +522,14 @@ int main(int argc, char **argv) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_iomgr_init(); - grpc_pollset_init(&g_pollset); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); test_grpc_fd(); test_grpc_fd_change(); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); + gpr_free(g_pollset); grpc_iomgr_shutdown(); return 0; } diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index 9725d8a3b6..746dfd85be 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -40,15 +40,18 @@ #include <unistd.h> #include <grpc/grpc.h> +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/time.h> #include "src/core/iomgr/iomgr.h" #include "src/core/iomgr/socket_utils_posix.h" +#include "src/core/iomgr/timer.h" #include "test/core/util/test_config.h" -static grpc_pollset_set g_pollset_set; -static grpc_pollset g_pollset; +static grpc_pollset_set *g_pollset_set; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; static int g_connections_complete = 0; static grpc_endpoint *g_connecting = NULL; @@ -57,10 +60,10 @@ static gpr_timespec test_deadline(void) { } static void finish_connection() { - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); g_connections_complete++; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, bool success) { @@ -98,14 +101,14 @@ void test_succeeds(void) { GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)&addr, addr_len)); GPR_ASSERT(0 == listen(svr_fd, 1)); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); connections_complete_before = g_connections_complete; - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); /* connect to it */ GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0); grpc_closure_init(&done, must_succeed, NULL); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set, + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, (struct sockaddr *)&addr, addr_len, gpr_inf_future(GPR_CLOCK_REALTIME)); @@ -117,19 +120,21 @@ void test_succeeds(void) { GPR_ASSERT(r >= 0); close(r); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (g_connections_complete == connections_complete_before) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); + grpc_exec_ctx_flush(&exec_ctx); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); + + grpc_exec_ctx_finish(&exec_ctx); } void test_fails(void) { @@ -144,118 +149,33 @@ void test_fails(void) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); connections_complete_before = g_connections_complete; - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); /* connect to a broken address */ grpc_closure_init(&done, must_fail, NULL); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set, + grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, (struct sockaddr *)&addr, addr_len, gpr_inf_future(GPR_CLOCK_REALTIME)); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); /* wait for the connection callback to finish */ while (g_connections_complete == connections_complete_before) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, - gpr_now(GPR_CLOCK_MONOTONIC), test_deadline()); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - } - - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); -} - -void test_times_out(void) { - struct sockaddr_in addr; - socklen_t addr_len = sizeof(addr); - int svr_fd; -#define NUM_CLIENT_CONNECTS 100 - int client_fd[NUM_CLIENT_CONNECTS]; - int i; - int r; - int connections_complete_before; - gpr_timespec connect_deadline; - grpc_closure done; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - gpr_log(GPR_DEBUG, "test_times_out"); - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - - /* create a dummy server */ - svr_fd = socket(AF_INET, SOCK_STREAM, 0); - GPR_ASSERT(svr_fd >= 0); - GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)&addr, addr_len)); - GPR_ASSERT(0 == listen(svr_fd, 1)); - /* Get its address */ - GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0); - - /* tie up the listen buffer, which is somewhat arbitrarily sized. */ - for (i = 0; i < NUM_CLIENT_CONNECTS; ++i) { - client_fd[i] = socket(AF_INET, SOCK_STREAM, 0); - grpc_set_socket_nonblocking(client_fd[i], 1); - do { - r = connect(client_fd[i], (struct sockaddr *)&addr, addr_len); - } while (r == -1 && errno == EINTR); - GPR_ASSERT(r < 0); - GPR_ASSERT(errno == EWOULDBLOCK || errno == EINPROGRESS); - } - - /* connect to dummy server address */ - - connect_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); - - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - connections_complete_before = g_connections_complete; - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - - grpc_closure_init(&done, must_fail, NULL); - grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, &g_pollset_set, - (struct sockaddr *)&addr, addr_len, connect_deadline); - - /* Make sure the event doesn't trigger early */ - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - for (;;) { - grpc_pollset_worker worker; - gpr_timespec now = gpr_now(connect_deadline.clock_type); - gpr_timespec continue_verifying_time = - gpr_time_from_seconds(5, GPR_TIMESPAN); - gpr_timespec grace_time = gpr_time_from_seconds(3, GPR_TIMESPAN); - gpr_timespec finish_time = - gpr_time_add(connect_deadline, continue_verifying_time); - gpr_timespec restart_verifying_time = - gpr_time_add(connect_deadline, grace_time); - int is_after_deadline = gpr_time_cmp(now, connect_deadline) > 0; - if (gpr_time_cmp(now, finish_time) > 0) { - break; + grpc_pollset_worker *worker = NULL; + gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); + gpr_timespec polling_deadline = test_deadline(); + if (!grpc_timer_check(&exec_ctx, now, &polling_deadline)) { + grpc_pollset_work(&exec_ctx, g_pollset, &worker, now, polling_deadline); } - gpr_log(GPR_DEBUG, "now=%lld.%09d connect_deadline=%lld.%09d", - (long long)now.tv_sec, (int)now.tv_nsec, - (long long)connect_deadline.tv_sec, (int)connect_deadline.tv_nsec); - if (is_after_deadline && gpr_time_cmp(now, restart_verifying_time) <= 0) { - /* allow some slack before insisting that things be done */ - } else { - GPR_ASSERT(g_connections_complete == - connections_complete_before + is_after_deadline); - } - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, - gpr_now(GPR_CLOCK_MONOTONIC), - GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); + grpc_exec_ctx_flush(&exec_ctx); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); - close(svr_fd); - for (i = 0; i < NUM_CLIENT_CONNECTS; ++i) { - close(client_fd[i]); - } + gpr_mu_unlock(g_mu); + grpc_exec_ctx_finish(&exec_ctx); } static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) { @@ -267,18 +187,19 @@ int main(int argc, char **argv) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - grpc_pollset_set_init(&g_pollset_set); - grpc_pollset_init(&g_pollset); - grpc_pollset_set_add_pollset(&exec_ctx, &g_pollset_set, &g_pollset); + g_pollset_set = grpc_pollset_set_create(); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_pollset_set_add_pollset(&exec_ctx, g_pollset_set, g_pollset); grpc_exec_ctx_finish(&exec_ctx); test_succeeds(); gpr_log(GPR_ERROR, "End of first test"); test_fails(); - test_times_out(); - grpc_pollset_set_destroy(&g_pollset_set); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_pollset_set_destroy(g_pollset_set); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); + gpr_free(g_pollset); return 0; } diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index d290c6bc3a..4351642ab6 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -36,8 +36,8 @@ #include <errno.h> #include <fcntl.h> #include <string.h> -#include <sys/types.h> #include <sys/socket.h> +#include <sys/types.h> #include <unistd.h> #include <grpc/grpc.h> @@ -45,10 +45,11 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "test/core/util/test_config.h" #include "test/core/iomgr/endpoint_tests.h" +#include "test/core/util/test_config.h" -static grpc_pollset g_pollset; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; /* General test notes: @@ -145,7 +146,7 @@ static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) { GPR_ASSERT(success); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); current_data = state->read_bytes % 256; read_bytes = count_slices(state->incoming.slices, state->incoming.count, ¤t_data); @@ -153,10 +154,10 @@ static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, bool success) { gpr_log(GPR_INFO, "Read %d bytes of %d", read_bytes, state->target_read_bytes); if (state->read_bytes >= state->target_read_bytes) { - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); } else { grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); } } @@ -175,7 +176,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { create_sockets(sv); ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size, "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); @@ -188,17 +189,17 @@ static void read_test(size_t num_bytes, size_t slice_size) { grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); gpr_slice_buffer_destroy(&state.incoming); grpc_endpoint_destroy(&exec_ctx, ep); @@ -221,7 +222,7 @@ static void large_read_test(size_t slice_size) { ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), slice_size, "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket(sv[0]); gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); @@ -234,17 +235,17 @@ static void large_read_test(size_t slice_size) { grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); gpr_slice_buffer_destroy(&state.incoming); grpc_endpoint_destroy(&exec_ctx, ep); @@ -283,11 +284,11 @@ static void write_done(grpc_exec_ctx *exec_ctx, 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)); + gpr_mu_lock(g_mu); gpr_log(GPR_INFO, "Signalling write done"); state->write_done = 1; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { @@ -303,12 +304,12 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0); for (;;) { - grpc_pollset_worker worker; - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + gpr_mu_lock(g_mu); + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10)); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); do { bytes_read = @@ -350,7 +351,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); state.ep = ep; state.write_done = 0; @@ -363,19 +364,19 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_endpoint_write(&exec_ctx, ep, &outgoing, &write_done_closure); drain_socket_blocking(sv[0], num_bytes, num_bytes); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); for (;;) { - grpc_pollset_worker worker; + grpc_pollset_worker *worker = NULL; if (state.write_done) { break; } - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); gpr_slice_buffer_destroy(&outgoing); grpc_endpoint_destroy(&exec_ctx, ep); @@ -386,7 +387,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { void on_fd_released(grpc_exec_ctx *exec_ctx, void *arg, bool success) { int *done = arg; *done = 1; - grpc_pollset_kick(&g_pollset, NULL); + grpc_pollset_kick(g_pollset, NULL); } /* Do a read_test, then release fd and try to read/write again. Verify that @@ -410,7 +411,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size, "test"); GPR_ASSERT(grpc_tcp_fd(ep) == sv[1] && sv[1] >= 0); - grpc_endpoint_add_to_pollset(&exec_ctx, ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, ep, g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); gpr_log(GPR_INFO, "Wrote %d bytes", written_bytes); @@ -423,27 +424,27 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { grpc_endpoint_read(&exec_ctx, ep, &state.incoming, &state.read_cb); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (state.read_bytes < state.target_read_bytes) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } GPR_ASSERT(state.read_bytes == state.target_read_bytes); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); gpr_slice_buffer_destroy(&state.incoming); grpc_tcp_destroy_and_release_fd(&exec_ctx, ep, &fd, &fd_released_cb); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); while (!fd_released_done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); } - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); GPR_ASSERT(fd_released_done == 1); GPR_ASSERT(fd == sv[1]); grpc_exec_ctx_finish(&exec_ctx); @@ -491,8 +492,8 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( slice_size, "test"); f.server_ep = grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"), slice_size, "test"); - grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, &g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); grpc_exec_ctx_finish(&exec_ctx); @@ -512,13 +513,15 @@ int main(int argc, char **argv) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - grpc_pollset_init(&g_pollset); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); run_tests(); - grpc_endpoint_tests(configs[0], &g_pollset); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); + gpr_free(g_pollset); return 0; } diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index 272d97bfcb..7933468355 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -32,24 +32,28 @@ */ #include "src/core/iomgr/tcp_server.h" -#include "src/core/iomgr/iomgr.h" -#include "src/core/iomgr/sockaddr_utils.h" + +#include <errno.h> +#include <netinet/in.h> +#include <string.h> +#include <sys/socket.h> +#include <unistd.h> + #include <grpc/grpc.h> +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/time.h> + +#include "src/core/iomgr/iomgr.h" +#include "src/core/iomgr/sockaddr_utils.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" -#include <errno.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <string.h> -#include <unistd.h> - #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x) -static grpc_pollset g_pollset; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; static int g_nconnects = 0; typedef struct on_connect_result { @@ -113,11 +117,11 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, grpc_endpoint_shutdown(exec_ctx, tcp); grpc_endpoint_destroy(exec_ctx, tcp); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); on_connect_result_set(&g_result, acceptor); g_nconnects++; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } static void test_no_op(void) { @@ -174,7 +178,7 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote, int clifd = socket(remote->sa_family, SOCK_STREAM, 0); int nconnects_before; - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); nconnects_before = g_nconnects; on_connect_result_init(&g_result); GPR_ASSERT(clifd >= 0); @@ -183,19 +187,19 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote, gpr_log(GPR_DEBUG, "wait"); while (g_nconnects == nconnects_before && gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) { - grpc_pollset_worker worker; - grpc_pollset_work(exec_ctx, &g_pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(exec_ctx, g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); } gpr_log(GPR_DEBUG, "wait done"); GPR_ASSERT(g_nconnects == nconnects_before + 1); close(clifd); *result = g_result; - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_unlock(g_mu); } /* Tests a tcp server with multiple ports. TODO(daniel-j-born): Multiple fds for @@ -210,7 +214,6 @@ static void test_connect(unsigned n) { unsigned svr1_fd_count; int svr1_port; grpc_tcp_server *s = grpc_tcp_server_create(NULL); - grpc_pollset *pollsets[1]; unsigned i; server_weak_ref weak_ref; server_weak_ref_init(&weak_ref); @@ -259,8 +262,7 @@ static void test_connect(unsigned n) { } } - pollsets[0] = &g_pollset; - grpc_tcp_server_start(&exec_ctx, s, pollsets, 1, on_connect, NULL); + grpc_tcp_server_start(&exec_ctx, s, &g_pollset, 1, on_connect, NULL); for (i = 0; i < n; i++) { on_connect_result result; @@ -312,7 +314,8 @@ int main(int argc, char **argv) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - grpc_pollset_init(&g_pollset); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); test_no_op(); test_no_op_with_start(); @@ -321,9 +324,10 @@ int main(int argc, char **argv) { test_connect(1); test_connect(10); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); + gpr_free(g_pollset); return 0; } diff --git a/test/core/iomgr/timer_heap_test.c b/test/core/iomgr/timer_heap_test.c index 077a9fd6bd..cd34696f7d 100644 --- a/test/core/iomgr/timer_heap_test.c +++ b/test/core/iomgr/timer_heap_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 @@ -38,6 +38,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include <grpc/support/useful.h> + #include "test/core/util/test_config.h" static gpr_timespec random_deadline(void) { @@ -57,79 +59,6 @@ static grpc_timer *create_test_elements(size_t num_elements) { return elems; } -static int cmp_elem(const void *a, const void *b) { - int i = *(const int *)a; - int j = *(const int *)b; - return i - j; -} - -static size_t *all_top(grpc_timer_heap *pq, size_t *n) { - size_t *vec = NULL; - size_t *need_to_check_children; - size_t num_need_to_check_children = 0; - - *n = 0; - if (pq->timer_count == 0) return vec; - need_to_check_children = - gpr_malloc(pq->timer_count * sizeof(*need_to_check_children)); - need_to_check_children[num_need_to_check_children++] = 0; - vec = gpr_malloc(pq->timer_count * sizeof(*vec)); - while (num_need_to_check_children > 0) { - size_t ind = need_to_check_children[0]; - size_t leftchild, rightchild; - num_need_to_check_children--; - memmove(need_to_check_children, need_to_check_children + 1, - num_need_to_check_children * sizeof(*need_to_check_children)); - vec[(*n)++] = ind; - leftchild = 1u + 2u * ind; - if (leftchild < pq->timer_count) { - if (gpr_time_cmp(pq->timers[leftchild]->deadline, - pq->timers[ind]->deadline) >= 0) { - need_to_check_children[num_need_to_check_children++] = leftchild; - } - rightchild = leftchild + 1; - if (rightchild < pq->timer_count && - gpr_time_cmp(pq->timers[rightchild]->deadline, - pq->timers[ind]->deadline) >= 0) { - need_to_check_children[num_need_to_check_children++] = rightchild; - } - } - } - - gpr_free(need_to_check_children); - - return vec; -} - -static void check_pq_top(grpc_timer *elements, grpc_timer_heap *pq, - uint8_t *inpq, size_t num_elements) { - gpr_timespec max_deadline = gpr_inf_past(GPR_CLOCK_REALTIME); - size_t *max_deadline_indices = - gpr_malloc(num_elements * sizeof(*max_deadline_indices)); - size_t *top_elements; - size_t num_max_deadline_indices = 0; - size_t num_top_elements; - size_t i; - for (i = 0; i < num_elements; ++i) { - if (inpq[i] && gpr_time_cmp(elements[i].deadline, max_deadline) >= 0) { - if (gpr_time_cmp(elements[i].deadline, max_deadline) > 0) { - num_max_deadline_indices = 0; - max_deadline = elements[i].deadline; - } - max_deadline_indices[num_max_deadline_indices++] = elements[i].heap_index; - } - } - qsort(max_deadline_indices, num_max_deadline_indices, - sizeof(*max_deadline_indices), cmp_elem); - top_elements = all_top(pq, &num_top_elements); - GPR_ASSERT(num_top_elements == num_max_deadline_indices); - for (i = 0; i < num_top_elements; i++) { - GPR_ASSERT(max_deadline_indices[i] == top_elements[i]); - } - gpr_free(max_deadline_indices); - gpr_free(top_elements); -} - static int contains(grpc_timer_heap *pq, grpc_timer *el) { size_t i; for (i = 0; i < pq->timer_count; i++) { @@ -145,15 +74,19 @@ static void check_valid(grpc_timer_heap *pq) { size_t right_child = left_child + 1u; if (left_child < pq->timer_count) { GPR_ASSERT(gpr_time_cmp(pq->timers[i]->deadline, - pq->timers[left_child]->deadline) >= 0); + pq->timers[left_child]->deadline) <= 0); } if (right_child < pq->timer_count) { GPR_ASSERT(gpr_time_cmp(pq->timers[i]->deadline, - pq->timers[right_child]->deadline) >= 0); + pq->timers[right_child]->deadline) <= 0); } } } +/******************************************************************************* + * test1 + */ + static void test1(void) { grpc_timer_heap pq; const size_t num_test_elements = 200; @@ -162,6 +95,8 @@ static void test1(void) { grpc_timer *test_elements = create_test_elements(num_test_elements); uint8_t *inpq = gpr_malloc(num_test_elements); + gpr_log(GPR_INFO, "test1"); + grpc_timer_heap_init(&pq); memset(inpq, 0, num_test_elements); GPR_ASSERT(grpc_timer_heap_is_empty(&pq)); @@ -172,7 +107,6 @@ static void test1(void) { check_valid(&pq); GPR_ASSERT(contains(&pq, &test_elements[i])); inpq[i] = 1; - check_pq_top(test_elements, &pq, inpq, num_test_elements); } for (i = 0; i < num_test_elements; ++i) { /* Test that check still succeeds even for element that wasn't just @@ -182,7 +116,7 @@ static void test1(void) { GPR_ASSERT(pq.timer_count == num_test_elements); - check_pq_top(test_elements, &pq, inpq, num_test_elements); + check_valid(&pq); for (i = 0; i < num_test_operations; ++i) { size_t elem_num = (size_t)rand() % num_test_elements; @@ -193,14 +127,12 @@ static void test1(void) { grpc_timer_heap_add(&pq, el); GPR_ASSERT(contains(&pq, el)); inpq[elem_num] = 1; - check_pq_top(test_elements, &pq, inpq, num_test_elements); check_valid(&pq); } else { GPR_ASSERT(contains(&pq, el)); grpc_timer_heap_remove(&pq, el); GPR_ASSERT(!contains(&pq, el)); inpq[elem_num] = 0; - check_pq_top(test_elements, &pq, inpq, num_test_elements); check_valid(&pq); } } @@ -210,7 +142,108 @@ static void test1(void) { gpr_free(inpq); } +/******************************************************************************* + * test2 + */ + +typedef struct { + grpc_timer elem; + bool inserted; +} elem_struct; + +static elem_struct *search_elems(elem_struct *elems, size_t count, + bool inserted) { + size_t *search_order = gpr_malloc(count * sizeof(*search_order)); + for (size_t i = 0; i < count; i++) { + search_order[i] = i; + } + for (size_t i = 0; i < count * 2; i++) { + size_t a = (size_t)rand() % count; + size_t b = (size_t)rand() % count; + GPR_SWAP(size_t, search_order[a], search_order[b]); + } + elem_struct *out = NULL; + for (size_t i = 0; out == NULL && i < count; i++) { + if (elems[search_order[i]].inserted == inserted) { + out = &elems[search_order[i]]; + } + } + gpr_free(search_order); + return out; +} + +static void test2(void) { + gpr_log(GPR_INFO, "test2"); + + grpc_timer_heap pq; + + elem_struct elems[1000]; + size_t num_inserted = 0; + + grpc_timer_heap_init(&pq); + memset(elems, 0, sizeof(elems)); + + for (size_t round = 0; round < 10000; round++) { + int r = rand() % 1000; + if (r <= 550) { + /* 55% of the time we try to add something */ + elem_struct *el = search_elems(elems, GPR_ARRAY_SIZE(elems), false); + if (el != NULL) { + el->elem.deadline = random_deadline(); + grpc_timer_heap_add(&pq, &el->elem); + el->inserted = true; + num_inserted++; + check_valid(&pq); + } + } else if (r <= 650) { + /* 10% of the time we try to remove something */ + elem_struct *el = search_elems(elems, GPR_ARRAY_SIZE(elems), true); + if (el != NULL) { + grpc_timer_heap_remove(&pq, &el->elem); + el->inserted = false; + num_inserted--; + check_valid(&pq); + } + } else { + /* the remaining times we pop */ + if (num_inserted > 0) { + grpc_timer *top = grpc_timer_heap_top(&pq); + grpc_timer_heap_pop(&pq); + for (size_t i = 0; i < GPR_ARRAY_SIZE(elems); i++) { + if (top == &elems[i].elem) { + GPR_ASSERT(elems[i].inserted); + elems[i].inserted = false; + } + } + num_inserted--; + check_valid(&pq); + } + } + + if (num_inserted) { + gpr_timespec *min_deadline = NULL; + for (size_t i = 0; i < GPR_ARRAY_SIZE(elems); i++) { + if (elems[i].inserted) { + if (min_deadline == NULL) { + min_deadline = &elems[i].elem.deadline; + } else { + if (gpr_time_cmp(elems[i].elem.deadline, *min_deadline) < 0) { + min_deadline = &elems[i].elem.deadline; + } + } + } + } + GPR_ASSERT( + 0 == gpr_time_cmp(grpc_timer_heap_top(&pq)->deadline, *min_deadline)); + } + } + + grpc_timer_heap_destroy(&pq); +} + static void shrink_test(void) { + gpr_log(GPR_INFO, "shrink_test"); + grpc_timer_heap pq; size_t i; size_t expected_size; @@ -274,6 +307,7 @@ int main(int argc, char **argv) { for (i = 0; i < 5; i++) { test1(); + test2(); shrink_test(); } diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c index 15de87c5a1..7a21fdd5c1 100644 --- a/test/core/iomgr/timer_list_test.c +++ b/test/core/iomgr/timer_list_test.c @@ -35,7 +35,6 @@ #include <string.h> -#include "src/core/iomgr/timer_internal.h" #include <grpc/support/log.h> #include "test/core/util/test_config.h" @@ -72,20 +71,19 @@ static void add_test(void) { } /* collect timers. Only the first batch should be ready. */ - GPR_ASSERT(10 == grpc_timer_check(&exec_ctx, - gpr_time_add(start, gpr_time_from_millis( - 500, GPR_TIMESPAN)), - NULL)); + GPR_ASSERT(grpc_timer_check( + &exec_ctx, gpr_time_add(start, gpr_time_from_millis(500, GPR_TIMESPAN)), + NULL)); grpc_exec_ctx_finish(&exec_ctx); for (i = 0; i < 20; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } - GPR_ASSERT(0 == grpc_timer_check(&exec_ctx, - gpr_time_add(start, gpr_time_from_millis( - 600, GPR_TIMESPAN)), - NULL)); + GPR_ASSERT(!grpc_timer_check( + &exec_ctx, + gpr_time_add(start, gpr_time_from_millis(600, GPR_TIMESPAN)), + NULL)); grpc_exec_ctx_finish(&exec_ctx); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); @@ -93,20 +91,19 @@ static void add_test(void) { } /* collect the rest of the timers */ - GPR_ASSERT(10 == grpc_timer_check( - &exec_ctx, gpr_time_add(start, gpr_time_from_millis( - 1500, GPR_TIMESPAN)), - NULL)); + GPR_ASSERT(grpc_timer_check( + &exec_ctx, gpr_time_add(start, gpr_time_from_millis(1500, GPR_TIMESPAN)), + NULL)); grpc_exec_ctx_finish(&exec_ctx); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - GPR_ASSERT(0 == grpc_timer_check(&exec_ctx, - gpr_time_add(start, gpr_time_from_millis( - 1600, GPR_TIMESPAN)), - NULL)); + GPR_ASSERT(!grpc_timer_check( + &exec_ctx, + gpr_time_add(start, gpr_time_from_millis(1600, GPR_TIMESPAN)), + NULL)); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); diff --git a/test/core/iomgr/workqueue_test.c b/test/core/iomgr/workqueue_test.c index 500170b542..8a1faf6303 100644 --- a/test/core/iomgr/workqueue_test.c +++ b/test/core/iomgr/workqueue_test.c @@ -34,18 +34,20 @@ #include "src/core/iomgr/workqueue.h" #include <grpc/grpc.h> +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include "test/core/util/test_config.h" -static grpc_pollset g_pollset; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; 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)); + gpr_mu_lock(g_mu); *(int *)p = 1; - grpc_pollset_kick(&g_pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_kick(g_pollset, NULL); + gpr_mu_unlock(g_mu); } static void test_ref_unref(void) { @@ -63,17 +65,17 @@ static void test_add_closure(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx); gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); - grpc_pollset_worker worker; + grpc_pollset_worker *worker = NULL; grpc_closure_init(&c, must_succeed, &done); grpc_workqueue_push(wq, &c, 1); - grpc_workqueue_add_to_pollset(&exec_ctx, wq, &g_pollset); + grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); GPR_ASSERT(!done); - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, - gpr_now(deadline.clock_type), deadline); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type), + deadline); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); @@ -87,18 +89,18 @@ static void test_flush(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx); gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); - grpc_pollset_worker worker; + grpc_pollset_worker *worker = NULL; grpc_closure_init(&c, must_succeed, &done); 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); + grpc_workqueue_add_to_pollset(&exec_ctx, wq, g_pollset); - gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); + gpr_mu_lock(g_mu); GPR_ASSERT(!done); - grpc_pollset_work(&exec_ctx, &g_pollset, &worker, - gpr_now(deadline.clock_type), deadline); - gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); + grpc_pollset_work(&exec_ctx, g_pollset, &worker, gpr_now(deadline.clock_type), + deadline); + gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); @@ -115,15 +117,18 @@ int main(int argc, char **argv) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); - grpc_pollset_init(&g_pollset); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); test_ref_unref(); test_add_closure(); test_flush(); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); + + gpr_free(g_pollset); return 0; } diff --git a/test/core/security/base64_test.c b/test/core/security/b64_test.c index e656d4c947..772514e1fd 100644 --- a/test/core/security/base64_test.c +++ b/test/core/security/b64_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 @@ -31,7 +31,7 @@ * */ -#include "src/core/security/base64.h" +#include "src/core/security/b64.h" #include <string.h> diff --git a/test/core/security/create_jwt.c b/test/core/security/create_jwt.c index 237dc9aa3e..4c0cf436ee 100644 --- a/test/core/security/create_jwt.c +++ b/test/core/security/create_jwt.c @@ -36,7 +36,7 @@ #include "src/core/security/credentials.h" #include "src/core/security/json_token.h" -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" #include <grpc/support/alloc.h> #include <grpc/support/cmdline.h> diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index 8a210bb3c3..98133ef5e5 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -32,25 +32,24 @@ */ #include <grpc/support/port_platform.h> + #include "src/core/security/credentials.h" +#include <openssl/rsa.h> #include <stdlib.h> #include <string.h> -#include "src/core/httpcli/httpcli.h" -#include "src/core/security/json_token.h" -#include "src/core/support/env.h" -#include "src/core/support/file.h" -#include "src/core/support/string.h" - -#include "test/core/util/test_config.h" - #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/time.h> -#include <openssl/rsa.h> +#include "src/core/httpcli/httpcli.h" +#include "src/core/security/json_token.h" +#include "src/core/support/env.h" +#include "src/core/support/tmpfile.h" +#include "src/core/support/string.h" +#include "test/core/util/test_config.h" /* -- Mock channel credentials. -- */ diff --git a/test/core/security/fetch_oauth2.c b/test/core/security/fetch_oauth2.c index ee1178cbdd..87b54f1a0c 100644 --- a/test/core/security/fetch_oauth2.c +++ b/test/core/security/fetch_oauth2.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 @@ #include <grpc/support/sync.h> #include "src/core/security/credentials.h" -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" #include "test/core/security/oauth2_utils.h" static grpc_call_credentials *create_refresh_token_creds( diff --git a/test/core/security/json_token_test.c b/test/core/security/json_token_test.c index 7c01a9ce5c..4d80c16fb9 100644 --- a/test/core/security/json_token_test.c +++ b/test/core/security/json_token_test.c @@ -33,16 +33,17 @@ #include "src/core/security/json_token.h" +#include <openssl/evp.h> #include <string.h> -#include "src/core/security/base64.h" #include <grpc/grpc_security.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/slice.h> -#include "test/core/util/test_config.h" + #include "src/core/json/json.h" -#include <openssl/evp.h> +#include "src/core/security/b64.h" +#include "test/core/util/test_config.h" /* This JSON key was generated with the GCE console and revoked immediately. The identifiers have been changed as well. diff --git a/test/core/security/jwt_verifier_test.c b/test/core/security/jwt_verifier_test.c index f396398cef..f6ec9e12ef 100644 --- a/test/core/security/jwt_verifier_test.c +++ b/test/core/security/jwt_verifier_test.c @@ -36,7 +36,7 @@ #include <string.h> #include "src/core/httpcli/httpcli.h" -#include "src/core/security/base64.h" +#include "src/core/security/b64.h" #include "src/core/security/json_token.h" #include "test/core/util/test_config.h" diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c index 55ac31e62c..9b70afffe1 100644 --- a/test/core/security/oauth2_utils.c +++ b/test/core/security/oauth2_utils.c @@ -45,7 +45,8 @@ #include "src/core/security/credentials.h" typedef struct { - grpc_pollset pollset; + gpr_mu *mu; + grpc_pollset *pollset; int is_done; char *token; } oauth2_request; @@ -66,11 +67,11 @@ static void on_oauth2_response(grpc_exec_ctx *exec_ctx, void *user_data, GPR_SLICE_LENGTH(token_slice)); token[GPR_SLICE_LENGTH(token_slice)] = '\0'; } - gpr_mu_lock(GRPC_POLLSET_MU(&request->pollset)); + gpr_mu_lock(request->mu); request->is_done = 1; request->token = token; - grpc_pollset_kick(&request->pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&request->pollset)); + grpc_pollset_kick(request->pollset, NULL); + gpr_mu_unlock(request->mu); } static void do_nothing(grpc_exec_ctx *exec_ctx, void *unused, bool success) {} @@ -82,28 +83,30 @@ char *grpc_test_fetch_oauth2_token_with_credentials( grpc_closure do_nothing_closure; grpc_auth_metadata_context null_ctx = {"", "", NULL, NULL}; - grpc_pollset_init(&request.pollset); + request.pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(request.pollset, &request.mu); request.is_done = 0; grpc_closure_init(&do_nothing_closure, do_nothing, NULL); - grpc_call_credentials_get_request_metadata(&exec_ctx, creds, &request.pollset, + grpc_call_credentials_get_request_metadata(&exec_ctx, creds, request.pollset, null_ctx, on_oauth2_response, &request); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&request.pollset)); + gpr_mu_lock(request.mu); while (!request.is_done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &request.pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, request.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); } - gpr_mu_unlock(GRPC_POLLSET_MU(&request.pollset)); + gpr_mu_unlock(request.mu); - grpc_pollset_shutdown(&exec_ctx, &request.pollset, &do_nothing_closure); + grpc_pollset_shutdown(&exec_ctx, request.pollset, &do_nothing_closure); grpc_exec_ctx_finish(&exec_ctx); - grpc_pollset_destroy(&request.pollset); + grpc_pollset_destroy(request.pollset); + gpr_free(request.pollset); return request.token; } diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c index 50fe61c996..09673f362c 100644 --- a/test/core/security/print_google_default_creds_token.c +++ b/test/core/security/print_google_default_creds_token.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 @@ -34,8 +34,6 @@ #include <stdio.h> #include <string.h> -#include "src/core/security/credentials.h" -#include "src/core/support/string.h" #include <grpc/grpc.h> #include <grpc/grpc_security.h> #include <grpc/support/alloc.h> @@ -44,8 +42,12 @@ #include <grpc/support/slice.h> #include <grpc/support/sync.h> +#include "src/core/security/credentials.h" +#include "src/core/support/string.h" + typedef struct { - grpc_pollset pollset; + gpr_mu *mu; + grpc_pollset *pollset; int is_done; } synchronizer; @@ -62,10 +64,10 @@ static void on_metadata_response(grpc_exec_ctx *exec_ctx, void *user_data, printf("\nGot token: %s\n\n", token); gpr_free(token); } - gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset)); + gpr_mu_lock(sync->mu); sync->is_done = 1; - grpc_pollset_kick(&sync->pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&sync->pollset)); + grpc_pollset_kick(sync->pollset, NULL); + gpr_mu_unlock(sync->mu); } int main(int argc, char **argv) { @@ -91,26 +93,30 @@ int main(int argc, char **argv) { goto end; } - grpc_pollset_init(&sync.pollset); + sync.pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(sync.pollset, &sync.mu); sync.is_done = 0; grpc_call_credentials_get_request_metadata( &exec_ctx, ((grpc_composite_channel_credentials *)creds)->call_creds, - &sync.pollset, context, on_metadata_response, &sync); + sync.pollset, context, on_metadata_response, &sync); - gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); + gpr_mu_lock(sync.mu); while (!sync.is_done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &sync.pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, sync.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); - grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); + gpr_mu_unlock(sync.mu); + grpc_exec_ctx_flush(&exec_ctx); + gpr_mu_lock(sync.mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); + gpr_mu_unlock(sync.mu); + + grpc_exec_ctx_finish(&exec_ctx); grpc_channel_credentials_release(creds); + gpr_free(sync.pollset); end: gpr_cmdline_destroy(cl); diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c index fb4bd30e2d..0e8c38a53e 100644 --- a/test/core/security/secure_endpoint_test.c +++ b/test/core/security/secure_endpoint_test.c @@ -36,16 +36,17 @@ #include <fcntl.h> #include <sys/types.h> -#include "src/core/security/secure_endpoint.h" -#include "src/core/iomgr/endpoint_pair.h" -#include "src/core/iomgr/iomgr.h" #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include "test/core/util/test_config.h" +#include "src/core/iomgr/endpoint_pair.h" +#include "src/core/iomgr/iomgr.h" +#include "src/core/security/secure_endpoint.h" #include "src/core/tsi/fake_transport_security.h" +#include "test/core/util/test_config.h" -static grpc_pollset g_pollset; +static gpr_mu *g_mu; +static grpc_pollset *g_pollset; static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( size_t slice_size, gpr_slice *leftover_slices, size_t leftover_nslices) { @@ -56,8 +57,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair( grpc_endpoint_pair tcp; tcp = grpc_iomgr_create_endpoint_pair("fixture", slice_size); - grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, &g_pollset); - grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, &g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, tcp.client, g_pollset); + grpc_endpoint_add_to_pollset(&exec_ctx, tcp.server, g_pollset); if (leftover_nslices == 0) { f.client_ep = @@ -181,13 +182,16 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); - grpc_pollset_init(&g_pollset); - grpc_endpoint_tests(configs[0], &g_pollset); + g_pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(g_pollset, &g_mu); + grpc_endpoint_tests(configs[0], g_pollset, g_mu); test_leftover(configs[1], 1); - grpc_closure_init(&destroyed, destroy_pollset, &g_pollset); - grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed); + grpc_closure_init(&destroyed, destroy_pollset, g_pollset); + grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); + gpr_free(g_pollset); + return 0; } diff --git a/test/core/security/security_connector_test.c b/test/core/security/security_connector_test.c index ee5435f01d..420e3a4c52 100644 --- a/test/core/security/security_connector_test.c +++ b/test/core/security/security_connector_test.c @@ -34,22 +34,21 @@ #include <stdio.h> #include <string.h> +#include <grpc/grpc_security.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/string_util.h> +#include <grpc/support/useful.h> + #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/tmpfile.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" -#include <grpc/grpc_security.h> - -#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) { grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name( ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME); diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c index 378a37f26c..eb86589681 100644 --- a/test/core/security/verify_jwt.c +++ b/test/core/security/verify_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 @@ -34,7 +34,6 @@ #include <stdio.h> #include <string.h> -#include "src/core/security/jwt_verifier.h" #include <grpc/grpc.h> #include <grpc/grpc_security.h> #include <grpc/support/alloc.h> @@ -43,8 +42,11 @@ #include <grpc/support/slice.h> #include <grpc/support/sync.h> +#include "src/core/security/jwt_verifier.h" + typedef struct { - grpc_pollset pollset; + grpc_pollset *pollset; + gpr_mu *mu; int is_done; int success; } synchronizer; @@ -77,10 +79,10 @@ static void on_jwt_verification_done(void *user_data, grpc_jwt_verifier_status_to_string(status)); } - gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset)); + gpr_mu_lock(sync->mu); sync->is_done = 1; - grpc_pollset_kick(&sync->pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&sync->pollset)); + grpc_pollset_kick(sync->pollset, NULL); + gpr_mu_unlock(sync->mu); } int main(int argc, char **argv) { @@ -103,23 +105,26 @@ int main(int argc, char **argv) { grpc_init(); - grpc_pollset_init(&sync.pollset); + sync.pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(sync.pollset, &sync.mu); sync.is_done = 0; - grpc_jwt_verifier_verify(&exec_ctx, verifier, &sync.pollset, jwt, aud, + grpc_jwt_verifier_verify(&exec_ctx, verifier, sync.pollset, jwt, aud, on_jwt_verification_done, &sync); - gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); + gpr_mu_lock(sync.mu); while (!sync.is_done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &sync.pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, sync.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); - gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); + gpr_mu_unlock(sync.mu); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); + gpr_mu_lock(sync.mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); + gpr_mu_unlock(sync.mu); + + gpr_free(sync.pollset); grpc_jwt_verifier_destroy(verifier); gpr_cmdline_destroy(cl); diff --git a/test/core/support/file_test.c b/test/core/support/load_file_test.c index 330b2173ef..e6ba617440 100644 --- a/test/core/support/file_test.c +++ b/test/core/support/load_file_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 @@ -38,7 +38,8 @@ #include <grpc/support/log.h> #include <grpc/support/slice.h> -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" +#include "src/core/support/tmpfile.h" #include "src/core/support/string.h" #include "test/core/util/test_config.h" diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index 4b31f810e5..ba382d242a 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -69,7 +69,8 @@ static int has_port_been_chosen(int port) { } typedef struct freereq { - grpc_pollset pollset; + gpr_mu *mu; + grpc_pollset *pollset; int done; } freereq; @@ -82,10 +83,10 @@ static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p, static void freed_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, const grpc_httpcli_response *response) { freereq *pr = arg; - gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset)); + gpr_mu_lock(pr->mu); pr->done = 1; - grpc_pollset_kick(&pr->pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset)); + grpc_pollset_kick(pr->pollset, NULL); + gpr_mu_unlock(pr->mu); } static void free_port_using_server(char *server, int port) { @@ -100,31 +101,34 @@ static void free_port_using_server(char *server, int port) { memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); - grpc_pollset_init(&pr.pollset); + + pr.pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(pr.pollset, &pr.mu); grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown, - &pr.pollset); + pr.pollset); req.host = server; gpr_asprintf(&path, "/drop/%d", port); req.path = path; grpc_httpcli_context_init(&context); - grpc_httpcli_get(&exec_ctx, &context, &pr.pollset, &req, + grpc_httpcli_get(&exec_ctx, &context, pr.pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), freed_port_from_server, &pr); - gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset)); + gpr_mu_lock(pr.mu); while (!pr.done) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &pr.pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)); } - gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset)); + gpr_mu_unlock(pr.mu); grpc_httpcli_context_destroy(&context); grpc_exec_ctx_finish(&exec_ctx); - grpc_pollset_shutdown(&exec_ctx, &pr.pollset, &shutdown_closure); + grpc_pollset_shutdown(&exec_ctx, pr.pollset, &shutdown_closure); grpc_exec_ctx_finish(&exec_ctx); + gpr_free(pr.pollset); gpr_free(path); } @@ -202,7 +206,8 @@ static int is_port_available(int *port, int is_tcp) { } typedef struct portreq { - grpc_pollset pollset; + gpr_mu *mu; + grpc_pollset *pollset; int port; int retries; char *server; @@ -234,7 +239,7 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, pr->retries++; req.host = pr->server; req.path = "/get"; - grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pollset, &req, + grpc_httpcli_get(exec_ctx, pr->ctx, pr->pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server, pr); return; @@ -246,10 +251,10 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, port = port * 10 + response->body[i] - '0'; } GPR_ASSERT(port > 1024); - gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset)); + gpr_mu_lock(pr->mu); pr->port = port; - grpc_pollset_kick(&pr->pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset)); + grpc_pollset_kick(pr->pollset, NULL); + gpr_mu_unlock(pr->mu); } static int pick_port_using_server(char *server) { @@ -263,9 +268,10 @@ static int pick_port_using_server(char *server) { memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); - grpc_pollset_init(&pr.pollset); + pr.pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(pr.pollset, &pr.mu); grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown, - &pr.pollset); + pr.pollset); pr.port = -1; pr.server = server; pr.ctx = &context; @@ -274,22 +280,23 @@ static int pick_port_using_server(char *server) { req.path = "/get"; grpc_httpcli_context_init(&context); - grpc_httpcli_get(&exec_ctx, &context, &pr.pollset, &req, + grpc_httpcli_get(&exec_ctx, &context, pr.pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server, &pr); grpc_exec_ctx_finish(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset)); + gpr_mu_lock(pr.mu); while (pr.port == -1) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &pr.pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)); } - gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset)); + gpr_mu_unlock(pr.mu); grpc_httpcli_context_destroy(&context); - grpc_pollset_shutdown(&exec_ctx, &pr.pollset, &shutdown_closure); + grpc_pollset_shutdown(&exec_ctx, pr.pollset, &shutdown_closure); grpc_exec_ctx_finish(&exec_ctx); + gpr_free(pr.pollset); return pr.port; } diff --git a/test/core/util/port_windows.c b/test/core/util/port_windows.c index 85d7c0ce07..3b20aeb718 100644 --- a/test/core/util/port_windows.c +++ b/test/core/util/port_windows.c @@ -129,7 +129,8 @@ static int is_port_available(int *port, int is_tcp) { } typedef struct portreq { - grpc_pollset pollset; + grpc_pollset *pollset; + gpr_mu *mu; int port; } portreq; @@ -145,10 +146,10 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, port = port * 10 + response->body[i] - '0'; } GPR_ASSERT(port > 1024); - gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset)); + gpr_mu_lock(pr->mu); pr->port = port; - grpc_pollset_kick(&pr->pollset, NULL); - gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset)); + grpc_pollset_kick(pr->pollset, NULL); + gpr_mu_unlock(pr->mu); } static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p, @@ -168,32 +169,34 @@ static int pick_port_using_server(char *server) { memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); - grpc_pollset_init(&pr.pollset); + pr.pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(pr.pollset, &pr.mu); pr.port = -1; req.host = server; req.path = "/get"; grpc_httpcli_context_init(&context); - grpc_httpcli_get(&exec_ctx, &context, &pr.pollset, &req, + grpc_httpcli_get(&exec_ctx, &context, pr.pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server, &pr); - gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset)); + gpr_mu_lock(pr.mu); while (pr.port == -1) { - grpc_pollset_worker worker; - grpc_pollset_work(&exec_ctx, &pr.pollset, &worker, + grpc_pollset_worker *worker = NULL; + grpc_pollset_work(&exec_ctx, pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)); - gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset)); + gpr_mu_unlock(pr.mu); grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset)); + gpr_mu_lock(pr.mu); } - gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset)); + gpr_mu_unlock(pr.mu); grpc_httpcli_context_destroy(&context); grpc_closure_init(&destroy_pollset_closure, destroy_pollset_and_shutdown, &pr.pollset); - grpc_pollset_shutdown(&exec_ctx, &pr.pollset, &destroy_pollset_closure); + grpc_pollset_shutdown(&exec_ctx, pr.pollset, &destroy_pollset_closure); + gpr_free(pr.pollset); grpc_exec_ctx_finish(&exec_ctx); return pr.port; diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c index 66470c0288..ab379441d8 100644 --- a/test/core/util/test_tcp_server.c +++ b/test/core/util/test_tcp_server.c @@ -57,8 +57,8 @@ void test_tcp_server_init(test_tcp_server *server, server->tcp_server = NULL; grpc_closure_init(&server->shutdown_complete, on_server_destroyed, server); server->shutdown = 0; - grpc_pollset_init(&server->pollset); - server->pollsets[0] = &server->pollset; + server->pollset = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(server->pollset, &server->mu); server->on_connect = on_connect; server->cb_data = user_data; } @@ -77,7 +77,7 @@ void test_tcp_server_start(test_tcp_server *server, int port) { grpc_tcp_server_add_port(server->tcp_server, &addr, sizeof(addr)); GPR_ASSERT(port_added == port); - grpc_tcp_server_start(&exec_ctx, server->tcp_server, server->pollsets, 1, + grpc_tcp_server_start(&exec_ctx, server->tcp_server, &server->pollset, 1, server->on_connect, server->cb_data); gpr_log(GPR_INFO, "test tcp server listening on 0.0.0.0:%d", port); @@ -85,15 +85,15 @@ void test_tcp_server_start(test_tcp_server *server, int port) { } void test_tcp_server_poll(test_tcp_server *server, int seconds) { - grpc_pollset_worker worker; + grpc_pollset_worker *worker = NULL; gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(seconds, GPR_TIMESPAN)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - gpr_mu_lock(GRPC_POLLSET_MU(&server->pollset)); - grpc_pollset_work(&exec_ctx, &server->pollset, &worker, + gpr_mu_lock(server->mu); + grpc_pollset_work(&exec_ctx, server->pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline); - gpr_mu_unlock(GRPC_POLLSET_MU(&server->pollset)); + gpr_mu_unlock(server->mu); grpc_exec_ctx_finish(&exec_ctx); } @@ -111,8 +111,9 @@ void test_tcp_server_destroy(test_tcp_server *server) { gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), shutdown_deadline) < 0) { test_tcp_server_poll(server, 1); } - grpc_pollset_shutdown(&exec_ctx, &server->pollset, &do_nothing_cb); + grpc_pollset_shutdown(&exec_ctx, server->pollset, &do_nothing_cb); grpc_exec_ctx_finish(&exec_ctx); - grpc_pollset_destroy(&server->pollset); + grpc_pollset_destroy(server->pollset); + gpr_free(server->pollset); grpc_shutdown(); } diff --git a/test/core/util/test_tcp_server.h b/test/core/util/test_tcp_server.h index 51119cf6c8..15fcb4fb87 100644 --- a/test/core/util/test_tcp_server.h +++ b/test/core/util/test_tcp_server.h @@ -41,8 +41,8 @@ typedef struct test_tcp_server { grpc_tcp_server *tcp_server; grpc_closure shutdown_complete; int shutdown; - grpc_pollset pollset; - grpc_pollset *pollsets[1]; + gpr_mu *mu; + grpc_pollset *pollset; grpc_tcp_server_cb on_connect; void *cb_data; } test_tcp_server; diff --git a/test/cpp/common/alarm_cpp_test.cc b/test/cpp/common/alarm_cpp_test.cc index 4745ef14ec..d4381c0515 100644 --- a/test/cpp/common/alarm_cpp_test.cc +++ b/test/cpp/common/alarm_cpp_test.cc @@ -55,6 +55,53 @@ TEST(AlarmTest, RegularExpiry) { EXPECT_EQ(junk, output_tag); } +TEST(AlarmTest, RegularExpiryChrono) { + CompletionQueue cq; + void* junk = reinterpret_cast<void*>(1618033); + std::chrono::system_clock::time_point one_sec_deadline = + std::chrono::system_clock::now() + std::chrono::seconds(1); + Alarm alarm(&cq, one_sec_deadline, junk); + + void* output_tag; + bool ok; + const CompletionQueue::NextStatus status = cq.AsyncNext( + (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2)); + + EXPECT_EQ(status, CompletionQueue::GOT_EVENT); + EXPECT_TRUE(ok); + EXPECT_EQ(junk, output_tag); +} + +TEST(AlarmTest, ZeroExpiry) { + CompletionQueue cq; + void* junk = reinterpret_cast<void*>(1618033); + Alarm alarm(&cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(0), junk); + + void* output_tag; + bool ok; + const CompletionQueue::NextStatus status = cq.AsyncNext( + (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(0)); + + EXPECT_EQ(status, CompletionQueue::GOT_EVENT); + EXPECT_TRUE(ok); + EXPECT_EQ(junk, output_tag); +} + +TEST(AlarmTest, NegativeExpiry) { + CompletionQueue cq; + void* junk = reinterpret_cast<void*>(1618033); + Alarm alarm(&cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(-1), junk); + + void* output_tag; + bool ok; + const CompletionQueue::NextStatus status = cq.AsyncNext( + (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(0)); + + EXPECT_EQ(status, CompletionQueue::GOT_EVENT); + EXPECT_TRUE(ok); + EXPECT_EQ(junk, output_tag); +} + TEST(AlarmTest, Cancellation) { CompletionQueue cq; void* junk = reinterpret_cast<void*>(1618033); diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index a15cbd7ee2..9ca3bf98f8 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -989,6 +989,10 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { if (server_try_cancel == CANCEL_AFTER_PROCESSING) { ServerTryCancel(&srv_ctx); + + // Client reads may fail bacause it is notified that the stream is + // cancelled. + ignore_cq_result = true; } // Client attemts to read the three messages from the server diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index ce8e4d2a10..dc2c4f6426 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -437,9 +437,10 @@ class End2endServerTryCancelTest : public End2endTest { break; case CANCEL_AFTER_PROCESSING: - // Server cancelled after writing all messages. Client must have read - // all messages - EXPECT_EQ(num_msgs_read, kNumResponseStreamsMsgs); + // Even though the Server cancelled after writing all messages, the RPC + // may be cancelled before the Client got a chance to read all the + // messages. + EXPECT_LE(num_msgs_read, kNumResponseStreamsMsgs); break; default: { @@ -519,7 +520,11 @@ class End2endServerTryCancelTest : public End2endTest { case CANCEL_AFTER_PROCESSING: EXPECT_EQ(num_msgs_sent, num_messages); - EXPECT_EQ(num_msgs_read, num_msgs_sent); + + // The Server cancelled after reading the last message and after writing + // the message to the client. However, the RPC cancellation might have + // taken effect before the client actually read the response. + EXPECT_LE(num_msgs_read, num_msgs_sent); break; default: @@ -904,9 +909,9 @@ TEST_P(End2endTest, SimultaneousReadWritesDone) { std::thread reader_thread(ReaderThreadFunc, stream.get(), &ev); gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); stream->WritesDone(); + reader_thread.join(); Status s = stream->Finish(); EXPECT_TRUE(s.ok()); - reader_thread.join(); } TEST_P(End2endTest, ChannelState) { diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc index 66d11d0dfc..7c3e514eff 100644 --- a/test/cpp/end2end/test_service_impl.cc +++ b/test/cpp/end2end/test_service_impl.cc @@ -326,7 +326,11 @@ void TestServiceImpl::ServerTryCancel(ServerContext* context) { EXPECT_FALSE(context->IsCancelled()); context->TryCancel(); gpr_log(GPR_INFO, "Server called TryCancel() to cancel the request"); - EXPECT_TRUE(context->IsCancelled()); + // Now wait until it's really canceled + while (!context->IsCancelled()) { + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000, GPR_TIMESPAN))); + } } } // namespace testing diff --git a/test/cpp/grpclb/grpclb_api_test.cc b/test/cpp/grpclb/grpclb_api_test.cc new file mode 100644 index 0000000000..bd4885fb4c --- /dev/null +++ b/test/cpp/grpclb/grpclb_api_test.cc @@ -0,0 +1,133 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <gtest/gtest.h> +#include <string> + +#include "src/core/client_config/lb_policies/load_balancer_api.h" +#include "src/proto/grpc/lb/v0/load_balancer.pb.h" // C++ version + +namespace grpc { +namespace { + +using grpc::lb::v0::LoadBalanceRequest; +using grpc::lb::v0::LoadBalanceResponse; + +class GrpclbTest : public ::testing::Test {}; + +TEST_F(GrpclbTest, CreateRequest) { + const std::string service_name = "AServiceName"; + LoadBalanceRequest request; + grpc_grpclb_request* c_req = grpc_grpclb_request_create(service_name.c_str()); + gpr_slice slice = grpc_grpclb_request_encode(c_req); + const int num_bytes_written = GPR_SLICE_LENGTH(slice); + EXPECT_GT(num_bytes_written, 0); + request.ParseFromArray(GPR_SLICE_START_PTR(slice), num_bytes_written); + EXPECT_EQ(request.initial_request().name(), service_name); + gpr_slice_unref(slice); + grpc_grpclb_request_destroy(c_req); +} + +TEST_F(GrpclbTest, ParseResponse) { + LoadBalanceResponse response; + const std::string client_config_str = "I'm a client config"; + auto* initial_response = response.mutable_initial_response(); + initial_response->set_client_config(client_config_str); + auto* client_stats_report_interval = + initial_response->mutable_client_stats_report_interval(); + client_stats_report_interval->set_seconds(123); + client_stats_report_interval->set_nanos(456); + + const std::string encoded_response = response.SerializeAsString(); + gpr_slice encoded_slice = + gpr_slice_from_copied_string(encoded_response.c_str()); + grpc_grpclb_response* c_response = grpc_grpclb_response_parse(encoded_slice); + EXPECT_TRUE(c_response->has_initial_response); + EXPECT_TRUE(c_response->initial_response.has_client_config); + EXPECT_FALSE(c_response->initial_response.has_load_balancer_delegate); + EXPECT_TRUE(strcmp(c_response->initial_response.client_config, + client_config_str.c_str()) == 0); + EXPECT_EQ(c_response->initial_response.client_stats_report_interval.seconds, + 123); + EXPECT_EQ(c_response->initial_response.client_stats_report_interval.nanos, + 456); + gpr_slice_unref(encoded_slice); + grpc_grpclb_response_destroy(c_response); +} + +TEST_F(GrpclbTest, ParseResponseServerList) { + LoadBalanceResponse response; + auto* serverlist = response.mutable_server_list(); + auto* server = serverlist->add_servers(); + server->set_ip_address("127.0.0.1"); + server->set_port(12345); + server->set_drop_request(true); + server = response.mutable_server_list()->add_servers(); + server->set_ip_address("10.0.0.1"); + server->set_port(54321); + server->set_drop_request(false); + auto* expiration_interval = serverlist->mutable_expiration_interval(); + expiration_interval->set_seconds(888); + expiration_interval->set_nanos(999); + + const std::string encoded_response = response.SerializeAsString(); + gpr_slice encoded_slice = + gpr_slice_from_copied_string(encoded_response.c_str()); + grpc_grpclb_serverlist* c_serverlist = + grpc_grpclb_response_parse_serverlist(encoded_slice); + ASSERT_EQ(c_serverlist->num_servers, 2ul); + EXPECT_TRUE(c_serverlist->servers[0]->has_ip_address); + EXPECT_TRUE(strcmp(c_serverlist->servers[0]->ip_address, "127.0.0.1") == 0); + EXPECT_EQ(c_serverlist->servers[0]->port, 12345); + EXPECT_TRUE(c_serverlist->servers[0]->drop_request); + EXPECT_TRUE(c_serverlist->servers[1]->has_ip_address); + EXPECT_TRUE(strcmp(c_serverlist->servers[1]->ip_address, "10.0.0.1") == 0); + EXPECT_EQ(c_serverlist->servers[1]->port, 54321); + EXPECT_FALSE(c_serverlist->servers[1]->drop_request); + + EXPECT_TRUE(c_serverlist->expiration_interval.has_seconds); + EXPECT_EQ(c_serverlist->expiration_interval.seconds, 888); + EXPECT_TRUE(c_serverlist->expiration_interval.has_nanos); + EXPECT_EQ(c_serverlist->expiration_interval.nanos, 999); + + gpr_slice_unref(encoded_slice); + grpc_grpclb_destroy_serverlist(c_serverlist); +} + +} // namespace +} // namespace grpc + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/cpp/interop/metrics_client.cc b/test/cpp/interop/metrics_client.cc index 0c140ffd85..bd48c7d4ef 100644 --- a/test/cpp/interop/metrics_client.cc +++ b/test/cpp/interop/metrics_client.cc @@ -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,39 +37,45 @@ #include <gflags/gflags.h> #include <grpc++/grpc++.h> -#include "test/cpp/util/metrics_server.h" -#include "test/cpp/util/test_config.h" #include "src/proto/grpc/testing/metrics.grpc.pb.h" #include "src/proto/grpc/testing/metrics.pb.h" +#include "test/cpp/util/metrics_server.h" +#include "test/cpp/util/test_config.h" DEFINE_string(metrics_server_address, "", "The metrics server addresses in the fomrat <hostname>:<port>"); +DEFINE_bool(total_only, false, + "If true, this prints only the total value of all gauges"); + +int kDeadlineSecs = 10; using grpc::testing::EmptyMessage; using grpc::testing::GaugeResponse; using grpc::testing::MetricsService; using grpc::testing::MetricsServiceImpl; -void PrintMetrics(const grpc::string& server_address) { - gpr_log(GPR_INFO, "creating a channel to %s", server_address.c_str()); - std::shared_ptr<grpc::Channel> channel( - grpc::CreateChannel(server_address, grpc::InsecureChannelCredentials())); - - std::unique_ptr<MetricsService::Stub> stub(MetricsService::NewStub(channel)); - +// Prints the values of all Gauges (unless total_only is set to 'true' in which +// case this only prints the sum of all gauge values). +bool PrintMetrics(std::unique_ptr<MetricsService::Stub> stub, bool total_only) { grpc::ClientContext context; EmptyMessage message; + std::chrono::system_clock::time_point deadline = + std::chrono::system_clock::now() + std::chrono::seconds(kDeadlineSecs); + + context.set_deadline(deadline); + std::unique_ptr<grpc::ClientReader<GaugeResponse>> reader( stub->GetAllGauges(&context, message)); GaugeResponse gauge_response; long overall_qps = 0; - int idx = 0; while (reader->Read(&gauge_response)) { if (gauge_response.value_case() == GaugeResponse::kLongValue) { - gpr_log(GPR_INFO, "Gauge: %d (%s: %ld)", ++idx, - gauge_response.name().c_str(), gauge_response.long_value()); + if (!total_only) { + gpr_log(GPR_INFO, "%s: %ld", gauge_response.name().c_str(), + gauge_response.long_value()); + } overall_qps += gauge_response.long_value(); } else { gpr_log(GPR_INFO, "Gauge %s is not a long value", @@ -77,12 +83,14 @@ void PrintMetrics(const grpc::string& server_address) { } } - gpr_log(GPR_INFO, "OVERALL: %ld", overall_qps); + gpr_log(GPR_INFO, "%ld", overall_qps); const grpc::Status status = reader->Finish(); if (!status.ok()) { gpr_log(GPR_ERROR, "Error in getting metrics from the client"); } + + return status.ok(); } int main(int argc, char** argv) { @@ -97,7 +105,12 @@ int main(int argc, char** argv) { return 1; } - PrintMetrics(FLAGS_metrics_server_address); + std::shared_ptr<grpc::Channel> channel(grpc::CreateChannel( + FLAGS_metrics_server_address, grpc::InsecureChannelCredentials())); + + if (!PrintMetrics(MetricsService::NewStub(channel), FLAGS_total_only)) { + return 1; + } return 0; } diff --git a/test/cpp/interop/reconnect_interop_client.cc b/test/cpp/interop/reconnect_interop_client.cc index 1f6b352db1..79a60cc860 100644 --- a/test/cpp/interop/reconnect_interop_client.cc +++ b/test/cpp/interop/reconnect_interop_client.cc @@ -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 diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server_main.cc index 18ac35d551..18ac35d551 100644 --- a/test/cpp/interop/server.cc +++ b/test/cpp/interop/server_main.cc diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index c94a523fa1..2dc83f0f29 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -46,10 +46,10 @@ #include "src/proto/grpc/testing/payloads.grpc.pb.h" #include "src/proto/grpc/testing/services.grpc.pb.h" -#include "test/cpp/qps/limit_cores.h" #include "test/cpp/qps/histogram.h" #include "test/cpp/qps/interarrival.h" -#include "test/cpp/qps/timer.h" +#include "test/cpp/qps/limit_cores.h" +#include "test/cpp/qps/usage_timer.h" #include "test/cpp/util/create_test_channel.h" namespace grpc { @@ -112,12 +112,12 @@ class ClientRequestCreator<ByteBuffer> { class Client { public: - Client() : timer_(new Timer), interarrival_timer_() {} + Client() : timer_(new UsageTimer), interarrival_timer_() {} virtual ~Client() {} ClientStats Mark(bool reset) { Histogram latencies; - Timer::Result timer_result; + UsageTimer::Result timer_result; // avoid std::vector for old compilers that expect a copy constructor if (reset) { @@ -125,7 +125,7 @@ class Client { for (size_t i = 0; i < threads_.size(); i++) { threads_[i]->BeginSwap(&to_merge[i]); } - std::unique_ptr<Timer> timer(new Timer); + std::unique_ptr<UsageTimer> timer(new UsageTimer); timer_.swap(timer); for (size_t i = 0; i < threads_.size(); i++) { threads_[i]->EndSwap(); @@ -294,7 +294,7 @@ class Client { }; std::vector<std::unique_ptr<Thread>> threads_; - std::unique_ptr<Timer> timer_; + std::unique_ptr<UsageTimer> timer_; InterarrivalTimer interarrival_timer_; std::vector<gpr_timespec> next_time_; diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index 9e8767d103..9e9da9909a 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -54,7 +54,7 @@ #include "src/proto/grpc/testing/services.grpc.pb.h" #include "test/cpp/qps/client.h" -#include "test/cpp/qps/timer.h" +#include "test/cpp/qps/usage_timer.h" #include "test/cpp/util/create_test_channel.h" namespace grpc { @@ -107,14 +107,14 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext { bool RunNextState(bool ok, Histogram* hist) GRPC_OVERRIDE { switch (next_state_) { case State::READY: - start_ = Timer::Now(); + start_ = UsageTimer::Now(); response_reader_ = start_req_(stub_, &context_, req_, cq_); response_reader_->Finish(&response_, &status_, ClientRpcContext::tag(this)); next_state_ = State::RESP_DONE; return true; case State::RESP_DONE: - hist->Add((Timer::Now() - start_) * 1e9); + hist->Add((UsageTimer::Now() - start_) * 1e9); callback_(status_, &response_); next_state_ = State::INVALID; return false; @@ -287,8 +287,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext { next_state_(State::INVALID), callback_(on_done), next_issue_(next_issue), - start_req_(start_req), - start_(Timer::Now()) {} + start_req_(start_req) {} ~ClientRpcContextStreamingImpl() GRPC_OVERRIDE {} void Start(CompletionQueue* cq) GRPC_OVERRIDE { cq_ = cq; @@ -314,7 +313,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext { if (!ok) { return false; } - start_ = Timer::Now(); + start_ = UsageTimer::Now(); next_state_ = State::WRITE_DONE; stream_->Write(req_, ClientRpcContext::tag(this)); return true; @@ -327,7 +326,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext { return true; break; case State::READ_DONE: - hist->Add((Timer::Now() - start_) * 1e9); + hist->Add((UsageTimer::Now() - start_) * 1e9); callback_(status_, &response_); next_state_ = State::STREAM_IDLE; break; // loop around @@ -415,8 +414,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext { next_state_(State::INVALID), callback_(on_done), next_issue_(next_issue), - start_req_(start_req), - start_(Timer::Now()) {} + start_req_(start_req) {} ~ClientRpcContextGenericStreamingImpl() GRPC_OVERRIDE {} void Start(CompletionQueue* cq) GRPC_OVERRIDE { cq_ = cq; @@ -445,7 +443,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext { if (!ok) { return false; } - start_ = Timer::Now(); + start_ = UsageTimer::Now(); next_state_ = State::WRITE_DONE; stream_->Write(req_, ClientRpcContext::tag(this)); return true; @@ -458,7 +456,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext { return true; break; case State::READ_DONE: - hist->Add((Timer::Now() - start_) * 1e9); + hist->Add((UsageTimer::Now() - start_) * 1e9); callback_(status_, &response_); next_state_ = State::STREAM_IDLE; break; // loop around diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index edfc246a25..4284e07bd4 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -58,7 +58,7 @@ #include "test/cpp/qps/client.h" #include "test/cpp/qps/histogram.h" #include "test/cpp/qps/interarrival.h" -#include "test/cpp/qps/timer.h" +#include "test/cpp/qps/usage_timer.h" namespace grpc { namespace testing { @@ -104,12 +104,12 @@ class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient { bool ThreadFunc(Histogram* histogram, size_t thread_idx) GRPC_OVERRIDE { WaitToIssue(thread_idx); auto* stub = channels_[thread_idx % channels_.size()].get_stub(); - double start = Timer::Now(); + double start = UsageTimer::Now(); GPR_TIMER_SCOPE("SynchronousUnaryClient::ThreadFunc", 0); grpc::ClientContext context; grpc::Status s = stub->UnaryCall(&context, request_, &responses_[thread_idx]); - histogram->Add((Timer::Now() - start) * 1e9); + histogram->Add((UsageTimer::Now() - start) * 1e9); return s.ok(); } }; @@ -143,10 +143,10 @@ class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient { bool ThreadFunc(Histogram* histogram, size_t thread_idx) GRPC_OVERRIDE { WaitToIssue(thread_idx); GPR_TIMER_SCOPE("SynchronousStreamingClient::ThreadFunc", 0); - double start = Timer::Now(); + double start = UsageTimer::Now(); if (stream_[thread_idx]->Write(request_) && stream_[thread_idx]->Read(&responses_[thread_idx])) { - histogram->Add((Timer::Now() - start) * 1e9); + histogram->Add((UsageTimer::Now() - start) * 1e9); return true; } return false; diff --git a/test/cpp/qps/qps-sweep.sh b/test/cpp/qps/qps-sweep.sh index 7a35788849..9d3f053a7b 100755 --- a/test/cpp/qps/qps-sweep.sh +++ b/test/cpp/qps/qps-sweep.sh @@ -72,7 +72,7 @@ for secure in true false; do --server_type=ASYNC_GENERIC_SERVER --outstanding_rpcs_per_channel=$deep \ --client_channels=$wide --bbuf_req_size=0 --bbuf_resp_size=0 \ --async_client_threads=0 --async_server_threads=0 --secure_test=$secure \ - --num_servers=1 --num_clients=0 |& tee /tmp/qps-test.$$ + --num_servers=1 --num_clients=0 2>&1 | tee /tmp/qps-test.$$ # Scenario 2b: QPS with a single server core "$bins"/opt/qps_driver --rpc_type=STREAMING --client_type=ASYNC_CLIENT \ diff --git a/test/cpp/qps/qps_openloop_test.cc b/test/cpp/qps/qps_openloop_test.cc index 0ac41d9f96..27f266b32b 100644 --- a/test/cpp/qps/qps_openloop_test.cc +++ b/test/cpp/qps/qps_openloop_test.cc @@ -35,6 +35,7 @@ #include <grpc/support/log.h> +#include "test/core/util/test_config.h" #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" #include "test/cpp/util/benchmark_config.h" @@ -55,11 +56,11 @@ static void RunQPS() { client_config.set_async_client_threads(8); client_config.set_rpc_type(STREAMING); client_config.mutable_load_params()->mutable_poisson()->set_offered_load( - 1000.0); + 1000.0 / GRPC_TEST_SLOWDOWN_FACTOR); ServerConfig server_config; server_config.set_server_type(ASYNC_SERVER); - server_config.set_async_server_threads(4); + server_config.set_async_server_threads(8); const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc index 9442017ddf..b83e9d1dd7 100644 --- a/test/cpp/qps/qps_worker.cc +++ b/test/cpp/qps/qps_worker.cc @@ -101,6 +101,19 @@ static std::unique_ptr<Server> CreateServer(const ServerConfig& config) { abort(); } +class ScopedProfile GRPC_FINAL { + public: + ScopedProfile(const char* filename, bool enable) : enable_(enable) { + if (enable_) grpc_profiler_start(filename); + } + ~ScopedProfile() { + if (enable_) grpc_profiler_stop(); + } + + private: + const bool enable_; +}; + class WorkerServiceImpl GRPC_FINAL : public WorkerService::Service { public: WorkerServiceImpl(int server_port, QpsWorker* worker) @@ -114,9 +127,8 @@ class WorkerServiceImpl GRPC_FINAL : public WorkerService::Service { return Status(StatusCode::RESOURCE_EXHAUSTED, ""); } - grpc_profiler_start("qps_client.prof"); + ScopedProfile profile("qps_client.prof", false); Status ret = RunClientBody(ctx, stream); - grpc_profiler_stop(); return ret; } @@ -128,9 +140,8 @@ class WorkerServiceImpl GRPC_FINAL : public WorkerService::Service { return Status(StatusCode::RESOURCE_EXHAUSTED, ""); } - grpc_profiler_start("qps_server.prof"); + ScopedProfile profile("qps_server.prof", false); Status ret = RunServerBody(ctx, stream); - grpc_profiler_stop(); return ret; } diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index 94a6f8acfa..de46452c3d 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -43,14 +43,14 @@ #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/util/port.h" #include "test/cpp/qps/limit_cores.h" -#include "test/cpp/qps/timer.h" +#include "test/cpp/qps/usage_timer.h" namespace grpc { namespace testing { class Server { public: - explicit Server(const ServerConfig& config) : timer_(new Timer) { + explicit Server(const ServerConfig& config) : timer_(new UsageTimer) { cores_ = LimitCores(config.core_list().data(), config.core_list_size()); if (config.port()) { port_ = config.port(); @@ -62,9 +62,9 @@ class Server { virtual ~Server() {} ServerStats Mark(bool reset) { - Timer::Result timer_result; + UsageTimer::Result timer_result; if (reset) { - std::unique_ptr<Timer> timer(new Timer); + std::unique_ptr<UsageTimer> timer(new UsageTimer); timer.swap(timer_); timer_result = timer->Mark(); } else { @@ -108,7 +108,7 @@ class Server { private: int port_; int cores_; - std::unique_ptr<Timer> timer_; + std::unique_ptr<UsageTimer> timer_; }; std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config); diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc index 4b778820d0..b7682f5763 100644 --- a/test/cpp/qps/server_sync.cc +++ b/test/cpp/qps/server_sync.cc @@ -34,18 +34,18 @@ #include <thread> #include <gflags/gflags.h> +#include <grpc++/security/server_credentials.h> +#include <grpc++/server.h> +#include <grpc++/server_builder.h> +#include <grpc++/server_context.h> #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/host_port.h> #include <grpc/support/log.h> -#include <grpc++/server.h> -#include <grpc++/server_builder.h> -#include <grpc++/server_context.h> -#include <grpc++/security/server_credentials.h> -#include "test/cpp/qps/server.h" -#include "test/cpp/qps/timer.h" #include "src/proto/grpc/testing/services.grpc.pb.h" +#include "test/cpp/qps/server.h" +#include "test/cpp/qps/usage_timer.h" namespace grpc { namespace testing { diff --git a/test/cpp/qps/timer.cc b/test/cpp/qps/usage_timer.cc index 3ec7f49f83..6663a9ac10 100644 --- a/test/cpp/qps/timer.cc +++ b/test/cpp/qps/usage_timer.cc @@ -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 @@ -31,15 +31,15 @@ * */ -#include "test/cpp/qps/timer.h" +#include "test/cpp/qps/usage_timer.h" -#include <sys/time.h> -#include <sys/resource.h> #include <grpc/support/time.h> +#include <sys/resource.h> +#include <sys/time.h> -Timer::Timer() : start_(Sample()) {} +UsageTimer::UsageTimer() : start_(Sample()) {} -double Timer::Now() { +double UsageTimer::Now() { auto ts = gpr_now(GPR_CLOCK_REALTIME); return ts.tv_sec + 1e-9 * ts.tv_nsec; } @@ -48,7 +48,7 @@ static double time_double(struct timeval* tv) { return tv->tv_sec + 1e-6 * tv->tv_usec; } -Timer::Result Timer::Sample() { +UsageTimer::Result UsageTimer::Sample() { struct rusage usage; struct timeval tv; gettimeofday(&tv, NULL); @@ -61,7 +61,7 @@ Timer::Result Timer::Sample() { return r; } -Timer::Result Timer::Mark() const { +UsageTimer::Result UsageTimer::Mark() const { Result s = Sample(); Result r; r.wall = s.wall - start_.wall; diff --git a/test/cpp/qps/timer.h b/test/cpp/qps/usage_timer.h index d1aee1a9d1..d19f820564 100644 --- a/test/cpp/qps/timer.h +++ b/test/cpp/qps/usage_timer.h @@ -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 @@ -31,12 +31,12 @@ * */ -#ifndef TEST_QPS_TIMER_H -#define TEST_QPS_TIMER_H +#ifndef TEST_QPS_USAGE_TIMER_H +#define TEST_QPS_USAGE_TIMER_H -class Timer { +class UsageTimer { public: - Timer(); + UsageTimer(); struct Result { double wall; diff --git a/test/cpp/util/metrics_server.cc b/test/cpp/util/metrics_server.cc index 07978d0bdb..34d51eb316 100644 --- a/test/cpp/util/metrics_server.cc +++ b/test/cpp/util/metrics_server.cc @@ -57,7 +57,7 @@ long Gauge::Get() { grpc::Status MetricsServiceImpl::GetAllGauges( ServerContext* context, const EmptyMessage* request, ServerWriter<GaugeResponse>* writer) { - gpr_log(GPR_INFO, "GetAllGauges called"); + gpr_log(GPR_DEBUG, "GetAllGauges called"); std::lock_guard<std::mutex> lock(mu_); for (auto it = gauges_.begin(); it != gauges_.end(); it++) { diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index 1086e14258..e314fd6d75 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -34,48 +34,140 @@ #include "test/cpp/util/test_credentials_provider.h" +#include <unordered_map> + +#include <grpc/support/sync.h> +#include <grpc++/impl/sync.h> + #include "test/core/end2end/data/ssl_test_data.h" +namespace { + +using grpc::ChannelArguments; +using grpc::ChannelCredentials; +using grpc::InsecureChannelCredentials; +using grpc::InsecureServerCredentials; +using grpc::ServerCredentials; +using grpc::SslCredentialsOptions; +using grpc::SslServerCredentialsOptions; +using grpc::testing::CredentialTypeProvider; + +// Provide test credentials. Thread-safe. +class CredentialsProvider { + public: + virtual ~CredentialsProvider() {} + + virtual void AddSecureType( + const grpc::string& type, + std::unique_ptr<CredentialTypeProvider> type_provider) = 0; + virtual std::shared_ptr<ChannelCredentials> GetChannelCredentials( + const grpc::string& type, ChannelArguments* args) = 0; + virtual std::shared_ptr<ServerCredentials> GetServerCredentials( + const grpc::string& type) = 0; + virtual std::vector<grpc::string> GetSecureCredentialsTypeList() = 0; +}; + +class DefaultCredentialsProvider : public CredentialsProvider { + public: + ~DefaultCredentialsProvider() override {} + + void AddSecureType( + const grpc::string& type, + std::unique_ptr<CredentialTypeProvider> type_provider) override { + // This clobbers any existing entry for type, except the defaults, which + // can't be clobbered. + grpc::unique_lock<grpc::mutex> lock(mu_); + added_secure_types_[type] = std::move(type_provider); + } + + std::shared_ptr<ChannelCredentials> GetChannelCredentials( + const grpc::string& type, ChannelArguments* args) override { + if (type == grpc::testing::kInsecureCredentialsType) { + return InsecureChannelCredentials(); + } else if (type == grpc::testing::kTlsCredentialsType) { + SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; + args->SetSslTargetNameOverride("foo.test.google.fr"); + return SslCredentials(ssl_opts); + } else { + grpc::unique_lock<grpc::mutex> lock(mu_); + auto it(added_secure_types_.find(type)); + if (it == added_secure_types_.end()) { + gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); + return nullptr; + } + return it->second->GetChannelCredentials(args); + } + } + + std::shared_ptr<ServerCredentials> GetServerCredentials( + const grpc::string& type) override { + if (type == grpc::testing::kInsecureCredentialsType) { + return InsecureServerCredentials(); + } else if (type == grpc::testing::kTlsCredentialsType) { + SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, + test_server1_cert}; + SslServerCredentialsOptions ssl_opts; + ssl_opts.pem_root_certs = ""; + ssl_opts.pem_key_cert_pairs.push_back(pkcp); + return SslServerCredentials(ssl_opts); + } else { + grpc::unique_lock<grpc::mutex> lock(mu_); + auto it(added_secure_types_.find(type)); + if (it == added_secure_types_.end()) { + gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); + return nullptr; + } + return it->second->GetServerCredentials(); + } + } + std::vector<grpc::string> GetSecureCredentialsTypeList() override { + std::vector<grpc::string> types; + types.push_back(grpc::testing::kTlsCredentialsType); + grpc::unique_lock<grpc::mutex> lock(mu_); + for (const auto& type_pair : added_secure_types_) { + types.push_back(type_pair.first); + } + return types; + } + + private: + grpc::mutex mu_; + std::unordered_map<grpc::string, std::unique_ptr<CredentialTypeProvider> > + added_secure_types_; +}; + +gpr_once g_once_init_provider = GPR_ONCE_INIT; +CredentialsProvider* g_provider = nullptr; + +void CreateDefaultProvider() { g_provider = new DefaultCredentialsProvider; } + +CredentialsProvider* GetProvider() { + gpr_once_init(&g_once_init_provider, &CreateDefaultProvider); + return g_provider; +} + +} // namespace + namespace grpc { namespace testing { -const char kTlsCredentialsType[] = "TLS_CREDENTIALS"; +void AddSecureType(const grpc::string& type, + std::unique_ptr<CredentialTypeProvider> type_provider) { + GetProvider()->AddSecureType(type, std::move(type_provider)); +} std::shared_ptr<ChannelCredentials> GetChannelCredentials( const grpc::string& type, ChannelArguments* args) { - if (type == kInsecureCredentialsType) { - return InsecureChannelCredentials(); - } else if (type == kTlsCredentialsType) { - SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; - args->SetSslTargetNameOverride("foo.test.google.fr"); - return SslCredentials(ssl_opts); - } else { - gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); - } - return nullptr; + return GetProvider()->GetChannelCredentials(type, args); } std::shared_ptr<ServerCredentials> GetServerCredentials( const grpc::string& type) { - if (type == kInsecureCredentialsType) { - return InsecureServerCredentials(); - } else if (type == kTlsCredentialsType) { - SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, - test_server1_cert}; - SslServerCredentialsOptions ssl_opts; - ssl_opts.pem_root_certs = ""; - ssl_opts.pem_key_cert_pairs.push_back(pkcp); - return SslServerCredentials(ssl_opts); - } else { - gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); - } - return nullptr; + return GetProvider()->GetServerCredentials(type); } std::vector<grpc::string> GetSecureCredentialsTypeList() { - std::vector<grpc::string> types; - types.push_back(kTlsCredentialsType); - return types; + return GetProvider()->GetSecureCredentialsTypeList(); } } // namespace testing diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h index f7253051a9..50fadb53a2 100644 --- a/test/cpp/util/test_credentials_provider.h +++ b/test/cpp/util/test_credentials_provider.h @@ -44,6 +44,23 @@ namespace grpc { namespace testing { const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS"; +const char kTlsCredentialsType[] = "TLS_CREDENTIALS"; + +// Provide test credentials of a particular type. +class CredentialTypeProvider { + public: + virtual ~CredentialTypeProvider() {} + + virtual std::shared_ptr<ChannelCredentials> GetChannelCredentials( + ChannelArguments* args) = 0; + virtual std::shared_ptr<ServerCredentials> GetServerCredentials() = 0; +}; + +// Add a secure type in addition to the defaults above +// (kInsecureCredentialsType, kTlsCredentialsType) that can be returned from the +// functions below. +void AddSecureType(const grpc::string& type, + std::unique_ptr<CredentialTypeProvider> type_provider); // Provide channel credentials according to the given type. Alter the channel // arguments if needed. diff --git a/test/distrib/csharp/DistribTest.sln b/test/distrib/csharp/DistribTest.sln index 0eca35c30f..78d5397ca9 100644 --- a/test/distrib/csharp/DistribTest.sln +++ b/test/distrib/csharp/DistribTest.sln @@ -8,13 +8,19 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {A3E61CC3-3710-49A3-A830-A0066EDBCE2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A3E61CC3-3710-49A3-A830-A0066EDBCE2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3E61CC3-3710-49A3-A830-A0066EDBCE2F}.Debug|x64.ActiveCfg = Debug|x64 + {A3E61CC3-3710-49A3-A830-A0066EDBCE2F}.Debug|x64.Build.0 = Debug|x64 {A3E61CC3-3710-49A3-A830-A0066EDBCE2F}.Release|Any CPU.ActiveCfg = Release|Any CPU {A3E61CC3-3710-49A3-A830-A0066EDBCE2F}.Release|Any CPU.Build.0 = Release|Any CPU + {A3E61CC3-3710-49A3-A830-A0066EDBCE2F}.Release|x64.ActiveCfg = Release|x64 + {A3E61CC3-3710-49A3-A830-A0066EDBCE2F}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/distrib/csharp/DistribTest/DistribTest.csproj b/test/distrib/csharp/DistribTest/DistribTest.csproj index 124fc1bdf0..7605495f0f 100644 --- a/test/distrib/csharp/DistribTest/DistribTest.csproj +++ b/test/distrib/csharp/DistribTest/DistribTest.csproj @@ -32,6 +32,26 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\x64\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>x64</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + <OutputPath>bin\x64\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <Optimize>true</Optimize> + <DebugType>pdbonly</DebugType> + <PlatformTarget>x64</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> <ItemGroup> <Reference Include="BouncyCastle.Crypto"> <HintPath>..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll</HintPath> diff --git a/test/distrib/csharp/run_distrib_test.bat b/test/distrib/csharp/run_distrib_test.bat new file mode 100644 index 0000000000..67bfc58ac8 --- /dev/null +++ b/test/distrib/csharp/run_distrib_test.bat @@ -0,0 +1,49 @@ +@rem Copyright 2016, Google Inc. +@rem All rights reserved. +@rem +@rem Redistribution and use in source and binary forms, with or without +@rem modification, are permitted provided that the following conditions are +@rem met: +@rem +@rem * Redistributions of source code must retain the above copyright +@rem notice, this list of conditions and the following disclaimer. +@rem * Redistributions in binary form must reproduce the above +@rem copyright notice, this list of conditions and the following disclaimer +@rem in the documentation and/or other materials provided with the +@rem distribution. +@rem * Neither the name of Google Inc. nor the names of its +@rem contributors may be used to endorse or promote products derived from +@rem this software without specific prior written permission. +@rem +@rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +@rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +@rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +@rem A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +@rem OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +@rem SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +@rem LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +@rem DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +@rem THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +@rem (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +@rem OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +@rem enter this directory +cd /d %~dp0 + +@rem extract input artifacts +powershell -Command "Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('../../../input_artifacts/csharp_nugets.zip', 'TestNugetFeed');" + +update_version.sh auto + +set NUGET=C:\nuget\nuget.exe +%NUGET% restore || goto :error + +@call build_vs2015.bat DistribTest.sln %MSBUILD_EXTRA_ARGS% || goto :error + +%DISTRIBTEST_OUTPATH%\DistribTest.exe || goto :error + +goto :EOF + +:error +echo Failed! +exit /b %errorlevel% diff --git a/test/distrib/csharp/run_distrib_test.sh b/test/distrib/csharp/run_distrib_test.sh index 1de62041b3..934174a9a4 100755 --- a/test/distrib/csharp/run_distrib_test.sh +++ b/test/distrib/csharp/run_distrib_test.sh @@ -34,9 +34,7 @@ cd $(dirname $0) unzip -o "$EXTERNAL_GIT_ROOT/input_artifacts/csharp_nugets.zip" -d TestNugetFeed -# Extract the version number from Grpc nuget package name. -CSHARP_VERSION=$(ls TestNugetFeed | grep '^Grpc\.[0-9].*\.nupkg$' | sed s/^Grpc\.// | sed s/\.nupkg$//) -./update_version.sh $CSHARP_VERSION +./update_version.sh auto nuget restore diff --git a/test/distrib/csharp/update_version.sh b/test/distrib/csharp/update_version.sh index f2554e8998..b0d07721f6 100755 --- a/test/distrib/csharp/update_version.sh +++ b/test/distrib/csharp/update_version.sh @@ -32,5 +32,13 @@ set -e cd $(dirname $0) +CSHARP_VERSION="$1" +if [ "$CSHARP_VERSION" == "auto" ] +then + # autodetect C# version + CSHARP_VERSION=$(ls TestNugetFeed | grep '^Grpc\.[0-9].*\.nupkg$' | sed s/^Grpc\.// | sed s/\.nupkg$//) + echo "Autodetected nuget ${CSHARP_VERSION}" +fi + # Replaces version placeholder with value provided as first argument. -sed -ibak "s/__GRPC_NUGET_VERSION__/$1/g" DistribTest/packages.config DistribTest/DistribTest.csproj +sed -ibak "s/__GRPC_NUGET_VERSION__/${CSHARP_VERSION}/g" DistribTest/packages.config DistribTest/DistribTest.csproj diff --git a/test/distrib/php/distribtest.php b/test/distrib/php/distribtest.php new file mode 100644 index 0000000000..4c34cd674b --- /dev/null +++ b/test/distrib/php/distribtest.php @@ -0,0 +1,45 @@ +<?php +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +$channel = new Grpc\Channel('localhost:1000', [ + 'credentials' => Grpc\ChannelCredentials::createInsecure() +]); + +$deadline = Grpc\Timeval::infFuture(); +$call = new Grpc\Call($channel, + 'dummy_method', + $deadline); + +$call->cancel(); +$channel->close(); diff --git a/test/distrib/php/run_distrib_test.sh b/test/distrib/php/run_distrib_test.sh new file mode 100755 index 0000000000..43b28d8429 --- /dev/null +++ b/test/distrib/php/run_distrib_test.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Copyright 2015-2016, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -ex + +cd $(dirname $0) + +cp -r $EXTERNAL_GIT_ROOT/input_artifacts/grpc-php.tgz . + +pecl install grpc-php.tgz + +php -d extension=grpc.so -d max_execution_time=300 distribtest.php |