diff options
author | Alistair Veitch <aveitch@google.com> | 2015-07-26 15:24:41 -0700 |
---|---|---|
committer | Alistair Veitch <aveitch@google.com> | 2015-07-26 15:24:41 -0700 |
commit | b4cbc1e2f72b18da3c84130c5bf7b28e344fba8f (patch) | |
tree | 5564c6754f30570bb59c6e62c2ddda405a51296b /test/core | |
parent | af5002f9ae647f8d82ec3b1cdaef4438cd6d2ad0 (diff) | |
parent | 5c575dd6e4b01cd68cca5d1917b58023dcf4ca0f (diff) |
post-merge
Diffstat (limited to 'test/core')
46 files changed, 1128 insertions, 320 deletions
diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index eca2a40c97..60129afc43 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -37,6 +37,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include <grpc/support/string_util.h> + #include "test/core/util/test_config.h" static void channel_init_func(grpc_channel_element *elem, grpc_channel *master, @@ -73,11 +75,14 @@ static void channel_func(grpc_channel_element *elem, grpc_transport_op *op) { ++*(int *)(elem->channel_data); } +static char *get_peer(grpc_call_element *elem) { return gpr_strdup("peer"); } + static void test_create_channel_stack(void) { - const grpc_channel_filter filter = { - call_func, channel_func, sizeof(int), - call_init_func, call_destroy_func, sizeof(int), - channel_init_func, channel_destroy_func, "some_test_filter"}; + const grpc_channel_filter filter = {call_func, channel_func, + sizeof(int), call_init_func, + call_destroy_func, sizeof(int), + channel_init_func, channel_destroy_func, + get_peer, "some_test_filter"}; const grpc_channel_filter *filters = &filter; grpc_channel_stack *channel_stack; grpc_call_stack *call_stack; diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c index 4033c18131..f5f21cff25 100644 --- a/test/core/compression/message_compress_test.c +++ b/test/core/compression/message_compress_test.c @@ -61,13 +61,15 @@ static void assert_passthrough(gpr_slice value, gpr_slice_buffer output; gpr_slice final; int was_compressed; + char *algorithm_name; + GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algorithm_name) != 0); gpr_log(GPR_INFO, "assert_passthrough: value_length=%d value_hash=0x%08x " "algorithm='%s' uncompressed_split='%s' compressed_split='%s'", GPR_SLICE_LENGTH(value), gpr_murmur_hash3(GPR_SLICE_START_PTR(value), GPR_SLICE_LENGTH(value), 0), - grpc_compression_algorithm_name(algorithm), + algorithm_name, grpc_slice_split_mode_name(uncompressed_split_mode), grpc_slice_split_mode_name(compressed_split_mode)); diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 407c72b519..c28932c52b 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -40,6 +40,7 @@ #include "src/core/surface/event_string.h" #include "src/core/support/string.h" #include <grpc/byte_buffer.h> +#include <grpc/byte_buffer_reader.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> @@ -144,7 +145,17 @@ static int byte_buffer_eq_slice(grpc_byte_buffer *bb, gpr_slice b) { } int byte_buffer_eq_string(grpc_byte_buffer *bb, const char *str) { - return byte_buffer_eq_slice(bb, gpr_slice_from_copied_string(str)); + grpc_byte_buffer_reader reader; + grpc_byte_buffer* rbb; + int res; + + grpc_byte_buffer_reader_init(&reader, bb); + rbb = grpc_raw_byte_buffer_from_reader(&reader); + res = byte_buffer_eq_slice(rbb, gpr_slice_from_copied_string(str)); + grpc_byte_buffer_reader_destroy(&reader); + grpc_byte_buffer_destroy(rbb); + + return res; } static void verify_matches(expectation *e, grpc_event *ev) { @@ -248,8 +259,8 @@ void cq_verify(cq_verifier *v) { } void cq_verify_empty(cq_verifier *v) { - gpr_timespec deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1)); + gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(1, GPR_TIMESPAN)); grpc_event ev; GPR_ASSERT(v->expect.next == &v->expect && "expectation queue must be empty"); diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index 7d3568c22e..453376caec 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -37,6 +37,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/host_port.h> #include <grpc/support/log.h> +#include <grpc/support/string_util.h> #include "test/core/end2end/cq_verifier.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" @@ -78,6 +79,7 @@ void test_connect(const char *server_host, const char *client_host, int port, size_t details_capacity = 0; int was_cancelled = 2; grpc_call_details call_details; + char *peer; if (port == 0) { port = grpc_pick_unused_port_or_die(); @@ -105,7 +107,12 @@ void test_connect(const char *server_host, const char *client_host, int port, cqv = cq_verifier_create(cq); /* Create client. */ - gpr_join_host_port(&client_hostport, client_host, port); + if (client_host[0] == 'i') { + /* for ipv4:/ipv6: addresses, just concatenate the port */ + gpr_asprintf(&client_hostport, "%s:%d", client_host, port); + } else { + gpr_join_host_port(&client_hostport, client_host, port); + } client = grpc_channel_create(client_hostport, NULL); gpr_log(GPR_INFO, "Testing with server=%s client=%s (expecting %s)", @@ -179,6 +186,10 @@ void test_connect(const char *server_host, const char *client_host, int port, cq_expect_completion(cqv, tag(1), 1); cq_verify(cqv); + peer = grpc_call_get_peer(c); + gpr_log(GPR_DEBUG, "got peer: '%s'", peer); + gpr_free(peer); + GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); GPR_ASSERT(0 == strcmp(details, "xyz")); GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); @@ -211,6 +222,10 @@ void test_connect(const char *server_host, const char *client_host, int port, drain_cq(cq); grpc_completion_queue_destroy(cq); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); gpr_free(details); } @@ -233,21 +248,31 @@ int main(int argc, char **argv) { /* :: and 0.0.0.0 are handled identically. */ test_connect("::", "127.0.0.1", 0, 1); test_connect("::", "::ffff:127.0.0.1", 0, 1); + test_connect("::", "ipv4:127.0.0.1", 0, 1); + test_connect("::", "ipv6:[::ffff:127.0.0.1]", 0, 1); test_connect("::", "localhost", 0, 1); test_connect("0.0.0.0", "127.0.0.1", 0, 1); test_connect("0.0.0.0", "::ffff:127.0.0.1", 0, 1); + test_connect("0.0.0.0", "ipv4:127.0.0.1", 0, 1); + test_connect("0.0.0.0", "ipv6:[::ffff:127.0.0.1]", 0, 1); test_connect("0.0.0.0", "localhost", 0, 1); if (do_ipv6) { test_connect("::", "::1", 0, 1); test_connect("0.0.0.0", "::1", 0, 1); + test_connect("::", "ipv6:[::1]", 0, 1); + test_connect("0.0.0.0", "ipv6:[::1]", 0, 1); } /* These only work when the families agree. */ test_connect("127.0.0.1", "127.0.0.1", 0, 1); + test_connect("127.0.0.1", "ipv4:127.0.0.1", 0, 1); if (do_ipv6) { test_connect("::1", "::1", 0, 1); test_connect("::1", "127.0.0.1", 0, 0); test_connect("127.0.0.1", "::1", 0, 0); + test_connect("::1", "ipv6:[::1]", 0, 1); + test_connect("::1", "ipv4:127.0.0.1", 0, 0); + test_connect("127.0.0.1", "ipv6:[::1]", 0, 0); } } diff --git a/test/core/end2end/fixtures/chttp2_fullstack_compression.c b/test/core/end2end/fixtures/chttp2_fullstack_compression.c new file mode 100644 index 0000000000..0a9a312296 --- /dev/null +++ b/test/core/end2end/fixtures/chttp2_fullstack_compression.c @@ -0,0 +1,135 @@ +/* + * + * Copyright 2015, 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 "test/core/end2end/end2end_tests.h" + +#include <string.h> + +#include "src/core/channel/channel_args.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 "test/core/util/port.h" +#include "test/core/util/test_config.h" + +typedef struct fullstack_compression_fixture_data { + char *localaddr; + grpc_channel_args* client_args_compression; + grpc_channel_args* server_args_compression; +} fullstack_compression_fixture_data; + +static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression( + grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_end2end_test_fixture f; + int port = grpc_pick_unused_port_or_die(); + fullstack_compression_fixture_data *ffd = + gpr_malloc(sizeof(fullstack_compression_fixture_data)); + memset(ffd, 0, sizeof(fullstack_compression_fixture_data)); + + gpr_join_host_port(&ffd->localaddr, "localhost", port); + + memset(&f, 0, sizeof(f)); + f.fixture_data = ffd; + f.cq = grpc_completion_queue_create(); + + return f; +} + +void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture *f, + grpc_channel_args *client_args) { + fullstack_compression_fixture_data *ffd = f->fixture_data; + if (ffd->client_args_compression != NULL) { + grpc_channel_args_destroy(ffd->client_args_compression); + } + ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( + client_args, GRPC_COMPRESS_GZIP); + f->client = grpc_channel_create(ffd->localaddr, ffd->client_args_compression); +} + +void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f, + grpc_channel_args *server_args) { + fullstack_compression_fixture_data *ffd = f->fixture_data; + if (ffd->server_args_compression != NULL) { + grpc_channel_args_destroy(ffd->server_args_compression); + } + ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( + server_args, GRPC_COMPRESS_GZIP); + if (f->server) { + grpc_server_destroy(f->server); + } + f->server = grpc_server_create(ffd->server_args_compression); + grpc_server_register_completion_queue(f->server, f->cq); + GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr)); + grpc_server_start(f->server); +} + +void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture *f) { + fullstack_compression_fixture_data *ffd = f->fixture_data; + grpc_channel_args_destroy(ffd->client_args_compression); + grpc_channel_args_destroy(ffd->server_args_compression); + gpr_free(ffd->localaddr); + gpr_free(ffd); +} + +/* All test configurations */ +static grpc_end2end_test_config configs[] = { + {"chttp2/fullstack_compression", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION, + chttp2_create_fixture_fullstack_compression, + chttp2_init_client_fullstack_compression, + chttp2_init_server_fullstack_compression, + chttp2_tear_down_fullstack_compression}, +}; + +int main(int argc, char **argv) { + size_t i; + + grpc_test_init(argc, argv); + grpc_init(); + + for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { + grpc_end2end_tests(configs[i]); + } + + grpc_shutdown(); + + return 0; +} diff --git a/test/core/end2end/fixtures/chttp2_socket_pair.c b/test/core/end2end/fixtures/chttp2_socket_pair.c index be523608d0..807fc8e7bc 100644 --- a/test/core/end2end/fixtures/chttp2_socket_pair.c +++ b/test/core/end2end/fixtures/chttp2_socket_pair.c @@ -36,6 +36,7 @@ #include <string.h> #include "src/core/channel/client_channel.h" +#include "src/core/channel/compress_filter.h" #include "src/core/channel/connected_channel.h" #include "src/core/channel/http_client_filter.h" #include "src/core/channel/http_server_filter.h" @@ -75,10 +76,11 @@ static void client_setup_transport(void *ts, grpc_transport *transport, sp_client_setup *cs = ts; const grpc_channel_filter *filters[] = {&grpc_http_client_filter, + &grpc_compress_filter, &grpc_connected_channel_filter}; size_t nfilters = sizeof(filters) / sizeof(*filters); grpc_channel *channel = grpc_channel_create_from_filters( - filters, nfilters, cs->client_args, mdctx, 1); + "socketpair-target", filters, nfilters, cs->client_args, mdctx, 1); cs->f->client = channel; diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c b/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c index f875ca54a5..21d4404237 100644 --- a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c +++ b/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c @@ -39,6 +39,7 @@ #include "src/core/channel/connected_channel.h" #include "src/core/channel/http_client_filter.h" #include "src/core/channel/http_server_filter.h" +#include "src/core/channel/compress_filter.h" #include "src/core/iomgr/endpoint_pair.h" #include "src/core/iomgr/iomgr.h" #include "src/core/surface/channel.h" @@ -75,10 +76,11 @@ static void client_setup_transport(void *ts, grpc_transport *transport, sp_client_setup *cs = ts; const grpc_channel_filter *filters[] = {&grpc_http_client_filter, + &grpc_compress_filter, &grpc_connected_channel_filter}; size_t nfilters = sizeof(filters) / sizeof(*filters); grpc_channel *channel = grpc_channel_create_from_filters( - filters, nfilters, cs->client_args, mdctx, 1); + "socketpair-target", filters, nfilters, cs->client_args, mdctx, 1); cs->f->client = channel; diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c b/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c index 52c0e2ca8b..c59628b959 100644 --- a/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c +++ b/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c @@ -39,6 +39,7 @@ #include "src/core/channel/connected_channel.h" #include "src/core/channel/http_client_filter.h" #include "src/core/channel/http_server_filter.h" +#include "src/core/channel/compress_filter.h" #include "src/core/iomgr/endpoint_pair.h" #include "src/core/iomgr/iomgr.h" #include "src/core/support/env.h" @@ -76,10 +77,11 @@ static void client_setup_transport(void *ts, grpc_transport *transport, sp_client_setup *cs = ts; const grpc_channel_filter *filters[] = {&grpc_http_client_filter, + &grpc_compress_filter, &grpc_connected_channel_filter}; size_t nfilters = sizeof(filters) / sizeof(*filters); grpc_channel *channel = grpc_channel_create_from_filters( - filters, nfilters, cs->client_args, mdctx, 1); + "socketpair-target", filters, nfilters, cs->client_args, mdctx, 1); cs->f->client = channel; diff --git a/test/core/end2end/gen_build_json.py b/test/core/end2end/gen_build_json.py index f1c7e85e08..8b0dd3166b 100755 --- a/test/core/end2end/gen_build_json.py +++ b/test/core/end2end/gen_build_json.py @@ -44,6 +44,7 @@ default_secure_fixture_options = FixtureOptions(True, ['windows', 'posix']) END2END_FIXTURES = { 'chttp2_fake_security': default_secure_fixture_options, 'chttp2_fullstack': default_unsecure_fixture_options, + 'chttp2_fullstack_compression': default_unsecure_fixture_options, 'chttp2_fullstack_with_poll': FixtureOptions(False, ['posix']), 'chttp2_fullstack_uds_posix': FixtureOptions(False, ['posix']), 'chttp2_simple_ssl_fullstack': default_secure_fixture_options, @@ -84,6 +85,7 @@ END2END_TESTS = { 'request_response_with_payload_and_call_creds': TestOptions(flaky=False, secure=True), 'request_with_large_metadata': default_test_options, 'request_with_payload': default_test_options, + 'request_with_compressed_payload': default_test_options, 'request_with_flags': default_test_options, 'server_finishes_request': default_test_options, 'simple_delayed_request': default_test_options, diff --git a/test/core/end2end/multiple_server_queues_test.c b/test/core/end2end/multiple_server_queues_test.c index e291e4e6d3..208d42e6e7 100644 --- a/test/core/end2end/multiple_server_queues_test.c +++ b/test/core/end2end/multiple_server_queues_test.c @@ -49,11 +49,12 @@ int main(int argc, char **argv) { grpc_server_register_completion_queue(server, cq2); grpc_server_start(server); grpc_server_shutdown_and_notify(server, cq2, NULL); - grpc_completion_queue_next(cq2, gpr_inf_future); /* cue queue hang */ + grpc_completion_queue_next( + cq2, gpr_inf_future(GPR_CLOCK_REALTIME)); /* cue queue hang */ grpc_completion_queue_shutdown(cq1); grpc_completion_queue_shutdown(cq2); - grpc_completion_queue_next(cq1, gpr_inf_future); - grpc_completion_queue_next(cq2, gpr_inf_future); + grpc_completion_queue_next(cq1, gpr_inf_future(GPR_CLOCK_REALTIME)); + grpc_completion_queue_next(cq2, gpr_inf_future(GPR_CLOCK_REALTIME)); grpc_server_destroy(server); grpc_completion_queue_destroy(cq1); grpc_completion_queue_destroy(cq2); diff --git a/test/core/end2end/no_server_test.c b/test/core/end2end/no_server_test.c index 35b837b7b5..79797f9375 100644 --- a/test/core/end2end/no_server_test.c +++ b/test/core/end2end/no_server_test.c @@ -85,8 +85,8 @@ int main(int argc, char **argv) { GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED); grpc_completion_queue_shutdown(cq); - while (grpc_completion_queue_next(cq, gpr_inf_future).type != - GRPC_QUEUE_SHUTDOWN) + while (grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME)) + .type != GRPC_QUEUE_SHUTDOWN) ; grpc_completion_queue_destroy(cq); grpc_call_destroy(call); diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index 9d716f1135..ea59a9385f 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -129,7 +129,8 @@ static void test_max_message_length(grpc_end2end_test_config config) { cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call(f.client, f.cq, "/foo", - "foo.test.google.fr:1234", gpr_inf_future); + "foo.test.google.fr:1234", + gpr_inf_future(GPR_CLOCK_REALTIME)); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); diff --git a/test/core/end2end/tests/request_with_compressed_payload.c b/test/core/end2end/tests/request_with_compressed_payload.c new file mode 100644 index 0000000000..2599f796d2 --- /dev/null +++ b/test/core/end2end/tests/request_with_compressed_payload.c @@ -0,0 +1,315 @@ +/* + * + * Copyright 2015, 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 "test/core/end2end/end2end_tests.h" + +#include <stdio.h> +#include <string.h> + +#include <grpc/byte_buffer.h> +#include <grpc/byte_buffer_reader.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/time.h> +#include <grpc/support/useful.h> + +#include "test/core/end2end/cq_verifier.h" +#include "src/core/channel/channel_args.h" +#include "src/core/channel/compress_filter.h" + +enum { TIMEOUT = 200000 }; + +static void *tag(gpr_intptr t) { return (void *)t; } + +static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, + const char *test_name, + grpc_channel_args *client_args, + grpc_channel_args *server_args) { + grpc_end2end_test_fixture f; + gpr_log(GPR_INFO, "%s/%s", test_name, config.name); + f = config.create_fixture(client_args, server_args); + config.init_client(&f, client_args); + config.init_server(&f, server_args); + return f; +} + +static gpr_timespec n_seconds_time(int n) { + return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n); +} + +static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); } + +static void drain_cq(grpc_completion_queue *cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, five_seconds_time()); + } while (ev.type != GRPC_QUEUE_SHUTDOWN); +} + +static void shutdown_server(grpc_end2end_test_fixture *f) { + if (!f->server) return; + grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000)); + GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(1000), + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)) + .type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->server); + f->server = NULL; +} + +static void shutdown_client(grpc_end2end_test_fixture *f) { + if (!f->client) return; + grpc_channel_destroy(f->client); + f->client = NULL; +} + +static void end_test(grpc_end2end_test_fixture *f) { + shutdown_server(f); + shutdown_client(f); + + grpc_completion_queue_shutdown(f->cq); + drain_cq(f->cq); + grpc_completion_queue_destroy(f->cq); +} + +static void request_with_payload_template( + grpc_end2end_test_config config, const char *test_name, + gpr_uint32 send_flags_bitmask, + grpc_compression_algorithm requested_compression_algorithm, + grpc_compression_algorithm expected_compression_algorithm, + grpc_metadata *client_metadata) { + grpc_call *c; + grpc_call *s; + gpr_slice request_payload_slice; + grpc_byte_buffer *request_payload; + gpr_timespec deadline = five_seconds_time(); + grpc_channel_args *client_args; + grpc_channel_args *server_args; + grpc_end2end_test_fixture f; + grpc_op ops[6]; + grpc_op *op; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array request_metadata_recv; + grpc_byte_buffer *request_payload_recv = NULL; + grpc_call_details call_details; + grpc_status_code status; + char *details = NULL; + size_t details_capacity = 0; + int was_cancelled = 2; + cq_verifier *cqv; + char str[1024]; + + memset(str, 'x', 1023); str[1023] = '\0'; + request_payload_slice = gpr_slice_from_copied_string(str); + request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); + + client_args = grpc_channel_args_set_compression_algorithm( + NULL, requested_compression_algorithm); + server_args = grpc_channel_args_set_compression_algorithm( + NULL, requested_compression_algorithm); + + f = begin_test(config, test_name, client_args, server_args); + cqv = cq_verifier_create(f.cq); + + c = grpc_channel_create_call(f.client, f.cq, "/foo", + "foo.test.google.fr", deadline); + GPR_ASSERT(c); + + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_metadata_array_init(&request_metadata_recv); + grpc_call_details_init(&call_details); + + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + if (client_metadata != NULL) { + op->data.send_initial_metadata.count = 1; + op->data.send_initial_metadata.metadata = client_metadata; + } else { + op->data.send_initial_metadata.count = 0; + } + op->flags = 0; + op++; + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message = request_payload; + op->flags = send_flags_bitmask; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &initial_metadata_recv; + op->flags = 0; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; + op->flags = 0; + op++; + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1))); + + GPR_ASSERT(GRPC_CALL_OK == + grpc_server_request_call(f.server, &s, &call_details, + &request_metadata_recv, f.cq, + f.cq, tag(101))); + cq_expect_completion(cqv, tag(101), 1); + cq_verify(cqv); + + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message = &request_payload_recv; + op->flags = 0; + op++; + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102))); + + cq_expect_completion(cqv, tag(102), 1); + cq_verify(cqv); + + op = ops; + op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; + op->data.recv_close_on_server.cancelled = &was_cancelled; + op->flags = 0; + op++; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = 0; + op->data.send_status_from_server.status = GRPC_STATUS_OK; + op->data.send_status_from_server.status_details = "xyz"; + op->flags = 0; + op++; + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(103))); + + cq_expect_completion(cqv, tag(103), 1); + cq_expect_completion(cqv, tag(1), 1); + cq_verify(cqv); + + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr")); + GPR_ASSERT(was_cancelled == 0); + + GPR_ASSERT(request_payload_recv->type == GRPC_BB_RAW); + GPR_ASSERT(request_payload_recv->data.raw.compression == + expected_compression_algorithm); + + GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, str)); + + gpr_free(details); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + + grpc_call_destroy(c); + grpc_call_destroy(s); + + cq_verifier_destroy(cqv); + + gpr_slice_unref(request_payload_slice); + grpc_byte_buffer_destroy(request_payload); + grpc_byte_buffer_destroy(request_payload_recv); + + grpc_channel_args_destroy(client_args); + grpc_channel_args_destroy(server_args); + + end_test(&f); + config.tear_down_data(&f); +} + +static void test_invoke_request_with_exceptionally_uncompressed_payload( + grpc_end2end_test_config config) { + request_with_payload_template( + config, "test_invoke_request_with_exceptionally_uncompressed_payload", + GRPC_WRITE_NO_COMPRESS, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_NONE, + NULL); +} + +static void test_invoke_request_with_uncompressed_payload( + grpc_end2end_test_config config) { + request_with_payload_template( + config, "test_invoke_request_with_uncompressed_payload", 0, + GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, NULL); +} + +static void test_invoke_request_with_compressed_payload( + grpc_end2end_test_config config) { + request_with_payload_template( + config, "test_invoke_request_with_compressed_payload", 0, + GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, NULL); +} + +static void test_invoke_request_with_compressed_payload_md_override( + grpc_end2end_test_config config) { + grpc_metadata gzip_compression_override; + grpc_metadata none_compression_override; + + gzip_compression_override.key = GRPC_COMPRESS_REQUEST_ALGORITHM_KEY; + gzip_compression_override.value = "gzip"; + gzip_compression_override.value_length = 4; + memset(&gzip_compression_override.internal_data, 0, + sizeof(gzip_compression_override.internal_data)); + + none_compression_override.key = GRPC_COMPRESS_REQUEST_ALGORITHM_KEY; + none_compression_override.value = "none"; + none_compression_override.value_length = 4; + memset(&none_compression_override.internal_data, 0, + sizeof(none_compression_override.internal_data)); + + /* Channel default NONE, call override to GZIP */ + request_with_payload_template( + config, "test_invoke_request_with_compressed_payload_md_override_1", 0, + GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, &gzip_compression_override); + + /* Channel default DEFLATE, call override to GZIP */ + request_with_payload_template( + config, "test_invoke_request_with_compressed_payload_md_override_2", 0, + GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_GZIP, &gzip_compression_override); + + /* Channel default DEFLATE, call override to NONE */ + request_with_payload_template( + config, "test_invoke_request_with_compressed_payload_md_override_3", 0, + GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_NONE, &none_compression_override); +} + +void grpc_end2end_tests(grpc_end2end_test_config config) { + test_invoke_request_with_exceptionally_uncompressed_payload(config); + test_invoke_request_with_uncompressed_payload(config); + test_invoke_request_with_compressed_payload(config); + test_invoke_request_with_compressed_payload_md_override(config); +} diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c index 6194b841d8..ca783afccd 100644 --- a/test/core/end2end/tests/simple_request.c +++ b/test/core/end2end/tests/simple_request.c @@ -114,11 +114,17 @@ static void simple_request_body(grpc_end2end_test_fixture f) { char *details = NULL; size_t details_capacity = 0; int was_cancelled = 2; + char *peer; c = grpc_channel_create_call(f.client, f.cq, "/foo", "foo.test.google.fr:1234", deadline); GPR_ASSERT(c); + peer = grpc_call_get_peer(c); + GPR_ASSERT(peer != NULL); + gpr_log(GPR_DEBUG, "client_peer_before_call=%s", peer); + gpr_free(peer); + grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); grpc_metadata_array_init(&request_metadata_recv); @@ -151,6 +157,15 @@ static void simple_request_body(grpc_end2end_test_fixture f) { cq_expect_completion(cqv, tag(101), 1); cq_verify(cqv); + peer = grpc_call_get_peer(s); + GPR_ASSERT(peer != NULL); + gpr_log(GPR_DEBUG, "server_peer=%s", peer); + gpr_free(peer); + peer = grpc_call_get_peer(c); + GPR_ASSERT(peer != NULL); + gpr_log(GPR_DEBUG, "client_peer=%s", peer); + gpr_free(peer); + op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; diff --git a/test/core/fling/client.c b/test/core/fling/client.c index 6741a9dec8..2b19654379 100644 --- a/test/core/fling/client.c +++ b/test/core/fling/client.c @@ -89,24 +89,26 @@ static void init_ping_pong_request(void) { } static void step_ping_pong_request(void) { - call = grpc_channel_create_call(channel, cq, "/Reflector/reflectUnary", - "localhost", gpr_inf_future); + call = + grpc_channel_create_call(channel, cq, "/Reflector/reflectUnary", + "localhost", gpr_inf_future(GPR_CLOCK_REALTIME)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops, op - ops, (void *)1)); - grpc_completion_queue_next(cq, gpr_inf_future); + grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME)); grpc_call_destroy(call); grpc_byte_buffer_destroy(response_payload_recv); call = NULL; } static void init_ping_pong_stream(void) { - call = grpc_channel_create_call(channel, cq, "/Reflector/reflectStream", - "localhost", gpr_inf_future); + call = + grpc_channel_create_call(channel, cq, "/Reflector/reflectStream", + "localhost", gpr_inf_future(GPR_CLOCK_REALTIME)); stream_init_op.op = GRPC_OP_SEND_INITIAL_METADATA; stream_init_op.data.send_initial_metadata.count = 0; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, &stream_init_op, 1, (void *)1)); - grpc_completion_queue_next(cq, gpr_inf_future); + grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME)); grpc_metadata_array_init(&initial_metadata_recv); @@ -119,7 +121,7 @@ static void init_ping_pong_stream(void) { static void step_ping_pong_stream(void) { GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, stream_step_ops, 2, (void *)1)); - grpc_completion_queue_next(cq, gpr_inf_future); + grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME)); grpc_byte_buffer_destroy(response_payload_recv); } @@ -208,8 +210,8 @@ int main(int argc, char **argv) { grpc_channel_destroy(channel); grpc_completion_queue_shutdown(cq); - while (grpc_completion_queue_next(cq, gpr_inf_future).type != - GRPC_QUEUE_SHUTDOWN) + while (grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME)) + .type != GRPC_QUEUE_SHUTDOWN) ; grpc_completion_queue_destroy(cq); grpc_byte_buffer_destroy(the_buffer); diff --git a/test/core/fling/server.c b/test/core/fling/server.c index 468013c3ec..082bbd368a 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -242,7 +242,7 @@ int main(int argc, char **argv) { } ev = grpc_completion_queue_next( cq, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000))); + gpr_time_from_micros(1000000, GPR_TIMESPAN))); s = ev.tag; switch (ev.type) { case GRPC_OP_COMPLETE: diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c index ca0b2d1519..4801eb3e39 100644 --- a/test/core/httpcli/httpcli_test.c +++ b/test/core/httpcli/httpcli_test.c @@ -145,8 +145,8 @@ int main(int argc, char **argv) { gpr_free(args[0]); gpr_free(args[2]); - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); grpc_test_init(argc, argv); grpc_init(); diff --git a/test/core/iomgr/alarm_heap_test.c b/test/core/iomgr/alarm_heap_test.c index b3e1e64d0f..66b6e4cb64 100644 --- a/test/core/iomgr/alarm_heap_test.c +++ b/test/core/iomgr/alarm_heap_test.c @@ -44,6 +44,7 @@ static gpr_timespec random_deadline(void) { gpr_timespec ts; ts.tv_sec = rand(); ts.tv_nsec = rand(); + ts.clock_type = GPR_CLOCK_REALTIME; return ts; } @@ -101,7 +102,7 @@ static int *all_top(grpc_alarm_heap *pq, int *n) { static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq, gpr_uint8 *inpq, int num_elements) { - gpr_timespec max_deadline = gpr_inf_past; + gpr_timespec max_deadline = gpr_inf_past(GPR_CLOCK_REALTIME); int *max_deadline_indices = gpr_malloc(num_elements * sizeof(int)); int *top_elements; int num_max_deadline_indices = 0; diff --git a/test/core/iomgr/alarm_list_test.c b/test/core/iomgr/alarm_list_test.c index 225c449d4b..56d662e61a 100644 --- a/test/core/iomgr/alarm_list_test.c +++ b/test/core/iomgr/alarm_list_test.c @@ -60,45 +60,51 @@ static void add_test(void) { /* 10 ms alarms. will expire in the current epoch */ for (i = 0; i < 10; i++) { - grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis(10)), + grpc_alarm_init(&alarms[i], + gpr_time_add(start, gpr_time_from_millis(10, GPR_TIMESPAN)), cb, (void *)(gpr_intptr)i, start); } /* 1010 ms alarms. will expire in the next epoch */ for (i = 10; i < 20; i++) { - grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis(1010)), + grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis( + 1010, GPR_TIMESPAN)), cb, (void *)(gpr_intptr)i, start); } /* collect alarms. Only the first batch should be ready. */ - GPR_ASSERT(10 == - grpc_alarm_check( - NULL, gpr_time_add(start, gpr_time_from_millis(500)), NULL)); + GPR_ASSERT(10 == grpc_alarm_check(NULL, + gpr_time_add(start, gpr_time_from_millis( + 500, GPR_TIMESPAN)), + NULL)); 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_alarm_check( - NULL, gpr_time_add(start, gpr_time_from_millis(600)), NULL)); + GPR_ASSERT(0 == grpc_alarm_check( + NULL, gpr_time_add( + start, gpr_time_from_millis(600, GPR_TIMESPAN)), + NULL)); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } /* collect the rest of the alarms */ - GPR_ASSERT(10 == - grpc_alarm_check( - NULL, gpr_time_add(start, gpr_time_from_millis(1500)), NULL)); + GPR_ASSERT( + 10 == grpc_alarm_check(NULL, gpr_time_add(start, gpr_time_from_millis( + 1500, GPR_TIMESPAN)), + NULL)); 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_alarm_check( - NULL, gpr_time_add(start, gpr_time_from_millis(1600)), NULL)); + GPR_ASSERT(0 == grpc_alarm_check(NULL, + 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); @@ -107,24 +113,30 @@ static void add_test(void) { grpc_alarm_list_shutdown(); } +static gpr_timespec tfm(int m) { + gpr_timespec t = gpr_time_from_millis(m, GPR_TIMESPAN); + t.clock_type = GPR_CLOCK_REALTIME; + return t; +} + /* Cleaning up a list with pending alarms. */ void destruction_test(void) { grpc_alarm alarms[5]; - grpc_alarm_list_init(gpr_time_0); + grpc_alarm_list_init(gpr_time_0(GPR_CLOCK_REALTIME)); memset(cb_called, 0, sizeof(cb_called)); - grpc_alarm_init(&alarms[0], gpr_time_from_millis(100), cb, - (void *)(gpr_intptr)0, gpr_time_0); - grpc_alarm_init(&alarms[1], gpr_time_from_millis(3), cb, - (void *)(gpr_intptr)1, gpr_time_0); - grpc_alarm_init(&alarms[2], gpr_time_from_millis(100), cb, - (void *)(gpr_intptr)2, gpr_time_0); - grpc_alarm_init(&alarms[3], gpr_time_from_millis(3), cb, - (void *)(gpr_intptr)3, gpr_time_0); - grpc_alarm_init(&alarms[4], gpr_time_from_millis(1), cb, - (void *)(gpr_intptr)4, gpr_time_0); - GPR_ASSERT(1 == grpc_alarm_check(NULL, gpr_time_from_millis(2), NULL)); + grpc_alarm_init(&alarms[0], tfm(100), cb, (void *)(gpr_intptr)0, + gpr_time_0(GPR_CLOCK_REALTIME)); + grpc_alarm_init(&alarms[1], tfm(3), cb, (void *)(gpr_intptr)1, + gpr_time_0(GPR_CLOCK_REALTIME)); + grpc_alarm_init(&alarms[2], tfm(100), cb, (void *)(gpr_intptr)2, + gpr_time_0(GPR_CLOCK_REALTIME)); + grpc_alarm_init(&alarms[3], tfm(3), cb, (void *)(gpr_intptr)3, + gpr_time_0(GPR_CLOCK_REALTIME)); + grpc_alarm_init(&alarms[4], tfm(1), cb, (void *)(gpr_intptr)4, + gpr_time_0(GPR_CLOCK_REALTIME)); + GPR_ASSERT(1 == grpc_alarm_check(NULL, tfm(2), NULL)); GPR_ASSERT(1 == cb_called[4][1]); grpc_alarm_cancel(&alarms[0]); grpc_alarm_cancel(&alarms[3]); diff --git a/test/core/iomgr/alarm_test.c b/test/core/iomgr/alarm_test.c index 362eb5fe63..55aa517529 100644 --- a/test/core/iomgr/alarm_test.c +++ b/test/core/iomgr/alarm_test.c @@ -41,6 +41,7 @@ #include <stdlib.h> #include <string.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> @@ -100,7 +101,7 @@ static void test_grpc_alarm(void) { alarm_arg arg2; void *fdone; - grpc_iomgr_init(); + grpc_init(); arg.counter = 0; arg.success = SUCCESS_NOT_SET; @@ -113,7 +114,7 @@ static void test_grpc_alarm(void) { gpr_event_init(&arg.fcb_arg); grpc_alarm_init(&alarm, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), alarm_cb, &arg, - gpr_now(GPR_CLOCK_REALTIME)); + gpr_now(GPR_CLOCK_MONOTONIC)); alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); gpr_mu_lock(&arg.mu); @@ -165,7 +166,7 @@ static void test_grpc_alarm(void) { gpr_event_init(&arg2.fcb_arg); grpc_alarm_init(&alarm_to_cancel, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), - alarm_cb, &arg2, gpr_now(GPR_CLOCK_REALTIME)); + alarm_cb, &arg2, gpr_now(GPR_CLOCK_MONOTONIC)); grpc_alarm_cancel(&alarm_to_cancel); alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); @@ -214,7 +215,7 @@ static void test_grpc_alarm(void) { gpr_mu_destroy(&arg2.mu); gpr_free(arg2.followup_closure); - grpc_iomgr_shutdown(); + grpc_shutdown(); } int main(int argc, char **argv) { diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 0cfba5fac8..cb6adc58cf 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -254,7 +254,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); while (!state.read_done || !state.write_done) { - GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0); + GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), deadline) < 0); grpc_pollset_work(g_pollset, deadline); } gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); @@ -350,14 +350,14 @@ static void shutdown_during_write_test(grpc_endpoint_test_config config, deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10); gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); while (!write_st.done) { - GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0); + GPR_ASSERT(gpr_time_cmp(gpr_now(deadline.clock_type), deadline) < 0); grpc_pollset_work(g_pollset, deadline); } gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); grpc_endpoint_destroy(write_st.ep); gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); while (!read_st.done) { - GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0); + GPR_ASSERT(gpr_time_cmp(gpr_now(deadline.clock_type), deadline) < 0); grpc_pollset_work(g_pollset, deadline); } gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index fe08ec495f..7d00c098cc 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -249,7 +249,7 @@ static int server_start(server *sv) { static void server_wait_and_shutdown(server *sv) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (!sv->done) { - grpc_pollset_work(&g_pollset, gpr_inf_future); + grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } @@ -356,7 +356,7 @@ static void client_start(client *cl, int port) { static void client_wait_and_shutdown(client *cl) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (!cl->done) { - grpc_pollset_work(&g_pollset, gpr_inf_future); + grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } @@ -445,7 +445,7 @@ static void test_grpc_fd_change(void) { /* And now wait for it to run. */ gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (a.cb_that_ran == NULL) { - grpc_pollset_work(&g_pollset, gpr_inf_future); + grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } GPR_ASSERT(a.cb_that_ran == first_read_callback); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); @@ -463,7 +463,7 @@ static void test_grpc_fd_change(void) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (b.cb_that_ran == NULL) { - grpc_pollset_work(&g_pollset, gpr_inf_future); + grpc_pollset_work(&g_pollset, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } /* Except now we verify that second_read_callback ran instead */ GPR_ASSERT(b.cb_that_ran == second_read_callback); diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index 710cd725df..38b7b5909d 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -79,6 +79,8 @@ void test_succeeds(void) { int r; int connections_complete_before; + gpr_log(GPR_DEBUG, "test_succeeds"); + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -95,7 +97,8 @@ void test_succeeds(void) { /* connect to it */ GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0); grpc_tcp_client_connect(must_succeed, NULL, &g_pollset_set, - (struct sockaddr *)&addr, addr_len, gpr_inf_future); + (struct sockaddr *)&addr, addr_len, + gpr_inf_future(GPR_CLOCK_REALTIME)); /* await the connection */ do { @@ -119,6 +122,8 @@ void test_fails(void) { socklen_t addr_len = sizeof(addr); int connections_complete_before; + gpr_log(GPR_DEBUG, "test_fails"); + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -128,7 +133,8 @@ void test_fails(void) { /* connect to a broken address */ grpc_tcp_client_connect(must_fail, NULL, &g_pollset_set, - (struct sockaddr *)&addr, addr_len, gpr_inf_future); + (struct sockaddr *)&addr, addr_len, + gpr_inf_future(GPR_CLOCK_REALTIME)); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); @@ -144,13 +150,15 @@ void test_times_out(void) { struct sockaddr_in addr; socklen_t addr_len = sizeof(addr); int svr_fd; -#define NUM_CLIENT_CONNECTS 10 +#define NUM_CLIENT_CONNECTS 100 int client_fd[NUM_CLIENT_CONNECTS]; int i; int r; int connections_complete_before; gpr_timespec connect_deadline; + gpr_log(GPR_DEBUG, "test_times_out"); + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -186,13 +194,15 @@ void test_times_out(void) { /* Make sure the event doesn't trigger early */ gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - while (gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(2)), - gpr_now(GPR_CLOCK_REALTIME)) > 0) { + while (gpr_time_cmp(gpr_time_add(connect_deadline, + gpr_time_from_seconds(2, GPR_TIMESPAN)), + gpr_now(connect_deadline.clock_type)) > 0) { int is_after_deadline = - gpr_time_cmp(connect_deadline, gpr_now(GPR_CLOCK_REALTIME)) <= 0; + gpr_time_cmp(connect_deadline, gpr_now(GPR_CLOCK_MONOTONIC)) <= 0; if (is_after_deadline && - gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(1)), - gpr_now(GPR_CLOCK_REALTIME)) > 0) { + gpr_time_cmp(gpr_time_add(connect_deadline, + gpr_time_from_seconds(1, GPR_TIMESPAN)), + gpr_now(GPR_CLOCK_MONOTONIC)) > 0) { /* allow some slack before insisting that things be done */ } else { GPR_ASSERT(g_connections_complete == diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index a23c64928e..4e7fb446a7 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -172,7 +172,7 @@ static void read_test(ssize_t num_bytes, ssize_t slice_size) { create_sockets(sv); - ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "read_test"), slice_size, "test"); grpc_endpoint_add_to_pollset(ep, &g_pollset); written_bytes = fill_socket_partial(sv[0], num_bytes); @@ -207,7 +207,8 @@ static void large_read_test(ssize_t slice_size) { create_sockets(sv); - ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), slice_size); + ep = grpc_tcp_create(grpc_fd_create(sv[1], "large_read_test"), slice_size, + "test"); grpc_endpoint_add_to_pollset(ep, &g_pollset); written_bytes = fill_socket(sv[0]); @@ -340,7 +341,7 @@ static void write_test(ssize_t num_bytes, ssize_t slice_size) { create_sockets(sv); ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_test"), - GRPC_TCP_DEFAULT_READ_SLICE_SIZE); + GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "test"); grpc_endpoint_add_to_pollset(ep, &g_pollset); state.ep = ep; @@ -394,7 +395,7 @@ static void write_error_test(ssize_t num_bytes, ssize_t slice_size) { create_sockets(sv); ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_error_test"), - GRPC_TCP_DEFAULT_READ_SLICE_SIZE); + GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "test"); grpc_endpoint_add_to_pollset(ep, &g_pollset); close(sv[0]); @@ -459,10 +460,10 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( grpc_endpoint_test_fixture f; create_sockets(sv); - f.client_ep = - grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"), slice_size); - f.server_ep = - grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"), slice_size); + f.client_ep = grpc_tcp_create(grpc_fd_create(sv[0], "fixture:client"), + slice_size, "test"); + f.server_ep = grpc_tcp_create(grpc_fd_create(sv[1], "fixture:server"), + slice_size, "test"); grpc_endpoint_add_to_pollset(f.client_ep, &g_pollset); grpc_endpoint_add_to_pollset(f.server_ep, &g_pollset); diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index 110a2eb1d9..f8d0fe8217 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -125,7 +125,7 @@ static void test_connect(int n) { gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); for (i = 0; i < n; i++) { - deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(4000); + deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10); nconnects_before = g_nconnects; clifd = socket(addr.ss_family, SOCK_STREAM, 0); @@ -135,7 +135,7 @@ static void test_connect(int n) { gpr_log(GPR_DEBUG, "wait"); while (g_nconnects == nconnects_before && - gpr_time_cmp(deadline, gpr_now(GPR_CLOCK_REALTIME)) > 0) { + gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) { grpc_pollset_work(&g_pollset, deadline); } gpr_log(GPR_DEBUG, "wait done"); diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index d3fea9680a..dd6e0d7bb3 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -826,8 +826,9 @@ static void on_jwt_creds_get_metadata_failure(void *user_data, static void test_jwt_creds_success(void) { char *json_key_string = test_json_key_str(); - grpc_credentials *jwt_creds = grpc_jwt_credentials_create( - json_key_string, grpc_max_auth_token_lifetime); + grpc_credentials *jwt_creds = + grpc_service_account_jwt_access_credentials_create( + json_key_string, grpc_max_auth_token_lifetime); GPR_ASSERT(grpc_credentials_has_request_metadata(jwt_creds)); GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds)); @@ -858,8 +859,9 @@ static void test_jwt_creds_success(void) { static void test_jwt_creds_signing_failure(void) { char *json_key_string = test_json_key_str(); - grpc_credentials *jwt_creds = grpc_jwt_credentials_create( - json_key_string, grpc_max_auth_token_lifetime); + grpc_credentials *jwt_creds = + grpc_service_account_jwt_access_credentials_create( + json_key_string, grpc_max_auth_token_lifetime); GPR_ASSERT(grpc_credentials_has_request_metadata(jwt_creds)); GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds)); @@ -900,7 +902,7 @@ static grpc_credentials *composite_inner_creds(grpc_credentials *creds, } static void test_google_default_creds_auth_key(void) { - grpc_jwt_credentials *jwt; + grpc_service_account_jwt_access_credentials *jwt; grpc_credentials *creds; char *json_key = test_json_key_str(); grpc_flush_cached_google_default_credentials(); @@ -909,7 +911,7 @@ static void test_google_default_creds_auth_key(void) { gpr_free(json_key); creds = grpc_google_default_credentials_create(); GPR_ASSERT(creds != NULL); - jwt = (grpc_jwt_credentials *)composite_inner_creds( + jwt = (grpc_service_account_jwt_access_credentials *)composite_inner_creds( creds, GRPC_CREDENTIALS_TYPE_JWT); GPR_ASSERT( strcmp(jwt->key.client_id, diff --git a/test/core/security/fetch_oauth2.c b/test/core/security/fetch_oauth2.c index 767f724b62..64c4dde5d9 100644 --- a/test/core/security/fetch_oauth2.c +++ b/test/core/security/fetch_oauth2.c @@ -44,35 +44,7 @@ #include "src/core/security/credentials.h" #include "src/core/support/file.h" - -typedef struct { - grpc_pollset pollset; - int is_done; -} synchronizer; - -static void on_oauth2_response(void *user_data, - grpc_credentials_md *md_elems, - size_t num_md, grpc_credentials_status status) { - synchronizer *sync = user_data; - char *token; - gpr_slice token_slice; - if (status == GRPC_CREDENTIALS_ERROR) { - gpr_log(GPR_ERROR, "Fetching token failed."); - } else { - GPR_ASSERT(num_md == 1); - token_slice = md_elems[0].value; - token = gpr_malloc(GPR_SLICE_LENGTH(token_slice) + 1); - memcpy(token, GPR_SLICE_START_PTR(token_slice), - GPR_SLICE_LENGTH(token_slice)); - token[GPR_SLICE_LENGTH(token_slice)] = '\0'; - printf("Got token: %s.\n", token); - gpr_free(token); - } - gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset)); - sync->is_done = 1; - grpc_pollset_kick(&sync->pollset); - gpr_mu_unlock(GRPC_POLLSET_MU(&sync->pollset)); -} +#include "test/core/security/oauth2_utils.h" static grpc_credentials *create_service_account_creds( const char *json_key_file_path, const char *scope) { @@ -101,10 +73,10 @@ static grpc_credentials *create_refresh_token_creds( } int main(int argc, char **argv) { - synchronizer sync; grpc_credentials *creds = NULL; char *json_key_file_path = NULL; char *json_refresh_token_file_path = NULL; + char *token = NULL; int use_gce = 0; char *scope = NULL; gpr_cmdline *cl = gpr_cmdline_create("fetch_oauth2"); @@ -175,16 +147,11 @@ int main(int argc, char **argv) { } GPR_ASSERT(creds != NULL); - grpc_pollset_init(&sync.pollset); - sync.is_done = 0; - - grpc_credentials_get_request_metadata(creds, &sync.pollset, "", on_oauth2_response, &sync); - - gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); - while (!sync.is_done) grpc_pollset_work(&sync.pollset, gpr_inf_future); - gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); - - grpc_pollset_destroy(&sync.pollset); + token = grpc_test_fetch_oauth2_token_with_credentials(creds); + if (token != NULL) { + printf("Got token: %s.\n", token); + gpr_free(token); + } grpc_credentials_release(creds); gpr_cmdline_destroy(cl); grpc_shutdown(); diff --git a/test/core/security/json_token_test.c b/test/core/security/json_token_test.c index b43e0425ee..da57cef15c 100644 --- a/test/core/security/json_token_test.c +++ b/test/core/security/json_token_test.c @@ -269,8 +269,8 @@ static void check_jwt_header(grpc_json *header) { static void check_jwt_claim(grpc_json *claim, const char *expected_audience, const char *expected_scope) { - gpr_timespec expiration = {0, 0}; - gpr_timespec issue_time = {0, 0}; + gpr_timespec expiration = gpr_time_0(GPR_CLOCK_REALTIME); + gpr_timespec issue_time = gpr_time_0(GPR_CLOCK_REALTIME); gpr_timespec parsed_lifetime; grpc_json *iss = NULL; grpc_json *scope = NULL; diff --git a/test/core/security/jwt_verifier_test.c b/test/core/security/jwt_verifier_test.c index 46b96d9ecb..98db56c0ef 100644 --- a/test/core/security/jwt_verifier_test.c +++ b/test/core/security/jwt_verifier_test.c @@ -1,35 +1,35 @@ /* - * - * Copyright 2015, 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. - * - */ +* +*Copyright 2015, 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 "src/core/security/jwt_verifier.h" @@ -115,7 +115,7 @@ static const char good_jwk_set[] = " ]" "}"; -static gpr_timespec expected_lifetime = {3600, 0}; +static gpr_timespec expected_lifetime = {3600, 0, GPR_TIMESPAN}; static const char good_google_email_keys_part1[] = "{\"e6b5137873db8d2ef81e06a47289e6434ec8a165\": \"-----BEGIN " @@ -201,9 +201,9 @@ static void test_expired_claims_failure(void) { gpr_slice s = gpr_slice_from_copied_string(expired_claims); grpc_json *json = grpc_json_parse_string_with_len( (char *)GPR_SLICE_START_PTR(s), GPR_SLICE_LENGTH(s)); - gpr_timespec exp_iat = {100, 0}; - gpr_timespec exp_exp = {120, 0}; - gpr_timespec exp_nbf = {60, 0}; + gpr_timespec exp_iat = {100, 0, GPR_CLOCK_REALTIME}; + gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME}; + gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME}; GPR_ASSERT(json != NULL); claims = grpc_jwt_claims_from_json(json, s); GPR_ASSERT(claims != NULL); diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c new file mode 100644 index 0000000000..ecd04fd9e1 --- /dev/null +++ b/test/core/security/oauth2_utils.c @@ -0,0 +1,93 @@ +/* + * + * Copyright 2015, 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 "test/core/security/oauth2_utils.h" + +#include <string.h> + +#include <grpc/grpc.h> +#include <grpc/grpc_security.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/slice.h> +#include <grpc/support/sync.h> + +#include "src/core/security/credentials.h" + +typedef struct { + grpc_pollset pollset; + int is_done; + char *token; +} oauth2_request; + +static void on_oauth2_response(void *user_data, grpc_credentials_md *md_elems, + size_t num_md, grpc_credentials_status status) { + oauth2_request *request = user_data; + char *token = NULL; + gpr_slice token_slice; + if (status == GRPC_CREDENTIALS_ERROR) { + gpr_log(GPR_ERROR, "Fetching token failed."); + } else { + GPR_ASSERT(num_md == 1); + token_slice = md_elems[0].value; + token = gpr_malloc(GPR_SLICE_LENGTH(token_slice) + 1); + memcpy(token, GPR_SLICE_START_PTR(token_slice), + GPR_SLICE_LENGTH(token_slice)); + token[GPR_SLICE_LENGTH(token_slice)] = '\0'; + } + gpr_mu_lock(GRPC_POLLSET_MU(&request->pollset)); + request->is_done = 1; + request->token = token; + grpc_pollset_kick(&request->pollset); + gpr_mu_unlock(GRPC_POLLSET_MU(&request->pollset)); +} + +static void do_nothing(void *unused) {} + +char *grpc_test_fetch_oauth2_token_with_credentials(grpc_credentials *creds) { + oauth2_request request; + grpc_pollset_init(&request.pollset); + request.is_done = 0; + + grpc_credentials_get_request_metadata(creds, &request.pollset, "", + on_oauth2_response, &request); + + gpr_mu_lock(GRPC_POLLSET_MU(&request.pollset)); + while (!request.is_done) + grpc_pollset_work(&request.pollset, gpr_inf_future(GPR_CLOCK_REALTIME)); + gpr_mu_unlock(GRPC_POLLSET_MU(&request.pollset)); + + grpc_pollset_shutdown(&request.pollset, do_nothing, NULL); + grpc_pollset_destroy(&request.pollset); + return request.token; +} diff --git a/test/core/security/oauth2_utils.h b/test/core/security/oauth2_utils.h new file mode 100644 index 0000000000..8082351b8a --- /dev/null +++ b/test/core/security/oauth2_utils.h @@ -0,0 +1,51 @@ +/* + * + * Copyright 2015, 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. + * + */ + +#ifndef GRPC_TEST_CORE_SECURITY_OAUTH2_UTILS_H +#define GRPC_TEST_CORE_SECURITY_OAUTH2_UTILS_H + +#include "src/core/security/credentials.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Fetch oauth2 access token with a credentials object. Does not take ownership. + Returns NULL on a failure. The caller should call gpr_free on the token. */ +char *grpc_test_fetch_oauth2_token_with_credentials(grpc_credentials *creds); + +#ifdef __cplusplus +} +#endif + +#endif /* GRPC_TEST_CORE_SECURITY_OAUTH2_UTILS_H */ diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c index 5b55a4da13..0875cfb4fb 100644 --- a/test/core/security/print_google_default_creds_token.c +++ b/test/core/security/print_google_default_creds_token.c @@ -95,7 +95,8 @@ int main(int argc, char **argv) { on_metadata_response, &sync); gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); - while (!sync.is_done) grpc_pollset_work(&sync.pollset, gpr_inf_future); + while (!sync.is_done) + grpc_pollset_work(&sync.pollset, gpr_inf_future(GPR_CLOCK_REALTIME)); gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); grpc_credentials_release(creds); diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c index e90be5de98..cb073f19c7 100644 --- a/test/core/security/verify_jwt.c +++ b/test/core/security/verify_jwt.c @@ -109,7 +109,8 @@ int main(int argc, char **argv) { on_jwt_verification_done, &sync); gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); - while (!sync.is_done) grpc_pollset_work(&sync.pollset, gpr_inf_future); + while (!sync.is_done) + grpc_pollset_work(&sync.pollset, gpr_inf_future(GPR_CLOCK_REALTIME)); gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); grpc_jwt_verifier_destroy(verifier); diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index a34dcf07c4..3292f8a64d 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -237,7 +237,8 @@ static void reader_thread(void* arg) { gpr_timespec interval; int counter = 0; printf(" Reader starting\n"); - interval = gpr_time_from_micros(args->read_iteration_interval_in_msec * 1000); + interval = gpr_time_from_micros(args->read_iteration_interval_in_msec * 1000, + GPR_TIMESPAN); gpr_mu_lock(args->mu); while (!args->stop_flag && records_read < args->total_records) { gpr_cv_wait(&args->stop, args->mu, interval); @@ -310,7 +311,7 @@ static void multiple_writers_single_reader(int circular_log) { /* Wait for writers to finish. */ gpr_mu_lock(&writers_mu); while (writers_count != 0) { - gpr_cv_wait(&writers_done, &writers_mu, gpr_inf_future); + gpr_cv_wait(&writers_done, &writers_mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } gpr_mu_unlock(&writers_mu); gpr_mu_destroy(&writers_mu); @@ -323,7 +324,7 @@ static void multiple_writers_single_reader(int circular_log) { } /* wait for reader to finish */ while (reader.running) { - gpr_cv_wait(&reader_done, &reader_mu, gpr_inf_future); + gpr_cv_wait(&reader_done, &reader_mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } if (circular_log) { /* Assert that there were no out-of-space errors. */ diff --git a/test/core/statistics/trace_test.c b/test/core/statistics/trace_test.c index b13fd03f70..187884d90f 100644 --- a/test/core/statistics/trace_test.c +++ b/test/core/statistics/trace_test.c @@ -136,7 +136,7 @@ static void test_concurrency(void) { gpr_mu_lock(&arg.mu); while (arg.num_done < NUM_THREADS) { gpr_log(GPR_INFO, "num done %d", arg.num_done); - gpr_cv_wait(&arg.done, &arg.mu, gpr_inf_future); + gpr_cv_wait(&arg.done, &arg.mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } gpr_mu_unlock(&arg.mu); census_tracing_shutdown(); diff --git a/test/core/statistics/window_stats_test.c b/test/core/statistics/window_stats_test.c index 1c66a87407..9e637ccce9 100644 --- a/test/core/statistics/window_stats_test.c +++ b/test/core/statistics/window_stats_test.c @@ -290,8 +290,8 @@ void infinite_interval_test(void) { int i; const int count = 100000; gpr_timespec increment = {0, 0}; - struct census_window_stats* stats = - census_window_stats_create(1, &gpr_inf_future, 10, &kMyStatInfo); + struct census_window_stats* stats = census_window_stats_create( + 1, &gpr_inf_future(GPR_CLOCK_REALTIME), 10, &kMyStatInfo); srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); for (i = 0; i < count; i++) { increment.tv_sec = rand() % 21600; /* 6 hours */ diff --git a/test/core/support/cancellable_test.c b/test/core/support/cancellable_test.c index 2f4b67a785..9b321d388e 100644 --- a/test/core/support/cancellable_test.c +++ b/test/core/support/cancellable_test.c @@ -55,7 +55,8 @@ struct test { static void thd_body(void *v) { struct test *t = v; gpr_mu_lock(&t->mu); - while (!gpr_cv_cancellable_wait(&t->cv, &t->mu, gpr_inf_future, &t->cancel)) { + while (!gpr_cv_cancellable_wait( + &t->cv, &t->mu, gpr_inf_future(GPR_CLOCK_REALTIME), &t->cancel)) { } t->n--; if (t->n == 0) { @@ -82,24 +83,29 @@ static void test(void) { /* Test timeout on event wait for uncancelled gpr_cancellable */ interval = gpr_now(GPR_CLOCK_REALTIME); - gpr_event_cancellable_wait(&t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000)), - &t.cancel); + gpr_event_cancellable_wait( + &t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)), + &t.cancel); interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); - GPR_ASSERT(gpr_time_cmp(interval, gpr_time_from_micros(500000)) >= 0); - GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(2000000), interval) >= 0); + GPR_ASSERT( + gpr_time_cmp(interval, gpr_time_from_micros(500000, GPR_TIMESPAN)) >= 0); + GPR_ASSERT( + gpr_time_cmp(gpr_time_from_micros(2000000, GPR_TIMESPAN), interval) >= 0); /* Test timeout on cv wait for uncancelled gpr_cancellable */ gpr_mu_lock(&t.mu); interval = gpr_now(GPR_CLOCK_REALTIME); while (!gpr_cv_cancellable_wait( - &t.cv, &t.mu, - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)), + &t.cv, &t.mu, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)), &t.cancel)) { } interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); - GPR_ASSERT(gpr_time_cmp(interval, gpr_time_from_micros(500000)) >= 0); - GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(2000000), interval) >= 0); + GPR_ASSERT( + gpr_time_cmp(interval, gpr_time_from_micros(500000, GPR_TIMESPAN)) >= 0); + GPR_ASSERT( + gpr_time_cmp(gpr_time_from_micros(2000000, GPR_TIMESPAN), interval) >= 0); gpr_mu_unlock(&t.mu); /* Create some threads. They all wait until cancelled; the last to finish @@ -113,8 +119,9 @@ static void test(void) { /* Wait a second, and check that no threads have finished waiting. */ gpr_mu_lock(&t.mu); - gpr_cv_wait(&t.cv, &t.mu, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000))); + gpr_cv_wait(&t.cv, &t.mu, + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN))); GPR_ASSERT(t.n == n); gpr_mu_unlock(&t.mu); @@ -125,28 +132,31 @@ static void test(void) { GPR_ASSERT(gpr_cancellable_is_cancelled(&t.cancel)); /* Wait for threads to finish. */ - gpr_event_wait(&t.done, gpr_inf_future); + gpr_event_wait(&t.done, gpr_inf_future(GPR_CLOCK_REALTIME)); GPR_ASSERT(t.n == 0); /* Test timeout on cv wait for cancelled gpr_cancellable */ gpr_mu_lock(&t.mu); interval = gpr_now(GPR_CLOCK_REALTIME); while (!gpr_cv_cancellable_wait( - &t.cv, &t.mu, - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)), + &t.cv, &t.mu, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)), &t.cancel)) { } interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); - GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(100000), interval) >= 0); + GPR_ASSERT( + gpr_time_cmp(gpr_time_from_micros(100000, GPR_TIMESPAN), interval) >= 0); gpr_mu_unlock(&t.mu); /* Test timeout on event wait for cancelled gpr_cancellable */ interval = gpr_now(GPR_CLOCK_REALTIME); - gpr_event_cancellable_wait(&t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000)), - &t.cancel); + gpr_event_cancellable_wait( + &t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)), + &t.cancel); interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); - GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(100000), interval) >= 0); + GPR_ASSERT( + gpr_time_cmp(gpr_time_from_micros(100000, GPR_TIMESPAN), interval) >= 0); gpr_mu_destroy(&t.mu); gpr_cv_destroy(&t.cv); diff --git a/test/core/support/stack_lockfree_test.c b/test/core/support/stack_lockfree_test.c index 42082de389..02ec3154d5 100644 --- a/test/core/support/stack_lockfree_test.c +++ b/test/core/support/stack_lockfree_test.c @@ -62,7 +62,7 @@ static void test_serial_sized(int size) { for (i = 1; i < size; i *= 2) { int j; for (j = 0; j <= i; j++) { - gpr_stack_lockfree_push(stack, j); + GPR_ASSERT(gpr_stack_lockfree_push(stack, j) == (j == 0)); } for (j = 0; j <= i; j++) { GPR_ASSERT(gpr_stack_lockfree_pop(stack) == i - j); diff --git a/test/core/support/string_test.c b/test/core/support/string_test.c index f04e72ac2b..9023d0746b 100644 --- a/test/core/support/string_test.c +++ b/test/core/support/string_test.c @@ -173,6 +173,119 @@ static void test_asprintf(void) { } } +static void test_strjoin(void) { + const char *parts[4] = {"one", "two", "three", "four"}; + size_t joined_len; + char *joined; + + LOG_TEST_NAME("test_strjoin"); + + joined = gpr_strjoin(parts, 4, &joined_len); + GPR_ASSERT(0 == strcmp("onetwothreefour", joined)); + gpr_free(joined); + + joined = gpr_strjoin(parts, 0, &joined_len); + GPR_ASSERT(0 == strcmp("", joined)); + gpr_free(joined); + + joined = gpr_strjoin(parts, 1, &joined_len); + GPR_ASSERT(0 == strcmp("one", joined)); + gpr_free(joined); +} + +static void test_strjoin_sep(void) { + const char *parts[4] = {"one", "two", "three", "four"}; + size_t joined_len; + char *joined; + + LOG_TEST_NAME("test_strjoin_sep"); + + joined = gpr_strjoin_sep(parts, 4, ", ", &joined_len); + GPR_ASSERT(0 == strcmp("one, two, three, four", joined)); + gpr_free(joined); + + /* empty separator */ + joined = gpr_strjoin_sep(parts, 4, "", &joined_len); + GPR_ASSERT(0 == strcmp("onetwothreefour", joined)); + gpr_free(joined); + + /* degenerated case specifying zero input parts */ + joined = gpr_strjoin_sep(parts, 0, ", ", &joined_len); + GPR_ASSERT(0 == strcmp("", joined)); + gpr_free(joined); + + /* single part should have no separator */ + joined = gpr_strjoin_sep(parts, 1, ", ", &joined_len); + GPR_ASSERT(0 == strcmp("one", joined)); + gpr_free(joined); +} + +static void test_strsplit(void) { + gpr_slice_buffer* parts; + gpr_slice str; + + LOG_TEST_NAME("test_strsplit"); + + parts = gpr_malloc(sizeof(gpr_slice_buffer)); + gpr_slice_buffer_init(parts); + + str = gpr_slice_from_copied_string("one, two, three, four"); + gpr_slice_split(str, ", ", parts); + GPR_ASSERT(4 == parts->count); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[0], "one")); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[1], "two")); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[2], "three")); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[3], "four")); + gpr_slice_buffer_reset_and_unref(parts); + gpr_slice_unref(str); + + /* separator not present in string */ + str = gpr_slice_from_copied_string("one two three four"); + gpr_slice_split(str, ", ", parts); + GPR_ASSERT(1 == parts->count); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[0], "one two three four")); + gpr_slice_buffer_reset_and_unref(parts); + gpr_slice_unref(str); + + /* separator at the end */ + str = gpr_slice_from_copied_string("foo,"); + gpr_slice_split(str, ",", parts); + GPR_ASSERT(2 == parts->count); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[0], "foo")); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[1], "")); + gpr_slice_buffer_reset_and_unref(parts); + gpr_slice_unref(str); + + /* separator at the beginning */ + str = gpr_slice_from_copied_string(",foo"); + gpr_slice_split(str, ",", parts); + GPR_ASSERT(2 == parts->count); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[0], "")); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[1], "foo")); + gpr_slice_buffer_reset_and_unref(parts); + gpr_slice_unref(str); + + /* standalone separator */ + str = gpr_slice_from_copied_string(","); + gpr_slice_split(str, ",", parts); + GPR_ASSERT(2 == parts->count); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[0], "")); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[1], "")); + gpr_slice_buffer_reset_and_unref(parts); + gpr_slice_unref(str); + + /* empty input */ + str = gpr_slice_from_copied_string(""); + gpr_slice_split(str, ", ", parts); + GPR_ASSERT(1 == parts->count); + GPR_ASSERT(0 == gpr_slice_str_cmp(parts->slices[0], "")); + gpr_slice_buffer_reset_and_unref(parts); + gpr_slice_unref(str); + + gpr_slice_buffer_destroy(parts); + gpr_free(parts); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_strdup(); @@ -180,5 +293,8 @@ int main(int argc, char **argv) { test_dump_slice(); test_parse_uint32(); test_asprintf(); + test_strjoin(); + test_strjoin_sep(); + test_strsplit(); return 0; } diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c index 99be5cdc90..f729eb0b92 100644 --- a/test/core/support/sync_test.c +++ b/test/core/support/sync_test.c @@ -81,13 +81,14 @@ void queue_destroy(queue *q) { void queue_append(queue *q, int x) { gpr_mu_lock(&q->mu); /* To wait for a predicate without a deadline, loop on the negation of the - predicate, and use gpr_cv_wait(..., gpr_inf_future) inside the loop + predicate, and use gpr_cv_wait(..., gpr_inf_future(GPR_CLOCK_REALTIME)) + inside the loop to release the lock, wait, and reacquire on each iteration. Code that makes the condition true should use gpr_cv_broadcast() on the corresponding condition variable. The predicate must be on state protected by the lock. */ while (q->length == N) { - gpr_cv_wait(&q->non_full, &q->mu, gpr_inf_future); + gpr_cv_wait(&q->non_full, &q->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } if (q->length == 0) { /* Wake threads blocked in queue_remove(). */ /* It's normal to use gpr_cv_broadcast() or gpr_signal() while @@ -209,7 +210,7 @@ static void test_create_threads(struct test *m, void (*body)(void *arg)) { static void test_wait(struct test *m) { gpr_mu_lock(&m->mu); while (m->done != 0) { - gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future); + gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } gpr_mu_unlock(&m->mu); } @@ -244,8 +245,8 @@ static void test(const char *name, void (*body)(void *m), struct test *m; gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; - gpr_timespec deadline = - gpr_time_add(start, gpr_time_from_micros(timeout_s * 1000000)); + gpr_timespec deadline = gpr_time_add( + start, gpr_time_from_micros(timeout_s * 1000000, GPR_TIMESPAN)); fprintf(stderr, "%s:", name); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { iterations <<= 1; @@ -306,7 +307,7 @@ static void inc_by_turns(void *v /*=m*/) { for (i = 0; i != m->iterations; i++) { gpr_mu_lock(&m->mu); while ((m->counter % m->threads) != id) { - gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future); + gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } m->counter++; gpr_cv_broadcast(&m->cv); @@ -323,8 +324,8 @@ static void inc_with_1ms_delay(void *v /*=m*/) { for (i = 0; i != m->iterations; i++) { gpr_timespec deadline; gpr_mu_lock(&m->mu); - deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000)); + deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000, GPR_TIMESPAN)); while (!gpr_cv_wait(&m->cv, &m->mu, deadline)) { } m->counter++; @@ -340,8 +341,8 @@ static void inc_with_1ms_delay_event(void *v /*=m*/) { gpr_int64 i; for (i = 0; i != m->iterations; i++) { gpr_timespec deadline; - deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000)); + deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000, GPR_TIMESPAN)); GPR_ASSERT(gpr_event_wait(&m->event, deadline) == NULL); gpr_mu_lock(&m->mu); m->counter++; @@ -379,14 +380,15 @@ static void consumer(void *v /*=m*/) { gpr_int64 i; int value; for (i = 0; i != n; i++) { - queue_remove(&m->q, &value, gpr_inf_future); + queue_remove(&m->q, &value, gpr_inf_future(GPR_CLOCK_REALTIME)); } gpr_mu_lock(&m->mu); m->counter = n; gpr_mu_unlock(&m->mu); - GPR_ASSERT(!queue_remove(&m->q, &value, - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000)))); + GPR_ASSERT( + !queue_remove(&m->q, &value, + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)))); mark_thread_done(m); } @@ -426,7 +428,8 @@ static void refcheck(void *v /*=m*/) { struct test *m = v; gpr_int64 n = m->iterations * m->threads; gpr_int64 i; - GPR_ASSERT(gpr_event_wait(&m->event, gpr_inf_future) == (void *)1); + GPR_ASSERT(gpr_event_wait(&m->event, gpr_inf_future(GPR_CLOCK_REALTIME)) == + (void *)1); GPR_ASSERT(gpr_event_get(&m->event) == (void *)1); for (i = 1; i != n; i++) { GPR_ASSERT(!gpr_unref(&m->refcount)); diff --git a/test/core/support/thd_test.c b/test/core/support/thd_test.c index bb3d54a262..7232cd9f5b 100644 --- a/test/core/support/thd_test.c +++ b/test/core/support/thd_test.c @@ -79,7 +79,7 @@ static void test(void) { } gpr_mu_lock(&t.mu); while (!t.is_done) { - gpr_cv_wait(&t.done_cv, &t.mu, gpr_inf_future); + gpr_cv_wait(&t.done_cv, &t.mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } gpr_mu_unlock(&t.mu); GPR_ASSERT(t.n == 0); diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c index c1dce777b0..594863c278 100644 --- a/test/core/support/time_test.c +++ b/test/core/support/time_test.c @@ -91,10 +91,10 @@ static void ts_to_s(gpr_timespec t, static void test_values(void) { int i; - gpr_timespec x = gpr_time_0; + gpr_timespec x = gpr_time_0(GPR_CLOCK_REALTIME); GPR_ASSERT(x.tv_sec == 0 && x.tv_nsec == 0); - x = gpr_inf_future; + x = gpr_inf_future(GPR_CLOCK_REALTIME); fprintf(stderr, "far future "); u_to_s(x.tv_sec, 16, 16, &to_fp, stderr); fprintf(stderr, "\n"); @@ -103,7 +103,7 @@ static void test_values(void) { ts_to_s(x, &to_fp, stderr); fprintf(stderr, "\n"); - x = gpr_inf_past; + x = gpr_inf_past(GPR_CLOCK_REALTIME); fprintf(stderr, "far past "); u_to_s(x.tv_sec, 16, 16, &to_fp, stderr); fprintf(stderr, "\n"); @@ -113,37 +113,37 @@ static void test_values(void) { fprintf(stderr, "\n"); for (i = 1; i != 1000 * 1000 * 1000; i *= 10) { - x = gpr_time_from_micros(i); + x = gpr_time_from_micros(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_US_PER_SEC && x.tv_nsec == (i % GPR_US_PER_SEC) * GPR_NS_PER_US); - x = gpr_time_from_nanos(i); + x = gpr_time_from_nanos(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_NS_PER_SEC && x.tv_nsec == (i % GPR_NS_PER_SEC)); - x = gpr_time_from_millis(i); + x = gpr_time_from_millis(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_MS_PER_SEC && x.tv_nsec == (i % GPR_MS_PER_SEC) * GPR_NS_PER_MS); } /* Test possible overflow in conversion of -ve values. */ - x = gpr_time_from_micros(-(LONG_MAX - 999997)); + x = gpr_time_from_micros(-(LONG_MAX - 999997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); - x = gpr_time_from_nanos(-(LONG_MAX - 999999997)); + x = gpr_time_from_nanos(-(LONG_MAX - 999999997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); - x = gpr_time_from_millis(-(LONG_MAX - 997)); + x = gpr_time_from_millis(-(LONG_MAX - 997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); /* Test general -ve values. */ for (i = -1; i > -1000 * 1000 * 1000; i *= 7) { - x = gpr_time_from_micros(i); + x = gpr_time_from_micros(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_US_PER_SEC + x.tv_nsec / GPR_NS_PER_US == i); - x = gpr_time_from_nanos(i); + x = gpr_time_from_nanos(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_NS_PER_SEC + x.tv_nsec == i); - x = gpr_time_from_millis(i); + x = gpr_time_from_millis(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_MS_PER_SEC + x.tv_nsec / GPR_NS_PER_MS == i); } } @@ -158,17 +158,19 @@ static void test_add_sub(void) { for (k = 1; k <= 10000000; k *= 10) { int sum = i + j; int diff = i - j; - gpr_timespec it = gpr_time_from_micros(i * k); - gpr_timespec jt = gpr_time_from_micros(j * k); + gpr_timespec it = gpr_time_from_micros(i * k, GPR_TIMESPAN); + gpr_timespec jt = gpr_time_from_micros(j * k, GPR_TIMESPAN); gpr_timespec sumt = gpr_time_add(it, jt); gpr_timespec difft = gpr_time_sub(it, jt); - if (gpr_time_cmp(gpr_time_from_micros(sum * k), sumt) != 0) { + if (gpr_time_cmp(gpr_time_from_micros(sum * k, GPR_TIMESPAN), sumt) != + 0) { fprintf(stderr, "i %d j %d sum %d sumt ", i, j, sum); ts_to_s(sumt, &to_fp, stderr); fprintf(stderr, "\n"); GPR_ASSERT(0); } - if (gpr_time_cmp(gpr_time_from_micros(diff * k), difft) != 0) { + if (gpr_time_cmp(gpr_time_from_micros(diff * k, GPR_TIMESPAN), difft) != + 0) { fprintf(stderr, "i %d j %d diff %d diff ", i, j, diff); ts_to_s(sumt, &to_fp, stderr); fprintf(stderr, "\n"); @@ -181,66 +183,76 @@ static void test_add_sub(void) { static void test_overflow(void) { /* overflow */ - gpr_timespec x = gpr_time_from_micros(1); + gpr_timespec x = gpr_time_from_micros(1, GPR_TIMESPAN); do { x = gpr_time_add(x, x); - } while (gpr_time_cmp(x, gpr_inf_future) < 0); - GPR_ASSERT(gpr_time_cmp(x, gpr_inf_future) == 0); - x = gpr_time_from_micros(-1); + } while (gpr_time_cmp(x, gpr_inf_future(GPR_TIMESPAN)) < 0); + GPR_ASSERT(gpr_time_cmp(x, gpr_inf_future(GPR_TIMESPAN)) == 0); + x = gpr_time_from_micros(-1, GPR_TIMESPAN); do { x = gpr_time_add(x, x); - } while (gpr_time_cmp(x, gpr_inf_past) > 0); - GPR_ASSERT(gpr_time_cmp(x, gpr_inf_past) == 0); + } while (gpr_time_cmp(x, gpr_inf_past(GPR_TIMESPAN)) > 0); + GPR_ASSERT(gpr_time_cmp(x, gpr_inf_past(GPR_TIMESPAN)) == 0); } static void test_sticky_infinities(void) { int i; int j; int k; - static const gpr_timespec *infinity[] = {&gpr_inf_future, &gpr_inf_past}; - static const gpr_timespec *addend[] = {&gpr_inf_future, &gpr_inf_past, - &gpr_time_0, NULL}; + gpr_timespec infinity[2]; + gpr_timespec addend[3]; + infinity[0] = gpr_inf_future(GPR_TIMESPAN); + infinity[1] = gpr_inf_past(GPR_TIMESPAN); + addend[0] = gpr_inf_future(GPR_TIMESPAN); + addend[1] = gpr_inf_past(GPR_TIMESPAN); + addend[2] = gpr_time_0(GPR_TIMESPAN); /* Infinities are sticky */ for (i = 0; i != sizeof(infinity) / sizeof(infinity[0]); i++) { for (j = 0; j != sizeof(addend) / sizeof(addend[0]); j++) { - if (addend[j] == NULL) { - for (k = -200; k <= 200; k++) { - gpr_timespec y = gpr_time_from_micros(k * 100000); - gpr_timespec x = gpr_time_add(*infinity[i], y); - GPR_ASSERT(gpr_time_cmp(x, *infinity[i]) == 0); - x = gpr_time_sub(*infinity[i], y); - GPR_ASSERT(gpr_time_cmp(x, *infinity[i]) == 0); - } - } else { - gpr_timespec x = gpr_time_add(*infinity[i], *addend[j]); - GPR_ASSERT(gpr_time_cmp(x, *infinity[i]) == 0); - x = gpr_time_sub(*infinity[i], *addend[j]); - GPR_ASSERT(gpr_time_cmp(x, *infinity[i]) == 0); - } + gpr_timespec x = gpr_time_add(infinity[i], addend[j]); + GPR_ASSERT(gpr_time_cmp(x, infinity[i]) == 0); + x = gpr_time_sub(infinity[i], addend[j]); + GPR_ASSERT(gpr_time_cmp(x, infinity[i]) == 0); + } + for (k = -200; k <= 200; k++) { + gpr_timespec y = gpr_time_from_micros(k * 100000, GPR_TIMESPAN); + gpr_timespec x = gpr_time_add(infinity[i], y); + GPR_ASSERT(gpr_time_cmp(x, infinity[i]) == 0); + x = gpr_time_sub(infinity[i], y); + GPR_ASSERT(gpr_time_cmp(x, infinity[i]) == 0); } } } static void test_similar(void) { - GPR_ASSERT(1 == gpr_time_similar(gpr_inf_future, gpr_inf_future, gpr_time_0)); - GPR_ASSERT(1 == gpr_time_similar(gpr_inf_past, gpr_inf_past, gpr_time_0)); - GPR_ASSERT(0 == gpr_time_similar(gpr_inf_past, gpr_inf_future, gpr_time_0)); - GPR_ASSERT(0 == gpr_time_similar(gpr_inf_future, gpr_inf_past, gpr_time_0)); - GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(10), - gpr_time_from_micros(10), gpr_time_0)); - GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(10), - gpr_time_from_micros(15), - gpr_time_from_micros(10))); - GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(15), - gpr_time_from_micros(10), - gpr_time_from_micros(10))); - GPR_ASSERT(0 == gpr_time_similar(gpr_time_from_micros(10), - gpr_time_from_micros(25), - gpr_time_from_micros(10))); - GPR_ASSERT(0 == gpr_time_similar(gpr_time_from_micros(25), - gpr_time_from_micros(10), - gpr_time_from_micros(10))); + GPR_ASSERT(1 == gpr_time_similar(gpr_inf_future(GPR_TIMESPAN), + gpr_inf_future(GPR_TIMESPAN), + gpr_time_0(GPR_TIMESPAN))); + GPR_ASSERT(1 == gpr_time_similar(gpr_inf_past(GPR_TIMESPAN), + gpr_inf_past(GPR_TIMESPAN), + gpr_time_0(GPR_TIMESPAN))); + GPR_ASSERT(0 == gpr_time_similar(gpr_inf_past(GPR_TIMESPAN), + gpr_inf_future(GPR_TIMESPAN), + gpr_time_0(GPR_TIMESPAN))); + GPR_ASSERT(0 == gpr_time_similar(gpr_inf_future(GPR_TIMESPAN), + gpr_inf_past(GPR_TIMESPAN), + gpr_time_0(GPR_TIMESPAN))); + GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_0(GPR_TIMESPAN))); + GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(15, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN))); + GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(15, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN))); + GPR_ASSERT(0 == gpr_time_similar(gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(25, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN))); + GPR_ASSERT(0 == gpr_time_similar(gpr_time_from_micros(25, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN))); } int main(int argc, char *argv[]) { diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c index 177adbebc2..0e59ea4b22 100644 --- a/test/core/surface/completion_queue_test.c +++ b/test/core/surface/completion_queue_test.c @@ -52,7 +52,7 @@ static void *create_test_tag(void) { static void shutdown_and_destroy(grpc_completion_queue *cc) { grpc_event ev; grpc_completion_queue_shutdown(cc); - ev = grpc_completion_queue_next(cc, gpr_inf_past); + ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME)); GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); grpc_completion_queue_destroy(cc); } @@ -89,7 +89,7 @@ static void test_cq_end_op(void) { grpc_cq_begin_op(cc); grpc_cq_end_op(cc, tag, 1, do_nothing_end_completion, NULL, &completion); - ev = grpc_completion_queue_next(cc, gpr_inf_past); + ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME)); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); GPR_ASSERT(ev.tag == tag); GPR_ASSERT(ev.success); @@ -103,8 +103,8 @@ static void test_shutdown_then_next_polling(void) { cc = grpc_completion_queue_create(); grpc_completion_queue_shutdown(cc); - GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_past).type == - GRPC_QUEUE_SHUTDOWN); + GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME)) + .type == GRPC_QUEUE_SHUTDOWN); grpc_completion_queue_destroy(cc); } @@ -114,8 +114,8 @@ static void test_shutdown_then_next_with_timeout(void) { cc = grpc_completion_queue_create(); grpc_completion_queue_shutdown(cc); - GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_future).type == - GRPC_QUEUE_SHUTDOWN); + GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_future(GPR_CLOCK_REALTIME)) + .type == GRPC_QUEUE_SHUTDOWN); grpc_completion_queue_destroy(cc); } @@ -144,7 +144,8 @@ static void test_pluck(void) { } for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { - ev = grpc_completion_queue_pluck(cc, tags[i], gpr_inf_past); + ev = grpc_completion_queue_pluck(cc, tags[i], + gpr_inf_past(GPR_CLOCK_REALTIME)); GPR_ASSERT(ev.tag == tags[i]); } @@ -156,7 +157,7 @@ static void test_pluck(void) { for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { ev = grpc_completion_queue_pluck(cc, tags[GPR_ARRAY_SIZE(tags) - i - 1], - gpr_inf_past); + gpr_inf_past(GPR_CLOCK_REALTIME)); GPR_ASSERT(ev.tag == tags[GPR_ARRAY_SIZE(tags) - i - 1]); } diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c index b2facd33b1..3a7a3a36ee 100644 --- a/test/core/surface/lame_client_test.c +++ b/test/core/surface/lame_client_test.c @@ -57,7 +57,7 @@ int main(int argc, char **argv) { grpc_metadata_array_init(&trailing_metadata_recv); - chan = grpc_lame_client_channel_create(); + chan = grpc_lame_client_channel_create("lampoon:national"); GPR_ASSERT(chan); cq = grpc_completion_queue_create(); call = grpc_channel_create_call(chan, cq, "/Foo", "anywhere", diff --git a/test/core/transport/chttp2/timeout_encoding_test.c b/test/core/transport/chttp2/timeout_encoding_test.c index 5bfb9cf0ec..ba6c3191f1 100644 --- a/test/core/transport/chttp2/timeout_encoding_test.c +++ b/test/core/transport/chttp2/timeout_encoding_test.c @@ -54,34 +54,35 @@ static void assert_encodes_as(gpr_timespec ts, const char *s) { void test_encoding(void) { LOG_TEST("test_encoding"); - assert_encodes_as(gpr_time_from_micros(-1), "1n"); - assert_encodes_as(gpr_time_from_seconds(-10), "1n"); - assert_encodes_as(gpr_time_from_nanos(10), "10n"); - assert_encodes_as(gpr_time_from_nanos(999999999), "1S"); - assert_encodes_as(gpr_time_from_micros(1), "1u"); - assert_encodes_as(gpr_time_from_micros(10), "10u"); - assert_encodes_as(gpr_time_from_micros(100), "100u"); - assert_encodes_as(gpr_time_from_micros(890), "890u"); - assert_encodes_as(gpr_time_from_micros(900), "900u"); - assert_encodes_as(gpr_time_from_micros(901), "901u"); - assert_encodes_as(gpr_time_from_millis(1), "1m"); - assert_encodes_as(gpr_time_from_millis(2), "2m"); - assert_encodes_as(gpr_time_from_micros(10001), "10100u"); - assert_encodes_as(gpr_time_from_micros(999999), "1S"); - assert_encodes_as(gpr_time_from_millis(1000), "1S"); - assert_encodes_as(gpr_time_from_millis(2000), "2S"); - assert_encodes_as(gpr_time_from_millis(2500), "2500m"); - assert_encodes_as(gpr_time_from_millis(59900), "59900m"); - assert_encodes_as(gpr_time_from_seconds(50), "50S"); - assert_encodes_as(gpr_time_from_seconds(59), "59S"); - assert_encodes_as(gpr_time_from_seconds(60), "1M"); - assert_encodes_as(gpr_time_from_seconds(80), "80S"); - assert_encodes_as(gpr_time_from_seconds(90), "90S"); - assert_encodes_as(gpr_time_from_minutes(2), "2M"); - assert_encodes_as(gpr_time_from_minutes(20), "20M"); - assert_encodes_as(gpr_time_from_hours(1), "1H"); - assert_encodes_as(gpr_time_from_hours(10), "10H"); - assert_encodes_as(gpr_time_from_seconds(1000000000), "1000000000S"); + assert_encodes_as(gpr_time_from_micros(-1, GPR_TIMESPAN), "1n"); + assert_encodes_as(gpr_time_from_seconds(-10, GPR_TIMESPAN), "1n"); + assert_encodes_as(gpr_time_from_nanos(10, GPR_TIMESPAN), "10n"); + assert_encodes_as(gpr_time_from_nanos(999999999, GPR_TIMESPAN), "1S"); + assert_encodes_as(gpr_time_from_micros(1, GPR_TIMESPAN), "1u"); + assert_encodes_as(gpr_time_from_micros(10, GPR_TIMESPAN), "10u"); + assert_encodes_as(gpr_time_from_micros(100, GPR_TIMESPAN), "100u"); + assert_encodes_as(gpr_time_from_micros(890, GPR_TIMESPAN), "890u"); + assert_encodes_as(gpr_time_from_micros(900, GPR_TIMESPAN), "900u"); + assert_encodes_as(gpr_time_from_micros(901, GPR_TIMESPAN), "901u"); + assert_encodes_as(gpr_time_from_millis(1, GPR_TIMESPAN), "1m"); + assert_encodes_as(gpr_time_from_millis(2, GPR_TIMESPAN), "2m"); + assert_encodes_as(gpr_time_from_micros(10001, GPR_TIMESPAN), "10100u"); + assert_encodes_as(gpr_time_from_micros(999999, GPR_TIMESPAN), "1S"); + assert_encodes_as(gpr_time_from_millis(1000, GPR_TIMESPAN), "1S"); + assert_encodes_as(gpr_time_from_millis(2000, GPR_TIMESPAN), "2S"); + assert_encodes_as(gpr_time_from_millis(2500, GPR_TIMESPAN), "2500m"); + assert_encodes_as(gpr_time_from_millis(59900, GPR_TIMESPAN), "59900m"); + assert_encodes_as(gpr_time_from_seconds(50, GPR_TIMESPAN), "50S"); + assert_encodes_as(gpr_time_from_seconds(59, GPR_TIMESPAN), "59S"); + assert_encodes_as(gpr_time_from_seconds(60, GPR_TIMESPAN), "1M"); + assert_encodes_as(gpr_time_from_seconds(80, GPR_TIMESPAN), "80S"); + assert_encodes_as(gpr_time_from_seconds(90, GPR_TIMESPAN), "90S"); + assert_encodes_as(gpr_time_from_minutes(2, GPR_TIMESPAN), "2M"); + assert_encodes_as(gpr_time_from_minutes(20, GPR_TIMESPAN), "20M"); + assert_encodes_as(gpr_time_from_hours(1, GPR_TIMESPAN), "1H"); + assert_encodes_as(gpr_time_from_hours(10, GPR_TIMESPAN), "10H"); + assert_encodes_as(gpr_time_from_seconds(1000000000, GPR_TIMESPAN), + "1000000000S"); } static void assert_decodes_as(const char *buffer, gpr_timespec expected) { @@ -91,7 +92,8 @@ static void assert_decodes_as(const char *buffer, gpr_timespec expected) { GPR_ASSERT(0 == gpr_time_cmp(got, expected)); } -void decode_suite(char ext, gpr_timespec (*answer)(long x)) { +void decode_suite(char ext, + gpr_timespec (*answer)(long x, gpr_clock_type clock)) { long test_vals[] = {1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 98765432, 9876543, 987654, 98765, 9876, 987, 98, 9}; @@ -99,19 +101,19 @@ void decode_suite(char ext, gpr_timespec (*answer)(long x)) { char *input; for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) { gpr_asprintf(&input, "%ld%c", test_vals[i], ext); - assert_decodes_as(input, answer(test_vals[i])); + assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN)); gpr_free(input); gpr_asprintf(&input, " %ld%c", test_vals[i], ext); - assert_decodes_as(input, answer(test_vals[i])); + assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN)); gpr_free(input); gpr_asprintf(&input, "%ld %c", test_vals[i], ext); - assert_decodes_as(input, answer(test_vals[i])); + assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN)); gpr_free(input); gpr_asprintf(&input, "%ld %c ", test_vals[i], ext); - assert_decodes_as(input, answer(test_vals[i])); + assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN)); gpr_free(input); } } @@ -124,7 +126,8 @@ void test_decoding(void) { decode_suite('S', gpr_time_from_seconds); decode_suite('M', gpr_time_from_minutes); decode_suite('H', gpr_time_from_hours); - assert_decodes_as("1000000000000000000000u", gpr_inf_future); + assert_decodes_as("1000000000000000000000u", + gpr_inf_future(GPR_CLOCK_REALTIME)); } void test_decoding_fails(void) { diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index 3218953166..7028ade7b2 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -51,13 +51,15 @@ extern "C" { #define GRPC_TEST_SLOWDOWN_FACTOR \ (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR) -#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \ - gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x))) +#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ + gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \ + gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x), \ + GPR_TIMESPAN)) -#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \ - gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x))) +#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ + gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \ + gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ + GPR_TIMESPAN)) #ifndef GRPC_TEST_CUSTOM_PICK_PORT #define GRPC_TEST_PICK_PORT |