From 58bbc864badff97950bb68a64ce3ade8662bec5d Mon Sep 17 00:00:00 2001
From: Craig Tiller <ctiller@google.com>
Date: Mon, 13 Jul 2015 09:51:17 -0700
Subject: [PATCH] Updating wrapped languages to new time functions

---
 include/grpc/support/time.h                   | 12 ++--
 src/core/client_config/subchannel.c           |  2 +-
 src/core/iomgr/iomgr.c                        | 14 ++--
 src/core/iomgr/pollset_posix.c                | 10 +--
 src/core/security/credentials.c               |  8 +--
 .../security/google_default_credentials.c     |  2 +-
 src/core/support/cancellable.c                |  5 +-
 src/core/support/time.c                       | 48 ++++++-------
 src/core/surface/completion_queue.c           |  5 +-
 src/core/surface/server.c                     |  6 +-
 src/core/transport/chttp2/timeout_encoding.c  | 12 ++--
 src/node/ext/timeval.cc                       |  3 +-
 src/php/ext/grpc/timeval.c                    |  5 +-
 src/ruby/ext/grpc/rb_completion_queue.c       |  3 +-
 test/core/end2end/cq_verifier.c               |  4 +-
 test/core/fling/server.c                      |  2 +-
 test/core/httpcli/httpcli_test.c              |  4 +-
 test/core/iomgr/alarm_list_test.c             | 36 ++++++----
 test/core/iomgr/tcp_client_posix_test.c       |  6 +-
 test/core/statistics/census_log_tests.c       |  3 +-
 test/core/support/cancellable_test.c          | 45 +++++++-----
 test/core/support/sync_test.c                 | 19 +++---
 test/core/support/time_test.c                 | 62 +++++++++--------
 .../transport/chttp2/timeout_encoding_test.c  | 68 ++++++++++---------
 test/core/util/test_config.h                  | 14 ++--
 25 files changed, 214 insertions(+), 184 deletions(-)

diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h
index dbf2548d1b..2a93377202 100644
--- a/include/grpc/support/time.h
+++ b/include/grpc/support/time.h
@@ -94,12 +94,12 @@ gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b);
 
 /* Return a timespec representing a given number of time units. LONG_MIN is
    interpreted as gpr_inf_past, and LONG_MAX as gpr_inf_future.  */
-gpr_timespec gpr_time_from_micros(long x);
-gpr_timespec gpr_time_from_nanos(long x);
-gpr_timespec gpr_time_from_millis(long x);
-gpr_timespec gpr_time_from_seconds(long x);
-gpr_timespec gpr_time_from_minutes(long x);
-gpr_timespec gpr_time_from_hours(long x);
+gpr_timespec gpr_time_from_micros(long x, gpr_clock_type clock_type);
+gpr_timespec gpr_time_from_nanos(long x, gpr_clock_type clock_type);
+gpr_timespec gpr_time_from_millis(long x, gpr_clock_type clock_type);
+gpr_timespec gpr_time_from_seconds(long x, gpr_clock_type clock_type);
+gpr_timespec gpr_time_from_minutes(long x, gpr_clock_type clock_type);
+gpr_timespec gpr_time_from_hours(long x, gpr_clock_type clock_type);
 
 gpr_int32 gpr_time_to_millis(gpr_timespec timespec);
 
diff --git a/src/core/client_config/subchannel.c b/src/core/client_config/subchannel.c
index 8cdad1015f..35f172683a 100644
--- a/src/core/client_config/subchannel.c
+++ b/src/core/client_config/subchannel.c
@@ -302,7 +302,7 @@ static void continue_connect(grpc_subchannel *c) {
 static void start_connect(grpc_subchannel *c) {
   gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
   c->next_attempt = now;
-  c->backoff_delta = gpr_time_from_seconds(1);
+  c->backoff_delta = gpr_time_from_seconds(1, GPR_TIMESPAN);
 
   continue_connect(c);
 }
diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c
index 2a90b9aced..0244f689b1 100644
--- a/src/core/iomgr/iomgr.c
+++ b/src/core/iomgr/iomgr.c
@@ -58,8 +58,8 @@ static void background_callback_executor(void *ignored) {
   gpr_mu_lock(&g_mu);
   while (!g_shutdown) {
     gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
-    gpr_timespec short_deadline =
-        gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100));
+    gpr_timespec short_deadline = gpr_time_add(
+        gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN));
     if (g_cbs_head) {
       grpc_iomgr_closure *closure = g_cbs_head;
       g_cbs_head = closure->next;
@@ -110,8 +110,8 @@ static size_t count_objects(void) {
 void grpc_iomgr_shutdown(void) {
   grpc_iomgr_object *obj;
   grpc_iomgr_closure *closure;
-  gpr_timespec shutdown_deadline =
-      gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10));
+  gpr_timespec shutdown_deadline = gpr_time_add(
+      gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN));
   gpr_timespec last_warning_time = gpr_now(GPR_CLOCK_REALTIME);
 
   gpr_mu_lock(&g_mu);
@@ -119,7 +119,7 @@ void grpc_iomgr_shutdown(void) {
   while (g_cbs_head != NULL || g_root_object.next != &g_root_object) {
     if (gpr_time_cmp(
             gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_warning_time),
-            gpr_time_from_seconds(1)) >= 0) {
+            gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) {
       if (g_cbs_head != NULL && g_root_object.next != &g_root_object) {
         gpr_log(GPR_DEBUG,
                 "Waiting for %d iomgr objects to be destroyed and executing "
@@ -151,8 +151,8 @@ void grpc_iomgr_shutdown(void) {
     }
     if (g_root_object.next != &g_root_object) {
       int timeout = 0;
-      gpr_timespec short_deadline =
-          gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100));
+      gpr_timespec short_deadline = gpr_time_add(
+          gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN));
       while (gpr_cv_wait(&g_rcv, &g_mu, short_deadline) && g_cbs_head == NULL) {
         if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > 0) {
           timeout = 1;
diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c
index e95d9d1458..7afff58eee 100644
--- a/src/core/iomgr/pollset_posix.c
+++ b/src/core/iomgr/pollset_posix.c
@@ -194,14 +194,14 @@ int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline,
   if (gpr_time_cmp(deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) {
     return -1;
   }
-  if (gpr_time_cmp(
-          deadline,
-          gpr_time_add(now, gpr_time_from_micros(max_spin_polling_us))) <= 0) {
+  if (gpr_time_cmp(deadline, gpr_time_add(now, gpr_time_from_micros(
+                                                   max_spin_polling_us,
+                                                   GPR_TIMESPAN))) <= 0) {
     return 0;
   }
   timeout = gpr_time_sub(deadline, now);
-  return gpr_time_to_millis(
-      gpr_time_add(timeout, gpr_time_from_nanos(GPR_NS_PER_SEC - 1)));
+  return gpr_time_to_millis(gpr_time_add(
+      timeout, gpr_time_from_nanos(GPR_NS_PER_SEC - 1, GPR_TIMESPAN)));
 }
 
 /*
diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c
index 5d03b7c063..fb59fa4b0e 100644
--- a/src/core/security/credentials.c
+++ b/src/core/security/credentials.c
@@ -347,8 +347,8 @@ static void jwt_get_request_metadata(grpc_credentials *creds,
                                      grpc_credentials_metadata_cb cb,
                                      void *user_data) {
   grpc_jwt_credentials *c = (grpc_jwt_credentials *)creds;
-  gpr_timespec refresh_threshold =
-      gpr_time_from_seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS);
+  gpr_timespec refresh_threshold = gpr_time_from_seconds(
+      GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN);
 
   /* See if we can return a cached jwt. */
   grpc_credentials_md_store *jwt_md = NULL;
@@ -565,8 +565,8 @@ static void oauth2_token_fetcher_get_request_metadata(
     grpc_credentials_metadata_cb cb, void *user_data) {
   grpc_oauth2_token_fetcher_credentials *c =
       (grpc_oauth2_token_fetcher_credentials *)creds;
-  gpr_timespec refresh_threshold =
-      gpr_time_from_seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS);
+  gpr_timespec refresh_threshold = gpr_time_from_seconds(
+      GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN);
   grpc_credentials_md_store *cached_access_token_md = NULL;
   {
     gpr_mu_lock(&c->mu);
diff --git a/src/core/security/google_default_credentials.c b/src/core/security/google_default_credentials.c
index 43f9f62198..833484310f 100644
--- a/src/core/security/google_default_credentials.c
+++ b/src/core/security/google_default_credentials.c
@@ -91,7 +91,7 @@ static int is_stack_running_on_compute_engine(void) {
 
   /* The http call is local. If it takes more than one sec, it is for sure not
      on compute engine. */
-  gpr_timespec max_detection_delay = gpr_time_from_seconds(1);
+  gpr_timespec max_detection_delay = gpr_time_from_seconds(1, GPR_TIMESPAN);
 
   grpc_pollset_init(&detector.pollset);
   detector.is_done = 0;
diff --git a/src/core/support/cancellable.c b/src/core/support/cancellable.c
index 3cbb318ab6..4756f1e125 100644
--- a/src/core/support/cancellable.c
+++ b/src/core/support/cancellable.c
@@ -121,8 +121,9 @@ void gpr_cancellable_cancel(gpr_cancellable *c) {
         } else {
           gpr_event ev;
           gpr_event_init(&ev);
-          gpr_event_wait(&ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
-                                           gpr_time_from_micros(1000)));
+          gpr_event_wait(
+              &ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+                                gpr_time_from_micros(1000, GPR_TIMESPAN)));
         }
       }
     } while (failures != 0);
diff --git a/src/core/support/time.c b/src/core/support/time.c
index aee64c9778..570f195bd1 100644
--- a/src/core/support/time.c
+++ b/src/core/support/time.c
@@ -99,13 +99,13 @@ gpr_timespec gpr_inf_past(gpr_clock_type type) {
 /* TODO(ctiller): consider merging _nanos, _micros, _millis into a single
    function for maintainability. Similarly for _seconds, _minutes, and _hours */
 
-gpr_timespec gpr_time_from_nanos(long ns) {
+gpr_timespec gpr_time_from_nanos(long ns, gpr_clock_type type) {
   gpr_timespec result;
-  result.clock_type = GPR_TIMESPAN;
+  result.clock_type = type;
   if (ns == LONG_MAX) {
-    result = gpr_inf_future(GPR_TIMESPAN);
+    result = gpr_inf_future(type);
   } else if (ns == LONG_MIN) {
-    result = gpr_inf_past(GPR_TIMESPAN);
+    result = gpr_inf_past(type);
   } else if (ns >= 0) {
     result.tv_sec = ns / GPR_NS_PER_SEC;
     result.tv_nsec = (int)(ns - result.tv_sec * GPR_NS_PER_SEC);
@@ -117,13 +117,13 @@ gpr_timespec gpr_time_from_nanos(long ns) {
   return result;
 }
 
-gpr_timespec gpr_time_from_micros(long us) {
+gpr_timespec gpr_time_from_micros(long us, gpr_clock_type type) {
   gpr_timespec result;
-  result.clock_type = GPR_TIMESPAN;
+  result.clock_type = type;
   if (us == LONG_MAX) {
-    result = gpr_inf_future(GPR_TIMESPAN);
+    result = gpr_inf_future(type);
   } else if (us == LONG_MIN) {
-    result = gpr_inf_past(GPR_TIMESPAN);
+    result = gpr_inf_past(type);
   } else if (us >= 0) {
     result.tv_sec = us / 1000000;
     result.tv_nsec = (int)((us - result.tv_sec * 1000000) * 1000);
@@ -135,13 +135,13 @@ gpr_timespec gpr_time_from_micros(long us) {
   return result;
 }
 
-gpr_timespec gpr_time_from_millis(long ms) {
+gpr_timespec gpr_time_from_millis(long ms, gpr_clock_type type) {
   gpr_timespec result;
-  result.clock_type = GPR_TIMESPAN;
+  result.clock_type = type;
   if (ms == LONG_MAX) {
-    result = gpr_inf_future(GPR_TIMESPAN);
+    result = gpr_inf_future(type);
   } else if (ms == LONG_MIN) {
-    result = gpr_inf_past(GPR_TIMESPAN);
+    result = gpr_inf_past(type);
   } else if (ms >= 0) {
     result.tv_sec = ms / 1000;
     result.tv_nsec = (int)((ms - result.tv_sec * 1000) * 1000000);
@@ -153,13 +153,13 @@ gpr_timespec gpr_time_from_millis(long ms) {
   return result;
 }
 
-gpr_timespec gpr_time_from_seconds(long s) {
+gpr_timespec gpr_time_from_seconds(long s, gpr_clock_type type) {
   gpr_timespec result;
-  result.clock_type = GPR_TIMESPAN;
+  result.clock_type = type;
   if (s == LONG_MAX) {
-    result = gpr_inf_future(GPR_TIMESPAN);
+    result = gpr_inf_future(type);
   } else if (s == LONG_MIN) {
-    result = gpr_inf_past(GPR_TIMESPAN);
+    result = gpr_inf_past(type);
   } else {
     result.tv_sec = s;
     result.tv_nsec = 0;
@@ -167,13 +167,13 @@ gpr_timespec gpr_time_from_seconds(long s) {
   return result;
 }
 
-gpr_timespec gpr_time_from_minutes(long m) {
+gpr_timespec gpr_time_from_minutes(long m, gpr_clock_type type) {
   gpr_timespec result;
-  result.clock_type = GPR_TIMESPAN;
+  result.clock_type = type;
   if (m >= LONG_MAX / 60) {
-    result = gpr_inf_future(GPR_TIMESPAN);
+    result = gpr_inf_future(type);
   } else if (m <= LONG_MIN / 60) {
-    result = gpr_inf_past(GPR_TIMESPAN);
+    result = gpr_inf_past(type);
   } else {
     result.tv_sec = m * 60;
     result.tv_nsec = 0;
@@ -181,13 +181,13 @@ gpr_timespec gpr_time_from_minutes(long m) {
   return result;
 }
 
-gpr_timespec gpr_time_from_hours(long h) {
+gpr_timespec gpr_time_from_hours(long h, gpr_clock_type type) {
   gpr_timespec result;
-  result.clock_type = GPR_TIMESPAN;
+  result.clock_type = type;
   if (h >= LONG_MAX / 3600) {
-    result = gpr_inf_future(GPR_TIMESPAN);
+    result = gpr_inf_future(type);
   } else if (h <= LONG_MIN / 3600) {
-    result = gpr_inf_past(GPR_TIMESPAN);
+    result = gpr_inf_past(type);
   } else {
     result.tv_sec = h * 3600;
     result.tv_nsec = 0;
diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c
index c67f75fc5c..7f135d4bdd 100644
--- a/src/core/surface/completion_queue.c
+++ b/src/core/surface/completion_queue.c
@@ -260,8 +260,9 @@ grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc) {
 void grpc_cq_hack_spin_pollset(grpc_completion_queue *cc) {
   gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
   grpc_pollset_kick(&cc->pollset);
-  grpc_pollset_work(&cc->pollset, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
-                                               gpr_time_from_millis(100)));
+  grpc_pollset_work(&cc->pollset,
+                    gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+                                 gpr_time_from_millis(100, GPR_TIMESPAN)));
   gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset));
 }
 
diff --git a/src/core/surface/server.c b/src/core/surface/server.c
index 650b8b86fe..37f0c3c005 100644
--- a/src/core/surface/server.c
+++ b/src/core/surface/server.c
@@ -487,9 +487,9 @@ static void maybe_finish_shutdown(grpc_server *server) {
 
   if (server->root_channel_data.next != &server->root_channel_data ||
       server->listeners_destroyed < num_listeners(server)) {
-    if (gpr_time_cmp(
-            gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), server->last_shutdown_message_time),
-            gpr_time_from_seconds(1)) >= 0) {
+    if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME),
+                                  server->last_shutdown_message_time),
+                     gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) {
       server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
       gpr_log(GPR_DEBUG,
               "Waiting for %d channels and %d/%d listeners to be destroyed"
diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c
index 7b19712d9c..1dd768ada4 100644
--- a/src/core/transport/chttp2/timeout_encoding.c
+++ b/src/core/transport/chttp2/timeout_encoding.c
@@ -159,22 +159,22 @@ int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) {
   /* decode unit specifier */
   switch (*p) {
     case 'n':
-      *timeout = gpr_time_from_nanos(x);
+      *timeout = gpr_time_from_nanos(x, GPR_TIMESPAN);
       break;
     case 'u':
-      *timeout = gpr_time_from_micros(x);
+      *timeout = gpr_time_from_micros(x, GPR_TIMESPAN);
       break;
     case 'm':
-      *timeout = gpr_time_from_millis(x);
+      *timeout = gpr_time_from_millis(x, GPR_TIMESPAN);
       break;
     case 'S':
-      *timeout = gpr_time_from_seconds(x);
+      *timeout = gpr_time_from_seconds(x, GPR_TIMESPAN);
       break;
     case 'M':
-      *timeout = gpr_time_from_minutes(x);
+      *timeout = gpr_time_from_minutes(x, GPR_TIMESPAN);
       break;
     case 'H':
-      *timeout = gpr_time_from_hours(x);
+      *timeout = gpr_time_from_hours(x, GPR_TIMESPAN);
       break;
     default:
       return 0;
diff --git a/src/node/ext/timeval.cc b/src/node/ext/timeval.cc
index e3620fc91d..60de4d816d 100644
--- a/src/node/ext/timeval.cc
+++ b/src/node/ext/timeval.cc
@@ -46,7 +46,8 @@ gpr_timespec MillisecondsToTimespec(double millis) {
   } else if (millis == -std::numeric_limits<double>::infinity()) {
     return gpr_inf_past(GPR_CLOCK_REALTIME);
   } else {
-    return gpr_time_from_micros(static_cast<int64_t>(millis * 1000));
+    return gpr_time_from_micros(static_cast<int64_t>(millis * 1000),
+                                GPR_CLOCK_REALTIME);
   }
 }
 
diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c
index d7530488e4..4fd069e19a 100644
--- a/src/php/ext/grpc/timeval.c
+++ b/src/php/ext/grpc/timeval.c
@@ -98,7 +98,7 @@ PHP_METHOD(Timeval, __construct) {
                          "Timeval expects a long", 1 TSRMLS_CC);
     return;
   }
-  gpr_timespec time = gpr_time_from_micros(microseconds);
+  gpr_timespec time = gpr_time_from_micros(microseconds, GPR_TIMESPAN);
   memcpy(&timeval->wrapped, &time, sizeof(gpr_timespec));
 }
 
@@ -217,7 +217,8 @@ PHP_METHOD(Timeval, now) {
  * @return Timeval Zero length time interval
  */
 PHP_METHOD(Timeval, zero) {
-  zval *grpc_php_timeval_zero = grpc_php_wrap_timeval(gpr_time_0);
+  zval *grpc_php_timeval_zero =
+      grpc_php_wrap_timeval(gpr_time_0(GPR_CLOCK_REALTIME));
   RETURN_ZVAL(grpc_php_timeval_zero,
               false, /* Copy original before returning? */
               true /* Destroy original before returning */);
diff --git a/src/ruby/ext/grpc/rb_completion_queue.c b/src/ruby/ext/grpc/rb_completion_queue.c
index 8a98e16308..f89439f4c1 100644
--- a/src/ruby/ext/grpc/rb_completion_queue.c
+++ b/src/ruby/ext/grpc/rb_completion_queue.c
@@ -91,7 +91,8 @@ static void grpc_rb_completion_queue_shutdown_drain(grpc_completion_queue *cq) {
    * - investigate further, this is probably another example of C-level cleanup
    * not working consistently in all cases.
    */
-  next_call.timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(5e3));
+  next_call.timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+                                   gpr_time_from_micros(5e3, GPR_TIMESPAN));
   do {
     rb_thread_call_without_gvl(grpc_rb_completion_queue_next_no_gil,
                                (void *)&next_call, NULL, NULL);
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/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_list_test.c b/test/core/iomgr/alarm_list_test.c
index 2d7cf6c3ec..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);
@@ -108,7 +114,7 @@ static void add_test(void) {
 }
 
 static gpr_timespec tfm(int m) {
-  gpr_timespec t = gpr_time_from_millis(m);
+  gpr_timespec t = gpr_time_from_millis(m, GPR_TIMESPAN);
   t.clock_type = GPR_CLOCK_REALTIME;
   return t;
 }
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 36b1d6c939..f08230902e 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -188,12 +188,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/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c
index 0f326d28e2..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);
diff --git a/test/core/support/cancellable_test.c b/test/core/support/cancellable_test.c
index ca206bd839..9b321d388e 100644
--- a/test/core/support/cancellable_test.c
+++ b/test/core/support/cancellable_test.c
@@ -83,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
@@ -114,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);
 
@@ -133,21 +139,24 @@ static void test(void) {
   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/sync_test.c b/test/core/support/sync_test.c
index 73dd06c96f..f729eb0b92 100644
--- a/test/core/support/sync_test.c
+++ b/test/core/support/sync_test.c
@@ -245,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;
@@ -324,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++;
@@ -341,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++;
@@ -385,9 +385,10 @@ static void consumer(void *v /*=m*/) {
   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);
 }
 
diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c
index 29908744ae..594863c278 100644
--- a/test/core/support/time_test.c
+++ b/test/core/support/time_test.c
@@ -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,12 +183,12 @@ 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(GPR_TIMESPAN)) < 0);
   GPR_ASSERT(gpr_time_cmp(x, gpr_inf_future(GPR_TIMESPAN)) == 0);
-  x = gpr_time_from_micros(-1);
+  x = gpr_time_from_micros(-1, GPR_TIMESPAN);
   do {
     x = gpr_time_add(x, x);
   } while (gpr_time_cmp(x, gpr_inf_past(GPR_TIMESPAN)) > 0);
@@ -214,7 +216,7 @@ static void test_sticky_infinities(void) {
       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_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);
@@ -236,21 +238,21 @@ static void test_similar(void) {
   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_time_from_micros(10),
+  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_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_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/transport/chttp2/timeout_encoding_test.c b/test/core/transport/chttp2/timeout_encoding_test.c
index b5ab26768b..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);
   }
 }
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
-- 
GitLab