diff options
author | Craig Tiller <ctiller@google.com> | 2015-07-17 22:59:53 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-07-17 22:59:53 -0700 |
commit | b5980be9a08678212e5dbd6549b923f545d83539 (patch) | |
tree | e0318622c5a5576377537783608b60516b46c4cf /test | |
parent | a14215a67841ea7920260c655c01e4570595a3db (diff) | |
parent | f87a0984ab727e95b068237f3bb0689d9685c8ea (diff) |
Merge github.com:grpc/grpc into sometimes-its-good-just-to-check-in-with-each-other
Diffstat (limited to 'test')
45 files changed, 563 insertions, 280 deletions
diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 407c72b519..81e158e969 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -248,8 +248,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/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/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/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index fe08ec495f..cd268661db 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_REALTIME)); } 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_REALTIME)); } 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_REALTIME)); } 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_REALTIME)); } /* 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..637886a738 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,12 +194,14 @@ 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)), + while (gpr_time_cmp(gpr_time_add(connect_deadline, + gpr_time_from_seconds(2, GPR_TIMESPAN)), gpr_now(GPR_CLOCK_REALTIME)) > 0) { int is_after_deadline = gpr_time_cmp(connect_deadline, gpr_now(GPR_CLOCK_REALTIME)) <= 0; if (is_after_deadline && - gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(1)), + gpr_time_cmp(gpr_time_add(connect_deadline, + gpr_time_from_seconds(1, GPR_TIMESPAN)), gpr_now(GPR_CLOCK_REALTIME)) > 0) { /* allow some slack before insisting that things be done */ } else { diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index 110a2eb1d9..83252a889b 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); diff --git a/test/core/security/fetch_oauth2.c b/test/core/security/fetch_oauth2.c index 767f724b62..e4d422ccc2 100644 --- a/test/core/security/fetch_oauth2.c +++ b/test/core/security/fetch_oauth2.c @@ -181,7 +181,8 @@ int main(int argc, char **argv) { 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); + while (!sync.is_done) + grpc_pollset_work(&sync.pollset, gpr_inf_future(GPR_CLOCK_REALTIME)); gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); grpc_pollset_destroy(&sync.pollset); 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/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/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/support/useful_test.c b/test/core/support/useful_test.c index feaf436379..cbf4f02e26 100644 --- a/test/core/support/useful_test.c +++ b/test/core/support/useful_test.c @@ -39,6 +39,7 @@ int main(int argc, char **argv) { int four[4]; int five[5]; + gpr_uint32 bitset = 0; grpc_test_init(argc, argv); GPR_ASSERT(GPR_MIN(1, 2) == 1); @@ -55,5 +56,18 @@ int main(int argc, char **argv) { GPR_ASSERT(GPR_ARRAY_SIZE(four) == 4); GPR_ASSERT(GPR_ARRAY_SIZE(five) == 5); + GPR_ASSERT(GPR_BITCOUNT((1u << 31) - 1) == 31); + GPR_ASSERT(GPR_BITCOUNT(1u << 3) == 1); + GPR_ASSERT(GPR_BITCOUNT(0) == 0); + + GPR_ASSERT(GPR_BITSET(&bitset, 3) == 8); + GPR_ASSERT(GPR_BITCOUNT(bitset) == 1); + GPR_ASSERT(GPR_BITGET(bitset, 3) == 1); + GPR_ASSERT(GPR_BITSET(&bitset, 1) == 10); + GPR_ASSERT(GPR_BITCOUNT(bitset) == 2); + GPR_ASSERT(GPR_BITCLEAR(&bitset, 3) == 2); + GPR_ASSERT(GPR_BITCOUNT(bitset) == 1); + GPR_ASSERT(GPR_BITGET(bitset, 3) == 0); + return 0; } 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/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..063c797ce9 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_REALTIME), \ + 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_REALTIME), \ + gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ + GPR_TIMESPAN)) #ifndef GRPC_TEST_CUSTOM_PICK_PORT #define GRPC_TEST_PICK_PORT diff --git a/test/cpp/common/auth_property_iterator_test.cc b/test/cpp/common/auth_property_iterator_test.cc new file mode 100644 index 0000000000..3d983fa310 --- /dev/null +++ b/test/cpp/common/auth_property_iterator_test.cc @@ -0,0 +1,101 @@ +/* + * + * 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 <grpc++/auth_context.h> +#include <gtest/gtest.h> +#include "src/cpp/common/secure_auth_context.h" +#include "src/core/security/security_context.h" + +namespace grpc { +namespace { + +class TestAuthPropertyIterator : public AuthPropertyIterator { + public: + TestAuthPropertyIterator() {} + TestAuthPropertyIterator(const grpc_auth_property* property, + const grpc_auth_property_iterator* iter) + : AuthPropertyIterator(property, iter) {} +}; + +class AuthPropertyIteratorTest : public ::testing::Test { + protected: + void SetUp() GRPC_OVERRIDE { + ctx_ = grpc_auth_context_create(NULL, 3); + ctx_->properties[0] = grpc_auth_property_init_from_cstring("name", "chapi"); + ctx_->properties[1] = grpc_auth_property_init_from_cstring("name", "chapo"); + ctx_->properties[2] = grpc_auth_property_init_from_cstring("foo", "bar"); + ctx_->peer_identity_property_name = ctx_->properties[0].name; + } + void TearDown() GRPC_OVERRIDE { + GRPC_AUTH_CONTEXT_UNREF(ctx_, "AuthPropertyIteratorTest"); + } + grpc_auth_context* ctx_; + +}; + +TEST_F(AuthPropertyIteratorTest, DefaultCtor) { + TestAuthPropertyIterator iter1; + TestAuthPropertyIterator iter2; + EXPECT_EQ(iter1, iter2); +} + +TEST_F(AuthPropertyIteratorTest, GeneralTest) { + grpc_auth_property_iterator c_iter = + grpc_auth_context_property_iterator(ctx_); + const grpc_auth_property* property = + grpc_auth_property_iterator_next(&c_iter); + TestAuthPropertyIterator iter(property, &c_iter); + TestAuthPropertyIterator empty_iter; + EXPECT_FALSE(iter == empty_iter); + AuthProperty p0 = *iter; + ++iter; + AuthProperty p1 = *iter; + iter++; + AuthProperty p2 = *iter; + EXPECT_EQ("name", p0.first); + EXPECT_EQ("chapi", p0.second); + EXPECT_EQ("name", p1.first); + EXPECT_EQ("chapo", p1.second); + EXPECT_EQ("foo", p2.first); + EXPECT_EQ("bar", p2.second); + ++iter; + EXPECT_EQ(empty_iter, iter); +} + +} // namespace +} // namespace grpc + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/cpp/common/secure_auth_context_test.cc b/test/cpp/common/secure_auth_context_test.cc index a1819dc4d6..f18a04178e 100644 --- a/test/cpp/common/secure_auth_context_test.cc +++ b/test/cpp/common/secure_auth_context_test.cc @@ -48,6 +48,7 @@ TEST_F(SecureAuthContextTest, EmptyContext) { EXPECT_TRUE(context.GetPeerIdentityPropertyName().empty()); EXPECT_TRUE(context.FindPropertyValues("").empty()); EXPECT_TRUE(context.FindPropertyValues("whatever").empty()); + EXPECT_TRUE(context.begin() == context.end()); } TEST_F(SecureAuthContextTest, Properties) { @@ -68,6 +69,51 @@ TEST_F(SecureAuthContextTest, Properties) { EXPECT_EQ("bar", bar[0]); } +TEST_F(SecureAuthContextTest, Iterators) { + grpc_auth_context* ctx = grpc_auth_context_create(NULL, 3); + ctx->properties[0] = grpc_auth_property_init_from_cstring("name", "chapi"); + ctx->properties[1] = grpc_auth_property_init_from_cstring("name", "chapo"); + ctx->properties[2] = grpc_auth_property_init_from_cstring("foo", "bar"); + ctx->peer_identity_property_name = ctx->properties[0].name; + + SecureAuthContext context(ctx); + AuthPropertyIterator iter = context.begin(); + EXPECT_TRUE(context.end() != iter); + AuthProperty p0 = *iter; + ++iter; + AuthProperty p1 = *iter; + iter++; + AuthProperty p2 = *iter; + EXPECT_EQ("name", p0.first); + EXPECT_EQ("chapi", p0.second); + EXPECT_EQ("name", p1.first); + EXPECT_EQ("chapo", p1.second); + EXPECT_EQ("foo", p2.first); + EXPECT_EQ("bar", p2.second); + ++iter; + EXPECT_EQ(context.end(), iter); + // Range-based for loop test. + int i = 0; + for (auto p : context) { + switch (i++) { + case 0: + EXPECT_EQ("name", p.first); + EXPECT_EQ("chapi", p.second); + break; + case 1: + EXPECT_EQ("name", p.first); + EXPECT_EQ("chapo", p.second); + break; + case 2: + EXPECT_EQ("foo", p.first); + EXPECT_EQ("bar", p.second); + break; + default: + EXPECT_TRUE(0); + } + } +} + } // namespace } // namespace grpc diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 4b27cfea21..89d9d635af 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -75,7 +75,7 @@ const char* kServerCancelAfterReads = "cancel_after_reads"; void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request, EchoResponse* response) { if (request->has_param() && request->param().echo_deadline()) { - gpr_timespec deadline = gpr_inf_future; + gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); if (context->deadline() != system_clock::time_point::max()) { Timepoint2Timespec(context->deadline(), &deadline); } @@ -117,14 +117,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { while (!context->IsCancelled()) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(request->param().client_cancel_after_us()))); + gpr_time_from_micros(request->param().client_cancel_after_us(), + GPR_TIMESPAN))); } return Status::CANCELLED; } else if (request->has_param() && request->param().server_cancel_after_us()) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(request->param().server_cancel_after_us()))); + gpr_time_from_micros(request->param().server_cancel_after_us(), + GPR_TIMESPAN))); return Status::CANCELLED; } else { EXPECT_FALSE(context->IsCancelled()); @@ -375,7 +377,8 @@ TEST_F(End2endTest, EchoDeadlineForNoDeadlineRpc) { Status s = stub_->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); EXPECT_TRUE(s.ok()); - EXPECT_EQ(response.param().request_deadline(), gpr_inf_future.tv_sec); + EXPECT_EQ(response.param().request_deadline(), + gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec); } TEST_F(End2endTest, UnimplementedRpc) { @@ -530,7 +533,7 @@ TEST_F(End2endTest, BadCredentials) { void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) { gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(delay_us))); + gpr_time_from_micros(delay_us, GPR_TIMESPAN))); while (!service->signal_client()) { } context->TryCancel(); diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc index d71345055d..5c7bb4e653 100644 --- a/test/cpp/end2end/server_crash_test.cc +++ b/test/cpp/end2end/server_crash_test.cc @@ -81,8 +81,8 @@ class ServiceImpl GRPC_FINAL gpr_log(GPR_INFO, "recv msg %s", request.message().c_str()); response.set_message(request.message()); stream->Write(response); - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(1, GPR_TIMESPAN))); } return Status::OK; } @@ -96,8 +96,8 @@ class ServiceImpl GRPC_FINAL msg << "Hello " << i; response.set_message(msg.str()); if (!writer->Write(response)) break; - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(1, GPR_TIMESPAN))); } return Status::OK; } @@ -144,8 +144,8 @@ class CrashTest : public ::testing::Test { TEST_F(CrashTest, ResponseStream) { auto server = CreateServerAndClient("response"); - 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))); KillClient(); server->Shutdown(); GPR_ASSERT(HadOneResponseStream()); @@ -154,8 +154,8 @@ TEST_F(CrashTest, ResponseStream) { TEST_F(CrashTest, BidiStream) { auto server = CreateServerAndClient("bidi"); - 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))); KillClient(); server->Shutdown(); GPR_ASSERT(HadOneBidiStream()); diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 58e8ba394d..e47139641b 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -71,7 +71,7 @@ namespace { void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request, EchoResponse* response) { if (request->has_param() && request->param().echo_deadline()) { - gpr_timespec deadline = gpr_inf_future; + gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); if (context->deadline() != system_clock::time_point::max()) { Timepoint2Timespec(context->deadline(), &deadline); } @@ -97,14 +97,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { while (!context->IsCancelled()) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(request->param().client_cancel_after_us()))); + gpr_time_from_micros(request->param().client_cancel_after_us(), + GPR_TIMESPAN))); } return Status::CANCELLED; } else if (request->has_param() && request->param().server_cancel_after_us()) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(request->param().server_cancel_after_us()))); + gpr_time_from_micros(request->param().server_cancel_after_us(), + GPR_TIMESPAN))); return Status::CANCELLED; } else { EXPECT_FALSE(context->IsCancelled()); diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 65ce2e9c2a..96149c5e75 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -64,6 +64,7 @@ DEFINE_string(test_case, "large_unary", "ping_pong : full-duplex streaming; " "cancel_after_begin : cancel stream after starting it; " "cancel_after_first_response: cancel on first response; " + "timeout_on_sleeping_server: deadline exceeds on stream; " "service_account_creds : large_unary with service_account auth; " "compute_engine_creds: large_unary with compute engine auth; " "jwt_token_creds: large_unary with JWT token auth; " @@ -101,6 +102,8 @@ int main(int argc, char** argv) { client.DoCancelAfterBegin(); } else if (FLAGS_test_case == "cancel_after_first_response") { client.DoCancelAfterFirstResponse(); + } else if (FLAGS_test_case == "timeout_on_sleeping_server") { + client.DoTimeoutOnSleepingServer(); } else if (FLAGS_test_case == "service_account_creds") { grpc::string json_key = GetServiceAccountJsonKey(); client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope); @@ -119,6 +122,7 @@ int main(int argc, char** argv) { client.DoPingPong(); client.DoCancelAfterBegin(); client.DoCancelAfterFirstResponse(); + client.DoTimeoutOnSleepingServer(); // service_account_creds and jwt_token_creds can only run with ssl. if (FLAGS_enable_ssl) { grpc::string json_key = GetServiceAccountJsonKey(); @@ -132,6 +136,7 @@ int main(int argc, char** argv) { "Unsupported test case %s. Valid options are all|empty_unary|" "large_unary|client_streaming|server_streaming|half_duplex|ping_pong|" "cancel_after_begin|cancel_after_first_response|" + "timeout_on_sleeping_server|" "service_account_creds|compute_engine_creds|jwt_token_creds", FLAGS_test_case.c_str()); ret = 1; diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index f08f90b139..d88eff759c 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -351,5 +351,26 @@ void InteropClient::DoCancelAfterFirstResponse() { gpr_log(GPR_INFO, "Canceling pingpong streaming done."); } +void InteropClient::DoTimeoutOnSleepingServer() { + gpr_log(GPR_INFO, "Sending Ping Pong streaming rpc with a short deadline..."); + std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); + + ClientContext context; + std::chrono::system_clock::time_point deadline = + std::chrono::system_clock::now() + std::chrono::milliseconds(1); + context.set_deadline(deadline); + std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest, + StreamingOutputCallResponse>> + stream(stub->FullDuplexCall(&context)); + + StreamingOutputCallRequest request; + request.mutable_payload()->set_body(grpc::string(27182, '\0')); + stream->Write(request); + + Status s = stream->Finish(); + GPR_ASSERT(s.error_code() == StatusCode::DEADLINE_EXCEEDED); + gpr_log(GPR_INFO, "Pingpong streaming timeout done."); +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index d9c895dfd9..d02e583d94 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -59,6 +59,7 @@ class InteropClient { void DoResponseStreamingWithSlowConsumer(); void DoCancelAfterBegin(); void DoCancelAfterFirstResponse(); + void DoTimeoutOnSleepingServer(); // Auth tests. // username is a string containing the user email void DoJwtTokenCreds(const grpc::string& username); diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc index 22b8910a24..db87872cf5 100644 --- a/test/cpp/interop/server.cc +++ b/test/cpp/interop/server.cc @@ -149,14 +149,12 @@ class TestServiceImpl : public TestService::Service { StreamingOutputCallResponse response; bool write_success = true; while (write_success && stream->Read(&request)) { - response.mutable_payload()->set_type(request.payload().type()); - if (request.response_parameters_size() == 0) { - return Status(grpc::StatusCode::INTERNAL, - "Request does not have response parameters."); + if (request.response_parameters_size() != 0) { + response.mutable_payload()->set_type(request.payload().type()); + response.mutable_payload()->set_body( + grpc::string(request.response_parameters(0).size(), '\0')); + write_success = stream->Write(response); } - response.mutable_payload()->set_body( - grpc::string(request.response_parameters(0).size(), '\0')); - write_success = stream->Write(response); } if (write_success) { return Status::OK; diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc index c2e750dcf7..30a78ffddf 100644 --- a/test/cpp/interop/server_helper.cc +++ b/test/cpp/interop/server_helper.cc @@ -58,5 +58,18 @@ std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { } } +InteropContextInspector::InteropContextInspector( + const ::grpc::ServerContext& context) + : context_(context) {} + +std::shared_ptr<const AuthContext> InteropContextInspector::GetAuthContext() + const { + return context_.auth_context(); +} + +bool InteropContextInspector::IsCancelled() const { + return context_.IsCancelled(); +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index f98e67bb67..ce977b4705 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -36,6 +36,7 @@ #include <memory> +#include <grpc++/server_context.h> #include <grpc++/server_credentials.h> namespace grpc { @@ -43,6 +44,18 @@ namespace testing { std::shared_ptr<ServerCredentials> CreateInteropServerCredentials(); +class InteropContextInspector { + public: + InteropContextInspector(const ::grpc::ServerContext& context); + + // Inspector methods, able to peek inside ServerContext, follow. + std::shared_ptr<const AuthContext> GetAuthContext() const; + bool IsCancelled() const; + + private: + const ::grpc::ServerContext& context_; +}; + } // namespace testing } // namespace grpc diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 5597bcd549..a0360295e0 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -186,7 +186,8 @@ std::unique_ptr<ScenarioResult> RunScenario( // Let everything warmup gpr_log(GPR_INFO, "Warming up"); gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); - gpr_sleep_until(gpr_time_add(start, gpr_time_from_seconds(warmup_seconds))); + gpr_sleep_until( + gpr_time_add(start, gpr_time_from_seconds(warmup_seconds, GPR_TIMESPAN))); // Start a run gpr_log(GPR_INFO, "Starting"); @@ -211,8 +212,8 @@ std::unique_ptr<ScenarioResult> RunScenario( // Wait some time gpr_log(GPR_INFO, "Running"); - gpr_sleep_until( - gpr_time_add(start, gpr_time_from_seconds(benchmark_seconds))); + gpr_sleep_until(gpr_time_add( + start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN))); // Finish a run std::unique_ptr<ScenarioResult> result(new ScenarioResult); diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index be23204608..846f8f31b0 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -80,7 +80,7 @@ class AsyncQpsServerTest : public Server { server_ = builder.BuildAndStart(); using namespace std::placeholders; - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 10000 / config.threads(); i++) { for (int j = 0; j < config.threads(); j++) { auto request_unary = std::bind( &TestService::AsyncService::RequestUnaryCall, &async_service_, _1, diff --git a/test/cpp/qps/worker.cc b/test/cpp/qps/worker.cc index 2bc0a56970..7cf4903148 100644 --- a/test/cpp/qps/worker.cc +++ b/test/cpp/qps/worker.cc @@ -57,8 +57,8 @@ static void RunServer() { QpsWorker worker(FLAGS_driver_port, FLAGS_server_port); while (!got_sigint) { - 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))); } } diff --git a/test/cpp/server/fixed_size_thread_pool_test.cc b/test/cpp/server/fixed_size_thread_pool_test.cc index d62f4e8132..442e974fc1 100644 --- a/test/cpp/server/fixed_size_thread_pool_test.cc +++ b/test/cpp/server/fixed_size_thread_pool_test.cc @@ -54,12 +54,12 @@ void Callback(std::mutex* mu, std::condition_variable* cv, bool* done) { cv->notify_all(); } -TEST_F(FixedSizeThreadPoolTest, ScheduleCallback) { +TEST_F(FixedSizeThreadPoolTest, Add) { std::mutex mu; std::condition_variable cv; bool done = false; std::function<void()> callback = std::bind(Callback, &mu, &cv, &done); - thread_pool_.ScheduleCallback(callback); + thread_pool_.Add(callback); // Wait for the callback to finish. std::unique_lock<std::mutex> lock(mu); diff --git a/test/cpp/util/time_test.cc b/test/cpp/util/time_test.cc index a3cfb1c961..4cb6ec4b4e 100644 --- a/test/cpp/util/time_test.cc +++ b/test/cpp/util/time_test.cc @@ -46,7 +46,8 @@ class TimeTest : public ::testing::Test {}; TEST_F(TimeTest, AbsolutePointTest) { long us = 10000000L; - gpr_timespec ts = gpr_time_from_micros(us); + gpr_timespec ts = gpr_time_from_micros(us, GPR_TIMESPAN); + ts.clock_type = GPR_CLOCK_REALTIME; system_clock::time_point tp{microseconds(us)}; system_clock::time_point tp_converted = Timespec2Timepoint(ts); gpr_timespec ts_converted; @@ -61,15 +62,17 @@ TEST_F(TimeTest, AbsolutePointTest) { // gpr_inf_future is treated specially and mapped to/from time_point::max() TEST_F(TimeTest, InfFuture) { EXPECT_EQ(system_clock::time_point::max(), - Timespec2Timepoint(gpr_inf_future)); + Timespec2Timepoint(gpr_inf_future(GPR_CLOCK_REALTIME))); gpr_timespec from_time_point_max; Timepoint2Timespec(system_clock::time_point::max(), &from_time_point_max); - EXPECT_EQ(0, gpr_time_cmp(gpr_inf_future, from_time_point_max)); + EXPECT_EQ( + 0, gpr_time_cmp(gpr_inf_future(GPR_CLOCK_REALTIME), from_time_point_max)); // This will cause an overflow Timepoint2Timespec( std::chrono::time_point<system_clock, std::chrono::seconds>::max(), &from_time_point_max); - EXPECT_EQ(0, gpr_time_cmp(gpr_inf_future, from_time_point_max)); + EXPECT_EQ( + 0, gpr_time_cmp(gpr_inf_future(GPR_CLOCK_REALTIME), from_time_point_max)); } } // namespace |