aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/backoff/BUILD36
-rw-r--r--test/core/backoff/backoff_test.c150
-rw-r--r--test/core/bad_client/bad_client.c15
-rw-r--r--test/core/bad_client/tests/window_overflow.c2
-rw-r--r--test/core/channel/channel_stack_test.c2
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_connectivity_test.c2
-rw-r--r--test/core/end2end/fixtures/http_proxy_fixture.c10
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer.c22
-rwxr-xr-xtest/core/end2end/gen_build_yaml.py1
-rwxr-xr-xtest/core/end2end/generate_tests.bzl1
-rw-r--r--test/core/end2end/h2_ssl_cert_test.cc (renamed from test/core/end2end/fixtures/h2_ssl_cert.c)87
-rw-r--r--test/core/end2end/invalid_call_argument_test.c2
-rw-r--r--test/core/end2end/tests/bad_ping.c17
-rw-r--r--test/core/end2end/tests/keepalive_timeout.c26
-rw-r--r--test/core/http/httpcli_test.c11
-rw-r--r--test/core/http/httpscli_test.c11
-rw-r--r--test/core/iomgr/endpoint_tests.c16
-rw-r--r--test/core/iomgr/ev_epollsig_linux_test.c6
-rw-r--r--test/core/iomgr/fd_posix_test.c24
-rw-r--r--test/core/iomgr/pollset_set_test.c24
-rw-r--r--test/core/iomgr/resolve_address_posix_test.c28
-rw-r--r--test/core/iomgr/resolve_address_test.c28
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c21
-rw-r--r--test/core/iomgr/tcp_client_uv_test.c20
-rw-r--r--test/core/iomgr/tcp_posix_test.c31
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c8
-rw-r--r--test/core/iomgr/tcp_server_uv_test.c4
-rw-r--r--test/core/iomgr/timer_list_test.c83
-rw-r--r--test/core/iomgr/udp_server_test.c12
-rw-r--r--test/core/security/credentials_test.c33
-rw-r--r--test/core/security/jwt_verifier_test.c14
-rw-r--r--test/core/security/oauth2_utils.c3
-rw-r--r--test/core/security/print_google_default_creds_token.c3
-rw-r--r--test/core/security/ssl_server_fuzzer.c3
-rw-r--r--test/core/security/verify_jwt.c8
-rw-r--r--test/core/slice/BUILD14
-rw-r--r--test/core/support/BUILD10
-rw-r--r--test/core/support/backoff_test.c143
-rw-r--r--test/core/surface/concurrent_connectivity_test.c10
-rw-r--r--test/core/surface/init_test.c2
-rw-r--r--test/core/transport/bdp_estimator_test.c24
-rw-r--r--test/core/transport/status_conversion_test.c13
-rw-r--r--test/core/transport/timeout_encoding_test.c119
-rw-r--r--test/core/util/BUILD8
-rw-r--r--test/core/util/fuzzer_corpus_test.cc136
-rw-r--r--test/core/util/grpc_fuzzer.bzl20
-rw-r--r--test/core/util/port_server_client.c14
-rw-r--r--test/core/util/test_tcp_server.c12
-rw-r--r--test/cpp/common/alarm_cpp_test.cc4
-rw-r--r--test/cpp/end2end/async_end2end_test.cc117
-rw-r--r--test/cpp/end2end/end2end_test.cc15
-rw-r--r--test/cpp/end2end/generic_end2end_test.cc2
-rw-r--r--test/cpp/end2end/test_service_impl.cc8
-rw-r--r--test/cpp/microbenchmarks/bm_call_create.cc2
-rw-r--r--test/cpp/microbenchmarks/bm_chttp2_transport.cc6
-rw-r--r--test/cpp/microbenchmarks/bm_cq_multiple_threads.cc6
-rw-r--r--test/cpp/microbenchmarks/bm_error.cc42
-rw-r--r--test/cpp/microbenchmarks/bm_fullstack_trickle.cc35
-rw-r--r--test/cpp/microbenchmarks/bm_pollset.cc9
-rw-r--r--test/cpp/microbenchmarks/fullstack_fixtures.h4
-rw-r--r--test/cpp/naming/resolver_component_test.cc8
-rw-r--r--test/cpp/qps/client.h28
-rw-r--r--test/cpp/qps/client_async.cc1
-rw-r--r--test/cpp/qps/client_sync.cc56
64 files changed, 966 insertions, 666 deletions
diff --git a/test/core/backoff/BUILD b/test/core/backoff/BUILD
new file mode 100644
index 0000000000..4ae762007c
--- /dev/null
+++ b/test/core/backoff/BUILD
@@ -0,0 +1,36 @@
+# Copyright 2016 gRPC authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_cc_binary")
+
+licenses(["notice"]) # Apache v2
+
+package(
+ features = [
+ "-layering_check",
+ "-parse_headers",
+ ],
+)
+
+grpc_cc_test(
+ name = "backoff_test",
+ srcs = ["backoff_test.c"],
+ language = "C",
+ deps = [
+ "//:grpc",
+ "//test/core/util:grpc_test_util",
+ "//:gpr",
+ "//test/core/util:gpr_test_util",
+ ],
+)
diff --git a/test/core/backoff/backoff_test.c b/test/core/backoff/backoff_test.c
new file mode 100644
index 0000000000..a29cce6cc7
--- /dev/null
+++ b/test/core/backoff/backoff_test.c
@@ -0,0 +1,150 @@
+/*
+ *
+ * Copyright 2016 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "src/core/lib/backoff/backoff.h"
+
+#include <grpc/support/log.h>
+
+#include "test/core/util/test_config.h"
+
+static void test_constant_backoff(void) {
+ grpc_backoff backoff;
+ grpc_backoff_init(&backoff, 200 /* initial timeout */, 1.0 /* multiplier */,
+ 0.0 /* jitter */, 100 /* min timeout */,
+ 1000 /* max timeout */);
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis next = grpc_backoff_begin(&exec_ctx, &backoff);
+ GPR_ASSERT(next - grpc_exec_ctx_now(&exec_ctx) == 200);
+ for (int i = 0; i < 10000; i++) {
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next - grpc_exec_ctx_now(&exec_ctx) == 200);
+ exec_ctx.now = next;
+ }
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+static void test_min_connect(void) {
+ grpc_backoff backoff;
+ grpc_backoff_init(&backoff, 100 /* initial timeout */, 1.0 /* multiplier */,
+ 0.0 /* jitter */, 200 /* min timeout */,
+ 1000 /* max timeout */);
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis next = grpc_backoff_begin(&exec_ctx, &backoff);
+ GPR_ASSERT(next - grpc_exec_ctx_now(&exec_ctx) == 200);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+static void test_no_jitter_backoff(void) {
+ grpc_backoff backoff;
+ grpc_backoff_init(&backoff, 2 /* initial timeout */, 2.0 /* multiplier */,
+ 0.0 /* jitter */, 1 /* min timeout */,
+ 513 /* max timeout */);
+ // x_1 = 2
+ // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 )
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ exec_ctx.now = 0;
+ exec_ctx.now_is_valid = true;
+ grpc_millis next = grpc_backoff_begin(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 2);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 6);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 14);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 30);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 62);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 126);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 254);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 510);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 1022);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ // Hit the maximum timeout. From this point onwards, retries will increase
+ // only by max timeout.
+ GPR_ASSERT(next == 1535);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 2048);
+ exec_ctx.now = next;
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+ GPR_ASSERT(next == 2561);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+static void test_jitter_backoff(void) {
+ const int64_t initial_timeout = 500;
+ const double jitter = 0.1;
+ grpc_backoff backoff;
+ grpc_backoff_init(&backoff, (grpc_millis)initial_timeout,
+ 1.0 /* multiplier */, jitter, 100 /* min timeout */,
+ 1000 /* max timeout */);
+
+ backoff.rng_state = 0; // force consistent PRNG
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis next = grpc_backoff_begin(&exec_ctx, &backoff);
+ GPR_ASSERT(next - grpc_exec_ctx_now(&exec_ctx) == 500);
+
+ int64_t expected_next_lower_bound =
+ (int64_t)((double)initial_timeout * (1 - jitter));
+ int64_t expected_next_upper_bound =
+ (int64_t)((double)initial_timeout * (1 + jitter));
+
+ for (int i = 0; i < 10000; i++) {
+ next = grpc_backoff_step(&exec_ctx, &backoff);
+
+ // next-now must be within (jitter*100)% of the previous timeout.
+ const int64_t timeout_millis = next - grpc_exec_ctx_now(&exec_ctx);
+ GPR_ASSERT(timeout_millis >= expected_next_lower_bound);
+ GPR_ASSERT(timeout_millis <= expected_next_upper_bound);
+
+ expected_next_lower_bound =
+ (int64_t)((double)timeout_millis * (1 - jitter));
+ expected_next_upper_bound =
+ (int64_t)((double)timeout_millis * (1 + jitter));
+ exec_ctx.now = next;
+ }
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ gpr_time_init();
+
+ test_constant_backoff();
+ test_min_connect();
+ test_no_jitter_backoff();
+ test_jitter_backoff();
+
+ return 0;
+}
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c
index fff0c793ed..b7b28a9ac4 100644
--- a/test/core/bad_client/bad_client.c
+++ b/test/core/bad_client/bad_client.c
@@ -84,13 +84,18 @@ void grpc_run_bad_client_test(
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_completion_queue *shutdown_cq;
- hex = gpr_dump(client_payload, client_payload_length,
- GPR_DUMP_HEX | GPR_DUMP_ASCII);
+ if (client_payload_length < 4 * 1024) {
+ hex = gpr_dump(client_payload, client_payload_length,
+ GPR_DUMP_HEX | GPR_DUMP_ASCII);
- /* Add a debug log */
- gpr_log(GPR_INFO, "TEST: %s", hex);
+ /* Add a debug log */
+ gpr_log(GPR_INFO, "TEST: %s", hex);
- gpr_free(hex);
+ gpr_free(hex);
+ } else {
+ gpr_log(GPR_INFO, "TEST: (%" PRIdPTR " byte long string)",
+ client_payload_length);
+ }
/* Init grpc */
grpc_init();
diff --git a/test/core/bad_client/tests/window_overflow.c b/test/core/bad_client/tests/window_overflow.c
index 18c647ad8a..e4b5f9711b 100644
--- a/test/core/bad_client/tests/window_overflow.c
+++ b/test/core/bad_client/tests/window_overflow.c
@@ -69,7 +69,7 @@ int main(int argc, char **argv) {
#define MAX_FRAME_SIZE 16384
#define MESSAGES_PER_FRAME (MAX_FRAME_SIZE / 5)
#define FRAME_SIZE (MESSAGES_PER_FRAME * 5)
-#define SEND_SIZE (100 * 1024)
+#define SEND_SIZE (6 * 1024 * 1024)
#define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1)
grpc_test_init(argc, argv);
diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c
index 7c3614b4a2..a07ef89ba8 100644
--- a/test/core/channel/channel_stack_test.c
+++ b/test/core/channel/channel_stack_test.c
@@ -125,7 +125,7 @@ static void test_create_channel_stack(void) {
.context = NULL,
.path = path,
.start_time = gpr_now(GPR_CLOCK_MONOTONIC),
- .deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC),
+ .deadline = GRPC_MILLIS_INF_FUTURE,
.arena = NULL};
grpc_error *error = grpc_call_stack_init(&exec_ctx, channel_stack, 1,
free_call, call_stack, &args);
diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
index 364e180963..4597285063 100644
--- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
+++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
@@ -106,7 +106,7 @@ static bool wait_loop(int deadline_seconds, gpr_event *ev) {
deadline_seconds--;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_timer_check(&exec_ctx, gpr_now(GPR_CLOCK_MONOTONIC), NULL);
+ grpc_timer_check(&exec_ctx, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
return false;
diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c
index a4cfc77bcb..d29401fdc3 100644
--- a/test/core/end2end/fixtures/http_proxy_fixture.c
+++ b/test/core/end2end/fixtures/http_proxy_fixture.c
@@ -412,8 +412,8 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg,
GPR_ASSERT(resolved_addresses->naddrs >= 1);
// Connect to requested address.
// The connection callback inherits our reference to conn.
- const gpr_timespec deadline = gpr_time_add(
- gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(10, GPR_TIMESPAN));
+ const grpc_millis deadline =
+ grpc_exec_ctx_now(exec_ctx) + 10 * GPR_MS_PER_SEC;
grpc_tcp_client_connect(exec_ctx, &conn->on_server_connect_done,
&conn->server_endpoint, conn->pollset_set, NULL,
&resolved_addresses->addrs[0], deadline);
@@ -469,14 +469,12 @@ static void thread_main(void* arg) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
do {
gpr_ref(&proxy->users);
- const gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
- const gpr_timespec deadline =
- gpr_time_add(now, gpr_time_from_seconds(1, GPR_TIMESPAN));
grpc_pollset_worker* worker = NULL;
gpr_mu_lock(proxy->mu);
GRPC_LOG_IF_ERROR(
"grpc_pollset_work",
- grpc_pollset_work(&exec_ctx, proxy->pollset, &worker, now, deadline));
+ grpc_pollset_work(&exec_ctx, proxy->pollset, &worker,
+ grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC));
gpr_mu_unlock(proxy->mu);
grpc_exec_ctx_flush(&exec_ctx);
} while (!gpr_unref(&proxy->users));
diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c
index 1228c9fe9a..0a787bbf30 100644
--- a/test/core/end2end/fuzzers/api_fuzzer.c
+++ b/test/core/end2end/fuzzers/api_fuzzer.c
@@ -60,7 +60,9 @@ extern gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type);
static gpr_timespec now_impl(gpr_clock_type clock_type) {
GPR_ASSERT(clock_type != GPR_TIMESPAN);
- return g_now;
+ gpr_timespec ts = g_now;
+ ts.clock_type = clock_type;
+ return ts;
}
////////////////////////////////////////////////////////////////////////////////
@@ -407,10 +409,8 @@ void my_resolve_address(grpc_exec_ctx *exec_ctx, const char *addr,
r->addrs = addresses;
r->lb_addrs = NULL;
grpc_timer_init(
- exec_ctx, &r->timer, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_seconds(1, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx),
- gpr_now(GPR_CLOCK_MONOTONIC));
+ exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx),
+ GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx));
}
grpc_ares_request *my_dns_lookup_ares(
@@ -424,10 +424,8 @@ grpc_ares_request *my_dns_lookup_ares(
r->addrs = NULL;
r->lb_addrs = lb_addrs;
grpc_timer_init(
- exec_ctx, &r->timer, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_seconds(1, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx),
- gpr_now(GPR_CLOCK_MONOTONIC));
+ exec_ctx, &r->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx),
+ GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx));
return NULL;
}
@@ -487,10 +485,8 @@ static void sched_connect(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
fc->ep = ep;
fc->deadline = deadline;
grpc_timer_init(
- exec_ctx, &fc->timer, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_millis(1, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx),
- gpr_now(GPR_CLOCK_MONOTONIC));
+ exec_ctx, &fc->timer, GPR_MS_PER_SEC + grpc_exec_ctx_now(exec_ctx),
+ GRPC_CLOSURE_CREATE(do_connect, fc, grpc_schedule_on_exec_ctx));
}
static void my_tcp_client_connect(grpc_exec_ctx *exec_ctx,
diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py
index 33fd97f3bd..e1dc69994c 100755
--- a/test/core/end2end/gen_build_yaml.py
+++ b/test/core/end2end/gen_build_yaml.py
@@ -60,7 +60,6 @@ END2END_FIXTURES = {
'h2_sockpair+trace': socketpair_unsecure_fixture_options._replace(
ci_mac=False, tracing=True, large_writes=False, exclude_iomgrs=['uv']),
'h2_ssl': default_secure_fixture_options,
- 'h2_ssl_cert': default_secure_fixture_options,
'h2_ssl_proxy': default_secure_fixture_options._replace(
includes_proxy=True, ci_mac=False, exclude_iomgrs=['uv']),
'h2_uds': uds_fixture_options,
diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl
index 9bbba26108..d48ddb4606 100755
--- a/test/core/end2end/generate_tests.bzl
+++ b/test/core/end2end/generate_tests.bzl
@@ -56,7 +56,6 @@ END2END_FIXTURES = {
'h2_sockpair+trace': fixture_options(fullstack=False, dns_resolver=False,
tracing=True),
'h2_ssl': fixture_options(secure=True),
- 'h2_ssl_cert': fixture_options(secure=True),
'h2_ssl_proxy': fixture_options(includes_proxy=True, secure=True),
'h2_uds': fixture_options(dns_resolver=False,
platforms=['linux', 'mac', 'posix']),
diff --git a/test/core/end2end/fixtures/h2_ssl_cert.c b/test/core/end2end/h2_ssl_cert_test.cc
index 9b1ddadfe4..6da5e8396e 100644
--- a/test/core/end2end/fixtures/h2_ssl_cert.c
+++ b/test/core/end2end/h2_ssl_cert_test.cc
@@ -16,7 +16,9 @@
*
*/
+extern "C" {
#include "test/core/end2end/end2end_tests.h"
+}
#include <stdio.h>
#include <string.h>
@@ -25,6 +27,7 @@
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
+extern "C" {
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/support/env.h"
@@ -34,8 +37,12 @@
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
+}
-extern void simple_request(grpc_end2end_test_config config);
+#include <gtest/gtest.h>
+
+namespace grpc {
+namespace testing {
typedef struct fullstack_secure_fixture_data {
char *localaddr;
@@ -46,7 +53,8 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data *ffd =
- gpr_malloc(sizeof(fullstack_secure_fixture_data));
+ static_cast<fullstack_secure_fixture_data *>(
+ gpr_malloc(sizeof(fullstack_secure_fixture_data)));
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
@@ -69,7 +77,8 @@ static void process_auth_failure(void *state, grpc_auth_context *ctx,
static void chttp2_init_client_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *client_args,
grpc_channel_credentials *creds) {
- fullstack_secure_fixture_data *ffd = f->fixture_data;
+ fullstack_secure_fixture_data *ffd =
+ static_cast<fullstack_secure_fixture_data *>(f->fixture_data);
f->client =
grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL);
GPR_ASSERT(f->client != NULL);
@@ -79,7 +88,8 @@ static void chttp2_init_client_secure_fullstack(
static void chttp2_init_server_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *server_args,
grpc_server_credentials *server_creds) {
- fullstack_secure_fixture_data *ffd = f->fixture_data;
+ fullstack_secure_fixture_data *ffd =
+ static_cast<fullstack_secure_fixture_data *>(f->fixture_data);
if (f->server) {
grpc_server_destroy(f->server);
}
@@ -92,7 +102,8 @@ static void chttp2_init_server_secure_fullstack(
}
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
- fullstack_secure_fixture_data *ffd = f->fixture_data;
+ fullstack_secure_fixture_data *ffd =
+ static_cast<fullstack_secure_fixture_data *>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
}
@@ -166,9 +177,10 @@ typedef enum { NONE, SELF_SIGNED, SIGNED, BAD_CERT_PAIR } certtype;
} \
ssl_creds = \
grpc_ssl_credentials_create(test_root_cert, key_cert_pair, NULL); \
- grpc_arg ssl_name_override = {GRPC_ARG_STRING, \
- GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, \
- {"foo.test.google.fr"}}; \
+ grpc_arg ssl_name_override = { \
+ GRPC_ARG_STRING, \
+ const_cast<char *>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), \
+ {const_cast<char *>("foo.test.google.fr")}}; \
grpc_channel_args *new_client_args = \
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); \
chttp2_init_client_secure_fullstack(f, new_client_args, ssl_creds); \
@@ -248,18 +260,6 @@ static grpc_end2end_test_config_wrapper configs[] = {
static void *tag(intptr_t t) { return (void *)t; }
-static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
- const char *test_name,
- grpc_channel_args *client_args,
- grpc_channel_args *server_args) {
- grpc_end2end_test_fixture f;
- gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
- f = config.create_fixture(client_args, server_args);
- config.init_server(&f, server_args);
- config.init_client(&f, client_args);
- return f;
-}
-
static gpr_timespec n_seconds_time(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
@@ -319,7 +319,7 @@ static void simple_request_body(grpc_end2end_test_fixture f,
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
- op->flags = 0;
+ op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
op->reserved = NULL;
op++;
error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
@@ -332,15 +332,40 @@ static void simple_request_body(grpc_end2end_test_fixture f,
cq_verifier_destroy(cqv);
}
+class H2SslCertTest
+ : public ::testing::TestWithParam<grpc_end2end_test_config_wrapper> {
+ protected:
+ H2SslCertTest() {
+ gpr_log(GPR_INFO, "SSL_CERT_tests/%s", GetParam().config.name);
+ }
+ void SetUp() override {
+ fixture_ = GetParam().config.create_fixture(nullptr, nullptr);
+ GetParam().config.init_server(&fixture_, nullptr);
+ GetParam().config.init_client(&fixture_, nullptr);
+ }
+ void TearDown() override {
+ end_test(&fixture_);
+ GetParam().config.tear_down_data(&fixture_);
+ }
+
+ grpc_end2end_test_fixture fixture_;
+};
+
+TEST_P(H2SslCertTest, SimpleRequestBody) {
+ simple_request_body(fixture_, GetParam().result);
+}
+
+INSTANTIATE_TEST_CASE_P(H2SslCert, H2SslCertTest, ::testing::ValuesIn(configs));
+
+} // namespace testing
+} // namespace grpc
+
int main(int argc, char **argv) {
- size_t i;
FILE *roots_file;
size_t roots_size = strlen(test_root_cert);
char *roots_filename;
grpc_test_init(argc, argv);
- grpc_end2end_tests_pre_init();
-
/* Set the SSL roots env var. */
roots_file =
gpr_tmpfile("chttp2_simple_ssl_cert_fullstack_test", &roots_filename);
@@ -351,21 +376,13 @@ int main(int argc, char **argv) {
gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_filename);
grpc_init();
-
- for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
- grpc_end2end_test_fixture f =
- begin_test(configs[i].config, "SSL_CERT_tests", NULL, NULL);
-
- simple_request_body(f, configs[i].result);
- end_test(&f);
- configs[i].config.tear_down_data(&f);
- }
-
+ ::testing::InitGoogleTest(&argc, argv);
+ int ret = RUN_ALL_TESTS();
grpc_shutdown();
/* Cleanup. */
remove(roots_filename);
gpr_free(roots_filename);
- return 0;
+ return ret;
}
diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c
index bf0d08adec..e3fd5a8fbe 100644
--- a/test/core/end2end/invalid_call_argument_test.c
+++ b/test/core/end2end/invalid_call_argument_test.c
@@ -92,7 +92,7 @@ static void prepare_test(int is_client) {
op = g_state.ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
- op->flags = 0;
+ op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
op->reserved = NULL;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
diff --git a/test/core/end2end/tests/bad_ping.c b/test/core/end2end/tests/bad_ping.c
index c97d11b306..d442f12480 100644
--- a/test/core/end2end/tests/bad_ping.c
+++ b/test/core/end2end/tests/bad_ping.c
@@ -155,14 +155,16 @@ static void test_bad_ping(grpc_end2end_test_config config) {
cq_verify(cqv);
// Send too many pings to the server to trigger the punishment:
- // The first ping is sent after data frames, it won't trigger a ping strike.
- // Each of the following pings will trigger a ping strike, and we need at
- // least (MAX_PING_STRIKES + 1) strikes to trigger the punishment. So
- // (MAX_PING_STRIKES + 2) pings are needed here.
+ // Each ping will trigger a ping strike, and we need at least MAX_PING_STRIKES
+ // strikes to trigger the punishment. So (MAX_PING_STRIKES + 1) pings are
+ // needed here.
int i;
- for (i = 200; i < 202 + MAX_PING_STRIKES; i++) {
- grpc_channel_ping(f.client, f.cq, tag(i), NULL);
- CQ_EXPECT_COMPLETION(cqv, tag(i), 1);
+ for (i = 1; i <= MAX_PING_STRIKES + 1; i++) {
+ grpc_channel_ping(f.client, f.cq, tag(200 + i), NULL);
+ CQ_EXPECT_COMPLETION(cqv, tag(200 + i), 1);
+ if (i == MAX_PING_STRIKES + 1) {
+ CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
+ }
cq_verify(cqv);
}
@@ -190,7 +192,6 @@ static void test_bad_ping(grpc_end2end_test_config config) {
GPR_ASSERT(GRPC_CALL_OK == error);
CQ_EXPECT_COMPLETION(cqv, tag(102), 1);
- CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);
grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
diff --git a/test/core/end2end/tests/keepalive_timeout.c b/test/core/end2end/tests/keepalive_timeout.c
index 8d01f23c00..c4280149c7 100644
--- a/test/core/end2end/tests/keepalive_timeout.c
+++ b/test/core/end2end/tests/keepalive_timeout.c
@@ -98,21 +98,21 @@ static void test_keepalive_timeout(grpc_end2end_test_config config) {
grpc_byte_buffer *response_payload =
grpc_raw_byte_buffer_create(&response_payload_slice, 1);
- grpc_arg keepalive_args[] = {{.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_KEEPALIVE_TIME_MS,
- .value.integer = 1500},
- {.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_KEEPALIVE_TIMEOUT_MS,
- .value.integer = 0},
- {.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_HTTP2_BDP_PROBE,
- .value.integer = 0}};
-
- grpc_channel_args client_args = {.num_args = GPR_ARRAY_SIZE(keepalive_args),
- .args = keepalive_args};
+ grpc_arg keepalive_arg_elems[] = {{.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_KEEPALIVE_TIME_MS,
+ .value.integer = 1500},
+ {.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_KEEPALIVE_TIMEOUT_MS,
+ .value.integer = 0},
+ {.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_HTTP2_BDP_PROBE,
+ .value.integer = 0}};
+ grpc_channel_args keepalive_args = {
+ .num_args = GPR_ARRAY_SIZE(keepalive_arg_elems),
+ .args = keepalive_arg_elems};
grpc_end2end_test_fixture f =
- begin_test(config, "keepalive_timeout", &client_args, NULL);
+ begin_test(config, "keepalive_timeout", &keepalive_args, NULL);
cq_verifier *cqv = cq_verifier_create(f.cq);
grpc_op ops[6];
grpc_op *op;
diff --git a/test/core/http/httpcli_test.c b/test/core/http/httpcli_test.c
index 8a53903763..cc1c16d695 100644
--- a/test/core/http/httpcli_test.c
+++ b/test/core/http/httpcli_test.c
@@ -35,8 +35,9 @@ static grpc_httpcli_context g_context;
static gpr_mu *g_mu;
static grpc_polling_entity g_pops;
-static gpr_timespec n_seconds_time(int seconds) {
- return grpc_timeout_seconds_to_deadline(seconds);
+static grpc_millis n_seconds_time(int seconds) {
+ return grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
}
static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
@@ -86,8 +87,7 @@ static void test_get(int port) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(1))));
+ &worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -128,8 +128,7 @@ static void test_post(int port) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(1))));
+ &worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/http/httpscli_test.c b/test/core/http/httpscli_test.c
index c7455bd8df..f8a3cfdd76 100644
--- a/test/core/http/httpscli_test.c
+++ b/test/core/http/httpscli_test.c
@@ -35,8 +35,9 @@ static grpc_httpcli_context g_context;
static gpr_mu *g_mu;
static grpc_polling_entity g_pops;
-static gpr_timespec n_seconds_time(int seconds) {
- return grpc_timeout_seconds_to_deadline(seconds);
+static grpc_millis n_seconds_time(int seconds) {
+ return grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
}
static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
@@ -87,8 +88,7 @@ static void test_get(int port) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(1))));
+ &worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -130,8 +130,7 @@ static void test_post(int port) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(1))));
+ &worker, n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c
index f8570edde7..61e901f645 100644
--- a/test/core/iomgr/endpoint_tests.c
+++ b/test/core/iomgr/endpoint_tests.c
@@ -176,10 +176,11 @@ static void read_and_write_test(grpc_endpoint_test_config config,
size_t num_bytes, size_t write_size,
size_t slice_size, bool shutdown) {
struct read_and_write_test_state state;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
grpc_endpoint_test_fixture f =
begin_test(config, "read_and_write_test", slice_size);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
gpr_log(GPR_DEBUG, "num_bytes=%" PRIuPTR " write_size=%" PRIuPTR
" slice_size=%" PRIuPTR " shutdown=%d",
num_bytes, write_size, slice_size, shutdown);
@@ -235,11 +236,10 @@ static void read_and_write_test(grpc_endpoint_test_config config,
gpr_mu_lock(g_mu);
while (!state.read_done || !state.write_done) {
grpc_pollset_worker *worker = NULL;
- GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), deadline) < 0);
+ GPR_ASSERT(grpc_exec_ctx_now(&exec_ctx) < deadline);
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
}
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(&exec_ctx);
@@ -265,14 +265,14 @@ static void wait_for_fail_count(grpc_exec_ctx *exec_ctx, int *fail_count,
int want_fail_count) {
grpc_exec_ctx_flush(exec_ctx);
gpr_mu_lock(g_mu);
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10);
- while (gpr_time_cmp(gpr_now(deadline.clock_type), deadline) < 0 &&
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
+ while (grpc_exec_ctx_now(exec_ctx) < deadline &&
*fail_count < want_fail_count) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(exec_ctx, g_pollset, &worker,
- gpr_now(deadline.clock_type), deadline)));
+ grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/ev_epollsig_linux_test.c b/test/core/iomgr/ev_epollsig_linux_test.c
index cca07bf002..37aadacd49 100644
--- a/test/core/iomgr/ev_epollsig_linux_test.c
+++ b/test/core/iomgr/ev_epollsig_linux_test.c
@@ -238,10 +238,8 @@ static void test_threading_loop(void *arg) {
grpc_pollset_worker *worker;
gpr_mu_lock(shared->mu);
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, shared->pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, shared->pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(shared->mu);
grpc_exec_ctx_finish(&exec_ctx);
}
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index 881277a8d6..1c62f34d3e 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -252,10 +252,8 @@ static void server_wait_and_shutdown(server *sv) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -371,10 +369,8 @@ static void client_wait_and_shutdown(client *cl) {
grpc_pollset_worker *worker = NULL;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -477,10 +473,8 @@ static void test_grpc_fd_change(void) {
while (a.cb_that_ran == NULL) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -503,10 +497,8 @@ static void test_grpc_fd_change(void) {
while (b.cb_that_ran == NULL) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))));
+ "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c
index aa1ad37927..cddc146ce0 100644
--- a/test/core/iomgr/pollset_set_test.c
+++ b/test/core/iomgr/pollset_set_test.c
@@ -204,7 +204,7 @@ static void pollset_set_test_basic() {
*/
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker;
- gpr_timespec deadline;
+ grpc_millis deadline;
test_fd tfds[10];
test_pollset pollsets[3];
@@ -257,10 +257,10 @@ static void pollset_set_test_basic() {
make_test_fds_readable(tfds, num_fds);
gpr_mu_lock(pollsets[i].mu);
- deadline = grpc_timeout_milliseconds_to_deadline(2);
+ deadline = grpc_timespec_to_millis_round_up(
+ grpc_timeout_milliseconds_to_deadline(2));
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline));
+ grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker, deadline));
gpr_mu_unlock(pollsets[i].mu);
grpc_exec_ctx_flush(&exec_ctx);
@@ -309,7 +309,7 @@ void pollset_set_test_dup_fds() {
*/
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker;
- gpr_timespec deadline;
+ grpc_millis deadline;
test_fd tfds[3];
test_pollset pollset;
@@ -339,10 +339,10 @@ void pollset_set_test_dup_fds() {
make_test_fds_readable(tfds, num_fds);
gpr_mu_lock(pollset.mu);
- deadline = grpc_timeout_milliseconds_to_deadline(2);
+ deadline = grpc_timespec_to_millis_round_up(
+ grpc_timeout_milliseconds_to_deadline(2));
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_pollset_work(&exec_ctx, pollset.ps, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline));
+ grpc_pollset_work(&exec_ctx, pollset.ps, &worker, deadline));
gpr_mu_unlock(pollset.mu);
grpc_exec_ctx_flush(&exec_ctx);
@@ -382,7 +382,7 @@ void pollset_set_test_empty_pollset() {
*/
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_worker *worker;
- gpr_timespec deadline;
+ grpc_millis deadline;
test_fd tfds[3];
test_pollset pollsets[2];
@@ -408,10 +408,10 @@ void pollset_set_test_empty_pollset() {
make_test_fds_readable(tfds, num_fds);
gpr_mu_lock(pollsets[0].mu);
- deadline = grpc_timeout_milliseconds_to_deadline(2);
+ deadline = grpc_timespec_to_millis_round_up(
+ grpc_timeout_milliseconds_to_deadline(2));
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline));
+ grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker, deadline));
gpr_mu_unlock(pollsets[0].mu);
grpc_exec_ctx_flush(&exec_ctx);
diff --git a/test/core/iomgr/resolve_address_posix_test.c b/test/core/iomgr/resolve_address_posix_test.c
index e4be99f03c..cb9d6080fb 100644
--- a/test/core/iomgr/resolve_address_posix_test.c
+++ b/test/core/iomgr/resolve_address_posix_test.c
@@ -72,35 +72,33 @@ void args_finish(grpc_exec_ctx *exec_ctx, args_struct *args) {
gpr_free(args->pollset);
}
-static gpr_timespec n_sec_deadline(int seconds) {
- return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_seconds(seconds, GPR_TIMESPAN));
+static grpc_millis n_sec_deadline(int seconds) {
+ return grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
}
static void actually_poll(void *argsp) {
args_struct *args = argsp;
- gpr_timespec deadline = n_sec_deadline(10);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis deadline = n_sec_deadline(10);
while (true) {
bool done = gpr_atm_acq_load(&args->done_atm) != 0;
if (done) {
break;
}
- gpr_timespec time_left =
- gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME));
- gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09d", done,
- time_left.tv_sec, time_left.tv_nsec);
- GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0);
+ grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx);
+ gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left);
+ GPR_ASSERT(time_left >= 0);
grpc_pollset_worker *worker = NULL;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_mu_lock(args->mu);
- GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, args->pollset, &worker,
- gpr_now(GPR_CLOCK_REALTIME), n_sec_deadline(1)));
+ GRPC_LOG_IF_ERROR("pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker,
+ n_sec_deadline(1)));
gpr_mu_unlock(args->mu);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
}
gpr_event_set(&args->ev, (void *)1);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void poll_pollset_until_request_done(args_struct *args) {
diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c
index 1110c04b6e..178bbbb95f 100644
--- a/test/core/iomgr/resolve_address_test.c
+++ b/test/core/iomgr/resolve_address_test.c
@@ -68,34 +68,32 @@ void args_finish(grpc_exec_ctx *exec_ctx, args_struct *args) {
gpr_free(args->pollset);
}
-static gpr_timespec n_sec_deadline(int seconds) {
- return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_seconds(seconds, GPR_TIMESPAN));
+static grpc_millis n_sec_deadline(int seconds) {
+ return grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
}
static void poll_pollset_until_request_done(args_struct *args) {
- gpr_timespec deadline = n_sec_deadline(10);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis deadline = n_sec_deadline(10);
while (true) {
bool done = gpr_atm_acq_load(&args->done_atm) != 0;
if (done) {
break;
}
- gpr_timespec time_left =
- gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME));
- gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09d", done,
- time_left.tv_sec, time_left.tv_nsec);
- GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0);
+ grpc_millis time_left = deadline - grpc_exec_ctx_now(&exec_ctx);
+ gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRIdPTR, done, time_left);
+ GPR_ASSERT(time_left >= 0);
grpc_pollset_worker *worker = NULL;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_mu_lock(args->mu);
- GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, args->pollset, &worker,
- gpr_now(GPR_CLOCK_REALTIME), n_sec_deadline(1)));
+ GRPC_LOG_IF_ERROR("pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker,
+ n_sec_deadline(1)));
gpr_mu_unlock(args->mu);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
}
gpr_event_set(&args->ev, (void *)1);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void must_succeed(grpc_exec_ctx *exec_ctx, void *argsp,
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 1032da942b..b8b76d1c42 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -46,8 +46,8 @@ static grpc_pollset *g_pollset;
static int g_connections_complete = 0;
static grpc_endpoint *g_connecting = NULL;
-static gpr_timespec test_deadline(void) {
- return grpc_timeout_seconds_to_deadline(10);
+static grpc_millis test_deadline(void) {
+ return grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
}
static void finish_connection() {
@@ -109,7 +109,7 @@ void test_succeeds(void) {
(socklen_t *)&resolved_addr.len) == 0);
GRPC_CLOSURE_INIT(&done, must_succeed, NULL, grpc_schedule_on_exec_ctx);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, NULL,
- &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, GRPC_MILLIS_INF_FUTURE);
/* await the connection */
do {
@@ -127,8 +127,8 @@ void test_succeeds(void) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_seconds_to_deadline(5))));
+ grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(5)))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -159,25 +159,24 @@ void test_fails(void) {
/* connect to a broken address */
GRPC_CLOSURE_INIT(&done, must_fail, NULL, grpc_schedule_on_exec_ctx);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, NULL,
- &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, GRPC_MILLIS_INF_FUTURE);
gpr_mu_lock(g_mu);
/* wait for the connection callback to finish */
while (g_connections_complete == connections_complete_before) {
grpc_pollset_worker *worker = NULL;
- gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
- gpr_timespec polling_deadline = test_deadline();
- switch (grpc_timer_check(&exec_ctx, now, &polling_deadline)) {
+ grpc_millis polling_deadline = test_deadline();
+ switch (grpc_timer_check(&exec_ctx, &polling_deadline)) {
case GRPC_TIMERS_FIRED:
break;
case GRPC_TIMERS_NOT_CHECKED:
- polling_deadline = now;
+ polling_deadline = 0;
/* fall through */
case GRPC_TIMERS_CHECKED_AND_EMPTY:
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- now, polling_deadline)));
+ polling_deadline)));
break;
}
gpr_mu_unlock(g_mu);
diff --git a/test/core/iomgr/tcp_client_uv_test.c b/test/core/iomgr/tcp_client_uv_test.c
index 0f1db4705b..edfccbe867 100644
--- a/test/core/iomgr/tcp_client_uv_test.c
+++ b/test/core/iomgr/tcp_client_uv_test.c
@@ -42,8 +42,8 @@ static grpc_pollset *g_pollset;
static int g_connections_complete = 0;
static grpc_endpoint *g_connecting = NULL;
-static gpr_timespec test_deadline(void) {
- return grpc_timeout_seconds_to_deadline(10);
+static grpc_millis test_deadline(void) {
+ return grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
}
static void finish_connection(grpc_exec_ctx *exec_ctx) {
@@ -110,7 +110,7 @@ void test_succeeds(void) {
(int *)&resolved_addr.len) == 0);
GRPC_CLOSURE_INIT(&done, must_succeed, NULL, grpc_schedule_on_exec_ctx);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, NULL, NULL,
- &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, GRPC_MILLIS_INF_FUTURE);
gpr_mu_lock(g_mu);
@@ -119,8 +119,8 @@ void test_succeeds(void) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_seconds_to_deadline(5))));
+ grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(5)))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -154,7 +154,7 @@ void test_fails(void) {
/* connect to a broken address */
GRPC_CLOSURE_INIT(&done, must_fail, NULL, grpc_schedule_on_exec_ctx);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, NULL, NULL,
- &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, GRPC_MILLIS_INF_FUTURE);
gpr_mu_lock(g_mu);
@@ -162,17 +162,17 @@ void test_fails(void) {
while (g_connections_complete == connections_complete_before) {
grpc_pollset_worker *worker = NULL;
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
- gpr_timespec polling_deadline = test_deadline();
- switch (grpc_timer_check(&exec_ctx, now, &polling_deadline)) {
+ grpc_millis polling_deadline = test_deadline();
+ switch (grpc_timer_check(&exec_ctx, &polling_deadline)) {
case GRPC_TIMERS_FIRED:
break;
case GRPC_TIMERS_NOT_CHECKED:
- polling_deadline = now;
+ polling_deadline = grpc_timespec_to_millis_round_up(now);
/* fall through */
case GRPC_TIMERS_CHECKED_AND_EMPTY:
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- now, polling_deadline)));
+ polling_deadline)));
break;
}
gpr_mu_unlock(g_mu);
diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c
index cfb3cf897c..6501160c6f 100644
--- a/test/core/iomgr/tcp_posix_test.c
+++ b/test/core/iomgr/tcp_posix_test.c
@@ -162,7 +162,8 @@ static void read_test(size_t num_bytes, size_t slice_size) {
grpc_endpoint *ep;
struct read_socket_state state;
size_t written_bytes;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR,
@@ -194,8 +195,7 @@ static void read_test(size_t num_bytes, size_t slice_size) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -215,7 +215,8 @@ static void large_read_test(size_t slice_size) {
grpc_endpoint *ep;
struct read_socket_state state;
ssize_t written_bytes;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size);
@@ -246,8 +247,7 @@ static void large_read_test(size_t slice_size) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -319,8 +319,8 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) {
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_milliseconds_to_deadline(10))));
+ grpc_timespec_to_millis_round_up(
+ grpc_timeout_milliseconds_to_deadline(10)))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
do {
@@ -353,7 +353,8 @@ static void write_test(size_t num_bytes, size_t slice_size) {
uint8_t current_data = 0;
grpc_slice_buffer outgoing;
grpc_closure write_done_closure;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_INFO,
@@ -390,8 +391,7 @@ static void write_test(size_t num_bytes, size_t slice_size) {
}
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -419,7 +419,8 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
struct read_socket_state state;
size_t written_bytes;
int fd;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(20);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_closure fd_released_cb;
int fd_released_done = 0;
@@ -457,8 +458,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_log(GPR_DEBUG, "wakeup: read=%" PRIdPTR " target=%" PRIdPTR,
state.read_bytes, state.target_read_bytes);
gpr_mu_unlock(g_mu);
@@ -476,8 +476,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_log(GPR_DEBUG, "wakeup: fd_released_done=%d", fd_released_done);
}
gpr_mu_unlock(g_mu);
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 4d84608376..782dfb413a 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -230,7 +230,8 @@ static void test_no_op_with_port_and_start(void) {
static grpc_error *tcp_connect(grpc_exec_ctx *exec_ctx, const test_addr *remote,
on_connect_result *result) {
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(10);
+ grpc_millis deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
int clifd;
int nconnects_before;
const struct sockaddr *remote_addr =
@@ -253,11 +254,10 @@ static grpc_error *tcp_connect(grpc_exec_ctx *exec_ctx, const test_addr *remote,
}
gpr_log(GPR_DEBUG, "wait");
while (g_nconnects == nconnects_before &&
- gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
+ deadline > grpc_exec_ctx_now(exec_ctx)) {
grpc_pollset_worker *worker = NULL;
grpc_error *err;
- if ((err = grpc_pollset_work(exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)) !=
+ if ((err = grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline)) !=
GRPC_ERROR_NONE) {
gpr_mu_unlock(g_mu);
close(clifd);
diff --git a/test/core/iomgr/tcp_server_uv_test.c b/test/core/iomgr/tcp_server_uv_test.c
index bd8ccb4f60..9fafd3177a 100644
--- a/test/core/iomgr/tcp_server_uv_test.c
+++ b/test/core/iomgr/tcp_server_uv_test.c
@@ -207,7 +207,7 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote,
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_timespec_to_millis_round_up(deadline))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(exec_ctx);
gpr_mu_lock(g_mu);
@@ -246,7 +246,7 @@ static void test_connect(unsigned n) {
GPR_ASSERT(GRPC_ERROR_NONE ==
grpc_tcp_server_add_port(s, &resolved_addr, &svr_port));
GPR_ASSERT(svr_port > 0);
- GPR_ASSERT(uv_ip6_addr("::", svr_port, (struct sockaddr_in6 *)addr) == 0);
+ GPR_ASSERT((uv_ip6_addr("::", svr_port, (struct sockaddr_in6 *)addr)) == 0);
/* Cannot use wildcard (port==0), because add_port() will try to reuse the
same port as a previous add_port(). */
svr1_port = grpc_pick_unused_port_or_die();
diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c
index 5f8b01fdc4..c3d9f9d88d 100644
--- a/test/core/iomgr/timer_list_test.c
+++ b/test/core/iomgr/timer_list_test.c
@@ -41,51 +41,45 @@ static void cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
}
static void add_test(void) {
- gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME);
int i;
grpc_timer timers[20];
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_INFO, "add_test");
- grpc_timer_list_init(start);
+ grpc_timer_list_init(&exec_ctx);
grpc_timer_trace.value = 1;
grpc_timer_check_trace.value = 1;
memset(cb_called, 0, sizeof(cb_called));
+ grpc_millis start = grpc_exec_ctx_now(&exec_ctx);
+
/* 10 ms timers. will expire in the current epoch */
for (i = 0; i < 10; i++) {
- grpc_timer_init(
- &exec_ctx, &timers[i],
- gpr_time_add(start, gpr_time_from_millis(10, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)i, grpc_schedule_on_exec_ctx),
- start);
+ grpc_timer_init(&exec_ctx, &timers[i], start + 10,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)i,
+ grpc_schedule_on_exec_ctx));
}
/* 1010 ms timers. will expire in the next epoch */
for (i = 10; i < 20; i++) {
- grpc_timer_init(
- &exec_ctx, &timers[i],
- gpr_time_add(start, gpr_time_from_millis(1010, GPR_TIMESPAN)),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)i, grpc_schedule_on_exec_ctx),
- start);
+ grpc_timer_init(&exec_ctx, &timers[i], start + 1010,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)i,
+ grpc_schedule_on_exec_ctx));
}
/* collect timers. Only the first batch should be ready. */
- GPR_ASSERT(grpc_timer_check(
- &exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(500, GPR_TIMESPAN)),
- NULL) == GRPC_TIMERS_FIRED);
+ exec_ctx.now = start + 500;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) == GRPC_TIMERS_FIRED);
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 20; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
GPR_ASSERT(cb_called[i][0] == 0);
}
- GPR_ASSERT(grpc_timer_check(
- &exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(600, GPR_TIMESPAN)),
- NULL) == GRPC_TIMERS_CHECKED_AND_EMPTY);
+ exec_ctx.now = start + 600;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) ==
+ GRPC_TIMERS_CHECKED_AND_EMPTY);
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 10));
@@ -93,20 +87,17 @@ static void add_test(void) {
}
/* collect the rest of the timers */
- GPR_ASSERT(grpc_timer_check(
- &exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(1500, GPR_TIMESPAN)),
- NULL) == GRPC_TIMERS_FIRED);
+ exec_ctx.now = start + 1500;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) == GRPC_TIMERS_FIRED);
grpc_exec_ctx_finish(&exec_ctx);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);
}
- GPR_ASSERT(grpc_timer_check(
- &exec_ctx,
- gpr_time_add(start, gpr_time_from_millis(1600, GPR_TIMESPAN)),
- NULL) == GRPC_TIMERS_CHECKED_AND_EMPTY);
+ exec_ctx.now = start + 1600;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) ==
+ GRPC_TIMERS_CHECKED_AND_EMPTY);
for (i = 0; i < 30; i++) {
GPR_ASSERT(cb_called[i][1] == (i < 20));
GPR_ASSERT(cb_called[i][0] == 0);
@@ -116,10 +107,6 @@ static void add_test(void) {
grpc_exec_ctx_finish(&exec_ctx);
}
-static gpr_timespec tfm(int m) {
- return gpr_time_from_millis(m, GPR_CLOCK_REALTIME);
-}
-
/* Cleaning up a list with pending timers. */
void destruction_test(void) {
grpc_timer timers[5];
@@ -127,32 +114,30 @@ void destruction_test(void) {
gpr_log(GPR_INFO, "destruction_test");
- grpc_timer_list_init(gpr_time_0(GPR_CLOCK_REALTIME));
+ exec_ctx.now_is_valid = true;
+ exec_ctx.now = 0;
+ grpc_timer_list_init(&exec_ctx);
grpc_timer_trace.value = 1;
grpc_timer_check_trace.value = 1;
memset(cb_called, 0, sizeof(cb_called));
grpc_timer_init(
- &exec_ctx, &timers[0], tfm(100),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)0, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
+ &exec_ctx, &timers[0], 100,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)0, grpc_schedule_on_exec_ctx));
grpc_timer_init(
- &exec_ctx, &timers[1], tfm(3),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)1, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
+ &exec_ctx, &timers[1], 3,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)1, grpc_schedule_on_exec_ctx));
grpc_timer_init(
- &exec_ctx, &timers[2], tfm(100),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)2, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
+ &exec_ctx, &timers[2], 100,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)2, grpc_schedule_on_exec_ctx));
grpc_timer_init(
- &exec_ctx, &timers[3], tfm(3),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)3, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
+ &exec_ctx, &timers[3], 3,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)3, grpc_schedule_on_exec_ctx));
grpc_timer_init(
- &exec_ctx, &timers[4], tfm(1),
- GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)4, grpc_schedule_on_exec_ctx),
- gpr_time_0(GPR_CLOCK_REALTIME));
- GPR_ASSERT(grpc_timer_check(&exec_ctx, tfm(2), NULL) == GRPC_TIMERS_FIRED);
+ &exec_ctx, &timers[4], 1,
+ GRPC_CLOSURE_CREATE(cb, (void *)(intptr_t)4, grpc_schedule_on_exec_ctx));
+ exec_ctx.now = 2;
+ GPR_ASSERT(grpc_timer_check(&exec_ctx, NULL) == GRPC_TIMERS_FIRED);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(1 == cb_called[4][1]);
grpc_timer_cancel(&exec_ctx, &timers[0]);
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index 1d051bea62..2e44d0abc8 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -226,7 +226,7 @@ static void test_receive(int number_of_clients) {
grpc_udp_server *s = grpc_udp_server_create(NULL);
int i;
int number_of_reads_before;
- gpr_timespec deadline;
+ grpc_millis deadline;
grpc_pollset *pollsets[1];
LOG_TEST("test_receive");
gpr_log(GPR_INFO, "clients=%d", number_of_clients);
@@ -252,7 +252,8 @@ static void test_receive(int number_of_clients) {
gpr_mu_lock(g_mu);
for (i = 0; i < number_of_clients; i++) {
- deadline = grpc_timeout_seconds_to_deadline(10);
+ deadline =
+ grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
number_of_reads_before = g_number_of_reads;
/* Create a socket, send a packet to the UDP server. */
@@ -262,14 +263,13 @@ static void test_receive(int number_of_clients) {
(socklen_t)resolved_addr.len) == 0);
GPR_ASSERT(5 == write(clifd, "hello", 5));
while (g_number_of_reads == number_of_reads_before &&
- gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
+ deadline > grpc_exec_ctx_now(&exec_ctx)) {
grpc_pollset_worker *worker = NULL;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
- grpc_pollset_work(&exec_ctx, g_pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
}
GPR_ASSERT(g_number_of_reads == number_of_reads_before + 1);
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c
index 5ac58070c8..34f310142c 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -194,14 +194,13 @@ static void test_add_abunch_to_md_array(void) {
static void test_oauth2_token_fetcher_creds_parsing_ok(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200, valid_oauth2_json_response);
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&exec_ctx, &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_OK);
- GPR_ASSERT(token_lifetime.tv_sec == 3599);
- GPR_ASSERT(token_lifetime.tv_nsec == 0);
+ GPR_ASSERT(token_lifetime == 3599 * GPR_MS_PER_SEC);
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(token_md), "authorization") == 0);
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(token_md),
"Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") ==
@@ -214,7 +213,7 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) {
static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(401, valid_oauth2_json_response);
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
@@ -227,7 +226,7 @@ static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) {
static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response = http_response(200, "");
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&exec_ctx, &response, &token_md, &token_lifetime) ==
@@ -239,7 +238,7 @@ static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) {
static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200,
"{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\","
@@ -255,7 +254,7 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) {
static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response = http_response(200,
"{"
" \"expires_in\":3599, "
@@ -270,7 +269,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) {
static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200,
"{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\","
@@ -287,7 +286,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime(
void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem token_md = GRPC_MDNULL;
- gpr_timespec token_lifetime;
+ grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200,
"{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\","
@@ -555,7 +554,7 @@ static void validate_compute_engine_http_request(
static int compute_engine_httpcli_get_success_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
validate_compute_engine_http_request(request);
*response = http_response(200, valid_oauth2_json_response);
@@ -565,7 +564,7 @@ static int compute_engine_httpcli_get_success_override(
static int compute_engine_httpcli_get_failure_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
validate_compute_engine_http_request(request);
*response = http_response(403, "Not Authorized.");
@@ -575,7 +574,7 @@ static int compute_engine_httpcli_get_failure_override(
static int httpcli_post_should_not_be_called(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- const char *body_bytes, size_t body_size, gpr_timespec deadline,
+ const char *body_bytes, size_t body_size, grpc_millis deadline,
grpc_closure *on_done, grpc_httpcli_response *response) {
GPR_ASSERT("HTTP POST should not be called" == NULL);
return 1;
@@ -583,7 +582,7 @@ static int httpcli_post_should_not_be_called(
static int httpcli_get_should_not_be_called(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline,
+ grpc_millis deadline,
grpc_closure *on_done,
grpc_httpcli_response *response) {
GPR_ASSERT("HTTP GET should not be called" == NULL);
@@ -663,7 +662,7 @@ static void validate_refresh_token_http_request(
static int refresh_token_httpcli_post_success(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- const char *body, size_t body_size, gpr_timespec deadline,
+ const char *body, size_t body_size, grpc_millis deadline,
grpc_closure *on_done, grpc_httpcli_response *response) {
validate_refresh_token_http_request(request, body, body_size);
*response = http_response(200, valid_oauth2_json_response);
@@ -673,7 +672,7 @@ static int refresh_token_httpcli_post_success(
static int refresh_token_httpcli_post_failure(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- const char *body, size_t body_size, gpr_timespec deadline,
+ const char *body, size_t body_size, grpc_millis deadline,
grpc_closure *on_done, grpc_httpcli_response *response) {
validate_refresh_token_http_request(request, body, body_size);
*response = http_response(403, "Not Authorized.");
@@ -932,7 +931,7 @@ static void test_google_default_creds_refresh_token(void) {
static int default_creds_gce_detection_httpcli_get_success_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, "");
grpc_http_header *headers = gpr_malloc(sizeof(*headers) * 1);
@@ -996,7 +995,7 @@ static void test_google_default_creds_gce(void) {
static int default_creds_gce_detection_httpcli_get_failure_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
/* No magic header. */
GPR_ASSERT(strcmp(request->http.path, "/") == 0);
diff --git a/test/core/security/jwt_verifier_test.c b/test/core/security/jwt_verifier_test.c
index 9b17fb516d..a4bfe0130e 100644
--- a/test/core/security/jwt_verifier_test.c
+++ b/test/core/security/jwt_verifier_test.c
@@ -324,7 +324,7 @@ static grpc_httpcli_response http_response(int status, char *body) {
static int httpcli_post_should_not_be_called(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- const char *body_bytes, size_t body_size, gpr_timespec deadline,
+ const char *body_bytes, size_t body_size, grpc_millis deadline,
grpc_closure *on_done, grpc_httpcli_response *response) {
GPR_ASSERT("HTTP POST should not be called" == NULL);
return 1;
@@ -332,7 +332,7 @@ static int httpcli_post_should_not_be_called(
static int httpcli_get_google_keys_for_email(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, good_google_email_keys());
GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
@@ -379,7 +379,7 @@ static void test_jwt_verifier_google_email_issuer_success(void) {
static int httpcli_get_custom_keys_for_email(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, gpr_strdup(good_jwk_set));
GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
@@ -413,7 +413,7 @@ static void test_jwt_verifier_custom_email_issuer_success(void) {
static int httpcli_get_jwk_set(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, gpr_strdup(good_jwk_set));
GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
@@ -425,7 +425,7 @@ static int httpcli_get_jwk_set(grpc_exec_ctx *exec_ctx,
static int httpcli_get_openid_config(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline,
+ grpc_millis deadline,
grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, gpr_strdup(good_openid_config));
@@ -471,7 +471,7 @@ static void on_verification_key_retrieval_error(grpc_exec_ctx *exec_ctx,
static int httpcli_get_bad_json(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_closure *on_done,
+ grpc_millis deadline, grpc_closure *on_done,
grpc_httpcli_response *response) {
*response = http_response(200, gpr_strdup("{\"bad\": \"stuff\"}"));
GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
@@ -581,7 +581,7 @@ static void test_jwt_verifier_bad_signature(void) {
static int httpcli_get_should_not_be_called(grpc_exec_ctx *exec_ctx,
const grpc_httpcli_request *request,
- gpr_timespec deadline,
+ grpc_millis deadline,
grpc_closure *on_done,
grpc_httpcli_response *response) {
GPR_ASSERT(0);
diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c
index d240403a29..73d6c5bc7d 100644
--- a/test/core/security/oauth2_utils.c
+++ b/test/core/security/oauth2_utils.c
@@ -104,8 +104,7 @@ char *grpc_test_fetch_oauth2_token_with_credentials(
"pollset_work",
grpc_pollset_work(&exec_ctx,
grpc_polling_entity_pollset(&request.pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC)))) {
+ &worker, GRPC_MILLIS_INF_FUTURE))) {
request.is_done = true;
}
}
diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c
index 3144717a85..29c38dfdf8 100644
--- a/test/core/security/print_google_default_creds_token.c
+++ b/test/core/security/print_google_default_creds_token.c
@@ -110,8 +110,7 @@ int main(int argc, char **argv) {
"pollset_work",
grpc_pollset_work(&exec_ctx,
grpc_polling_entity_pollset(&sync.pops), &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))))
+ GRPC_MILLIS_INF_FUTURE)))
sync.is_done = true;
gpr_mu_unlock(sync.mu);
grpc_exec_ctx_flush(&exec_ctx);
diff --git a/test/core/security/ssl_server_fuzzer.c b/test/core/security/ssl_server_fuzzer.c
index 9858b11c7c..f9b754b8f2 100644
--- a/test/core/security/ssl_server_fuzzer.c
+++ b/test/core/security/ssl_server_fuzzer.c
@@ -84,8 +84,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_security_status status =
grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc);
GPR_ASSERT(status == GRPC_SECURITY_OK);
- gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_seconds(1, GPR_TIMESPAN));
+ grpc_millis deadline = GPR_MS_PER_SEC + grpc_exec_ctx_now(&exec_ctx);
struct handshake_state state;
state.done_callback_called = false;
diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c
index 5faa6352a8..cec6fb94b4 100644
--- a/test/core/security/verify_jwt.c
+++ b/test/core/security/verify_jwt.c
@@ -102,11 +102,9 @@ int main(int argc, char **argv) {
gpr_mu_lock(sync.mu);
while (!sync.is_done) {
grpc_pollset_worker *worker = NULL;
- if (!GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, sync.pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_inf_future(GPR_CLOCK_MONOTONIC))))
+ if (!GRPC_LOG_IF_ERROR("pollset_work",
+ grpc_pollset_work(&exec_ctx, sync.pollset, &worker,
+ GRPC_MILLIS_INF_FUTURE)))
sync.is_done = true;
gpr_mu_unlock(sync.mu);
grpc_exec_ctx_flush(&exec_ctx);
diff --git a/test/core/slice/BUILD b/test/core/slice/BUILD
index f86a3a6082..ad2308a4d6 100644
--- a/test/core/slice/BUILD
+++ b/test/core/slice/BUILD
@@ -21,10 +21,22 @@ licenses(["notice"]) # Apache v2
load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_fuzzer(
+ name = "percent_encode_fuzzer",
+ srcs = ["percent_encode_fuzzer.c"],
+ language = "C",
+ corpus = "percent_encode_corpus",
+ deps = [
+ "//:gpr",
+ "//:grpc",
+ "//test/core/util:grpc_test_util",
+ ],
+)
+
+grpc_fuzzer(
name = "percent_decode_fuzzer",
srcs = ["percent_decode_fuzzer.c"],
language = "C",
- corpus = "response_corpus",
+ corpus = "percent_decode_corpus",
deps = [
"//:gpr",
"//:grpc",
diff --git a/test/core/support/BUILD b/test/core/support/BUILD
index 096576e13c..407c3eff7b 100644
--- a/test/core/support/BUILD
+++ b/test/core/support/BUILD
@@ -39,16 +39,6 @@ grpc_cc_test(
)
grpc_cc_test(
- name = "backoff_test",
- srcs = ["backoff_test.c"],
- language = "C",
- deps = [
- "//:gpr",
- "//test/core/util:gpr_test_util",
- ],
-)
-
-grpc_cc_test(
name = "cmdline_test",
srcs = ["cmdline_test.c"],
language = "C",
diff --git a/test/core/support/backoff_test.c b/test/core/support/backoff_test.c
deleted file mode 100644
index 23e3005af0..0000000000
--- a/test/core/support/backoff_test.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- *
- * Copyright 2016 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "src/core/lib/support/backoff.h"
-
-#include <grpc/support/log.h>
-
-#include "test/core/util/test_config.h"
-
-static void test_constant_backoff(void) {
- gpr_backoff backoff;
- gpr_backoff_init(&backoff, 200 /* initial timeout */, 1.0 /* multiplier */,
- 0.0 /* jitter */, 100 /* min timeout */,
- 1000 /* max timeout */);
-
- gpr_timespec now = gpr_time_0(GPR_TIMESPAN);
- gpr_timespec next = gpr_backoff_begin(&backoff, now);
- GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 200);
- for (int i = 0; i < 10000; i++) {
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 200);
- now = next;
- }
-}
-
-static void test_min_connect(void) {
- gpr_backoff backoff;
- gpr_backoff_init(&backoff, 100 /* initial timeout */, 1.0 /* multiplier */,
- 0.0 /* jitter */, 200 /* min timeout */,
- 1000 /* max timeout */);
-
- gpr_timespec now = gpr_time_0(GPR_TIMESPAN);
- gpr_timespec next = gpr_backoff_begin(&backoff, now);
- GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 200);
-}
-
-static void test_no_jitter_backoff(void) {
- gpr_backoff backoff;
- gpr_backoff_init(&backoff, 2 /* initial timeout */, 2.0 /* multiplier */,
- 0.0 /* jitter */, 1 /* min timeout */,
- 513 /* max timeout */);
- // x_1 = 2
- // x_n = 2**i + x_{i-1} ( = 2**(n+1) - 2 )
- gpr_timespec now = gpr_time_0(GPR_TIMESPAN);
- gpr_timespec next = gpr_backoff_begin(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(2, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(6, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(14, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(30, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(62, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(126, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(254, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(510, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(1022, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- // Hit the maximum timeout. From this point onwards, retries will increase
- // only by max timeout.
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(1535, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(2048, GPR_TIMESPAN), next) == 0);
- now = next;
- next = gpr_backoff_step(&backoff, now);
- GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(2561, GPR_TIMESPAN), next) == 0);
-}
-
-static void test_jitter_backoff(void) {
- const int64_t initial_timeout = 500;
- const double jitter = 0.1;
- gpr_backoff backoff;
- gpr_backoff_init(&backoff, initial_timeout, 1.0 /* multiplier */, jitter,
- 100 /* min timeout */, 1000 /* max timeout */);
-
- backoff.rng_state = 0; // force consistent PRNG
-
- gpr_timespec now = gpr_time_0(GPR_TIMESPAN);
- gpr_timespec next = gpr_backoff_begin(&backoff, now);
- GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 500);
-
- int64_t expected_next_lower_bound =
- (int64_t)((double)initial_timeout * (1 - jitter));
- int64_t expected_next_upper_bound =
- (int64_t)((double)initial_timeout * (1 + jitter));
-
- for (int i = 0; i < 10000; i++) {
- next = gpr_backoff_step(&backoff, now);
-
- // next-now must be within (jitter*100)% of the previous timeout.
- const int64_t timeout_millis = gpr_time_to_millis(gpr_time_sub(next, now));
- GPR_ASSERT(timeout_millis >= expected_next_lower_bound);
- GPR_ASSERT(timeout_millis <= expected_next_upper_bound);
-
- expected_next_lower_bound =
- (int64_t)((double)timeout_millis * (1 - jitter));
- expected_next_upper_bound =
- (int64_t)((double)timeout_millis * (1 + jitter));
- now = next;
- }
-}
-
-int main(int argc, char **argv) {
- grpc_test_init(argc, argv);
- gpr_time_init();
-
- test_constant_backoff();
- test_min_connect();
- test_no_jitter_backoff();
- test_jitter_backoff();
-
- return 0;
-}
diff --git a/test/core/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
index ec2cd8610b..3595885ff6 100644
--- a/test/core/surface/concurrent_connectivity_test.c
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -135,14 +135,12 @@ void bad_server_thread(void *vargs) {
gpr_mu_lock(args->mu);
while (gpr_atm_acq_load(&args->stop) == 0) {
- gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
- gpr_timespec deadline =
- gpr_time_add(now, gpr_time_from_millis(100, GPR_TIMESPAN));
+ grpc_millis deadline = grpc_exec_ctx_now(&exec_ctx) + 100;
grpc_pollset_worker *worker = NULL;
- if (!GRPC_LOG_IF_ERROR("pollset_work",
- grpc_pollset_work(&exec_ctx, args->pollset, &worker,
- now, deadline))) {
+ if (!GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker, deadline))) {
gpr_atm_rel_store(&args->stop, 1);
}
gpr_mu_unlock(args->mu);
diff --git a/test/core/surface/init_test.c b/test/core/surface/init_test.c
index a9e80575af..b835a2a884 100644
--- a/test/core/surface/init_test.c
+++ b/test/core/surface/init_test.c
@@ -53,7 +53,7 @@ static void test_plugin() {
}
static void test_repeatedly() {
- for (int i = 0; i < 100000; i++) {
+ for (int i = 0; i < 1000; i++) {
grpc_init();
grpc_shutdown();
}
diff --git a/test/core/transport/bdp_estimator_test.c b/test/core/transport/bdp_estimator_test.c
index dda48f45b1..4912ad5887 100644
--- a/test/core/transport/bdp_estimator_test.c
+++ b/test/core/transport/bdp_estimator_test.c
@@ -24,9 +24,22 @@
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
#include <limits.h>
+#include "src/core/lib/iomgr/timer_manager.h"
#include "src/core/lib/support/string.h"
#include "test/core/util/test_config.h"
+extern gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type);
+
+static int g_clock = 0;
+
+static gpr_timespec fake_gpr_now(gpr_clock_type clock_type) {
+ return (gpr_timespec){
+ .tv_sec = g_clock, .tv_nsec = 0, .clock_type = clock_type,
+ };
+}
+
+static void inc_time(void) { g_clock += 30; }
+
static void test_noop(void) {
gpr_log(GPR_INFO, "test_noop");
grpc_bdp_estimator est;
@@ -44,16 +57,19 @@ static void test_get_estimate_no_samples(void) {
static void add_samples(grpc_bdp_estimator *estimator, int64_t *samples,
size_t n) {
grpc_bdp_estimator_add_incoming_bytes(estimator, 1234567);
- GPR_ASSERT(grpc_bdp_estimator_need_ping(estimator) == true);
+ inc_time();
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ GPR_ASSERT(grpc_bdp_estimator_need_ping(&exec_ctx, estimator) == true);
grpc_bdp_estimator_schedule_ping(estimator);
grpc_bdp_estimator_start_ping(estimator);
for (size_t i = 0; i < n; i++) {
grpc_bdp_estimator_add_incoming_bytes(estimator, samples[i]);
- GPR_ASSERT(grpc_bdp_estimator_need_ping(estimator) == false);
+ GPR_ASSERT(grpc_bdp_estimator_need_ping(&exec_ctx, estimator) == false);
}
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_millis(1, GPR_TIMESPAN)));
- grpc_bdp_estimator_complete_ping(estimator);
+ grpc_bdp_estimator_complete_ping(&exec_ctx, estimator);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void add_sample(grpc_bdp_estimator *estimator, int64_t sample) {
@@ -130,7 +146,9 @@ static void test_get_estimate_random_values(size_t n) {
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
+ gpr_now_impl = fake_gpr_now;
grpc_init();
+ grpc_timer_manager_set_threading(false);
test_noop();
test_get_estimate_no_samples();
test_get_estimate_1_sample();
diff --git a/test/core/transport/status_conversion_test.c b/test/core/transport/status_conversion_test.c
index 89558964c1..de8fa4458a 100644
--- a/test/core/transport/status_conversion_test.c
+++ b/test/core/transport/status_conversion_test.c
@@ -22,8 +22,13 @@
#define GRPC_STATUS_TO_HTTP2_ERROR(a, b) \
GPR_ASSERT(grpc_status_to_http2_error(a) == (b))
-#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \
- GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b))
+#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \
+ do { \
+ grpc_exec_ctx my_exec_ctx = GRPC_EXEC_CTX_INIT; \
+ GPR_ASSERT(grpc_http2_error_to_grpc_status(&my_exec_ctx, a, deadline) == \
+ (b)); \
+ grpc_exec_ctx_finish(&my_exec_ctx); \
+ } while (0)
#define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \
GPR_ASSERT(grpc_status_to_http2_status(a) == (b))
#define HTTP2_STATUS_TO_GRPC_STATUS(a, b) \
@@ -79,7 +84,7 @@ int main(int argc, char **argv) {
GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_UNAVAILABLE, 200);
GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_DATA_LOSS, 200);
- const gpr_timespec before_deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ const grpc_millis before_deadline = GRPC_MILLIS_INF_FUTURE;
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_NO_ERROR, before_deadline,
GRPC_STATUS_INTERNAL);
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_PROTOCOL_ERROR, before_deadline,
@@ -107,7 +112,7 @@ int main(int argc, char **argv) {
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INADEQUATE_SECURITY, before_deadline,
GRPC_STATUS_PERMISSION_DENIED);
- const gpr_timespec after_deadline = gpr_inf_past(GPR_CLOCK_MONOTONIC);
+ const grpc_millis after_deadline = 0;
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_NO_ERROR, after_deadline,
GRPC_STATUS_INTERNAL);
HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_PROTOCOL_ERROR, after_deadline,
diff --git a/test/core/transport/timeout_encoding_test.c b/test/core/transport/timeout_encoding_test.c
index 6388ffbcec..30357faed3 100644
--- a/test/core/transport/timeout_encoding_test.c
+++ b/test/core/transport/timeout_encoding_test.c
@@ -25,12 +25,13 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
+#include "src/core/lib/support/murmur_hash.h"
#include "src/core/lib/support/string.h"
#include "test/core/util/test_config.h"
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x)
-static void assert_encodes_as(gpr_timespec ts, const char *s) {
+static void assert_encodes_as(grpc_millis ts, const char *s) {
char buffer[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE];
grpc_http2_encode_timeout(ts, buffer);
gpr_log(GPR_INFO, "check '%s' == '%s'", buffer, s);
@@ -39,47 +40,43 @@ 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, 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");
+ assert_encodes_as(-1, "1n");
+ assert_encodes_as(-10, "1n");
+ assert_encodes_as(1, "1m");
+ assert_encodes_as(10, "10m");
+ assert_encodes_as(100, "100m");
+ assert_encodes_as(890, "890m");
+ assert_encodes_as(900, "900m");
+ assert_encodes_as(901, "901m");
+ assert_encodes_as(1000, "1S");
+ assert_encodes_as(2000, "2S");
+ assert_encodes_as(2500, "2500m");
+ assert_encodes_as(59900, "59900m");
+ assert_encodes_as(50000, "50S");
+ assert_encodes_as(59000, "59S");
+ assert_encodes_as(60000, "1M");
+ assert_encodes_as(80000, "80S");
+ assert_encodes_as(90000, "90S");
+ assert_encodes_as(120000, "2M");
+ assert_encodes_as(20 * 60 * GPR_MS_PER_SEC, "20M");
+ assert_encodes_as(60 * 60 * GPR_MS_PER_SEC, "1H");
+ assert_encodes_as(10 * 60 * 60 * GPR_MS_PER_SEC, "10H");
}
-static void assert_decodes_as(const char *buffer, gpr_timespec expected) {
- gpr_timespec got;
- gpr_log(GPR_INFO, "check decoding '%s'", buffer);
+static void assert_decodes_as(const char *buffer, grpc_millis expected) {
+ grpc_millis got;
+ uint32_t hash = gpr_murmur_hash3(buffer, strlen(buffer), 0);
+ gpr_log(GPR_INFO, "check decoding '%s' (hash=0x%x)", buffer, hash);
GPR_ASSERT(1 == grpc_http2_decode_timeout(
grpc_slice_from_static_string(buffer), &got));
- GPR_ASSERT(0 == gpr_time_cmp(got, expected));
+ if (got != expected) {
+ gpr_log(GPR_ERROR, "got:'%" PRIdPTR "' != expected:'%" PRIdPTR "'", got,
+ expected);
+ abort();
+ }
}
-void decode_suite(char ext,
- gpr_timespec (*answer)(int64_t x, gpr_clock_type clock)) {
+void decode_suite(char ext, grpc_millis (*answer)(int64_t x)) {
long test_vals[] = {1, 12, 123, 1234, 12345, 123456,
1234567, 12345678, 123456789, 98765432, 9876543, 987654,
98765, 9876, 987, 98, 9};
@@ -87,41 +84,57 @@ void decode_suite(char ext,
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], GPR_TIMESPAN));
+ assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
gpr_asprintf(&input, " %ld%c", test_vals[i], ext);
- assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN));
+ assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
gpr_asprintf(&input, "%ld %c", test_vals[i], ext);
- assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN));
+ assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
gpr_asprintf(&input, "%ld %c ", test_vals[i], ext);
- assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN));
+ assert_decodes_as(input, answer(test_vals[i]));
gpr_free(input);
}
}
+static grpc_millis millis_from_nanos(int64_t x) {
+ return (grpc_millis)(x / GPR_NS_PER_MS + (x % GPR_NS_PER_MS != 0));
+}
+static grpc_millis millis_from_micros(int64_t x) {
+ return (grpc_millis)(x / GPR_US_PER_MS + (x % GPR_US_PER_MS != 0));
+}
+static grpc_millis millis_from_millis(int64_t x) { return (grpc_millis)x; }
+static grpc_millis millis_from_seconds(int64_t x) {
+ return (grpc_millis)(x * GPR_MS_PER_SEC);
+}
+static grpc_millis millis_from_minutes(int64_t x) {
+ return (grpc_millis)(x * 60 * GPR_MS_PER_SEC);
+}
+static grpc_millis millis_from_hours(int64_t x) {
+ return (grpc_millis)(x * 3600 * GPR_MS_PER_SEC);
+}
+
void test_decoding(void) {
LOG_TEST("test_decoding");
- decode_suite('n', gpr_time_from_nanos);
- decode_suite('u', gpr_time_from_micros);
- decode_suite('m', gpr_time_from_millis);
- decode_suite('S', gpr_time_from_seconds);
- decode_suite('M', gpr_time_from_minutes);
- decode_suite('H', gpr_time_from_hours);
- assert_decodes_as("1000000000S",
- gpr_time_from_seconds(1000 * 1000 * 1000, GPR_TIMESPAN));
- assert_decodes_as("1000000000000000000000u", gpr_inf_future(GPR_TIMESPAN));
- assert_decodes_as("1000000001S", gpr_inf_future(GPR_TIMESPAN));
- assert_decodes_as("2000000001S", gpr_inf_future(GPR_TIMESPAN));
- assert_decodes_as("9999999999S", gpr_inf_future(GPR_TIMESPAN));
+ decode_suite('n', millis_from_nanos);
+ decode_suite('u', millis_from_micros);
+ decode_suite('m', millis_from_millis);
+ decode_suite('S', millis_from_seconds);
+ decode_suite('M', millis_from_minutes);
+ decode_suite('H', millis_from_hours);
+ assert_decodes_as("1000000000S", millis_from_seconds(1000 * 1000 * 1000));
+ assert_decodes_as("1000000000000000000000u", GRPC_MILLIS_INF_FUTURE);
+ assert_decodes_as("1000000001S", GRPC_MILLIS_INF_FUTURE);
+ assert_decodes_as("2000000001S", GRPC_MILLIS_INF_FUTURE);
+ assert_decodes_as("9999999999S", GRPC_MILLIS_INF_FUTURE);
}
static void assert_decoding_fails(const char *s) {
- gpr_timespec x;
+ grpc_millis x;
GPR_ASSERT(0 ==
grpc_http2_decode_timeout(grpc_slice_from_static_string(s), &x));
}
diff --git a/test/core/util/BUILD b/test/core/util/BUILD
index 10eefe159a..abb50a0c99 100644
--- a/test/core/util/BUILD
+++ b/test/core/util/BUILD
@@ -89,12 +89,16 @@ grpc_cc_library(
)
grpc_cc_library(
- name = "one_corpus_entry_fuzzer",
- srcs = ["one_corpus_entry_fuzzer.c"],
+ name = "fuzzer_corpus_test",
+ srcs = ["fuzzer_corpus_test.cc"],
deps = [
":gpr_test_util",
"//:grpc",
],
+ external_deps = [
+ "gtest",
+ "gflags",
+ ],
)
sh_library(
diff --git a/test/core/util/fuzzer_corpus_test.cc b/test/core/util/fuzzer_corpus_test.cc
new file mode 100644
index 0000000000..a5e99a1bac
--- /dev/null
+++ b/test/core/util/fuzzer_corpus_test.cc
@@ -0,0 +1,136 @@
+/*
+ *
+ * Copyright 2016 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdbool.h>
+
+#include <dirent.h>
+#include <gflags/gflags.h>
+#include <grpc/support/log.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#include "src/core/lib/iomgr/load_file.h"
+#include "test/core/util/test_config.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
+extern "C" bool squelch;
+extern "C" bool leak_check;
+
+DEFINE_string(file, "", "Use this file as test data");
+DEFINE_string(directory, "", "Use this directory as test data");
+
+class FuzzerCorpusTest : public ::testing::TestWithParam<std::string> {};
+
+TEST_P(FuzzerCorpusTest, RunOneExample) {
+ gpr_log(GPR_DEBUG, "Example file: %s", GetParam().c_str());
+ grpc_slice buffer;
+ squelch = false;
+ leak_check = false;
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
+ grpc_load_file(GetParam().c_str(), 0, &buffer)));
+ LLVMFuzzerTestOneInput(GRPC_SLICE_START_PTR(buffer),
+ GRPC_SLICE_LENGTH(buffer));
+ grpc_slice_unref(buffer);
+}
+
+class ExampleGenerator
+ : public ::testing::internal::ParamGeneratorInterface<std::string> {
+ public:
+ virtual ::testing::internal::ParamIteratorInterface<std::string>* Begin()
+ const;
+ virtual ::testing::internal::ParamIteratorInterface<std::string>* End() const;
+
+ private:
+ void Materialize() const {
+ if (examples_.empty()) {
+ if (!FLAGS_file.empty()) examples_.push_back(FLAGS_file);
+ if (!FLAGS_directory.empty()) {
+ DIR* dp;
+ struct dirent* ep;
+ dp = opendir(FLAGS_directory.c_str());
+
+ if (dp != NULL) {
+ while ((ep = readdir(dp)) != nullptr) {
+ if (ep->d_type == DT_REG) {
+ examples_.push_back(FLAGS_directory + "/" + ep->d_name);
+ }
+ }
+
+ (void)closedir(dp);
+ } else {
+ perror("Couldn't open the directory");
+ abort();
+ }
+ }
+ }
+ }
+
+ mutable std::vector<std::string> examples_;
+};
+
+class ExampleIterator
+ : public ::testing::internal::ParamIteratorInterface<std::string> {
+ public:
+ ExampleIterator(const ExampleGenerator& base_,
+ std::vector<std::string>::const_iterator begin)
+ : base_(base_), begin_(begin), current_(begin) {}
+
+ virtual const ExampleGenerator* BaseGenerator() const { return &base_; }
+
+ virtual void Advance() { current_++; }
+ virtual ExampleIterator* Clone() const { return new ExampleIterator(*this); }
+ virtual const std::string* Current() const { return &*current_; }
+
+ virtual bool Equals(const ParamIteratorInterface<std::string>& other) const {
+ return &base_ == other.BaseGenerator() &&
+ current_ == dynamic_cast<const ExampleIterator*>(&other)->current_;
+ }
+
+ private:
+ ExampleIterator(const ExampleIterator& other)
+ : base_(other.base_), begin_(other.begin_), current_(other.current_) {}
+
+ const ExampleGenerator& base_;
+ const std::vector<std::string>::const_iterator begin_;
+ std::vector<std::string>::const_iterator current_;
+};
+
+::testing::internal::ParamIteratorInterface<std::string>*
+ExampleGenerator::Begin() const {
+ Materialize();
+ return new ExampleIterator(*this, examples_.begin());
+}
+
+::testing::internal::ParamIteratorInterface<std::string>*
+ExampleGenerator::End() const {
+ Materialize();
+ return new ExampleIterator(*this, examples_.end());
+}
+
+INSTANTIATE_TEST_CASE_P(
+ CorpusExamples, FuzzerCorpusTest,
+ ::testing::internal::ParamGenerator<std::string>(new ExampleGenerator));
+
+int main(int argc, char** argv) {
+ grpc_test_init(argc, argv);
+ ::gflags::ParseCommandLineFlags(&argc, &argv, true);
+ ::testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
diff --git a/test/core/util/grpc_fuzzer.bzl b/test/core/util/grpc_fuzzer.bzl
index 41f6cdc8ba..55b6f1c1a5 100644
--- a/test/core/util/grpc_fuzzer.bzl
+++ b/test/core/util/grpc_fuzzer.bzl
@@ -12,19 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//bazel:grpc_build_system.bzl", "grpc_cc_binary")
+load("//bazel:grpc_build_system.bzl", "grpc_cc_test")
def grpc_fuzzer(name, corpus, srcs = [], deps = [], **kwargs):
- grpc_cc_binary(
- name = '%s/one_entry.bin' % name,
+ grpc_cc_test(
+ name = name,
srcs = srcs,
- deps = deps + ["//test/core/util:one_corpus_entry_fuzzer"],
+ deps = deps + ["//test/core/util:fuzzer_corpus_test"],
+ data = [corpus],
+ args = ['--directory', '$(location %s)' % corpus],
+ external_deps = [
+ 'gtest',
+ ],
**kwargs
)
- for entry in native.glob(['%s/*' % corpus]):
- native.sh_test(
- name = '%s/one_entry/%s' % (name, entry),
- data = [':%s/one_entry.bin' % name, entry],
- srcs = ['//test/core/util:fuzzer_one_entry_runner'],
- args = ['$(location :%s/one_entry.bin)' % name, '$(location %s)' % entry]
- )
diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c
index ba4028dbee..7b94ac4ada 100644
--- a/test/core/util/port_server_client.c
+++ b/test/core/util/port_server_client.c
@@ -88,7 +88,7 @@ void grpc_free_port_using_server(int port) {
grpc_resource_quota *resource_quota =
grpc_resource_quota_create("port_server_client/free");
grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req,
- grpc_timeout_seconds_to_deadline(30),
+ grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC,
GRPC_CLOSURE_CREATE(freed_port_from_server, &pr,
grpc_schedule_on_exec_ctx),
&rsp);
@@ -100,8 +100,8 @@ void grpc_free_port_using_server(int port) {
if (!GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_seconds_to_deadline(1)))) {
+ &worker,
+ grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) {
pr.done = 1;
}
}
@@ -173,7 +173,7 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
grpc_resource_quota *resource_quota =
grpc_resource_quota_create("port_server_client/pick_retry");
grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, resource_quota, &req,
- grpc_timeout_seconds_to_deadline(10),
+ grpc_exec_ctx_now(exec_ctx) + 30 * GPR_MS_PER_SEC,
GRPC_CLOSURE_CREATE(got_port_from_server, pr,
grpc_schedule_on_exec_ctx),
&pr->response);
@@ -224,7 +224,7 @@ int grpc_pick_port_using_server(void) {
grpc_resource_quota_create("port_server_client/pick");
grpc_httpcli_get(
&exec_ctx, &context, &pr.pops, resource_quota, &req,
- grpc_timeout_seconds_to_deadline(30),
+ grpc_exec_ctx_now(&exec_ctx) + 30 * GPR_MS_PER_SEC,
GRPC_CLOSURE_CREATE(got_port_from_server, &pr, grpc_schedule_on_exec_ctx),
&pr.response);
grpc_resource_quota_unref_internal(&exec_ctx, resource_quota);
@@ -235,8 +235,8 @@ int grpc_pick_port_using_server(void) {
if (!GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops),
- &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- grpc_timeout_seconds_to_deadline(1)))) {
+ &worker,
+ grpc_exec_ctx_now(&exec_ctx) + GPR_MS_PER_SEC))) {
pr.port = 0;
}
}
diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c
index d3a1de8a3b..611ecb330c 100644
--- a/test/core/util/test_tcp_server.c
+++ b/test/core/util/test_tcp_server.c
@@ -31,6 +31,7 @@
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/tcp_server.h"
#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
static void on_server_destroyed(grpc_exec_ctx *exec_ctx, void *data,
grpc_error *error) {
@@ -78,14 +79,13 @@ void test_tcp_server_start(test_tcp_server *server, int port) {
void test_tcp_server_poll(test_tcp_server *server, int seconds) {
grpc_pollset_worker *worker = NULL;
- gpr_timespec deadline =
- gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_seconds(seconds, GPR_TIMESPAN));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_millis deadline = grpc_timespec_to_millis_round_up(
+ grpc_timeout_seconds_to_deadline(seconds));
gpr_mu_lock(server->mu);
- GRPC_LOG_IF_ERROR("pollset_work",
- grpc_pollset_work(&exec_ctx, server->pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC), deadline));
+ GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, server->pollset, &worker, deadline));
gpr_mu_unlock(server->mu);
grpc_exec_ctx_finish(&exec_ctx);
}
diff --git a/test/cpp/common/alarm_cpp_test.cc b/test/cpp/common/alarm_cpp_test.cc
index 212972d25d..7adc3102f4 100644
--- a/test/cpp/common/alarm_cpp_test.cc
+++ b/test/cpp/common/alarm_cpp_test.cc
@@ -142,7 +142,7 @@ TEST(AlarmTest, ZeroExpiry) {
void* output_tag;
bool ok;
const CompletionQueue::NextStatus status = cq.AsyncNext(
- (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(0));
+ (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(1));
EXPECT_EQ(status, CompletionQueue::GOT_EVENT);
EXPECT_TRUE(ok);
@@ -158,7 +158,7 @@ TEST(AlarmTest, NegativeExpiry) {
void* output_tag;
bool ok;
const CompletionQueue::NextStatus status = cq.AsyncNext(
- (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(0));
+ (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(1));
EXPECT_EQ(status, CompletionQueue::GOT_EVENT);
EXPECT_TRUE(ok);
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index bbefbac4d0..a14b4d5295 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -102,7 +102,23 @@ class Verifier {
explicit Verifier(bool spin) : spin_(spin) {}
// Expect sets the expected ok value for a specific tag
Verifier& Expect(int i, bool expect_ok) {
- expectations_[tag(i)] = expect_ok;
+ return ExpectUnless(i, expect_ok, false);
+ }
+ // ExpectUnless sets the expected ok value for a specific tag
+ // unless the tag was already marked seen (as a result of ExpectMaybe)
+ Verifier& ExpectUnless(int i, bool expect_ok, bool seen) {
+ if (!seen) {
+ expectations_[tag(i)] = expect_ok;
+ }
+ return *this;
+ }
+ // ExpectMaybe sets the expected ok value for a specific tag, but does not
+ // require it to appear
+ // If it does, sets *seen to true
+ Verifier& ExpectMaybe(int i, bool expect_ok, bool* seen) {
+ if (!*seen) {
+ maybe_expectations_[tag(i)] = MaybeExpect{expect_ok, seen};
+ }
return *this;
}
@@ -122,12 +138,7 @@ class Verifier {
} else {
EXPECT_TRUE(cq->Next(&got_tag, &ok));
}
- auto it = expectations_.find(got_tag);
- EXPECT_TRUE(it != expectations_.end());
- if (!ignore_ok) {
- EXPECT_EQ(it->second, ok);
- }
- expectations_.erase(it);
+ GotTag(got_tag, ok, ignore_ok);
return detag(got_tag);
}
@@ -138,7 +149,7 @@ class Verifier {
// This version of Verify allows optionally ignoring the
// outcome of the expectation
void Verify(CompletionQueue* cq, bool ignore_ok) {
- GPR_ASSERT(!expectations_.empty());
+ GPR_ASSERT(!expectations_.empty() || !maybe_expectations_.empty());
while (!expectations_.empty()) {
Next(cq, ignore_ok);
}
@@ -177,16 +188,43 @@ class Verifier {
EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline),
CompletionQueue::GOT_EVENT);
}
- auto it = expectations_.find(got_tag);
- EXPECT_TRUE(it != expectations_.end());
- EXPECT_EQ(it->second, ok);
- expectations_.erase(it);
+ GotTag(got_tag, ok, false);
}
}
}
private:
+ void GotTag(void* got_tag, bool ok, bool ignore_ok) {
+ auto it = expectations_.find(got_tag);
+ if (it != expectations_.end()) {
+ if (!ignore_ok) {
+ EXPECT_EQ(it->second, ok);
+ }
+ expectations_.erase(it);
+ } else {
+ auto it2 = maybe_expectations_.find(got_tag);
+ if (it2 != maybe_expectations_.end()) {
+ if (it2->second.seen != nullptr) {
+ EXPECT_FALSE(*it2->second.seen);
+ *it2->second.seen = true;
+ }
+ if (!ignore_ok) {
+ EXPECT_EQ(it2->second.ok, ok);
+ }
+ } else {
+ gpr_log(GPR_ERROR, "Unexpected tag: %p", tag);
+ abort();
+ }
+ }
+ }
+
+ struct MaybeExpect {
+ bool ok;
+ bool* seen;
+ };
+
std::map<void*, bool> expectations_;
+ std::map<void*, MaybeExpect> maybe_expectations_;
bool spin_;
};
@@ -534,18 +572,21 @@ TEST_P(AsyncEnd2endTest, SimpleClientStreamingWithCoalescingApi) {
service_->RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
tag(2));
- auto verif = Verifier(GetParam().disable_blocking);
- verif.Expect(2, true);
-
cli_stream->Write(send_request, tag(3));
- verif.Expect(3, true);
- // Drain tag 2, optional to get tag 3 now
- while (verif.Next(cq_.get(), false) != 2) {
- }
+ bool seen3 = false;
+
+ Verifier(GetParam().disable_blocking)
+ .Expect(2, true)
+ .ExpectMaybe(3, true, &seen3)
+ .Verify(cq_.get());
srv_stream.Read(&recv_request, tag(4));
- verif.Expect(4, true).Verify(cq_.get());
+
+ Verifier(GetParam().disable_blocking)
+ .ExpectUnless(3, true, seen3)
+ .Expect(4, true)
+ .Verify(cq_.get());
EXPECT_EQ(send_request.message(), recv_request.message());
@@ -814,19 +855,21 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWAF) {
service_->RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
tag(2));
- auto verif = Verifier(GetParam().disable_blocking);
- verif.Expect(2, true);
-
cli_stream->WriteLast(send_request, WriteOptions(), tag(3));
- verif.Expect(3, true);
- // Drain tag 2, optional to get tag 3 now
- while (verif.Next(cq_.get(), false) != 2) {
- }
+ bool seen3 = false;
+
+ Verifier(GetParam().disable_blocking)
+ .Expect(2, true)
+ .ExpectMaybe(3, true, &seen3)
+ .Verify(cq_.get());
srv_stream.Read(&recv_request, tag(4));
- verif.Expect(4, true).Verify(cq_.get());
+ Verifier(GetParam().disable_blocking)
+ .ExpectUnless(3, true, seen3)
+ .Expect(4, true)
+ .Verify(cq_.get());
EXPECT_EQ(send_request.message(), recv_request.message());
srv_stream.Read(&recv_request, tag(5));
@@ -868,19 +911,21 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWL) {
service_->RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
tag(2));
- auto verif = Verifier(GetParam().disable_blocking);
- verif.Expect(2, true);
-
cli_stream->WriteLast(send_request, WriteOptions(), tag(3));
- verif.Expect(3, true);
- // Drain tag 2, optional to get tag 3 now
- while (verif.Next(cq_.get(), false) != 2) {
- }
+ bool seen3 = false;
+
+ Verifier(GetParam().disable_blocking)
+ .Expect(2, true)
+ .ExpectMaybe(3, true, &seen3)
+ .Verify(cq_.get());
srv_stream.Read(&recv_request, tag(4));
- verif.Expect(4, true).Verify(cq_.get());
+ Verifier(GetParam().disable_blocking)
+ .ExpectUnless(3, true, seen3)
+ .Expect(4, true)
+ .Verify(cq_.get());
EXPECT_EQ(send_request.message(), recv_request.message());
srv_stream.Read(&recv_request, tag(5));
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 810ee303f2..c5178526f8 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -1280,6 +1280,8 @@ TEST_P(ProxyEnd2endTest, RpcDeadlineExpires) {
EchoResponse response;
request.set_message("Hello");
request.mutable_param()->set_skip_cancelled_check(true);
+ // Let server sleep for 2 ms first to guarantee expiry
+ request.mutable_param()->set_server_sleep_us(2 * 1000);
ClientContext context;
std::chrono::system_clock::time_point deadline =
@@ -1407,6 +1409,10 @@ TEST_P(ProxyEnd2endTest, HugeResponse) {
}
TEST_P(ProxyEnd2endTest, Peer) {
+ // Peer is not meaningful for inproc
+ if (GetParam().inproc) {
+ return;
+ }
ResetStub();
EchoRequest request;
EchoResponse response;
@@ -1775,11 +1781,10 @@ std::vector<TestScenario> CreateTestScenarios(bool use_proxy,
credentials_types.push_back(kInsecureCredentialsType);
}
GPR_ASSERT(!credentials_types.empty());
- for (auto it = credentials_types.begin(); it != credentials_types.end();
- ++it) {
- scenarios.emplace_back(false, false, *it);
+ for (const auto& cred : credentials_types) {
+ scenarios.emplace_back(false, false, cred);
if (use_proxy) {
- scenarios.emplace_back(true, false, *it);
+ scenarios.emplace_back(true, false, cred);
}
}
if (test_inproc && insec_ok()) {
@@ -1798,7 +1803,7 @@ INSTANTIATE_TEST_CASE_P(End2endServerTryCancel, End2endServerTryCancelTest,
INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest,
::testing::ValuesIn(CreateTestScenarios(true, true,
- true, false)));
+ true, true)));
INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest,
::testing::ValuesIn(CreateTestScenarios(false, false,
diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc
index 33b35108d2..9450182302 100644
--- a/test/cpp/end2end/generic_end2end_test.cc
+++ b/test/cpp/end2end/generic_end2end_test.cc
@@ -145,7 +145,7 @@ class GenericEnd2endTest : public ::testing::Test {
if (check_deadline) {
EXPECT_TRUE(gpr_time_similar(deadline, srv_ctx.raw_deadline(),
- gpr_time_from_millis(100, GPR_TIMESPAN)));
+ gpr_time_from_millis(1000, GPR_TIMESPAN)));
}
ByteBuffer recv_buffer;
diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc
index 4fa98c24f5..e4f7c08f25 100644
--- a/test/cpp/end2end/test_service_impl.cc
+++ b/test/cpp/end2end/test_service_impl.cc
@@ -73,6 +73,14 @@ void CheckServerAuthContext(
Status TestServiceImpl::Echo(ServerContext* context, const EchoRequest* request,
EchoResponse* response) {
+ // A bit of sleep to make sure that short deadline tests fail
+ if (request->has_param() && request->param().server_sleep_us() > 0) {
+ gpr_sleep_until(
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_time_from_micros(request->param().server_sleep_us(),
+ GPR_TIMESPAN)));
+ }
+
if (request->has_param() && request->param().server_die()) {
gpr_log(GPR_ERROR, "The request should not reach application handler.");
GPR_ASSERT(0);
diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc
index cadc9b2a11..cf9a42e8c6 100644
--- a/test/cpp/microbenchmarks/bm_call_create.cc
+++ b/test/cpp/microbenchmarks/bm_call_create.cc
@@ -554,7 +554,7 @@ static void BM_IsolatedFilter(benchmark::State &state) {
grpc_exec_ctx_flush(&exec_ctx);
grpc_call_stack *call_stack = static_cast<grpc_call_stack *>(
gpr_zalloc(channel_stack->call_stack_size));
- gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ grpc_millis deadline = GRPC_MILLIS_INF_FUTURE;
gpr_timespec start_time = gpr_now(GPR_CLOCK_MONOTONIC);
grpc_slice method = grpc_slice_from_static_string("/foo/bar");
grpc_call_final_info final_info;
diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc
index 070034fe33..6f9dee7822 100644
--- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc
+++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc
@@ -321,7 +321,7 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State &state) {
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
- b.deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ b.deadline = GRPC_MILLIS_INF_FUTURE;
std::vector<grpc_mdelem> elems = Metadata::GetElems(f.exec_ctx());
std::vector<grpc_linked_mdelem> storage(elems.size());
for (size_t i = 0; i < elems.size(); i++) {
@@ -410,7 +410,7 @@ static void BM_TransportStreamSend(benchmark::State &state) {
grpc_metadata_batch b;
grpc_metadata_batch_init(&b);
- b.deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ b.deadline = GRPC_MILLIS_INF_FUTURE;
std::vector<grpc_mdelem> elems =
RepresentativeClientInitialMetadata::GetElems(f.exec_ctx());
std::vector<grpc_linked_mdelem> storage(elems.size());
@@ -542,7 +542,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) {
grpc_metadata_batch_init(&b);
grpc_metadata_batch b_recv;
grpc_metadata_batch_init(&b_recv);
- b.deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ b.deadline = GRPC_MILLIS_INF_FUTURE;
std::vector<grpc_mdelem> elems =
RepresentativeClientInitialMetadata::GetElems(f.exec_ctx());
std::vector<grpc_linked_mdelem> storage(elems.size());
diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
index 5c9405f583..57a69acf01 100644
--- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
+++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
@@ -73,9 +73,9 @@ static void cq_done_cb(grpc_exec_ctx* exec_ctx, void* done_arg,
/* Queues a completion tag if deadline is > 0.
* Does nothing if deadline is 0 (i.e gpr_time_0(GPR_CLOCK_MONOTONIC)) */
static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps,
- grpc_pollset_worker** worker, gpr_timespec now,
- gpr_timespec deadline) {
- if (gpr_time_cmp(deadline, gpr_time_0(GPR_CLOCK_MONOTONIC)) == 0) {
+ grpc_pollset_worker** worker,
+ grpc_millis deadline) {
+ if (deadline == 0) {
gpr_log(GPR_DEBUG, "no-op");
return GRPC_ERROR_NONE;
}
diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc
index bd5f02e172..56b80dfcf6 100644
--- a/test/cpp/microbenchmarks/bm_error.cc
+++ b/test/cpp/microbenchmarks/bm_error.cc
@@ -159,39 +159,39 @@ BENCHMARK(BM_ErrorGetPresentInt);
// Fixtures for tests: generate different kinds of errors
class ErrorNone {
public:
- gpr_timespec deadline() const { return deadline_; }
+ grpc_millis deadline() const { return deadline_; }
grpc_error* error() const { return GRPC_ERROR_NONE; }
private:
- const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ const grpc_millis deadline_ = GRPC_MILLIS_INF_FUTURE;
};
class ErrorCancelled {
public:
- gpr_timespec deadline() const { return deadline_; }
+ grpc_millis deadline() const { return deadline_; }
grpc_error* error() const { return GRPC_ERROR_CANCELLED; }
private:
- const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ const grpc_millis deadline_ = GRPC_MILLIS_INF_FUTURE;
};
class SimpleError {
public:
- gpr_timespec deadline() const { return deadline_; }
+ grpc_millis deadline() const { return deadline_; }
grpc_error* error() const { return error_.get(); }
private:
- const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ const grpc_millis deadline_ = GRPC_MILLIS_INF_FUTURE;
ErrorPtr error_{GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error")};
};
class ErrorWithGrpcStatus {
public:
- gpr_timespec deadline() const { return deadline_; }
+ grpc_millis deadline() const { return deadline_; }
grpc_error* error() const { return error_.get(); }
private:
- const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ const grpc_millis deadline_ = GRPC_MILLIS_INF_FUTURE;
ErrorPtr error_{grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_ERROR_INT_GRPC_STATUS,
GRPC_STATUS_UNIMPLEMENTED)};
@@ -199,11 +199,11 @@ class ErrorWithGrpcStatus {
class ErrorWithHttpError {
public:
- gpr_timespec deadline() const { return deadline_; }
+ grpc_millis deadline() const { return deadline_; }
grpc_error* error() const { return error_.get(); }
private:
- const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ const grpc_millis deadline_ = GRPC_MILLIS_INF_FUTURE;
ErrorPtr error_{grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_ERROR_INT_HTTP2_ERROR,
GRPC_HTTP2_COMPRESSION_ERROR)};
@@ -211,11 +211,11 @@ class ErrorWithHttpError {
class ErrorWithNestedGrpcStatus {
public:
- gpr_timespec deadline() const { return deadline_; }
+ grpc_millis deadline() const { return deadline_; }
grpc_error* error() const { return error_.get(); }
private:
- const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ const grpc_millis deadline_ = GRPC_MILLIS_INF_FUTURE;
ErrorPtr nested_error_{grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_ERROR_INT_GRPC_STATUS,
GRPC_STATUS_UNIMPLEMENTED)};
@@ -248,12 +248,14 @@ template <class Fixture>
static void BM_ErrorGetStatus(benchmark::State& state) {
TrackCounters track_counters;
Fixture fixture;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
grpc_status_code status;
grpc_slice slice;
- grpc_error_get_status(fixture.error(), fixture.deadline(), &status, &slice,
- NULL);
+ grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(),
+ &status, &slice, NULL);
}
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
@@ -261,11 +263,13 @@ template <class Fixture>
static void BM_ErrorGetStatusCode(benchmark::State& state) {
TrackCounters track_counters;
Fixture fixture;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
grpc_status_code status;
- grpc_error_get_status(fixture.error(), fixture.deadline(), &status, NULL,
- NULL);
+ grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(),
+ &status, NULL, NULL);
}
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
@@ -273,11 +277,13 @@ template <class Fixture>
static void BM_ErrorHttpError(benchmark::State& state) {
TrackCounters track_counters;
Fixture fixture;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
grpc_http2_error_code error;
- grpc_error_get_status(fixture.error(), fixture.deadline(), NULL, NULL,
- &error);
+ grpc_error_get_status(&exec_ctx, fixture.error(), fixture.deadline(), NULL,
+ NULL, &error);
}
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc
index 2656566a50..adb5e6657f 100644
--- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc
+++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc
@@ -29,6 +29,7 @@
extern "C" {
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/ext/transport/chttp2/transport/internal.h"
+#include "src/core/lib/iomgr/timer_manager.h"
#include "test/core/util/trickle_endpoint.h"
}
@@ -45,6 +46,22 @@ DEFINE_int32(warmup_max_time_seconds, 10,
namespace grpc {
namespace testing {
+gpr_atm g_now_us = 0;
+
+static gpr_timespec fake_now(gpr_clock_type clock_type) {
+ gpr_timespec t;
+ gpr_atm now = gpr_atm_no_barrier_load(&g_now_us);
+ t.tv_sec = now / GPR_US_PER_SEC;
+ t.tv_nsec = (now % GPR_US_PER_SEC) * GPR_NS_PER_US;
+ t.clock_type = clock_type;
+ return t;
+}
+
+static void inc_time() {
+ gpr_atm_no_barrier_fetch_add(&g_now_us, 100);
+ grpc_timer_manager_tick();
+}
+
static void* tag(intptr_t x) { return reinterpret_cast<void*>(x); }
template <class A0>
@@ -158,6 +175,7 @@ class TrickledCHTTP2 : public EndpointPairFixture {
void Step(bool update_stats) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ inc_time();
size_t client_backlog =
grpc_trickle_endpoint_trickle(&exec_ctx, endpoint_pair_.client);
size_t server_backlog =
@@ -212,9 +230,8 @@ static void TrickleCQNext(TrickledCHTTP2* fixture, void** t, bool* ok,
int64_t iteration) {
while (true) {
fixture->Log(iteration);
- switch (fixture->cq()->AsyncNext(
- t, ok, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
- gpr_time_from_micros(100, GPR_TIMESPAN)))) {
+ switch (
+ fixture->cq()->AsyncNext(t, ok, gpr_inf_past(GPR_CLOCK_MONOTONIC))) {
case CompletionQueue::TIMEOUT:
fixture->Step(iteration != -1);
break;
@@ -289,9 +306,15 @@ static void BM_PumpStreamServerToClient_Trickle(benchmark::State& state) {
inner_loop(false);
}
response_rw.Finish(Status::OK, tag(1));
- need_tags = (1 << 0) | (1 << 1);
+ grpc::Status status;
+ request_rw->Finish(&status, tag(2));
+ need_tags = (1 << 0) | (1 << 1) | (1 << 2);
while (need_tags) {
TrickleCQNext(fixture.get(), &t, &ok, -1);
+ if (t == tag(0) && ok) {
+ request_rw->Read(&recv_response, tag(0));
+ continue;
+ }
int i = (int)(intptr_t)t;
GPR_ASSERT(need_tags & (1 << i));
need_tags &= ~(1 << i);
@@ -419,8 +442,12 @@ BENCHMARK(BM_PumpUnbalancedUnary_Trickle)->Apply(UnaryTrickleArgs);
}
}
+extern "C" gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type);
+
int main(int argc, char** argv) {
::benchmark::Initialize(&argc, argv);
::grpc::testing::InitTest(&argc, &argv, false);
+ grpc_timer_manager_set_threading(false);
+ gpr_now_impl = ::grpc::testing::fake_now;
::benchmark::RunSpecifiedBenchmarks();
}
diff --git a/test/cpp/microbenchmarks/bm_pollset.cc b/test/cpp/microbenchmarks/bm_pollset.cc
index 1fc1f2f83b..eab1e89480 100644
--- a/test/cpp/microbenchmarks/bm_pollset.cc
+++ b/test/cpp/microbenchmarks/bm_pollset.cc
@@ -117,11 +117,9 @@ static void BM_PollEmptyPollset(benchmark::State& state) {
gpr_mu* mu;
grpc_pollset_init(ps, &mu);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- gpr_timespec now = gpr_time_0(GPR_CLOCK_MONOTONIC);
- gpr_timespec deadline = gpr_inf_past(GPR_CLOCK_MONOTONIC);
gpr_mu_lock(mu);
while (state.KeepRunning()) {
- GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, NULL, now, deadline));
+ GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, NULL, 0));
}
grpc_closure shutdown_ps_closure;
GRPC_CLOSURE_INIT(&shutdown_ps_closure, shutdown_ps, ps,
@@ -223,8 +221,6 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) {
gpr_mu* mu;
grpc_pollset_init(ps, &mu);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- gpr_timespec now = gpr_time_0(GPR_CLOCK_MONOTONIC);
- gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
grpc_wakeup_fd wakeup_fd;
GRPC_ERROR_UNREF(grpc_wakeup_fd_init(&wakeup_fd));
grpc_fd* wakeup = grpc_fd_create(wakeup_fd.read_fd, "wakeup_read");
@@ -245,7 +241,8 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) {
grpc_fd_notify_on_read(&exec_ctx, wakeup, continue_closure);
gpr_mu_lock(mu);
while (!done) {
- GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, NULL, now, deadline));
+ GRPC_ERROR_UNREF(
+ grpc_pollset_work(&exec_ctx, ps, NULL, GRPC_MILLIS_INF_FUTURE));
}
grpc_fd_orphan(&exec_ctx, wakeup, NULL, NULL, false /* already_closed */,
"done");
diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h
index ecd28c3f8a..a7f8504505 100644
--- a/test/cpp/microbenchmarks/fullstack_fixtures.h
+++ b/test/cpp/microbenchmarks/fullstack_fixtures.h
@@ -85,7 +85,7 @@ class FullstackFixture : public BaseFixture {
}
virtual ~FullstackFixture() {
- server_->Shutdown();
+ server_->Shutdown(gpr_inf_past(GPR_CLOCK_MONOTONIC));
cq_->Shutdown();
void* tag;
bool ok;
@@ -212,7 +212,7 @@ class EndpointPairFixture : public BaseFixture {
}
virtual ~EndpointPairFixture() {
- server_->Shutdown();
+ server_->Shutdown(gpr_inf_past(GPR_CLOCK_MONOTONIC));
cq_->Shutdown();
void* tag;
bool ok;
diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc
index cc851ca9d5..7d0371bea4 100644
--- a/test/cpp/naming/resolver_component_test.cc
+++ b/test/cpp/naming/resolver_component_test.cc
@@ -199,10 +199,10 @@ void PollPollsetUntilRequestDone(ArgsStruct *args) {
grpc_pollset_worker *worker = NULL;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_mu_lock(args->mu);
- GRPC_LOG_IF_ERROR(
- "pollset_work",
- grpc_pollset_work(&exec_ctx, args->pollset, &worker,
- gpr_now(GPR_CLOCK_REALTIME), NSecondDeadline(1)));
+ GRPC_LOG_IF_ERROR("pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker,
+ grpc_timespec_to_millis_round_up(
+ NSecondDeadline(1))));
gpr_mu_unlock(args->mu);
grpc_exec_ctx_finish(&exec_ctx);
}
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index 7fbaf63492..abf755b393 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -226,6 +226,7 @@ class Client {
}
virtual void DestroyMultithreading() = 0;
+ virtual void InitThreadFunc(size_t thread_idx) = 0;
virtual bool ThreadFunc(HistogramEntry* histogram, size_t thread_idx) = 0;
void SetupLoadTest(const ClientConfig& config, size_t num_threads) {
@@ -299,13 +300,18 @@ class Client {
Thread& operator=(const Thread&);
void ThreadFunc() {
+ int wait_loop = 0;
while (!gpr_event_wait(
&client_->start_requests_,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_seconds(1, GPR_TIMESPAN)))) {
- gpr_log(GPR_INFO, "Waiting for benchmark to start");
+ gpr_time_from_seconds(20, GPR_TIMESPAN)))) {
+ gpr_log(GPR_INFO, "%" PRIdPTR ": Waiting for benchmark to start (%d)",
+ idx_, wait_loop);
+ wait_loop++;
}
+ client_->InitThreadFunc(idx_);
+
for (;;) {
// run the loop body
HistogramEntry entry;
@@ -380,6 +386,13 @@ class ClientImpl : public Client {
config.server_targets(i % config.server_targets_size()), config,
create_stub_, i);
}
+ std::vector<std::unique_ptr<std::thread>> connecting_threads;
+ for (auto& c : channels_) {
+ connecting_threads.emplace_back(c.WaitForReady());
+ }
+ for (auto& t : connecting_threads) {
+ t->join();
+ }
ClientRequestCreator<RequestType> create_req(&request_,
config.payload_config());
@@ -414,14 +427,19 @@ class ClientImpl : public Client {
!config.security_params().use_test_ca(),
std::shared_ptr<CallCredentials>(), args);
gpr_log(GPR_INFO, "Connecting to %s", target.c_str());
- GPR_ASSERT(channel_->WaitForConnected(
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_seconds(300, GPR_TIMESPAN))));
stub_ = create_stub(channel_);
}
Channel* get_channel() { return channel_.get(); }
StubType* get_stub() { return stub_.get(); }
+ std::unique_ptr<std::thread> WaitForReady() {
+ return std::unique_ptr<std::thread>(new std::thread([this]() {
+ GPR_ASSERT(channel_->WaitForConnected(
+ gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_seconds(10, GPR_TIMESPAN))));
+ }));
+ }
+
private:
void set_channel_args(const ClientConfig& config, ChannelArguments* args) {
for (auto channel_arg : config.channel_args()) {
diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc
index f5807da81e..9ed4e0b355 100644
--- a/test/cpp/qps/client_async.cc
+++ b/test/cpp/qps/client_async.cc
@@ -236,6 +236,7 @@ class AsyncClient : public ClientImpl<StubType, RequestType> {
this->EndThreads(); // this needed for resolution
}
+ void InitThreadFunc(size_t thread_idx) override final {}
bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override final {
void* got_tag;
bool ok;
diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc
index 5d212f1acc..94554a46b2 100644
--- a/test/cpp/qps/client_sync.cc
+++ b/test/cpp/qps/client_sync.cc
@@ -103,6 +103,8 @@ class SynchronousUnaryClient final : public SynchronousClient {
}
~SynchronousUnaryClient() {}
+ void InitThreadFunc(size_t thread_idx) override {}
+
bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override {
if (!WaitToIssue(thread_idx)) {
return true;
@@ -174,13 +176,7 @@ class SynchronousStreamingPingPongClient final
grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>> {
public:
SynchronousStreamingPingPongClient(const ClientConfig& config)
- : SynchronousStreamingClient(config) {
- for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) {
- auto* stub = channels_[thread_idx % channels_.size()].get_stub();
- stream_[thread_idx] = stub->StreamingCall(&context_[thread_idx]);
- messages_issued_[thread_idx] = 0;
- }
- }
+ : SynchronousStreamingClient(config) {}
~SynchronousStreamingPingPongClient() {
std::vector<std::thread> cleanup_threads;
for (size_t i = 0; i < num_threads_; i++) {
@@ -196,6 +192,12 @@ class SynchronousStreamingPingPongClient final
}
}
+ void InitThreadFunc(size_t thread_idx) override {
+ auto* stub = channels_[thread_idx % channels_.size()].get_stub();
+ stream_[thread_idx] = stub->StreamingCall(&context_[thread_idx]);
+ messages_issued_[thread_idx] = 0;
+ }
+
bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override {
if (!WaitToIssue(thread_idx)) {
return true;
@@ -228,14 +230,7 @@ class SynchronousStreamingFromClientClient final
: public SynchronousStreamingClient<grpc::ClientWriter<SimpleRequest>> {
public:
SynchronousStreamingFromClientClient(const ClientConfig& config)
- : SynchronousStreamingClient(config), last_issue_(num_threads_) {
- for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) {
- auto* stub = channels_[thread_idx % channels_.size()].get_stub();
- stream_[thread_idx] = stub->StreamingFromClient(&context_[thread_idx],
- &responses_[thread_idx]);
- last_issue_[thread_idx] = UsageTimer::Now();
- }
- }
+ : SynchronousStreamingClient(config), last_issue_(num_threads_) {}
~SynchronousStreamingFromClientClient() {
std::vector<std::thread> cleanup_threads;
for (size_t i = 0; i < num_threads_; i++) {
@@ -251,6 +246,13 @@ class SynchronousStreamingFromClientClient final
}
}
+ void InitThreadFunc(size_t thread_idx) override {
+ auto* stub = channels_[thread_idx % channels_.size()].get_stub();
+ stream_[thread_idx] = stub->StreamingFromClient(&context_[thread_idx],
+ &responses_[thread_idx]);
+ last_issue_[thread_idx] = UsageTimer::Now();
+ }
+
bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override {
// Figure out how to make histogram sensible if this is rate-paced
if (!WaitToIssue(thread_idx)) {
@@ -279,13 +281,12 @@ class SynchronousStreamingFromServerClient final
: public SynchronousStreamingClient<grpc::ClientReader<SimpleResponse>> {
public:
SynchronousStreamingFromServerClient(const ClientConfig& config)
- : SynchronousStreamingClient(config), last_recv_(num_threads_) {
- for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) {
- auto* stub = channels_[thread_idx % channels_.size()].get_stub();
- stream_[thread_idx] =
- stub->StreamingFromServer(&context_[thread_idx], request_);
- last_recv_[thread_idx] = UsageTimer::Now();
- }
+ : SynchronousStreamingClient(config), last_recv_(num_threads_) {}
+ void InitThreadFunc(size_t thread_idx) override {
+ auto* stub = channels_[thread_idx % channels_.size()].get_stub();
+ stream_[thread_idx] =
+ stub->StreamingFromServer(&context_[thread_idx], request_);
+ last_recv_[thread_idx] = UsageTimer::Now();
}
bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override {
GPR_TIMER_SCOPE("SynchronousStreamingFromServerClient::ThreadFunc", 0);
@@ -311,12 +312,7 @@ class SynchronousStreamingBothWaysClient final
grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>> {
public:
SynchronousStreamingBothWaysClient(const ClientConfig& config)
- : SynchronousStreamingClient(config) {
- for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) {
- auto* stub = channels_[thread_idx % channels_.size()].get_stub();
- stream_[thread_idx] = stub->StreamingBothWays(&context_[thread_idx]);
- }
- }
+ : SynchronousStreamingClient(config) {}
~SynchronousStreamingBothWaysClient() {
std::vector<std::thread> cleanup_threads;
for (size_t i = 0; i < num_threads_; i++) {
@@ -332,6 +328,10 @@ class SynchronousStreamingBothWaysClient final
}
}
+ void InitThreadFunc(size_t thread_idx) override {
+ auto* stub = channels_[thread_idx % channels_.size()].get_stub();
+ stream_[thread_idx] = stub->StreamingBothWays(&context_[thread_idx]);
+ }
bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override {
// TODO (vjpai): Do this
return true;