aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/iomgr
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-07-13 08:41:49 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-07-13 08:41:49 -0700
commit143e7bf0cfcbfd60422f4e8f15e6b5c18259c8cd (patch)
treecbeb3f4da486b08a6cdae1be6754c523e2a361fb /test/core/iomgr
parentf0fb537da9e67902f56b50d3d0f516b295609d88 (diff)
Introduce a clock type field onto gpr_timespec.
Use it to validate that arithmetic on time types makes even some vague kind of sense.
Diffstat (limited to 'test/core/iomgr')
-rw-r--r--test/core/iomgr/alarm_heap_test.c3
-rw-r--r--test/core/iomgr/alarm_list_test.c30
-rw-r--r--test/core/iomgr/fd_posix_test.c8
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c6
4 files changed, 28 insertions, 19 deletions
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..2d7cf6c3ec 100644
--- a/test/core/iomgr/alarm_list_test.c
+++ b/test/core/iomgr/alarm_list_test.c
@@ -107,24 +107,30 @@ static void add_test(void) {
grpc_alarm_list_shutdown();
}
+static gpr_timespec tfm(int m) {
+ gpr_timespec t = gpr_time_from_millis(m);
+ 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..36b1d6c939 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -95,7 +95,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 {
@@ -128,7 +129,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));