diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-02-25 08:36:40 -0800 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-02-25 08:36:40 -0800 |
commit | 8ad8a41a84bf7e17c6e9a5fd8d975370a222c0fe (patch) | |
tree | 257d00e77bda0bc5e53b770ba9fa7cc300c449bb /test/core/iomgr | |
parent | 517aa0c5358f860582e6143a29522699f61fba15 (diff) |
Introduce slowdown factor for unit test deadlines
Dramatically lowers (eliminates maybe?) false negatives from ?SAN runs.
Diffstat (limited to 'test/core/iomgr')
-rw-r--r-- | test/core/iomgr/alarm_list_test.c | 14 | ||||
-rw-r--r-- | test/core/iomgr/alarm_test.c | 17 | ||||
-rw-r--r-- | test/core/iomgr/endpoint_tests.c | 10 | ||||
-rw-r--r-- | test/core/iomgr/resolve_address_test.c | 16 | ||||
-rw-r--r-- | test/core/iomgr/tcp_client_posix_test.c | 11 | ||||
-rw-r--r-- | test/core/iomgr/tcp_posix_test.c | 15 | ||||
-rw-r--r-- | test/core/iomgr/tcp_server_posix_test.c | 2 |
7 files changed, 43 insertions, 42 deletions
diff --git a/test/core/iomgr/alarm_list_test.c b/test/core/iomgr/alarm_list_test.c index f2ccd1fb35..684e3f579a 100644 --- a/test/core/iomgr/alarm_list_test.c +++ b/test/core/iomgr/alarm_list_test.c @@ -61,13 +61,13 @@ 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)), - cb, (void *)(gpr_intptr)i, start); + 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)), - cb, (void *)(gpr_intptr)i, start); + cb, (void *)(gpr_intptr) i, start); } /* collect alarms. Only the first batch should be ready. */ @@ -115,15 +115,15 @@ void destruction_test(void) { 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); + (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); + (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); + (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); + (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); + (void *)(gpr_intptr) 4, gpr_time_0); GPR_ASSERT(1 == grpc_alarm_check(NULL, gpr_time_from_millis(2), NULL)); GPR_ASSERT(1 == cb_called[4][1]); grpc_alarm_cancel(&alarms[0]); diff --git a/test/core/iomgr/alarm_test.c b/test/core/iomgr/alarm_test.c index 18f57725a2..8d49332fa6 100644 --- a/test/core/iomgr/alarm_test.c +++ b/test/core/iomgr/alarm_test.c @@ -113,10 +113,10 @@ static void test_grpc_alarm(void) { gpr_cv_init(&arg.cv); gpr_event_init(&arg.fcb_arg); - grpc_alarm_init(&alarm, gpr_time_add(gpr_time_from_millis(100), gpr_now()), - alarm_cb, &arg, gpr_now()); + grpc_alarm_init(&alarm, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), alarm_cb, &arg, + gpr_now()); - alarm_deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(1)); + alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); gpr_mu_lock(&arg.mu); while (arg.done == 0) { if (gpr_cv_wait(&arg.cv, &arg.mu, alarm_deadline)) { @@ -126,7 +126,7 @@ static void test_grpc_alarm(void) { } gpr_mu_unlock(&arg.mu); - followup_deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(5)); + followup_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); fdone = gpr_event_wait(&arg.fcb_arg, followup_deadline); if (arg.counter != 1) { @@ -162,12 +162,11 @@ static void test_grpc_alarm(void) { gpr_cv_init(&arg2.cv); gpr_event_init(&arg2.fcb_arg); - grpc_alarm_init(&alarm_to_cancel, - gpr_time_add(gpr_time_from_millis(100), gpr_now()), alarm_cb, - &arg2, gpr_now()); + grpc_alarm_init(&alarm_to_cancel, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), + alarm_cb, &arg2, gpr_now()); grpc_alarm_cancel(&alarm_to_cancel); - alarm_deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(1)); + alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); gpr_mu_lock(&arg2.mu); while (arg2.done == 0) { gpr_cv_wait(&arg2.cv, &arg2.mu, alarm_deadline); @@ -176,7 +175,7 @@ static void test_grpc_alarm(void) { gpr_log(GPR_INFO, "alarm done = %d", arg2.done); - followup_deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(5)); + followup_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); fdone = gpr_event_wait(&arg2.fcb_arg, followup_deadline); if (arg2.counter != arg2.done_success_ctr) { diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index c08ee7d48f..e63048e26c 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -39,6 +39,7 @@ #include <grpc/support/slice.h> #include <grpc/support/log.h> #include <grpc/support/time.h> +#include "test/core/util/test_config.h" /* General test notes: @@ -211,7 +212,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, size_t num_bytes, size_t write_size, size_t slice_size, int shutdown) { struct read_and_write_test_state state; - gpr_timespec deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(20)); + gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); grpc_endpoint_test_fixture f = begin_test(config, __FUNCTION__, slice_size); if (shutdown) { @@ -290,7 +291,7 @@ static void shutdown_during_write_test_read_handler( if (error != GRPC_ENDPOINT_CB_OK) { grpc_endpoint_destroy(st->ep); - gpr_event_set(&st->ev, (void *)(gpr_intptr)error); + gpr_event_set(&st->ev, (void *)(gpr_intptr) error); } else { grpc_endpoint_notify_on_read( st->ep, shutdown_during_write_test_read_handler, user_data); @@ -309,7 +310,7 @@ static void shutdown_during_write_test_write_handler( gpr_log(GPR_ERROR, "shutdown_during_write_test_write_handler completed unexpectedly"); } - gpr_event_set(&st->ev, (void *)(gpr_intptr)1); + gpr_event_set(&st->ev, (void *)(gpr_intptr) 1); } static void shutdown_during_write_test(grpc_endpoint_test_config config, @@ -345,8 +346,7 @@ static void shutdown_during_write_test(grpc_endpoint_test_config config, abort(); case GRPC_ENDPOINT_WRITE_PENDING: grpc_endpoint_shutdown(write_st.ep); - deadline = - gpr_time_add(gpr_now(), gpr_time_from_micros(10 * GPR_US_PER_SEC)); + deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10); GPR_ASSERT(gpr_event_wait(&write_st.ev, deadline)); grpc_endpoint_destroy(write_st.ep); GPR_ASSERT(gpr_event_wait(&read_st.ev, deadline)); diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c index 0961a3659f..668c5399f9 100644 --- a/test/core/iomgr/resolve_address_test.c +++ b/test/core/iomgr/resolve_address_test.c @@ -39,7 +39,7 @@ #include "test/core/util/test_config.h" static gpr_timespec test_deadline(void) { - return gpr_time_add(gpr_now(), gpr_time_from_micros(100000000)); + return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(100); } static void must_succeed(void* evp, grpc_resolved_addresses* p) { @@ -83,8 +83,9 @@ static void test_ipv6_with_port(void) { } static void test_ipv6_without_port(void) { - const char* const kCases[] = {"2001:db8::1", "2001:db8::1.2.3.4", - "[2001:db8::1]", }; + const char* const kCases[] = { + "2001:db8::1", "2001:db8::1.2.3.4", "[2001:db8::1]", + }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { gpr_event ev; @@ -95,7 +96,9 @@ static void test_ipv6_without_port(void) { } static void test_invalid_ip_addresses(void) { - const char* const kCases[] = {"293.283.1238.3:1", "[2001:db8::11111]:1", }; + const char* const kCases[] = { + "293.283.1238.3:1", "[2001:db8::11111]:1", + }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { gpr_event ev; @@ -106,8 +109,9 @@ static void test_invalid_ip_addresses(void) { } static void test_unparseable_hostports(void) { - const char* const kCases[] = {"[", "[::1", "[::1]bad", - "[1.2.3.4]", "[localhost]", "[localhost]:1", }; + const char* const kCases[] = { + "[", "[::1", "[::1]bad", "[1.2.3.4]", "[localhost]", "[localhost]:1", + }; unsigned i; for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { gpr_event ev; diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index ad5a317044..3c4d8fed4f 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -43,9 +43,10 @@ #include "src/core/iomgr/socket_utils_posix.h" #include <grpc/support/log.h> #include <grpc/support/time.h> +#include "test/core/util/test_config.h" static gpr_timespec test_deadline(void) { - return gpr_time_add(gpr_now(), gpr_time_from_seconds(10)); + return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10); } static void must_succeed(void *arg, grpc_endpoint *tcp) { @@ -150,13 +151,12 @@ void test_times_out(void) { /* connect to dummy server address */ - connect_deadline = gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)); + connect_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); grpc_tcp_client_connect(must_fail, &ev, (struct sockaddr *)&addr, addr_len, connect_deadline); /* Make sure the event doesn't trigger early */ - GPR_ASSERT(!gpr_event_wait( - &ev, gpr_time_add(gpr_now(), gpr_time_from_micros(500000)))); + GPR_ASSERT(!gpr_event_wait(&ev, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(500))); /* Now wait until it should have triggered */ sleep(1); @@ -168,7 +168,8 @@ void test_times_out(void) { } } -int main(void) { +int main(int argc, char **argv) { + grpc_test_init(argc, argv); grpc_iomgr_init(); test_succeeds(); gpr_log(GPR_ERROR, "End of first test"); diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index 0f81ba7734..59e525a8e1 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -163,8 +163,7 @@ static void read_test(ssize_t num_bytes, ssize_t slice_size) { grpc_endpoint *ep; struct read_socket_state state; ssize_t written_bytes; - gpr_timespec rel_deadline = {20, 0}; - gpr_timespec deadline = gpr_time_add(gpr_now(), rel_deadline); + gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); gpr_log(GPR_INFO, "Read test of size %d, slice size %d", num_bytes, slice_size); @@ -206,8 +205,7 @@ static void large_read_test(ssize_t slice_size) { grpc_endpoint *ep; struct read_socket_state state; ssize_t written_bytes; - gpr_timespec rel_deadline = {20, 0}; - gpr_timespec deadline = gpr_time_add(gpr_now(), rel_deadline); + gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); gpr_log(GPR_INFO, "Start large read test, slice size %d", slice_size); @@ -343,8 +341,7 @@ static void write_test(ssize_t num_bytes, ssize_t slice_size) { size_t num_blocks; gpr_slice *slices; int current_data = 0; - gpr_timespec rel_deadline = {20, 0}; - gpr_timespec deadline = gpr_time_add(gpr_now(), rel_deadline); + gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); gpr_log(GPR_INFO, "Start write test with %d bytes, slice size %d", num_bytes, slice_size); @@ -400,8 +397,7 @@ static void write_error_test(ssize_t num_bytes, ssize_t slice_size) { size_t num_blocks; gpr_slice *slices; int current_data = 0; - gpr_timespec rel_deadline = {20, 0}; - gpr_timespec deadline = gpr_time_add(gpr_now(), rel_deadline); + gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); gpr_log(GPR_INFO, "Start write error test with %d bytes, slice size %d", num_bytes, slice_size); @@ -482,7 +478,8 @@ static grpc_endpoint_test_fixture create_fixture_tcp_socketpair( } static grpc_endpoint_test_config configs[] = { - {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, }; + {"tcp/tcp_socketpair", create_fixture_tcp_socketpair, clean_up}, +}; int main(int argc, char **argv) { grpc_test_init(argc, argv); diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index b26115bcd0..2689c3f38e 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -123,7 +123,7 @@ static void test_connect(int n) { grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); for (i = 0; i < n; i++) { - deadline = gpr_time_add(gpr_now(), gpr_time_from_micros(10000000)); + deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); nconnects_before = nconnects; clifd = socket(addr.ss_family, SOCK_STREAM, 0); |