aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/bad_client/bad_client.c7
-rw-r--r--test/core/census/mlog_test.c6
-rw-r--r--test/core/client_config/lb_policies_test.c18
-rw-r--r--test/core/client_config/resolvers/dns_resolver_connectivity_test.c148
-rw-r--r--test/core/compression/compression_test.c102
-rw-r--r--test/core/end2end/fixtures/h2_full+trace.c132
-rw-r--r--test/core/end2end/fixtures/h2_sockpair+trace.c23
-rw-r--r--test/core/end2end/fixtures/h2_sockpair.c23
-rw-r--r--test/core/end2end/fixtures/h2_sockpair_1byte.c23
-rw-r--r--test/core/end2end/fixtures/h2_uchannel.c18
-rwxr-xr-xtest/core/end2end/gen_build_yaml.py16
-rw-r--r--test/core/end2end/invalid_call_argument_test.c40
-rw-r--r--test/core/httpcli/httpcli_test.c34
-rw-r--r--test/core/httpcli/httpscli_test.c36
-rw-r--r--test/core/iomgr/timer_heap_test.c196
-rw-r--r--test/core/iomgr/udp_server_test.c22
-rw-r--r--test/core/security/security_connector_test.c58
-rw-r--r--test/core/support/backoff_test.c107
-rw-r--r--test/core/support/load_file_test.c14
-rw-r--r--test/core/support/thd_test.c15
-rw-r--r--test/core/surface/concurrent_connectivity_test.c81
-rw-r--r--test/core/tsi/transport_security_test.c195
-rw-r--r--test/core/util/port_posix.c169
-rw-r--r--test/core/util/port_server_client.c215
-rw-r--r--test/core/util/port_server_client.h42
-rw-r--r--test/core/util/port_windows.c91
-rw-r--r--test/core/util/test_config.c149
-rw-r--r--test/cpp/codegen/codegen_test.cc49
-rw-r--r--test/cpp/end2end/async_end2end_test.cc232
-rw-r--r--test/cpp/end2end/end2end_test.cc34
-rw-r--r--test/cpp/end2end/test_service_impl.cc15
-rw-r--r--test/cpp/interop/reconnect_interop_server.cc12
-rw-r--r--test/cpp/qps/async_streaming_ping_pong_test.cc2
-rw-r--r--test/cpp/qps/async_unary_ping_pong_test.cc2
-rw-r--r--test/cpp/qps/client.h35
-rw-r--r--test/cpp/qps/driver.cc47
-rw-r--r--test/cpp/qps/generic_async_streaming_ping_pong_test.cc2
-rw-r--r--test/cpp/qps/qps_openloop_test.cc2
-rw-r--r--test/cpp/qps/qps_test.cc2
-rw-r--r--test/cpp/qps/secure_sync_unary_ping_pong_test.cc2
-rw-r--r--test/cpp/qps/server_async.cc3
-rw-r--r--test/cpp/qps/sync_streaming_ping_pong_test.cc2
-rw-r--r--test/cpp/qps/sync_unary_ping_pong_test.cc2
-rw-r--r--test/cpp/util/test_credentials_provider.h5
44 files changed, 1701 insertions, 727 deletions
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c
index 1a2ca6f0c0..ba1901301c 100644
--- a/test/core/bad_client/bad_client.c
+++ b/test/core/bad_client/bad_client.c
@@ -67,11 +67,8 @@ static void done_write(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
static void server_setup_transport(void *ts, grpc_transport *transport) {
thd_args *a = ts;
- static grpc_channel_filter const *extra_filters[] = {
- &grpc_http_server_filter};
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_server_setup_transport(&exec_ctx, a->server, transport, extra_filters,
- GPR_ARRAY_SIZE(extra_filters),
+ grpc_server_setup_transport(&exec_ctx, a->server, transport,
grpc_server_get_channel_args(a->server));
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -105,7 +102,7 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator,
sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);
/* Create server, completion events */
- a.server = grpc_server_create_from_filters(NULL, 0, NULL);
+ a.server = grpc_server_create(NULL, NULL);
a.cq = grpc_completion_queue_create(NULL);
gpr_event_init(&a.done_thd);
gpr_event_init(&a.done_write);
diff --git a/test/core/census/mlog_test.c b/test/core/census/mlog_test.c
index 5b6c5946ab..000ac7335a 100644
--- a/test/core/census/mlog_test.c
+++ b/test/core/census/mlog_test.c
@@ -332,7 +332,7 @@ static void multiple_writers_single_reader(int circular_log) {
static void setup_test(int circular_log) {
census_log_initialize(LOG_SIZE_IN_MB, circular_log);
- GPR_ASSERT(census_log_remaining_space() == LOG_SIZE_IN_BYTES);
+ // GPR_ASSERT(census_log_remaining_space() == LOG_SIZE_IN_BYTES);
}
// Attempts to create a record of invalid size (size >
@@ -352,8 +352,8 @@ void test_invalid_record_size(void) {
// check can fail if the thread is context switched to a new CPU during the
// start_write execution (multiple blocks get allocated), but this has not
// been observed in practice.
- GPR_ASSERT(LOG_SIZE_IN_BYTES - CENSUS_LOG_MAX_RECORD_SIZE ==
- census_log_remaining_space());
+ // GPR_ASSERT(LOG_SIZE_IN_BYTES - CENSUS_LOG_MAX_RECORD_SIZE ==
+ // census_log_remaining_space());
census_log_shutdown();
}
diff --git a/test/core/client_config/lb_policies_test.c b/test/core/client_config/lb_policies_test.c
index cb99b3da3e..1ea0c423c1 100644
--- a/test/core/client_config/lb_policies_test.c
+++ b/test/core/client_config/lb_policies_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -52,6 +52,8 @@
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
+#define RETRY_TIMEOUT 300
+
typedef struct servers_fixture {
size_t num_servers;
grpc_server **servers;
@@ -303,8 +305,8 @@ static int *perform_request(servers_fixture *f, grpc_channel *client,
s_idx = -1;
while ((ev = grpc_completion_queue_next(
- f->cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), NULL)).type !=
- GRPC_QUEUE_TIMEOUT) {
+ f->cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10 * RETRY_TIMEOUT),
+ NULL)).type != GRPC_QUEUE_TIMEOUT) {
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
read_tag = ((int)(intptr_t)ev.tag);
gpr_log(GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%d",
@@ -376,9 +378,9 @@ static int *perform_request(servers_fixture *f, grpc_channel *client,
}
}
- GPR_ASSERT(grpc_completion_queue_next(f->cq,
- GRPC_TIMEOUT_MILLIS_TO_DEADLINE(200),
- NULL).type == GRPC_QUEUE_TIMEOUT);
+ GPR_ASSERT(grpc_completion_queue_next(
+ f->cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2 * RETRY_TIMEOUT),
+ NULL).type == GRPC_QUEUE_TIMEOUT);
grpc_metadata_array_destroy(&rdata->initial_metadata_recv);
grpc_metadata_array_destroy(&rdata->trailing_metadata_recv);
@@ -506,7 +508,7 @@ void run_spec(const test_spec *spec) {
arg.type = GRPC_ARG_INTEGER;
arg.key = "grpc.testing.fixed_reconnect_backoff";
- arg.value.integer = 100;
+ arg.value.integer = RETRY_TIMEOUT;
args.num_args = 1;
args.args = &arg;
@@ -542,7 +544,7 @@ static grpc_channel *create_client(const servers_fixture *f) {
arg.type = GRPC_ARG_INTEGER;
arg.key = "grpc.testing.fixed_reconnect_backoff";
- arg.value.integer = 100;
+ arg.value.integer = RETRY_TIMEOUT;
args.num_args = 1;
args.args = &arg;
diff --git a/test/core/client_config/resolvers/dns_resolver_connectivity_test.c b/test/core/client_config/resolvers/dns_resolver_connectivity_test.c
new file mode 100644
index 0000000000..75d1eb674f
--- /dev/null
+++ b/test/core/client_config/resolvers/dns_resolver_connectivity_test.c
@@ -0,0 +1,148 @@
+/*
+ *
+ * Copyright 2015-2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/core/client_config/resolvers/dns_resolver.h"
+
+#include <string.h>
+
+#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
+
+#include "src/core/iomgr/resolve_address.h"
+#include "src/core/iomgr/timer.h"
+#include "test/core/util/test_config.h"
+
+static void subchannel_factory_ref(grpc_subchannel_factory *scv) {}
+static void subchannel_factory_unref(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_factory *scv) {}
+static grpc_subchannel *subchannel_factory_create_subchannel(
+ grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory,
+ grpc_subchannel_args *args) {
+ return NULL;
+}
+
+static const grpc_subchannel_factory_vtable sc_vtable = {
+ subchannel_factory_ref, subchannel_factory_unref,
+ subchannel_factory_create_subchannel};
+
+static grpc_subchannel_factory sc_factory = {&sc_vtable};
+
+static gpr_mu g_mu;
+static bool g_fail_resolution = true;
+
+static grpc_resolved_addresses *my_resolve_address(const char *name,
+ const char *addr) {
+ gpr_mu_lock(&g_mu);
+ GPR_ASSERT(0 == strcmp("test", name));
+ if (g_fail_resolution) {
+ g_fail_resolution = false;
+ gpr_mu_unlock(&g_mu);
+ return NULL;
+ } else {
+ gpr_mu_unlock(&g_mu);
+ grpc_resolved_addresses *addrs = gpr_malloc(sizeof(*addrs));
+ addrs->naddrs = 1;
+ addrs->addrs = gpr_malloc(sizeof(*addrs->addrs));
+ addrs->addrs[0].len = 123;
+ return addrs;
+ }
+}
+
+static grpc_resolver *create_resolver(const char *name) {
+ grpc_resolver_factory *factory = grpc_dns_resolver_factory_create();
+ grpc_uri *uri = grpc_uri_parse(name, 0);
+ GPR_ASSERT(uri);
+ grpc_resolver_args args;
+ memset(&args, 0, sizeof(args));
+ args.uri = uri;
+ args.subchannel_factory = &sc_factory;
+ grpc_resolver *resolver =
+ grpc_resolver_factory_create_resolver(factory, &args);
+ grpc_resolver_factory_unref(factory);
+ grpc_uri_destroy(uri);
+ return resolver;
+}
+
+static void on_done(grpc_exec_ctx *exec_ctx, void *ev, bool success) {
+ gpr_event_set(ev, (void *)1);
+}
+
+// interleave waiting for an event with a timer check
+static bool wait_loop(int deadline_seconds, gpr_event *ev) {
+ while (deadline_seconds) {
+ gpr_log(GPR_DEBUG, "Test: waiting for %d more seconds", deadline_seconds);
+ if (gpr_event_wait(ev, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1))) return true;
+ deadline_seconds--;
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_timer_check(&exec_ctx, gpr_now(GPR_CLOCK_MONOTONIC), NULL);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ return false;
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+
+ grpc_init();
+ gpr_mu_init(&g_mu);
+ grpc_blocking_resolve_address = my_resolve_address;
+
+ grpc_resolver *resolver = create_resolver("dns:test");
+
+ grpc_client_config *config = (grpc_client_config *)1;
+
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ gpr_event ev1;
+ gpr_event_init(&ev1);
+ grpc_resolver_next(&exec_ctx, resolver, &config,
+ grpc_closure_create(on_done, &ev1));
+ grpc_exec_ctx_flush(&exec_ctx);
+ GPR_ASSERT(wait_loop(5, &ev1));
+ GPR_ASSERT(config == NULL);
+
+ gpr_event ev2;
+ gpr_event_init(&ev2);
+ grpc_resolver_next(&exec_ctx, resolver, &config,
+ grpc_closure_create(on_done, &ev2));
+ grpc_exec_ctx_flush(&exec_ctx);
+ GPR_ASSERT(wait_loop(30, &ev2));
+ GPR_ASSERT(config != NULL);
+
+ grpc_client_config_unref(&exec_ctx, config);
+ GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test");
+ grpc_exec_ctx_finish(&exec_ctx);
+
+ grpc_shutdown();
+ gpr_mu_destroy(&g_mu);
+}
diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c
index 26d7b2b6cc..5d8231fd7f 100644
--- a/test/core/compression/compression_test.c
+++ b/test/core/compression/compression_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -93,18 +93,98 @@ static void test_compression_algorithm_name(void) {
}
static void test_compression_algorithm_for_level(void) {
- size_t i;
- grpc_compression_level levels[] = {
- GRPC_COMPRESS_LEVEL_NONE, GRPC_COMPRESS_LEVEL_LOW,
- GRPC_COMPRESS_LEVEL_MED, GRPC_COMPRESS_LEVEL_HIGH};
- grpc_compression_algorithm algorithms[] = {
- GRPC_COMPRESS_NONE, GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_DEFLATE,
- GRPC_COMPRESS_DEFLATE};
gpr_log(GPR_DEBUG, "test_compression_algorithm_for_level");
- for (i = 0; i < GPR_ARRAY_SIZE(levels); i++) {
- GPR_ASSERT(algorithms[i] ==
- grpc_compression_algorithm_for_level(levels[i]));
+ {
+ /* accept only identity (aka none) */
+ uint32_t accepted_encodings = 0;
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH,
+ accepted_encodings));
+ }
+
+ {
+ /* accept only gzip */
+ uint32_t accepted_encodings = 0;
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP);
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_GZIP ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_GZIP ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_GZIP ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH,
+ accepted_encodings));
+ }
+
+ {
+ /* accept only deflate */
+ uint32_t accepted_encodings = 0;
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH,
+ accepted_encodings));
+ }
+
+ {
+ /* accept gzip and deflate */
+ uint32_t accepted_encodings = 0;
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP);
+ GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
+
+ GPR_ASSERT(GRPC_COMPRESS_NONE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_GZIP ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_LOW,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_MED,
+ accepted_encodings));
+
+ GPR_ASSERT(GRPC_COMPRESS_DEFLATE ==
+ grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH,
+ accepted_encodings));
}
}
diff --git a/test/core/end2end/fixtures/h2_full+trace.c b/test/core/end2end/fixtures/h2_full+trace.c
new file mode 100644
index 0000000000..90b0063089
--- /dev/null
+++ b/test/core/end2end/fixtures/h2_full+trace.c
@@ -0,0 +1,132 @@
+/*
+ *
+ * Copyright 2015-2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <string.h>
+
+#include "src/core/channel/client_channel.h"
+#include "src/core/channel/connected_channel.h"
+#include "src/core/channel/http_server_filter.h"
+#include "src/core/surface/channel.h"
+#include "src/core/surface/server.h"
+#include "src/core/transport/chttp2_transport.h"
+#include <grpc/support/alloc.h>
+#include <grpc/support/host_port.h>
+#include <grpc/support/log.h>
+#include <grpc/support/sync.h>
+#include <grpc/support/thd.h>
+#include <grpc/support/useful.h>
+#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
+#include "src/core/support/env.h"
+
+typedef struct fullstack_fixture_data {
+ char *localaddr;
+} fullstack_fixture_data;
+
+static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
+ grpc_channel_args *client_args, grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ int port = grpc_pick_unused_port_or_die();
+ fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data));
+ memset(&f, 0, sizeof(f));
+
+ gpr_join_host_port(&ffd->localaddr, "localhost", port);
+
+ f.fixture_data = ffd;
+ f.cq = grpc_completion_queue_create(NULL);
+
+ return f;
+}
+
+void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f,
+ grpc_channel_args *client_args) {
+ fullstack_fixture_data *ffd = f->fixture_data;
+ f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL);
+ GPR_ASSERT(f->client);
+}
+
+void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f,
+ grpc_channel_args *server_args) {
+ fullstack_fixture_data *ffd = f->fixture_data;
+ if (f->server) {
+ grpc_server_destroy(f->server);
+ }
+ f->server = grpc_server_create(server_args, NULL);
+ grpc_server_register_completion_queue(f->server, f->cq, NULL);
+ GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
+ grpc_server_start(f->server);
+}
+
+void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) {
+ fullstack_fixture_data *ffd = f->fixture_data;
+ gpr_free(ffd->localaddr);
+ gpr_free(ffd);
+}
+
+/* All test configurations */
+static grpc_end2end_test_config configs[] = {
+ {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION,
+ chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
+ chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
+};
+
+int main(int argc, char **argv) {
+ size_t i;
+
+ /* force tracing on, with a value to force many
+ code paths in trace.c to be taken */
+ gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
+
+#ifdef GPR_POSIX_SOCKET
+ g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10.0 : 1.0;
+#else
+ g_fixture_slowdown_factor = 10.0;
+#endif
+
+ grpc_test_init(argc, argv);
+ grpc_init();
+
+ for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
+ grpc_end2end_tests(argc, argv, configs[i]);
+ }
+
+ GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0));
+ GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1));
+ GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1));
+
+ grpc_shutdown();
+
+ return 0;
+}
diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.c b/test/core/end2end/fixtures/h2_sockpair+trace.c
index 511c8b1a46..482aa8dba8 100644
--- a/test/core/end2end/fixtures/h2_sockpair+trace.c
+++ b/test/core/end2end/fixtures/h2_sockpair+trace.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,11 +59,8 @@
static void server_setup_transport(void *ts, grpc_transport *transport) {
grpc_end2end_test_fixture *f = ts;
- static grpc_channel_filter const *extra_filters[] = {
- &grpc_http_server_filter};
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters,
- GPR_ARRAY_SIZE(extra_filters),
+ grpc_server_setup_transport(&exec_ctx, f->server, transport,
grpc_server_get_channel_args(f->server));
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -77,17 +74,9 @@ static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts,
grpc_transport *transport) {
sp_client_setup *cs = ts;
- const grpc_channel_filter *filters[] = {&grpc_http_client_filter,
- &grpc_compress_filter,
- &grpc_connected_channel_filter};
- size_t nfilters = sizeof(filters) / sizeof(*filters);
- grpc_channel *channel = grpc_channel_create_from_filters(
- exec_ctx, "socketpair-target", filters, nfilters, cs->client_args, 1);
-
- cs->f->client = channel;
-
- grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel),
- transport);
+ cs->f->client =
+ grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args,
+ GRPC_CLIENT_DIRECT_CHANNEL, transport);
}
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
@@ -126,7 +115,7 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
grpc_endpoint_pair *sfd = f->fixture_data;
grpc_transport *transport;
GPR_ASSERT(!f->server);
- f->server = grpc_server_create_from_filters(NULL, 0, server_args);
+ f->server = grpc_server_create(server_args, NULL);
grpc_server_register_completion_queue(f->server, f->cq, NULL);
grpc_server_start(f->server);
transport =
diff --git a/test/core/end2end/fixtures/h2_sockpair.c b/test/core/end2end/fixtures/h2_sockpair.c
index 6b4787b1e5..cf1c4ac2ae 100644
--- a/test/core/end2end/fixtures/h2_sockpair.c
+++ b/test/core/end2end/fixtures/h2_sockpair.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,11 +58,8 @@
static void server_setup_transport(void *ts, grpc_transport *transport) {
grpc_end2end_test_fixture *f = ts;
- static grpc_channel_filter const *extra_filters[] = {
- &grpc_http_server_filter};
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters,
- GPR_ARRAY_SIZE(extra_filters),
+ grpc_server_setup_transport(&exec_ctx, f->server, transport,
grpc_server_get_channel_args(f->server));
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -76,17 +73,9 @@ static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts,
grpc_transport *transport) {
sp_client_setup *cs = ts;
- const grpc_channel_filter *filters[] = {&grpc_http_client_filter,
- &grpc_compress_filter,
- &grpc_connected_channel_filter};
- size_t nfilters = sizeof(filters) / sizeof(*filters);
- grpc_channel *channel = grpc_channel_create_from_filters(
- exec_ctx, "socketpair-target", filters, nfilters, cs->client_args, 1);
-
- cs->f->client = channel;
-
- grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel),
- transport);
+ cs->f->client =
+ grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args,
+ GRPC_CLIENT_DIRECT_CHANNEL, transport);
}
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
@@ -125,7 +114,7 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
grpc_endpoint_pair *sfd = f->fixture_data;
grpc_transport *transport;
GPR_ASSERT(!f->server);
- f->server = grpc_server_create_from_filters(NULL, 0, server_args);
+ f->server = grpc_server_create(server_args, NULL);
grpc_server_register_completion_queue(f->server, f->cq, NULL);
grpc_server_start(f->server);
transport =
diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.c b/test/core/end2end/fixtures/h2_sockpair_1byte.c
index 3ae8e96683..f49938c619 100644
--- a/test/core/end2end/fixtures/h2_sockpair_1byte.c
+++ b/test/core/end2end/fixtures/h2_sockpair_1byte.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,11 +58,8 @@
static void server_setup_transport(void *ts, grpc_transport *transport) {
grpc_end2end_test_fixture *f = ts;
- static grpc_channel_filter const *extra_filters[] = {
- &grpc_http_server_filter};
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters,
- GPR_ARRAY_SIZE(extra_filters),
+ grpc_server_setup_transport(&exec_ctx, f->server, transport,
grpc_server_get_channel_args(f->server));
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -76,17 +73,9 @@ static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts,
grpc_transport *transport) {
sp_client_setup *cs = ts;
- const grpc_channel_filter *filters[] = {&grpc_http_client_filter,
- &grpc_compress_filter,
- &grpc_connected_channel_filter};
- size_t nfilters = sizeof(filters) / sizeof(*filters);
- grpc_channel *channel = grpc_channel_create_from_filters(
- exec_ctx, "socketpair-target", filters, nfilters, cs->client_args, 1);
-
- cs->f->client = channel;
-
- grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel),
- transport);
+ cs->f->client =
+ grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args,
+ GRPC_CLIENT_DIRECT_CHANNEL, transport);
}
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
@@ -125,7 +114,7 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
grpc_endpoint_pair *sfd = f->fixture_data;
grpc_transport *transport;
GPR_ASSERT(!f->server);
- f->server = grpc_server_create_from_filters(NULL, 0, server_args);
+ f->server = grpc_server_create(server_args, NULL);
grpc_server_register_completion_queue(f->server, f->cq, NULL);
grpc_server_start(f->server);
transport =
diff --git a/test/core/end2end/fixtures/h2_uchannel.c b/test/core/end2end/fixtures/h2_uchannel.c
index 87bbd64d09..25a4804bea 100644
--- a/test/core/end2end/fixtures/h2_uchannel.c
+++ b/test/core/end2end/fixtures/h2_uchannel.c
@@ -91,9 +91,6 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
grpc_chttp2_transport_start_reading(exec_ctx, c->result->transport, NULL,
0);
GPR_ASSERT(c->result->transport);
- c->result->filters = gpr_malloc(sizeof(grpc_channel_filter *));
- c->result->filters[0] = &grpc_http_client_filter;
- c->result->num_filters = 1;
} else {
memset(c->result, 0, sizeof(*c->result));
}
@@ -179,18 +176,12 @@ static const grpc_subchannel_factory_vtable test_subchannel_factory_vtable = {
grpc_channel *channel_create(const char *target, const grpc_channel_args *args,
grpc_subchannel **sniffed_subchannel) {
grpc_channel *channel = NULL;
-#define MAX_FILTERS 1
- const grpc_channel_filter *filters[MAX_FILTERS];
grpc_resolver *resolver;
subchannel_factory *f;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- size_t n = 0;
-
- filters[n++] = &grpc_client_channel_filter;
- GPR_ASSERT(n <= MAX_FILTERS);
channel =
- grpc_channel_create_from_filters(&exec_ctx, target, filters, n, args, 1);
+ grpc_channel_create(&exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL);
f = gpr_malloc(sizeof(*f));
f->sniffed_subchannel = sniffed_subchannel;
@@ -285,7 +276,7 @@ static void chttp2_init_client_micro_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args) {
micro_fullstack_fixture_data *ffd = f->fixture_data;
grpc_connectivity_state conn_state;
- grpc_connected_subchannel *connected;
+ grpc_connected_subchannel *connected_subchannel;
char *ipv4_localaddr;
gpr_asprintf(&ipv4_localaddr, "ipv4:%s", ffd->localaddr);
@@ -302,9 +293,10 @@ static void chttp2_init_client_micro_fullstack(grpc_end2end_test_fixture *f,
GPR_ASSERT(conn_state == GRPC_CHANNEL_IDLE);
GPR_ASSERT(ffd->sniffed_subchannel != NULL);
- connected = connect_subchannel(ffd->sniffed_subchannel);
+ connected_subchannel = connect_subchannel(ffd->sniffed_subchannel);
f->client = grpc_client_uchannel_create(ffd->sniffed_subchannel, client_args);
- grpc_client_uchannel_set_connected_subchannel(f->client, connected);
+ grpc_client_uchannel_set_connected_subchannel(f->client,
+ connected_subchannel);
gpr_log(GPR_INFO, "CHANNEL WRAPPING SUBCHANNEL: %p(%p)", f->client,
ffd->sniffed_subchannel);
diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py
index 4dfafcea24..fa32601c60 100755
--- a/test/core/end2end/gen_build_yaml.py
+++ b/test/core/end2end/gen_build_yaml.py
@@ -59,6 +59,7 @@ END2END_FIXTURES = {
platforms=['linux']),
'h2_full+poll+pipe': default_unsecure_fixture_options._replace(
platforms=['linux']),
+ 'h2_full+trace': default_unsecure_fixture_options._replace(tracing=True),
'h2_oauth2': default_secure_fixture_options._replace(ci_mac=False),
'h2_proxy': default_unsecure_fixture_options._replace(includes_proxy=True,
ci_mac=False),
@@ -66,7 +67,7 @@ END2END_FIXTURES = {
ci_mac=False),
'h2_sockpair': socketpair_unsecure_fixture_options._replace(ci_mac=False),
'h2_sockpair+trace': socketpair_unsecure_fixture_options._replace(
- tracing=True),
+ ci_mac=False, tracing=True),
'h2_ssl': default_secure_fixture_options,
'h2_ssl+poll': default_secure_fixture_options._replace(platforms=['linux']),
'h2_ssl_proxy': default_secure_fixture_options._replace(includes_proxy=True,
@@ -150,7 +151,6 @@ def without(l, e):
def main():
sec_deps = [
- 'end2end_certs',
'grpc_test_util',
'grpc',
'gpr_test_util',
@@ -193,18 +193,6 @@ def main():
'deps': unsec_deps,
'vs_proj_dir': 'test/end2end/tests',
}
- ] + [
- {
- 'name': 'end2end_certs',
- 'build': 'private',
- 'language': 'c',
- 'src': [
- "test/core/end2end/data/test_root_cert.c",
- "test/core/end2end/data/server1_cert.c",
- "test/core/end2end/data/server1_key.c"
- ],
- 'vs_proj_dir': 'test/end2end',
- }
],
'targets': [
{
diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c
index 4029e96a41..2fa1a0a108 100644
--- a/test/core/end2end/invalid_call_argument_test.c
+++ b/test/core/end2end/invalid_call_argument_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -145,6 +145,8 @@ static void cleanup_test() {
}
static void test_non_null_reserved_on_start_batch() {
+ gpr_log(GPR_INFO, "test_non_null_reserved_on_start_batch");
+
prepare_test(1);
GPR_ASSERT(GRPC_CALL_ERROR ==
grpc_call_start_batch(g_state.call, NULL, 0, NULL, tag(1)));
@@ -152,6 +154,8 @@ static void test_non_null_reserved_on_start_batch() {
}
static void test_non_null_reserved_on_op() {
+ gpr_log(GPR_INFO, "test_non_null_reserved_on_op");
+
grpc_op *op;
prepare_test(1);
@@ -168,6 +172,8 @@ static void test_non_null_reserved_on_op() {
}
static void test_send_initial_metadata_more_than_once() {
+ gpr_log(GPR_INFO, "test_send_initial_metadata_more_than_once");
+
grpc_op *op;
prepare_test(1);
@@ -196,6 +202,8 @@ static void test_send_initial_metadata_more_than_once() {
}
static void test_too_many_metadata() {
+ gpr_log(GPR_INFO, "test_too_many_metadata");
+
grpc_op *op;
prepare_test(1);
@@ -212,6 +220,8 @@ static void test_too_many_metadata() {
}
static void test_send_null_message() {
+ gpr_log(GPR_INFO, "test_send_null_message");
+
grpc_op *op;
prepare_test(1);
@@ -233,6 +243,8 @@ static void test_send_null_message() {
}
static void test_send_messages_at_the_same_time() {
+ gpr_log(GPR_INFO, "test_send_messages_at_the_same_time");
+
grpc_op *op;
gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
grpc_byte_buffer *request_payload =
@@ -262,6 +274,8 @@ static void test_send_messages_at_the_same_time() {
}
static void test_send_server_status_from_client() {
+ gpr_log(GPR_INFO, "test_send_server_status_from_client");
+
grpc_op *op;
prepare_test(1);
@@ -280,6 +294,8 @@ static void test_send_server_status_from_client() {
}
static void test_receive_initial_metadata_twice_at_client() {
+ gpr_log(GPR_INFO, "test_receive_initial_metadata_twice_at_client");
+
grpc_op *op;
prepare_test(1);
op = g_state.ops;
@@ -306,6 +322,8 @@ static void test_receive_initial_metadata_twice_at_client() {
}
static void test_receive_message_with_invalid_flags() {
+ gpr_log(GPR_INFO, "test_receive_message_with_invalid_flags");
+
grpc_op *op;
grpc_byte_buffer *payload = NULL;
prepare_test(1);
@@ -322,6 +340,8 @@ static void test_receive_message_with_invalid_flags() {
}
static void test_receive_two_messages_at_the_same_time() {
+ gpr_log(GPR_INFO, "test_receive_two_messages_at_the_same_time");
+
grpc_op *op;
grpc_byte_buffer *payload = NULL;
prepare_test(1);
@@ -343,6 +363,8 @@ static void test_receive_two_messages_at_the_same_time() {
}
static void test_recv_close_on_server_from_client() {
+ gpr_log(GPR_INFO, "test_recv_close_on_server_from_client");
+
grpc_op *op;
prepare_test(1);
@@ -359,6 +381,8 @@ static void test_recv_close_on_server_from_client() {
}
static void test_recv_status_on_client_twice() {
+ gpr_log(GPR_INFO, "test_recv_status_on_client_twice");
+
grpc_op *op;
prepare_test(1);
@@ -395,6 +419,8 @@ static void test_recv_status_on_client_twice() {
}
static void test_send_close_from_client_on_server() {
+ gpr_log(GPR_INFO, "test_send_close_from_client_on_server");
+
grpc_op *op;
prepare_test(0);
@@ -410,6 +436,8 @@ static void test_send_close_from_client_on_server() {
}
static void test_recv_status_on_client_from_server() {
+ gpr_log(GPR_INFO, "test_recv_status_on_client_from_server");
+
grpc_op *op;
prepare_test(0);
@@ -431,6 +459,8 @@ static void test_recv_status_on_client_from_server() {
}
static void test_send_status_from_server_with_invalid_flags() {
+ gpr_log(GPR_INFO, "test_send_status_from_server_with_invalid_flags");
+
grpc_op *op;
prepare_test(0);
@@ -449,6 +479,8 @@ static void test_send_status_from_server_with_invalid_flags() {
}
static void test_too_many_trailing_metadata() {
+ gpr_log(GPR_INFO, "test_too_many_trailing_metadata");
+
grpc_op *op;
prepare_test(0);
@@ -468,6 +500,8 @@ static void test_too_many_trailing_metadata() {
}
static void test_send_server_status_twice() {
+ gpr_log(GPR_INFO, "test_send_server_status_twice");
+
grpc_op *op;
prepare_test(0);
@@ -493,6 +527,8 @@ static void test_send_server_status_twice() {
}
static void test_recv_close_on_server_with_invalid_flags() {
+ gpr_log(GPR_INFO, "test_recv_close_on_server_with_invalid_flags");
+
grpc_op *op;
prepare_test(0);
@@ -509,6 +545,8 @@ static void test_recv_close_on_server_with_invalid_flags() {
}
static void test_recv_close_on_server_twice() {
+ gpr_log(GPR_INFO, "test_recv_close_on_server_twice");
+
grpc_op *op;
prepare_test(0);
diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c
index da1463329d..fbc5d4abe7 100644
--- a/test/core/httpcli/httpcli_test.c
+++ b/test/core/httpcli/httpcli_test.c
@@ -144,31 +144,35 @@ int main(int argc, char **argv) {
char *lslash = strrchr(me, '/');
char *args[4];
int port = grpc_pick_unused_port_or_die();
+ int arg_shift = 0;
+ /* figure out where we are */
+ char *root;
+ if (lslash) {
+ root = gpr_malloc((size_t)(lslash - me + 1));
+ memcpy(root, me, (size_t)(lslash - me));
+ root[lslash - me] = 0;
+ } else {
+ root = gpr_strdup(".");
+ }
GPR_ASSERT(argc <= 2);
if (argc == 2) {
args[0] = gpr_strdup(argv[1]);
} else {
- /* figure out where we are */
- char *root;
- if (lslash) {
- root = gpr_malloc((size_t)(lslash - me + 1));
- memcpy(root, me, (size_t)(lslash - me));
- root[lslash - me] = 0;
- } else {
- root = gpr_strdup(".");
- }
- gpr_asprintf(&args[0], "%s/../../test/core/httpcli/test_server.py", root);
- gpr_free(root);
+ arg_shift = 1;
+ gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root);
+ gpr_asprintf(&args[1], "%s/../../test/core/httpcli/test_server.py", root);
}
/* start the server */
- args[1] = "--port";
- gpr_asprintf(&args[2], "%d", port);
- server = gpr_subprocess_create(3, (const char **)args);
+ args[1 + arg_shift] = "--port";
+ gpr_asprintf(&args[2 + arg_shift], "%d", port);
+ server = gpr_subprocess_create(3 + arg_shift, (const char **)args);
GPR_ASSERT(server);
gpr_free(args[0]);
- gpr_free(args[2]);
+ if (arg_shift) gpr_free(args[1]);
+ gpr_free(args[2 + arg_shift]);
+ gpr_free(root);
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(5, GPR_TIMESPAN)));
diff --git a/test/core/httpcli/httpscli_test.c b/test/core/httpcli/httpscli_test.c
index 7f765bc614..04c57db286 100644
--- a/test/core/httpcli/httpscli_test.c
+++ b/test/core/httpcli/httpscli_test.c
@@ -146,32 +146,36 @@ int main(int argc, char **argv) {
char *lslash = strrchr(me, '/');
char *args[5];
int port = grpc_pick_unused_port_or_die();
+ int arg_shift = 0;
+ /* figure out where we are */
+ char *root;
+ if (lslash) {
+ root = gpr_malloc((size_t)(lslash - me + 1));
+ memcpy(root, me, (size_t)(lslash - me));
+ root[lslash - me] = 0;
+ } else {
+ root = gpr_strdup(".");
+ }
GPR_ASSERT(argc <= 2);
if (argc == 2) {
args[0] = gpr_strdup(argv[1]);
} else {
- /* figure out where we are */
- char *root;
- if (lslash) {
- root = gpr_malloc((size_t)(lslash - me + 1));
- memcpy(root, me, (size_t)(lslash - me));
- root[lslash - me] = 0;
- } else {
- root = gpr_strdup(".");
- }
- gpr_asprintf(&args[0], "%s/../../test/core/httpcli/test_server.py", root);
- gpr_free(root);
+ arg_shift = 1;
+ gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root);
+ gpr_asprintf(&args[1], "%s/../../test/core/httpcli/test_server.py", root);
}
/* start the server */
- args[1] = "--port";
- gpr_asprintf(&args[2], "%d", port);
- args[3] = "--ssl";
- server = gpr_subprocess_create(4, (const char **)args);
+ args[1 + arg_shift] = "--port";
+ gpr_asprintf(&args[2 + arg_shift], "%d", port);
+ args[3 + arg_shift] = "--ssl";
+ server = gpr_subprocess_create(4 + arg_shift, (const char **)args);
GPR_ASSERT(server);
gpr_free(args[0]);
- gpr_free(args[2]);
+ if (arg_shift) gpr_free(args[1]);
+ gpr_free(args[2 + arg_shift]);
+ gpr_free(root);
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(5, GPR_TIMESPAN)));
diff --git a/test/core/iomgr/timer_heap_test.c b/test/core/iomgr/timer_heap_test.c
index 077a9fd6bd..dd23a99520 100644
--- a/test/core/iomgr/timer_heap_test.c
+++ b/test/core/iomgr/timer_heap_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -38,6 +38,8 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include <grpc/support/useful.h>
+
#include "test/core/util/test_config.h"
static gpr_timespec random_deadline(void) {
@@ -57,79 +59,6 @@ static grpc_timer *create_test_elements(size_t num_elements) {
return elems;
}
-static int cmp_elem(const void *a, const void *b) {
- int i = *(const int *)a;
- int j = *(const int *)b;
- return i - j;
-}
-
-static size_t *all_top(grpc_timer_heap *pq, size_t *n) {
- size_t *vec = NULL;
- size_t *need_to_check_children;
- size_t num_need_to_check_children = 0;
-
- *n = 0;
- if (pq->timer_count == 0) return vec;
- need_to_check_children =
- gpr_malloc(pq->timer_count * sizeof(*need_to_check_children));
- need_to_check_children[num_need_to_check_children++] = 0;
- vec = gpr_malloc(pq->timer_count * sizeof(*vec));
- while (num_need_to_check_children > 0) {
- size_t ind = need_to_check_children[0];
- size_t leftchild, rightchild;
- num_need_to_check_children--;
- memmove(need_to_check_children, need_to_check_children + 1,
- num_need_to_check_children * sizeof(*need_to_check_children));
- vec[(*n)++] = ind;
- leftchild = 1u + 2u * ind;
- if (leftchild < pq->timer_count) {
- if (gpr_time_cmp(pq->timers[leftchild]->deadline,
- pq->timers[ind]->deadline) >= 0) {
- need_to_check_children[num_need_to_check_children++] = leftchild;
- }
- rightchild = leftchild + 1;
- if (rightchild < pq->timer_count &&
- gpr_time_cmp(pq->timers[rightchild]->deadline,
- pq->timers[ind]->deadline) >= 0) {
- need_to_check_children[num_need_to_check_children++] = rightchild;
- }
- }
- }
-
- gpr_free(need_to_check_children);
-
- return vec;
-}
-
-static void check_pq_top(grpc_timer *elements, grpc_timer_heap *pq,
- uint8_t *inpq, size_t num_elements) {
- gpr_timespec max_deadline = gpr_inf_past(GPR_CLOCK_REALTIME);
- size_t *max_deadline_indices =
- gpr_malloc(num_elements * sizeof(*max_deadline_indices));
- size_t *top_elements;
- size_t num_max_deadline_indices = 0;
- size_t num_top_elements;
- size_t i;
- for (i = 0; i < num_elements; ++i) {
- if (inpq[i] && gpr_time_cmp(elements[i].deadline, max_deadline) >= 0) {
- if (gpr_time_cmp(elements[i].deadline, max_deadline) > 0) {
- num_max_deadline_indices = 0;
- max_deadline = elements[i].deadline;
- }
- max_deadline_indices[num_max_deadline_indices++] = elements[i].heap_index;
- }
- }
- qsort(max_deadline_indices, num_max_deadline_indices,
- sizeof(*max_deadline_indices), cmp_elem);
- top_elements = all_top(pq, &num_top_elements);
- GPR_ASSERT(num_top_elements == num_max_deadline_indices);
- for (i = 0; i < num_top_elements; i++) {
- GPR_ASSERT(max_deadline_indices[i] == top_elements[i]);
- }
- gpr_free(max_deadline_indices);
- gpr_free(top_elements);
-}
-
static int contains(grpc_timer_heap *pq, grpc_timer *el) {
size_t i;
for (i = 0; i < pq->timer_count; i++) {
@@ -145,15 +74,19 @@ static void check_valid(grpc_timer_heap *pq) {
size_t right_child = left_child + 1u;
if (left_child < pq->timer_count) {
GPR_ASSERT(gpr_time_cmp(pq->timers[i]->deadline,
- pq->timers[left_child]->deadline) >= 0);
+ pq->timers[left_child]->deadline) <= 0);
}
if (right_child < pq->timer_count) {
GPR_ASSERT(gpr_time_cmp(pq->timers[i]->deadline,
- pq->timers[right_child]->deadline) >= 0);
+ pq->timers[right_child]->deadline) <= 0);
}
}
}
+/*******************************************************************************
+ * test1
+ */
+
static void test1(void) {
grpc_timer_heap pq;
const size_t num_test_elements = 200;
@@ -162,6 +95,8 @@ static void test1(void) {
grpc_timer *test_elements = create_test_elements(num_test_elements);
uint8_t *inpq = gpr_malloc(num_test_elements);
+ gpr_log(GPR_INFO, "test1");
+
grpc_timer_heap_init(&pq);
memset(inpq, 0, num_test_elements);
GPR_ASSERT(grpc_timer_heap_is_empty(&pq));
@@ -172,7 +107,6 @@ static void test1(void) {
check_valid(&pq);
GPR_ASSERT(contains(&pq, &test_elements[i]));
inpq[i] = 1;
- check_pq_top(test_elements, &pq, inpq, num_test_elements);
}
for (i = 0; i < num_test_elements; ++i) {
/* Test that check still succeeds even for element that wasn't just
@@ -182,7 +116,7 @@ static void test1(void) {
GPR_ASSERT(pq.timer_count == num_test_elements);
- check_pq_top(test_elements, &pq, inpq, num_test_elements);
+ check_valid(&pq);
for (i = 0; i < num_test_operations; ++i) {
size_t elem_num = (size_t)rand() % num_test_elements;
@@ -193,14 +127,12 @@ static void test1(void) {
grpc_timer_heap_add(&pq, el);
GPR_ASSERT(contains(&pq, el));
inpq[elem_num] = 1;
- check_pq_top(test_elements, &pq, inpq, num_test_elements);
check_valid(&pq);
} else {
GPR_ASSERT(contains(&pq, el));
grpc_timer_heap_remove(&pq, el);
GPR_ASSERT(!contains(&pq, el));
inpq[elem_num] = 0;
- check_pq_top(test_elements, &pq, inpq, num_test_elements);
check_valid(&pq);
}
}
@@ -210,7 +142,110 @@ static void test1(void) {
gpr_free(inpq);
}
+/*******************************************************************************
+ * test2
+ */
+
+typedef struct {
+ grpc_timer elem;
+ bool inserted;
+} elem_struct;
+
+static elem_struct *search_elems(elem_struct *elems, size_t count,
+ bool inserted) {
+ size_t *search_order = gpr_malloc(count * sizeof(*search_order));
+ for (size_t i = 0; i < count; i++) {
+ search_order[i] = i;
+ }
+ for (size_t i = 0; i < count * 2; i++) {
+ size_t a = (size_t)rand() % count;
+ size_t b = (size_t)rand() % count;
+ GPR_SWAP(size_t, search_order[a], search_order[b]);
+ }
+ elem_struct *out = NULL;
+ for (size_t i = 0; out == NULL && i < count; i++) {
+ if (elems[search_order[i]].inserted == inserted) {
+ out = &elems[search_order[i]];
+ }
+ }
+ gpr_free(search_order);
+ return out;
+}
+
+static void test2(void) {
+ gpr_log(GPR_INFO, "test2");
+
+ grpc_timer_heap pq;
+
+ static const size_t elems_size = 1000;
+ elem_struct *elems = gpr_malloc(elems_size * sizeof(elem_struct));
+ size_t num_inserted = 0;
+
+ grpc_timer_heap_init(&pq);
+ memset(elems, 0, elems_size);
+
+ for (size_t round = 0; round < 10000; round++) {
+ int r = rand() % 1000;
+ if (r <= 550) {
+ /* 55% of the time we try to add something */
+ elem_struct *el = search_elems(elems, GPR_ARRAY_SIZE(elems), false);
+ if (el != NULL) {
+ el->elem.deadline = random_deadline();
+ grpc_timer_heap_add(&pq, &el->elem);
+ el->inserted = true;
+ num_inserted++;
+ check_valid(&pq);
+ }
+ } else if (r <= 650) {
+ /* 10% of the time we try to remove something */
+ elem_struct *el = search_elems(elems, GPR_ARRAY_SIZE(elems), true);
+ if (el != NULL) {
+ grpc_timer_heap_remove(&pq, &el->elem);
+ el->inserted = false;
+ num_inserted--;
+ check_valid(&pq);
+ }
+ } else {
+ /* the remaining times we pop */
+ if (num_inserted > 0) {
+ grpc_timer *top = grpc_timer_heap_top(&pq);
+ grpc_timer_heap_pop(&pq);
+ for (size_t i = 0; i < elems_size; i++) {
+ if (top == &elems[i].elem) {
+ GPR_ASSERT(elems[i].inserted);
+ elems[i].inserted = false;
+ }
+ }
+ num_inserted--;
+ check_valid(&pq);
+ }
+ }
+
+ if (num_inserted) {
+ gpr_timespec *min_deadline = NULL;
+ for (size_t i = 0; i < elems_size; i++) {
+ if (elems[i].inserted) {
+ if (min_deadline == NULL) {
+ min_deadline = &elems[i].elem.deadline;
+ } else {
+ if (gpr_time_cmp(elems[i].elem.deadline, *min_deadline) < 0) {
+ min_deadline = &elems[i].elem.deadline;
+ }
+ }
+ }
+ }
+ GPR_ASSERT(
+ 0 == gpr_time_cmp(grpc_timer_heap_top(&pq)->deadline, *min_deadline));
+ }
+ }
+
+ grpc_timer_heap_destroy(&pq);
+ gpr_free(elems);
+}
+
static void shrink_test(void) {
+ gpr_log(GPR_INFO, "shrink_test");
+
grpc_timer_heap pq;
size_t i;
size_t expected_size;
@@ -274,6 +309,7 @@ int main(int argc, char **argv) {
for (i = 0; i < 5; i++) {
test1();
+ test2();
shrink_test();
}
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index 2e253d8a8a..ce3c23b4bf 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -31,8 +31,9 @@
*
*/
-#include "src/core/iomgr/udp_server.h"
#include "src/core/iomgr/iomgr.h"
+#include "src/core/iomgr/pollset_posix.h"
+#include "src/core/iomgr/udp_server.h"
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
@@ -48,6 +49,7 @@
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x)
static grpc_pollset g_pollset;
+static gpr_mu *g_mu;
static int g_number_of_reads = 0;
static int g_number_of_bytes_read = 0;
@@ -56,14 +58,14 @@ static void on_read(grpc_exec_ctx *exec_ctx, grpc_fd *emfd,
char read_buffer[512];
ssize_t byte_count;
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
byte_count = recv(emfd->fd, read_buffer, sizeof(read_buffer), 0);
g_number_of_reads++;
g_number_of_bytes_read += (int)byte_count;
grpc_pollset_kick(&g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
}
static void test_no_op(void) {
@@ -142,7 +144,7 @@ static void test_receive(int number_of_clients) {
pollsets[0] = &g_pollset;
grpc_udp_server_start(&exec_ctx, s, pollsets, 1, NULL);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
for (i = 0; i < number_of_clients; i++) {
deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
@@ -155,19 +157,19 @@ static void test_receive(int number_of_clients) {
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) {
- grpc_pollset_worker worker;
+ grpc_pollset_worker *worker = NULL;
grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_lock(g_mu);
}
GPR_ASSERT(g_number_of_reads == number_of_reads_before + 1);
close(clifd);
}
GPR_ASSERT(g_number_of_bytes_read == 5 * number_of_clients);
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_mu_unlock(g_mu);
grpc_udp_server_destroy(&exec_ctx, s, NULL);
grpc_exec_ctx_finish(&exec_ctx);
@@ -181,8 +183,8 @@ int main(int argc, char **argv) {
grpc_closure destroyed;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
- grpc_iomgr_init();
- grpc_pollset_init(&g_pollset);
+ grpc_init();
+ grpc_pollset_init(&g_pollset, &g_mu);
test_no_op();
test_no_op_with_start();
diff --git a/test/core/security/security_connector_test.c b/test/core/security/security_connector_test.c
index 420e3a4c52..609d874fd1 100644
--- a/test/core/security/security_connector_test.c
+++ b/test/core/security/security_connector_test.c
@@ -80,13 +80,14 @@ static int check_peer_property(const tsi_peer *peer,
static int check_ssl_peer_equivalence(const tsi_peer *original,
const tsi_peer *reconstructed) {
- /* The reconstructed peer only has CN and SAN properties. */
+ /* The reconstructed peer only has CN, SAN and pem cert properties. */
size_t i;
for (i = 0; i < original->property_count; i++) {
const tsi_peer_property *prop = &original->properties[i];
if ((strcmp(prop->name, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY) == 0) ||
(strcmp(prop->name, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) ==
- 0)) {
+ 0) ||
+ (strcmp(prop->name, TSI_X509_PEM_CERT_PROPERTY) == 0)) {
if (!check_peer_property(reconstructed, prop)) return 0;
}
}
@@ -164,24 +165,50 @@ static int check_x509_cn(const grpc_auth_context *ctx,
return 1;
}
+static int check_x509_pem_cert(const grpc_auth_context *ctx,
+ const char *expected_pem_cert) {
+ grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name(
+ ctx, GRPC_X509_PEM_CERT_PROPERTY_NAME);
+ const grpc_auth_property *prop = grpc_auth_property_iterator_next(&it);
+ if (prop == NULL) {
+ gpr_log(GPR_ERROR, "Pem certificate property not found.");
+ return 0;
+ }
+ if (strncmp(prop->value, expected_pem_cert, prop->value_length) != 0) {
+ gpr_log(GPR_ERROR, "Expected pem cert %s and got %s", expected_pem_cert,
+ prop->value);
+ return 0;
+ }
+ if (grpc_auth_property_iterator_next(&it) != NULL) {
+ gpr_log(GPR_ERROR, "Expected only one property for pem cert.");
+ return 0;
+ }
+ return 1;
+}
+
static void test_cn_only_ssl_peer_to_auth_context(void) {
tsi_peer peer;
tsi_peer rpeer;
grpc_auth_context *ctx;
const char *expected_cn = "cn1";
- GPR_ASSERT(tsi_construct_peer(2, &peer) == TSI_OK);
+ const char *expected_pem_cert = "pem_cert1";
+ GPR_ASSERT(tsi_construct_peer(3, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_X509_CERTIFICATE_TYPE,
&peer.properties[0]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, expected_cn,
&peer.properties[1]) == TSI_OK);
+ GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
+ TSI_X509_PEM_CERT_PROPERTY, expected_pem_cert,
+ &peer.properties[2]) == TSI_OK);
ctx = tsi_ssl_peer_to_auth_context(&peer);
GPR_ASSERT(ctx != NULL);
GPR_ASSERT(grpc_auth_context_peer_is_authenticated(ctx));
GPR_ASSERT(check_identity(ctx, GRPC_X509_CN_PROPERTY_NAME, &expected_cn, 1));
GPR_ASSERT(check_transport_security_type(ctx));
GPR_ASSERT(check_x509_cn(ctx, expected_cn));
+ GPR_ASSERT(check_x509_pem_cert(ctx, expected_pem_cert));
rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx);
GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer));
@@ -197,7 +224,8 @@ static void test_cn_and_one_san_ssl_peer_to_auth_context(void) {
grpc_auth_context *ctx;
const char *expected_cn = "cn1";
const char *expected_san = "san1";
- GPR_ASSERT(tsi_construct_peer(3, &peer) == TSI_OK);
+ const char *expected_pem_cert = "pem_cert1";
+ GPR_ASSERT(tsi_construct_peer(4, &peer) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_X509_CERTIFICATE_TYPE,
&peer.properties[0]) == TSI_OK);
@@ -207,6 +235,9 @@ static void test_cn_and_one_san_ssl_peer_to_auth_context(void) {
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, expected_san,
&peer.properties[2]) == TSI_OK);
+ GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
+ TSI_X509_PEM_CERT_PROPERTY, expected_pem_cert,
+ &peer.properties[3]) == TSI_OK);
ctx = tsi_ssl_peer_to_auth_context(&peer);
GPR_ASSERT(ctx != NULL);
GPR_ASSERT(grpc_auth_context_peer_is_authenticated(ctx));
@@ -214,6 +245,7 @@ static void test_cn_and_one_san_ssl_peer_to_auth_context(void) {
check_identity(ctx, GRPC_X509_SAN_PROPERTY_NAME, &expected_san, 1));
GPR_ASSERT(check_transport_security_type(ctx));
GPR_ASSERT(check_x509_cn(ctx, expected_cn));
+ GPR_ASSERT(check_x509_pem_cert(ctx, expected_pem_cert));
rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx);
GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer));
@@ -229,8 +261,9 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) {
grpc_auth_context *ctx;
const char *expected_cn = "cn1";
const char *expected_sans[] = {"san1", "san2", "san3"};
+ const char *expected_pem_cert = "pem_cert1";
size_t i;
- GPR_ASSERT(tsi_construct_peer(2 + GPR_ARRAY_SIZE(expected_sans), &peer) ==
+ GPR_ASSERT(tsi_construct_peer(3 + GPR_ARRAY_SIZE(expected_sans), &peer) ==
TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_X509_CERTIFICATE_TYPE,
@@ -238,10 +271,13 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) {
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, expected_cn,
&peer.properties[1]) == TSI_OK);
+ GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
+ TSI_X509_PEM_CERT_PROPERTY, expected_pem_cert,
+ &peer.properties[2]) == TSI_OK);
for (i = 0; i < GPR_ARRAY_SIZE(expected_sans); i++) {
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY,
- expected_sans[i], &peer.properties[2 + i]) == TSI_OK);
+ expected_sans[i], &peer.properties[3 + i]) == TSI_OK);
}
ctx = tsi_ssl_peer_to_auth_context(&peer);
GPR_ASSERT(ctx != NULL);
@@ -250,6 +286,7 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) {
GPR_ARRAY_SIZE(expected_sans)));
GPR_ASSERT(check_transport_security_type(ctx));
GPR_ASSERT(check_x509_cn(ctx, expected_cn));
+ GPR_ASSERT(check_x509_pem_cert(ctx, expected_pem_cert));
rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx);
GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer));
@@ -265,9 +302,10 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context(
tsi_peer rpeer;
grpc_auth_context *ctx;
const char *expected_cn = "cn1";
+ const char *expected_pem_cert = "pem_cert1";
const char *expected_sans[] = {"san1", "san2", "san3"};
size_t i;
- GPR_ASSERT(tsi_construct_peer(4 + GPR_ARRAY_SIZE(expected_sans), &peer) ==
+ GPR_ASSERT(tsi_construct_peer(5 + GPR_ARRAY_SIZE(expected_sans), &peer) ==
TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_X509_CERTIFICATE_TYPE,
@@ -279,10 +317,13 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context(
&peer.properties[2]) == TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
"chapi", "chapo", &peer.properties[3]) == TSI_OK);
+ GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
+ TSI_X509_PEM_CERT_PROPERTY, expected_pem_cert,
+ &peer.properties[4]) == TSI_OK);
for (i = 0; i < GPR_ARRAY_SIZE(expected_sans); i++) {
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY,
- expected_sans[i], &peer.properties[4 + i]) == TSI_OK);
+ expected_sans[i], &peer.properties[5 + i]) == TSI_OK);
}
ctx = tsi_ssl_peer_to_auth_context(&peer);
GPR_ASSERT(ctx != NULL);
@@ -291,6 +332,7 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context(
GPR_ARRAY_SIZE(expected_sans)));
GPR_ASSERT(check_transport_security_type(ctx));
GPR_ASSERT(check_x509_cn(ctx, expected_cn));
+ GPR_ASSERT(check_x509_pem_cert(ctx, expected_pem_cert));
rpeer = tsi_shallow_peer_from_ssl_auth_context(ctx);
GPR_ASSERT(check_ssl_peer_equivalence(&peer, &rpeer));
diff --git a/test/core/support/backoff_test.c b/test/core/support/backoff_test.c
new file mode 100644
index 0000000000..870b60b2d5
--- /dev/null
+++ b/test/core/support/backoff_test.c
@@ -0,0 +1,107 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/core/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, 1.0, 0.0, 1000, 1000);
+
+ 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)) == 1000);
+ for (int i = 0; i < 10000; i++) {
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_to_millis(gpr_time_sub(next, now)) == 1000);
+ now = next;
+ }
+}
+
+static void test_no_jitter_backoff(void) {
+ gpr_backoff backoff;
+ gpr_backoff_init(&backoff, 2.0, 0.0, 1, 513);
+
+ 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(1, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(3, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(7, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(15, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(31, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(63, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(127, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(255, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(511, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(1023, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(1536, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(2049, GPR_TIMESPAN), next) == 0);
+ now = next;
+ next = gpr_backoff_step(&backoff, now);
+ GPR_ASSERT(gpr_time_cmp(gpr_time_from_millis(2562, GPR_TIMESPAN), next) == 0);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ gpr_time_init();
+
+ test_constant_backoff();
+ test_no_jitter_backoff();
+
+ return 0;
+}
diff --git a/test/core/support/load_file_test.c b/test/core/support/load_file_test.c
index e6ba617440..70189b739d 100644
--- a/test/core/support/load_file_test.c
+++ b/test/core/support/load_file_test.c
@@ -135,33 +135,33 @@ static void test_load_big_file(void) {
gpr_slice slice;
int success;
char *tmp_name;
- unsigned char buffer[124631];
+ static const size_t buffer_size = 124631;
+ unsigned char *buffer = gpr_malloc(buffer_size);
unsigned char *current;
size_t i;
LOG_TEST_NAME("test_load_big_file");
- for (i = 0; i < sizeof(buffer); i++) {
- buffer[i] = 42;
- }
+ memset(buffer, 42, buffer_size);
tmp = gpr_tmpfile(prefix, &tmp_name);
GPR_ASSERT(tmp != NULL);
GPR_ASSERT(tmp_name != NULL);
- GPR_ASSERT(fwrite(buffer, 1, sizeof(buffer), tmp) == sizeof(buffer));
+ GPR_ASSERT(fwrite(buffer, 1, buffer_size, tmp) == buffer_size);
fclose(tmp);
slice = gpr_load_file(tmp_name, 0, &success);
GPR_ASSERT(success == 1);
- GPR_ASSERT(GPR_SLICE_LENGTH(slice) == sizeof(buffer));
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == buffer_size);
current = GPR_SLICE_START_PTR(slice);
- for (i = 0; i < sizeof(buffer); i++) {
+ for (i = 0; i < buffer_size; i++) {
GPR_ASSERT(current[i] == 42);
}
remove(tmp_name);
gpr_free(tmp_name);
gpr_slice_unref(slice);
+ gpr_free(buffer);
}
int main(int argc, char **argv) {
diff --git a/test/core/support/thd_test.c b/test/core/support/thd_test.c
index f7807d280a..0c176da2d3 100644
--- a/test/core/support/thd_test.c
+++ b/test/core/support/thd_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,8 @@
#include <grpc/support/time.h>
#include "test/core/util/test_config.h"
+#define NUM_THREADS 300
+
struct test {
gpr_mu mu;
int n;
@@ -79,15 +81,14 @@ static void test_options(void) {
static void test(void) {
int i;
gpr_thd_id thd;
- gpr_thd_id thds[1000];
+ gpr_thd_id thds[NUM_THREADS];
struct test t;
- int n = 1000;
gpr_thd_options options = gpr_thd_options_default();
gpr_mu_init(&t.mu);
gpr_cv_init(&t.done_cv);
- t.n = n;
+ t.n = NUM_THREADS;
t.is_done = 0;
- for (i = 0; i != n; i++) {
+ for (i = 0; i < NUM_THREADS; i++) {
GPR_ASSERT(gpr_thd_new(&thd, &thd_body, &t, NULL));
}
gpr_mu_lock(&t.mu);
@@ -97,10 +98,10 @@ static void test(void) {
gpr_mu_unlock(&t.mu);
GPR_ASSERT(t.n == 0);
gpr_thd_options_set_joinable(&options);
- for (i = 0; i < n; i++) {
+ for (i = 0; i < NUM_THREADS; i++) {
GPR_ASSERT(gpr_thd_new(&thds[i], &thd_body_joinable, NULL, &options));
}
- for (i = 0; i < n; i++) {
+ for (i = 0; i < NUM_THREADS; i++) {
gpr_thd_join(thds[i]);
}
}
diff --git a/test/core/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
new file mode 100644
index 0000000000..96761b0502
--- /dev/null
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -0,0 +1,81 @@
+/*
+*
+* Copyright 2016, Google Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following disclaimer
+* in the documentation and/or other materials provided with the
+* distribution.
+* * Neither the name of Google Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from
+* this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+#include <stdio.h>
+
+#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/thd.h>
+#include "test/core/util/test_config.h"
+
+#define NUM_THREADS 100
+#define NUM_OUTER_LOOPS 10
+#define NUM_INNER_LOOPS 10
+#define DELAY_MILLIS 10
+#define POLL_MILLIS 3000
+
+void create_loop_destroy(void* unused) {
+ for (int i = 0; i < NUM_OUTER_LOOPS; ++i) {
+ grpc_completion_queue* cq = grpc_completion_queue_create(NULL);
+ grpc_channel* chan = grpc_insecure_channel_create("localhost", NULL, NULL);
+
+ for (int j = 0; j < NUM_INNER_LOOPS; ++j) {
+ gpr_timespec later_time = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(DELAY_MILLIS);
+ grpc_connectivity_state state =
+ grpc_channel_check_connectivity_state(chan, 1);
+ grpc_channel_watch_connectivity_state(chan, state, later_time, cq, NULL);
+ gpr_timespec poll_time = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(POLL_MILLIS);
+ GPR_ASSERT(grpc_completion_queue_next(cq, poll_time, NULL).type ==
+ GRPC_OP_COMPLETE);
+ }
+ grpc_channel_destroy(chan);
+ grpc_completion_queue_destroy(cq);
+ }
+}
+
+int main(int argc, char** argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+ gpr_thd_id threads[NUM_THREADS];
+ for (size_t i = 0; i < NUM_THREADS; ++i) {
+ gpr_thd_options options = gpr_thd_options_default();
+ gpr_thd_options_set_joinable(&options);
+ gpr_thd_new(&threads[i], create_loop_destroy, NULL, &options);
+ }
+ for (size_t i = 0; i < NUM_THREADS; ++i) {
+ gpr_thd_join(threads[i]);
+ }
+ grpc_shutdown();
+ return 0;
+}
diff --git a/test/core/tsi/transport_security_test.c b/test/core/tsi/transport_security_test.c
index 7ce343987b..667d3f0349 100644
--- a/test/core/tsi/transport_security_test.c
+++ b/test/core/tsi/transport_security_test.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -61,35 +61,37 @@ typedef struct {
of '#' will be replaced with a null character before processing. */
const char *dns_names;
+ /* Comma separated list of IP SANs to match aggainst */
+ const char *ip_names;
} cert_name_test_entry;
/* Largely inspired from:
chromium/src/net/cert/x509_certificate_unittest.cc.
TODO(jboeuf) uncomment test cases as we fix tsi_ssl_peer_matches_name. */
const cert_name_test_entry cert_name_test_entries[] = {
- {1, "foo.com", "foo.com", NULL},
- {1, "f", "f", NULL},
- {0, "h", "i", NULL},
- {1, "bar.foo.com", "*.foo.com", NULL},
+ {1, "foo.com", "foo.com", NULL, NULL},
+ {1, "f", "f", NULL, NULL},
+ {0, "h", "i", NULL, NULL},
+ {1, "bar.foo.com", "*.foo.com", NULL, NULL},
{1, "www.test.fr", "common.name",
- "*.test.com,*.test.co.uk,*.test.de,*.test.fr"},
+ "*.test.com,*.test.co.uk,*.test.de,*.test.fr", NULL},
/*
{1, "wwW.tESt.fr", "common.name", ",*.*,*.test.de,*.test.FR,www"},
*/
- {0, "f.uk", ".uk", NULL},
- {0, "w.bar.foo.com", "?.bar.foo.com", NULL},
- {0, "www.foo.com", "(www|ftp).foo.com", NULL},
- {0, "www.foo.com", "www.foo.com#", NULL}, /* # = null char. */
- {0, "www.foo.com", "", "www.foo.com#*.foo.com,#,#"},
- {0, "www.house.example", "ww.house.example", NULL},
- {0, "test.org", "", "www.test.org,*.test.org,*.org"},
- {0, "w.bar.foo.com", "w*.bar.foo.com", NULL},
- {0, "www.bar.foo.com", "ww*ww.bar.foo.com", NULL},
- {0, "wwww.bar.foo.com", "ww*ww.bar.foo.com", NULL},
- {0, "wwww.bar.foo.com", "w*w.bar.foo.com", NULL},
- {0, "wwww.bar.foo.com", "w*w.bar.foo.c0m", NULL},
- {0, "WALLY.bar.foo.com", "wa*.bar.foo.com", NULL},
- {0, "wally.bar.foo.com", "*Ly.bar.foo.com", NULL},
+ {0, "f.uk", ".uk", NULL, NULL},
+ {0, "w.bar.foo.com", "?.bar.foo.com", NULL, NULL},
+ {0, "www.foo.com", "(www|ftp).foo.com", NULL, NULL},
+ {0, "www.foo.com", "www.foo.com#", NULL, NULL}, /* # = null char. */
+ {0, "www.foo.com", "", "www.foo.com#*.foo.com,#,#", NULL},
+ {0, "www.house.example", "ww.house.example", NULL, NULL},
+ {0, "test.org", "", "www.test.org,*.test.org,*.org", NULL},
+ {0, "w.bar.foo.com", "w*.bar.foo.com", NULL, NULL},
+ {0, "www.bar.foo.com", "ww*ww.bar.foo.com", NULL, NULL},
+ {0, "wwww.bar.foo.com", "ww*ww.bar.foo.com", NULL, NULL},
+ {0, "wwww.bar.foo.com", "w*w.bar.foo.com", NULL, NULL},
+ {0, "wwww.bar.foo.com", "w*w.bar.foo.c0m", NULL, NULL},
+ {0, "WALLY.bar.foo.com", "wa*.bar.foo.com", NULL, NULL},
+ {0, "wally.bar.foo.com", "*Ly.bar.foo.com", NULL, NULL},
/*
{1, "ww%57.foo.com", "", "www.foo.com"},
{1, "www&.foo.com", "www%26.foo.com", NULL},
@@ -97,94 +99,108 @@ const cert_name_test_entry cert_name_test_entries[] = {
/* Common name must not be used if subject alternative name was provided. */
{0, "www.test.co.jp", "www.test.co.jp",
- "*.test.de,*.jp,www.test.co.uk,www.*.co.jp"},
+ "*.test.de,*.jp,www.test.co.uk,www.*.co.jp", NULL},
{0, "www.bar.foo.com", "www.bar.foo.com",
- "*.foo.com,*.*.foo.com,*.*.bar.foo.com,*..bar.foo.com,"},
+ "*.foo.com,*.*.foo.com,*.*.bar.foo.com,*..bar.foo.com,", NULL},
/* IDN tests */
- {1, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br", NULL},
- {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL},
+ {1, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br", NULL, NULL},
+ {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL, NULL},
{0, "xn--poema-9qae5a.com.br", "",
"*.xn--poema-9qae5a.com.br,"
"xn--poema-*.com.br,"
"xn--*-9qae5a.com.br,"
- "*--poema-9qae5a.com.br"},
+ "*--poema-9qae5a.com.br",
+ NULL},
/* The following are adapted from the examples quoted from
http://tools.ietf.org/html/rfc6125#section-6.4.3
(e.g., *.example.com would match foo.example.com but
not bar.foo.example.com or example.com). */
- {1, "foo.example.com", "*.example.com", NULL},
- {0, "bar.foo.example.com", "*.example.com", NULL},
- {0, "example.com", "*.example.com", NULL},
+ {1, "foo.example.com", "*.example.com", NULL, NULL},
+ {0, "bar.foo.example.com", "*.example.com", NULL, NULL},
+ {0, "example.com", "*.example.com", NULL, NULL},
/* Partial wildcards are disallowed, though RFC 2818 rules allow them.
That is, forms such as baz*.example.net, *baz.example.net, and
b*z.example.net should NOT match domains. Instead, the wildcard must
always be the left-most label, and only a single label. */
- {0, "baz1.example.net", "baz*.example.net", NULL},
- {0, "foobaz.example.net", "*baz.example.net", NULL},
- {0, "buzz.example.net", "b*z.example.net", NULL},
- {0, "www.test.example.net", "www.*.example.net", NULL},
+ {0, "baz1.example.net", "baz*.example.net", NULL, NULL},
+ {0, "foobaz.example.net", "*baz.example.net", NULL, NULL},
+ {0, "buzz.example.net", "b*z.example.net", NULL, NULL},
+ {0, "www.test.example.net", "www.*.example.net", NULL, NULL},
/* Wildcards should not be valid for public registry controlled domains,
and unknown/unrecognized domains, at least three domain components must
be present. */
- {1, "www.test.example", "*.test.example", NULL},
- {1, "test.example.co.uk", "*.example.co.uk", NULL},
- {0, "test.example", "*.example", NULL},
+ {1, "www.test.example", "*.test.example", NULL, NULL},
+ {1, "test.example.co.uk", "*.example.co.uk", NULL, NULL},
+ {0, "test.example", "*.example", NULL, NULL},
/*
{0, "example.co.uk", "*.co.uk", NULL},
*/
- {0, "foo.com", "*.com", NULL},
- {0, "foo.us", "*.us", NULL},
- {0, "foo", "*", NULL},
+ {0, "foo.com", "*.com", NULL, NULL},
+ {0, "foo.us", "*.us", NULL, NULL},
+ {0, "foo", "*", NULL, NULL},
/* IDN variants of wildcards and registry controlled domains. */
- {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL},
- {1, "test.example.xn--mgbaam7a8h", "*.example.xn--mgbaam7a8h", NULL},
+ {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL, NULL},
+ {1, "test.example.xn--mgbaam7a8h", "*.example.xn--mgbaam7a8h", NULL, NULL},
/*
{0, "xn--poema-9qae5a.com.br", "*.com.br", NULL},
*/
- {0, "example.xn--mgbaam7a8h", "*.xn--mgbaam7a8h", NULL},
+ {0, "example.xn--mgbaam7a8h", "*.xn--mgbaam7a8h", NULL, NULL},
/* Wildcards should be permissible for 'private' registry controlled
domains. */
- {1, "www.appspot.com", "*.appspot.com", NULL},
- {1, "foo.s3.amazonaws.com", "*.s3.amazonaws.com", NULL},
+ {1, "www.appspot.com", "*.appspot.com", NULL, NULL},
+ {1, "foo.s3.amazonaws.com", "*.s3.amazonaws.com", NULL, NULL},
/* Multiple wildcards are not valid. */
- {0, "foo.example.com", "*.*.com", NULL},
- {0, "foo.bar.example.com", "*.bar.*.com", NULL},
+ {0, "foo.example.com", "*.*.com", NULL, NULL},
+ {0, "foo.bar.example.com", "*.bar.*.com", NULL, NULL},
/* Absolute vs relative DNS name tests. Although not explicitly specified
in RFC 6125, absolute reference names (those ending in a .) should
match either absolute or relative presented names. */
- {1, "foo.com", "foo.com.", NULL},
- {1, "foo.com.", "foo.com", NULL},
- {1, "foo.com.", "foo.com.", NULL},
- {1, "f", "f.", NULL},
- {1, "f.", "f", NULL},
- {1, "f.", "f.", NULL},
- {1, "www-3.bar.foo.com", "*.bar.foo.com.", NULL},
- {1, "www-3.bar.foo.com.", "*.bar.foo.com", NULL},
- {1, "www-3.bar.foo.com.", "*.bar.foo.com.", NULL},
- {0, ".", ".", NULL},
- {0, "example.com", "*.com.", NULL},
- {0, "example.com.", "*.com", NULL},
- {0, "example.com.", "*.com.", NULL},
- {0, "foo.", "*.", NULL},
- {0, "foo", "*.", NULL},
+ {1, "foo.com", "foo.com.", NULL, NULL},
+ {1, "foo.com.", "foo.com", NULL, NULL},
+ {1, "foo.com.", "foo.com.", NULL, NULL},
+ {1, "f", "f.", NULL, NULL},
+ {1, "f.", "f", NULL, NULL},
+ {1, "f.", "f.", NULL, NULL},
+ {1, "www-3.bar.foo.com", "*.bar.foo.com.", NULL, NULL},
+ {1, "www-3.bar.foo.com.", "*.bar.foo.com", NULL, NULL},
+ {1, "www-3.bar.foo.com.", "*.bar.foo.com.", NULL, NULL},
+ {0, ".", ".", NULL, NULL},
+ {0, "example.com", "*.com.", NULL, NULL},
+ {0, "example.com.", "*.com", NULL, NULL},
+ {0, "example.com.", "*.com.", NULL, NULL},
+ {0, "foo.", "*.", NULL, NULL},
+ {0, "foo", "*.", NULL, NULL},
/*
{0, "foo.co.uk", "*.co.uk.", NULL},
{0, "foo.co.uk.", "*.co.uk.", NULL},
*/
/* An empty CN is OK. */
- {1, "test.foo.com", "", "test.foo.com"},
+ {1, "test.foo.com", "", "test.foo.com", NULL},
/* An IP should not be used for the CN. */
- {0, "173.194.195.139", "173.194.195.139", NULL},
+ {0, "173.194.195.139", "173.194.195.139", NULL, NULL},
+ /* An IP can be used if the SAN IP is present */
+ {1, "173.194.195.139", "foo.example.com", NULL, "173.194.195.139"},
+ {0, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8"},
+ {0, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8,8.8.4.4"},
+ {1, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8,173.194.195.139"},
+ {0, "173.194.195.139", "foo.example.com", NULL, "173.194.195.13"},
+ {0, "2001:db8:a0b:12f0::1", "foo.example.com", NULL, "173.194.195.13"},
+ {1, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
+ "2001:db8:a0b:12f0::1"},
+ {0, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
+ "2001:db8:a0b:12f0::2"},
+ {1, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
+ "2001:db8:a0b:12f0::2,2001:db8:a0b:12f0::1,8.8.8.8"},
};
typedef struct name_list {
@@ -196,7 +212,7 @@ typedef struct {
size_t name_count;
char *buffer;
name_list *names;
-} parsed_dns_names;
+} parsed_names;
name_list *name_list_add(const char *n) {
name_list *result = gpr_malloc(sizeof(name_list));
@@ -205,18 +221,18 @@ name_list *name_list_add(const char *n) {
return result;
}
-static parsed_dns_names parse_dns_names(const char *dns_names_str) {
- parsed_dns_names result;
+static parsed_names parse_names(const char *names_str) {
+ parsed_names result;
name_list *current_nl;
size_t i;
- memset(&result, 0, sizeof(parsed_dns_names));
- if (dns_names_str == 0) return result;
+ memset(&result, 0, sizeof(parsed_names));
+ if (names_str == 0) return result;
result.name_count = 1;
- result.buffer = gpr_strdup(dns_names_str);
+ result.buffer = gpr_strdup(names_str);
result.names = name_list_add(result.buffer);
current_nl = result.names;
- for (i = 0; i < strlen(dns_names_str); i++) {
- if (dns_names_str[i] == ',') {
+ for (i = 0; i < strlen(names_str); i++) {
+ if (names_str[i] == ',') {
result.buffer[i] = '\0';
result.name_count++;
i++;
@@ -227,7 +243,7 @@ static parsed_dns_names parse_dns_names(const char *dns_names_str) {
return result;
}
-static void destruct_parsed_dns_names(parsed_dns_names *pdn) {
+static void destruct_parsed_names(parsed_names *pdn) {
name_list *nl = pdn->names;
if (pdn->buffer != NULL) gpr_free(pdn->buffer);
while (nl != NULL) {
@@ -237,8 +253,8 @@ static void destruct_parsed_dns_names(parsed_dns_names *pdn) {
}
}
-static char *processed_dns_name(const char *dns_name) {
- char *result = gpr_strdup(dns_name);
+static char *processed_name(const char *name) {
+ char *result = gpr_strdup(name);
size_t i;
for (i = 0; i < strlen(result); i++) {
if (result[i] == '#') {
@@ -253,31 +269,48 @@ static tsi_peer peer_from_cert_name_test_entry(
size_t i;
tsi_peer peer;
name_list *nl;
- parsed_dns_names dns_entries = parse_dns_names(entry->dns_names);
+ parsed_names dns_entries = parse_names(entry->dns_names);
+ parsed_names ip_entries = parse_names(entry->ip_names);
nl = dns_entries.names;
- GPR_ASSERT(tsi_construct_peer(1 + dns_entries.name_count, &peer) == TSI_OK);
+ GPR_ASSERT(tsi_construct_peer(
+ 1 + dns_entries.name_count + ip_entries.name_count, &peer) ==
+ TSI_OK);
GPR_ASSERT(tsi_construct_string_peer_property_from_cstring(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, entry->common_name,
&peer.properties[0]) == TSI_OK);
i = 1;
while (nl != NULL) {
- char *processed = processed_dns_name(nl->name);
+ char *processed = processed_name(nl->name);
GPR_ASSERT(tsi_construct_string_peer_property(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, processed,
strlen(nl->name), &peer.properties[i++]) == TSI_OK);
nl = nl->next;
gpr_free(processed);
}
- destruct_parsed_dns_names(&dns_entries);
+
+ nl = ip_entries.names;
+ while (nl != NULL) {
+ char *processed = processed_name(nl->name);
+ GPR_ASSERT(tsi_construct_string_peer_property(
+ TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, processed,
+ strlen(nl->name), &peer.properties[i++]) == TSI_OK);
+ nl = nl->next;
+ gpr_free(processed);
+ }
+ destruct_parsed_names(&dns_entries);
+ destruct_parsed_names(&ip_entries);
return peer;
}
char *cert_name_test_entry_to_string(const cert_name_test_entry *entry) {
char *s;
- gpr_asprintf(
- &s, "{ success = %s, host_name = %s, common_name = %s, dns_names = %s}",
- entry->expected ? "true" : "false", entry->host_name, entry->common_name,
- entry->dns_names != NULL ? entry->dns_names : "");
+ gpr_asprintf(&s,
+ "{ success = %s, host_name = %s, common_name = %s, dns_names = "
+ "%s, ip_names = %s}",
+ entry->expected ? "true" : "false", entry->host_name,
+ entry->common_name,
+ entry->dns_names != NULL ? entry->dns_names : "",
+ entry->ip_names != NULL ? entry->ip_names : "");
return s;
}
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c
index ba382d242a..5c0b2717cb 100644
--- a/test/core/util/port_posix.c
+++ b/test/core/util/port_posix.c
@@ -38,7 +38,6 @@
#include "test/core/util/port.h"
#include <errno.h>
-#include <math.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
@@ -50,8 +49,8 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include "src/core/httpcli/httpcli.h"
#include "src/core/support/env.h"
+#include "test/core/util/port_server_client.h"
#define NUM_RANDOM_PORTS_TO_PICK 100
@@ -68,76 +67,12 @@ static int has_port_been_chosen(int port) {
return 0;
}
-typedef struct freereq {
- gpr_mu *mu;
- grpc_pollset *pollset;
- int done;
-} freereq;
-
-static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p,
- bool success) {
- grpc_pollset_destroy(p);
- grpc_shutdown();
-}
-
-static void freed_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
- const grpc_httpcli_response *response) {
- freereq *pr = arg;
- gpr_mu_lock(pr->mu);
- pr->done = 1;
- grpc_pollset_kick(pr->pollset, NULL);
- gpr_mu_unlock(pr->mu);
-}
-
-static void free_port_using_server(char *server, int port) {
- grpc_httpcli_context context;
- grpc_httpcli_request req;
- freereq pr;
- char *path;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_closure shutdown_closure;
-
- grpc_init();
-
- memset(&pr, 0, sizeof(pr));
- memset(&req, 0, sizeof(req));
-
- pr.pollset = gpr_malloc(grpc_pollset_size());
- grpc_pollset_init(pr.pollset, &pr.mu);
- grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown,
- pr.pollset);
-
- req.host = server;
- gpr_asprintf(&path, "/drop/%d", port);
- req.path = path;
-
- grpc_httpcli_context_init(&context);
- grpc_httpcli_get(&exec_ctx, &context, pr.pollset, &req,
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), freed_port_from_server,
- &pr);
- gpr_mu_lock(pr.mu);
- while (!pr.done) {
- grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, pr.pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
- }
- gpr_mu_unlock(pr.mu);
-
- grpc_httpcli_context_destroy(&context);
- grpc_exec_ctx_finish(&exec_ctx);
- grpc_pollset_shutdown(&exec_ctx, pr.pollset, &shutdown_closure);
- grpc_exec_ctx_finish(&exec_ctx);
- gpr_free(pr.pollset);
- gpr_free(path);
-}
-
-static void free_chosen_ports() {
+static void free_chosen_ports(void) {
char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
if (env != NULL) {
size_t i;
for (i = 0; i < num_chosen_ports; i++) {
- free_port_using_server(env, chosen_ports[i]);
+ grpc_free_port_using_server(env, chosen_ports[i]);
}
gpr_free(env);
}
@@ -205,102 +140,6 @@ static int is_port_available(int *port, int is_tcp) {
return 1;
}
-typedef struct portreq {
- gpr_mu *mu;
- grpc_pollset *pollset;
- int port;
- int retries;
- char *server;
- grpc_httpcli_context *ctx;
-} portreq;
-
-static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
- const grpc_httpcli_response *response) {
- size_t i;
- int port = 0;
- portreq *pr = arg;
- int failed = 0;
-
- if (!response) {
- failed = 1;
- gpr_log(GPR_DEBUG,
- "failed port pick from server: retrying [response=NULL]");
- } else if (response->status != 200) {
- failed = 1;
- gpr_log(GPR_DEBUG, "failed port pick from server: status=%d",
- response->status);
- }
-
- if (failed) {
- grpc_httpcli_request req;
- memset(&req, 0, sizeof(req));
- GPR_ASSERT(pr->retries < 10);
- sleep(1 + (unsigned)(pow(1.3, pr->retries) * rand() / RAND_MAX));
- pr->retries++;
- req.host = pr->server;
- req.path = "/get";
- grpc_httpcli_get(exec_ctx, pr->ctx, pr->pollset, &req,
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server,
- pr);
- return;
- }
- GPR_ASSERT(response);
- GPR_ASSERT(response->status == 200);
- for (i = 0; i < response->body_length; i++) {
- GPR_ASSERT(response->body[i] >= '0' && response->body[i] <= '9');
- port = port * 10 + response->body[i] - '0';
- }
- GPR_ASSERT(port > 1024);
- gpr_mu_lock(pr->mu);
- pr->port = port;
- grpc_pollset_kick(pr->pollset, NULL);
- gpr_mu_unlock(pr->mu);
-}
-
-static int pick_port_using_server(char *server) {
- grpc_httpcli_context context;
- grpc_httpcli_request req;
- portreq pr;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_closure shutdown_closure;
-
- grpc_init();
-
- memset(&pr, 0, sizeof(pr));
- memset(&req, 0, sizeof(req));
- pr.pollset = gpr_malloc(grpc_pollset_size());
- grpc_pollset_init(pr.pollset, &pr.mu);
- grpc_closure_init(&shutdown_closure, destroy_pollset_and_shutdown,
- pr.pollset);
- pr.port = -1;
- pr.server = server;
- pr.ctx = &context;
-
- req.host = server;
- req.path = "/get";
-
- grpc_httpcli_context_init(&context);
- grpc_httpcli_get(&exec_ctx, &context, pr.pollset, &req,
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server,
- &pr);
- grpc_exec_ctx_finish(&exec_ctx);
- gpr_mu_lock(pr.mu);
- while (pr.port == -1) {
- grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, pr.pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
- }
- gpr_mu_unlock(pr.mu);
-
- grpc_httpcli_context_destroy(&context);
- grpc_pollset_shutdown(&exec_ctx, pr.pollset, &shutdown_closure);
- grpc_exec_ctx_finish(&exec_ctx);
- gpr_free(pr.pollset);
-
- return pr.port;
-}
-
int grpc_pick_unused_port(void) {
/* We repeatedly pick a port and then see whether or not it is
available for use both as a TCP socket and a UDP socket. First, we
@@ -320,7 +159,7 @@ int grpc_pick_unused_port(void) {
char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
if (env) {
- int port = pick_port_using_server(env);
+ int port = grpc_pick_port_using_server(env);
gpr_free(env);
if (port != 0) {
chose_port(port);
diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c
new file mode 100644
index 0000000000..653ecb2709
--- /dev/null
+++ b/test/core/util/port_server_client.c
@@ -0,0 +1,215 @@
+/*
+ *
+ * Copyright 2015-2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc/support/port_platform.h>
+#include "test/core/util/test_config.h"
+
+#ifdef GRPC_TEST_PICK_PORT
+#include "test/core/util/port_server_client.h"
+
+#include <math.h>
+#include <string.h>
+
+#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include <grpc/support/sync.h>
+#include <grpc/support/time.h>
+
+#include "src/core/httpcli/httpcli.h"
+
+typedef struct freereq {
+ gpr_mu *mu;
+ grpc_pollset *pollset;
+ int done;
+} freereq;
+
+static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p,
+ bool success) {
+ grpc_pollset_destroy(p);
+ gpr_free(p);
+ grpc_shutdown();
+}
+
+static void freed_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
+ const grpc_httpcli_response *response) {
+ freereq *pr = arg;
+ gpr_mu_lock(pr->mu);
+ pr->done = 1;
+ grpc_pollset_kick(pr->pollset, NULL);
+ gpr_mu_unlock(pr->mu);
+}
+
+void grpc_free_port_using_server(char *server, int port) {
+ grpc_httpcli_context context;
+ grpc_httpcli_request req;
+ freereq pr;
+ char *path;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_closure *shutdown_closure;
+
+ grpc_init();
+
+ memset(&pr, 0, sizeof(pr));
+ memset(&req, 0, sizeof(req));
+
+ pr.pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(pr.pollset, &pr.mu);
+ shutdown_closure =
+ grpc_closure_create(destroy_pollset_and_shutdown, pr.pollset);
+
+ req.host = server;
+ gpr_asprintf(&path, "/drop/%d", port);
+ req.path = path;
+
+ grpc_httpcli_context_init(&context);
+ grpc_httpcli_get(&exec_ctx, &context, pr.pollset, &req,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), freed_port_from_server,
+ &pr);
+ gpr_mu_lock(pr.mu);
+ while (!pr.done) {
+ grpc_pollset_worker *worker = NULL;
+ grpc_pollset_work(&exec_ctx, pr.pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
+ }
+ gpr_mu_unlock(pr.mu);
+
+ grpc_httpcli_context_destroy(&context);
+ grpc_exec_ctx_finish(&exec_ctx);
+ grpc_pollset_shutdown(&exec_ctx, pr.pollset, shutdown_closure);
+ grpc_exec_ctx_finish(&exec_ctx);
+ gpr_free(path);
+}
+
+typedef struct portreq {
+ gpr_mu *mu;
+ grpc_pollset *pollset;
+ int port;
+ int retries;
+ char *server;
+ grpc_httpcli_context *ctx;
+} portreq;
+
+static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
+ const grpc_httpcli_response *response) {
+ size_t i;
+ int port = 0;
+ portreq *pr = arg;
+ int failed = 0;
+
+ if (!response) {
+ failed = 1;
+ gpr_log(GPR_DEBUG,
+ "failed port pick from server: retrying [response=NULL]");
+ } else if (response->status != 200) {
+ failed = 1;
+ gpr_log(GPR_DEBUG, "failed port pick from server: status=%d",
+ response->status);
+ }
+
+ if (failed) {
+ grpc_httpcli_request req;
+ memset(&req, 0, sizeof(req));
+ GPR_ASSERT(pr->retries < 10);
+ gpr_sleep_until(gpr_time_add(
+ gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_millis(
+ (int64_t)(1000.0 * (1 + pow(1.3, pr->retries) * rand() / RAND_MAX)),
+ GPR_TIMESPAN)));
+ pr->retries++;
+ req.host = pr->server;
+ req.path = "/get";
+ grpc_httpcli_get(exec_ctx, pr->ctx, pr->pollset, &req,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server,
+ pr);
+ return;
+ }
+ GPR_ASSERT(response);
+ GPR_ASSERT(response->status == 200);
+ for (i = 0; i < response->body_length; i++) {
+ GPR_ASSERT(response->body[i] >= '0' && response->body[i] <= '9');
+ port = port * 10 + response->body[i] - '0';
+ }
+ GPR_ASSERT(port > 1024);
+ gpr_mu_lock(pr->mu);
+ pr->port = port;
+ grpc_pollset_kick(pr->pollset, NULL);
+ gpr_mu_unlock(pr->mu);
+}
+
+int grpc_pick_port_using_server(char *server) {
+ grpc_httpcli_context context;
+ grpc_httpcli_request req;
+ portreq pr;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_closure *shutdown_closure;
+
+ grpc_init();
+
+ memset(&pr, 0, sizeof(pr));
+ memset(&req, 0, sizeof(req));
+ pr.pollset = gpr_malloc(grpc_pollset_size());
+ grpc_pollset_init(pr.pollset, &pr.mu);
+ shutdown_closure =
+ grpc_closure_create(destroy_pollset_and_shutdown, pr.pollset);
+ pr.port = -1;
+ pr.server = server;
+ pr.ctx = &context;
+
+ req.host = server;
+ req.path = "/get";
+
+ grpc_httpcli_context_init(&context);
+ grpc_httpcli_get(&exec_ctx, &context, pr.pollset, &req,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server,
+ &pr);
+ grpc_exec_ctx_finish(&exec_ctx);
+ gpr_mu_lock(pr.mu);
+ while (pr.port == -1) {
+ grpc_pollset_worker *worker = NULL;
+ grpc_pollset_work(&exec_ctx, pr.pollset, &worker,
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
+ }
+ gpr_mu_unlock(pr.mu);
+
+ grpc_httpcli_context_destroy(&context);
+ grpc_pollset_shutdown(&exec_ctx, pr.pollset, shutdown_closure);
+ grpc_exec_ctx_finish(&exec_ctx);
+
+ return pr.port;
+}
+
+#endif // GRPC_TEST_PICK_PORT
diff --git a/test/core/util/port_server_client.h b/test/core/util/port_server_client.h
new file mode 100644
index 0000000000..fc209cde5b
--- /dev/null
+++ b/test/core/util/port_server_client.h
@@ -0,0 +1,42 @@
+/*
+ *
+ * Copyright 2015-2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPC_TEST_CORE_UTIL_PORT_SERVER_CLIENT_H
+#define GRPC_TEST_CORE_UTIL_PORT_SERVER_CLIENT_H
+
+// C interface to port_server.py
+
+int grpc_pick_port_using_server(char *server);
+void grpc_free_port_using_server(char *server, int port);
+
+#endif // GRPC_TEST_CORE_UTIL_PORT_SERVER_CLIENT_H
diff --git a/test/core/util/port_windows.c b/test/core/util/port_windows.c
index 3b20aeb718..a810683440 100644
--- a/test/core/util/port_windows.c
+++ b/test/core/util/port_windows.c
@@ -47,8 +47,8 @@
#include <grpc/support/log.h>
#include "src/core/support/env.h"
-#include "src/core/httpcli/httpcli.h"
#include "src/core/iomgr/sockaddr_utils.h"
+#include "test/core/util/port_server_client.h"
#define NUM_RANDOM_PORTS_TO_PICK 100
@@ -65,7 +65,18 @@ static int has_port_been_chosen(int port) {
return 0;
}
-static void free_chosen_ports(void) { gpr_free(chosen_ports); }
+static void free_chosen_ports(void) {
+ char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
+ if (env != NULL) {
+ size_t i;
+ for (i = 0; i < num_chosen_ports; i++) {
+ grpc_free_port_using_server(env, chosen_ports[i]);
+ }
+ gpr_free(env);
+ }
+
+ gpr_free(chosen_ports);
+}
static void chose_port(int port) {
if (chosen_ports == NULL) {
@@ -128,80 +139,6 @@ static int is_port_available(int *port, int is_tcp) {
return 1;
}
-typedef struct portreq {
- grpc_pollset *pollset;
- gpr_mu *mu;
- int port;
-} portreq;
-
-static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
- const grpc_httpcli_response *response) {
- size_t i;
- int port = 0;
- portreq *pr = arg;
- GPR_ASSERT(response);
- GPR_ASSERT(response->status == 200);
- for (i = 0; i < response->body_length; i++) {
- GPR_ASSERT(response->body[i] >= '0' && response->body[i] <= '9');
- port = port * 10 + response->body[i] - '0';
- }
- GPR_ASSERT(port > 1024);
- gpr_mu_lock(pr->mu);
- pr->port = port;
- grpc_pollset_kick(pr->pollset, NULL);
- gpr_mu_unlock(pr->mu);
-}
-
-static void destroy_pollset_and_shutdown(grpc_exec_ctx *exec_ctx, void *p,
- bool success) {
- grpc_pollset_destroy(p);
- grpc_shutdown();
-}
-
-static int pick_port_using_server(char *server) {
- grpc_httpcli_context context;
- grpc_httpcli_request req;
- portreq pr;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_closure destroy_pollset_closure;
-
- grpc_init();
-
- memset(&pr, 0, sizeof(pr));
- memset(&req, 0, sizeof(req));
- pr.pollset = gpr_malloc(grpc_pollset_size());
- grpc_pollset_init(pr.pollset, &pr.mu);
- pr.port = -1;
-
- req.host = server;
- req.path = "/get";
-
- grpc_httpcli_context_init(&context);
- grpc_httpcli_get(&exec_ctx, &context, pr.pollset, &req,
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server,
- &pr);
- gpr_mu_lock(pr.mu);
- while (pr.port == -1) {
- grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, pr.pollset, &worker,
- gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
- gpr_mu_unlock(pr.mu);
- grpc_exec_ctx_flush(&exec_ctx);
- gpr_mu_lock(pr.mu);
- }
- gpr_mu_unlock(pr.mu);
-
- grpc_httpcli_context_destroy(&context);
- grpc_closure_init(&destroy_pollset_closure, destroy_pollset_and_shutdown,
- &pr.pollset);
- grpc_pollset_shutdown(&exec_ctx, pr.pollset, &destroy_pollset_closure);
- gpr_free(pr.pollset);
-
- grpc_exec_ctx_finish(&exec_ctx);
- return pr.port;
-}
-
int grpc_pick_unused_port(void) {
/* We repeatedly pick a port and then see whether or not it is
available for use both as a TCP socket and a UDP socket. First, we
@@ -221,7 +158,7 @@ int grpc_pick_unused_port(void) {
char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
if (env) {
- int port = pick_port_using_server(env);
+ int port = grpc_pick_port_using_server(env);
gpr_free(env);
if (port != 0) {
return port;
diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c
index 14bfc957cb..bf672e8f67 100644
--- a/test/core/util/test_config.c
+++ b/test/core/util/test_config.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,11 +33,13 @@
#include "test/core/util/test_config.h"
-#include <grpc/support/port_platform.h>
#include <grpc/support/log.h>
-#include "src/core/support/string.h"
-#include <stdlib.h>
+#include <grpc/support/port_platform.h>
#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "src/core/support/string.h"
double g_fixture_slowdown_factor = 1.0;
@@ -52,14 +54,125 @@ static unsigned seed(void) { return _getpid(); }
#endif
#if GPR_WINDOWS_CRASH_HANDLER
-LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) {
- gpr_log(GPR_DEBUG, "Exception handler called, dumping information");
- while (ex_info->ExceptionRecord) {
- DWORD code = ex_info->ExceptionRecord->ExceptionCode;
- DWORD flgs = ex_info->ExceptionRecord->ExceptionFlags;
- PVOID addr = ex_info->ExceptionRecord->ExceptionAddress;
- gpr_log("code: %x - flags: %d - address: %p", code, flgs, addr);
- ex_info->ExceptionRecord = ex_info->ExceptionRecord->ExceptionRecord;
+#include <windows.h>
+
+#include <tchar.h>
+
+// disable warning 4091 - dbghelp.h is broken for msvc2015
+#pragma warning(disable : 4091)
+#define DBGHELP_TRANSLATE_TCHAR
+#include <dbghelp.h>
+
+#ifdef _MSC_VER
+#pragma comment(lib, "dbghelp.lib")
+#endif
+
+static void print_current_stack() {
+ typedef USHORT(WINAPI * CaptureStackBackTraceType)(
+ __in ULONG, __in ULONG, __out PVOID *, __out_opt PULONG);
+ CaptureStackBackTraceType func = (CaptureStackBackTraceType)(GetProcAddress(
+ LoadLibrary(_T("kernel32.dll")), "RtlCaptureStackBackTrace"));
+
+ if (func == NULL) return; // WOE 29.SEP.2010
+
+// Quote from Microsoft Documentation:
+// ## Windows Server 2003 and Windows XP:
+// ## The sum of the FramesToSkip and FramesToCapture parameters must be less
+// than 63.
+#define MAX_CALLERS 62
+
+ void *callers_stack[MAX_CALLERS];
+ unsigned short frames;
+ SYMBOL_INFOW *symbol;
+ HANDLE process;
+ process = GetCurrentProcess();
+ SymInitialize(process, NULL, TRUE);
+ frames = (func)(0, MAX_CALLERS, callers_stack, NULL);
+ symbol =
+ (SYMBOL_INFOW *)calloc(sizeof(SYMBOL_INFOW) + 256 * sizeof(wchar_t), 1);
+ symbol->MaxNameLen = 255;
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFOW);
+
+ const unsigned short MAX_CALLERS_SHOWN = 32;
+ frames = frames < MAX_CALLERS_SHOWN ? frames : MAX_CALLERS_SHOWN;
+ for (unsigned int i = 0; i < frames; i++) {
+ SymFromAddrW(process, (DWORD64)(callers_stack[i]), 0, symbol);
+ fwprintf(stderr, L"*** %d: %016I64X %ls - %016I64X\n", i,
+ (DWORD64)callers_stack[i], symbol->Name, (DWORD64)symbol->Address);
+ }
+
+ free(symbol);
+}
+
+static void print_stack_from_context(CONTEXT c) {
+ STACKFRAME s; // in/out stackframe
+ memset(&s, 0, sizeof(s));
+ DWORD imageType;
+#ifdef _M_IX86
+ // normally, call ImageNtHeader() and use machine info from PE header
+ imageType = IMAGE_FILE_MACHINE_I386;
+ s.AddrPC.Offset = c.Eip;
+ s.AddrPC.Mode = AddrModeFlat;
+ s.AddrFrame.Offset = c.Ebp;
+ s.AddrFrame.Mode = AddrModeFlat;
+ s.AddrStack.Offset = c.Esp;
+ s.AddrStack.Mode = AddrModeFlat;
+#elif _M_X64
+ imageType = IMAGE_FILE_MACHINE_AMD64;
+ s.AddrPC.Offset = c.Rip;
+ s.AddrPC.Mode = AddrModeFlat;
+ s.AddrFrame.Offset = c.Rsp;
+ s.AddrFrame.Mode = AddrModeFlat;
+ s.AddrStack.Offset = c.Rsp;
+ s.AddrStack.Mode = AddrModeFlat;
+#elif _M_IA64
+ imageType = IMAGE_FILE_MACHINE_IA64;
+ s.AddrPC.Offset = c.StIIP;
+ s.AddrPC.Mode = AddrModeFlat;
+ s.AddrFrame.Offset = c.IntSp;
+ s.AddrFrame.Mode = AddrModeFlat;
+ s.AddrBStore.Offset = c.RsBSP;
+ s.AddrBStore.Mode = AddrModeFlat;
+ s.AddrStack.Offset = c.IntSp;
+ s.AddrStack.Mode = AddrModeFlat;
+#else
+#error "Platform not supported!"
+#endif
+
+ HANDLE process = GetCurrentProcess();
+ HANDLE thread = GetCurrentThread();
+
+ SYMBOL_INFOW *symbol =
+ (SYMBOL_INFOW *)calloc(sizeof(SYMBOL_INFOW) + 256 * sizeof(wchar_t), 1);
+ symbol->MaxNameLen = 255;
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFOW);
+
+ while (StackWalk(imageType, process, thread, &s, &c, 0,
+ SymFunctionTableAccess, SymGetModuleBase, 0)) {
+ BOOL has_symbol =
+ SymFromAddrW(process, (DWORD64)(s.AddrPC.Offset), 0, symbol);
+ fwprintf(
+ stderr, L"*** %016I64X %ls - %016I64X\n", (DWORD64)(s.AddrPC.Offset),
+ has_symbol ? symbol->Name : L"<<no symbol>>", (DWORD64)symbol->Address);
+ }
+
+ free(symbol);
+}
+
+static LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) {
+ fprintf(stderr, "Exception handler called, dumping information\n");
+ bool try_to_print_stack = true;
+ PEXCEPTION_RECORD exrec = ex_info->ExceptionRecord;
+ while (exrec) {
+ DWORD code = exrec->ExceptionCode;
+ DWORD flgs = exrec->ExceptionFlags;
+ PVOID addr = exrec->ExceptionAddress;
+ if (code == EXCEPTION_STACK_OVERFLOW) try_to_print_stack = false;
+ fprintf(stderr, "code: %x - flags: %d - address: %p\n", code, flgs, addr);
+ exrec = exrec->ExceptionRecord;
+ }
+ if (try_to_print_stack) {
+ print_stack_from_context(*ex_info->ContextRecord);
}
if (IsDebuggerPresent()) {
__debugbreak();
@@ -69,8 +182,9 @@ LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) {
return EXCEPTION_EXECUTE_HANDLER;
}
-void abort_handler(int sig) {
- gpr_log(GPR_DEBUG, "Abort handler called.");
+static void abort_handler(int sig) {
+ fprintf(stderr, "Abort handler called.\n");
+ print_current_stack(NULL);
if (IsDebuggerPresent()) {
__debugbreak();
} else {
@@ -79,17 +193,20 @@ void abort_handler(int sig) {
}
static void install_crash_handler() {
+ if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) {
+ fprintf(stderr, "SymInitialize failed: %d\n", GetLastError());
+ }
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)crash_handler);
_set_abort_behavior(0, _WRITE_ABORT_MSG);
_set_abort_behavior(0, _CALL_REPORTFAULT);
signal(SIGABRT, abort_handler);
}
#elif GPR_POSIX_CRASH_HANDLER
+#include <errno.h>
#include <execinfo.h>
+#include <grpc/support/useful.h>
#include <stdio.h>
#include <string.h>
-#include <grpc/support/useful.h>
-#include <errno.h>
static char g_alt_stack[MINSIGSTKSZ];
diff --git a/test/cpp/codegen/codegen_test.cc b/test/cpp/codegen/codegen_test.cc
new file mode 100644
index 0000000000..735755a5d0
--- /dev/null
+++ b/test/cpp/codegen/codegen_test.cc
@@ -0,0 +1,49 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <gtest/gtest.h>
+
+namespace grpc {
+namespace {
+
+class CodegenTest : public ::testing::Test {};
+
+TEST_F(CodegenTest, Build) {}
+
+} // namespace
+} // namespace grpc
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 9ca3bf98f8..dc8c2bb6e5 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -68,6 +68,7 @@ namespace testing {
namespace {
void* tag(int i) { return (void*)(intptr_t)i; }
+int detag(void* p) { return static_cast<int>(reinterpret_cast<intptr_t>(p)); }
#ifdef GPR_POSIX_SOCKET
static int maybe_assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds,
@@ -106,37 +107,50 @@ class PollingOverrider {
class Verifier {
public:
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 *this;
}
+ // Next waits for 1 async tag to complete, checks its
+ // expectations, and returns the tag
+ int Next(CompletionQueue* cq, bool ignore_ok) {
+ bool ok;
+ void* got_tag;
+ if (spin_) {
+ for (;;) {
+ auto r = cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME));
+ if (r == CompletionQueue::TIMEOUT) continue;
+ if (r == CompletionQueue::GOT_EVENT) break;
+ gpr_log(GPR_ERROR, "unexpected result from AsyncNext");
+ abort();
+ }
+ } 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);
+ return detag(got_tag);
+ }
+
+ // Verify keeps calling Next until all currently set
+ // expected tags are complete
void Verify(CompletionQueue* cq) { Verify(cq, false); }
+ // This version of Verify allows optionally ignoring the
+ // outcome of the expectation
void Verify(CompletionQueue* cq, bool ignore_ok) {
GPR_ASSERT(!expectations_.empty());
while (!expectations_.empty()) {
- bool ok;
- void* got_tag;
- if (spin_) {
- for (;;) {
- auto r = cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME));
- if (r == CompletionQueue::TIMEOUT) continue;
- if (r == CompletionQueue::GOT_EVENT) break;
- gpr_log(GPR_ERROR, "unexpected result from AsyncNext");
- abort();
- }
- } 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);
+ Next(cq, ignore_ok);
}
}
+ // This version of Verify stops after a certain deadline
void Verify(CompletionQueue* cq,
std::chrono::system_clock::time_point deadline) {
if (expectations_.empty()) {
@@ -793,7 +807,8 @@ TEST_P(AsyncEnd2endTest, UnimplementedRpc) {
}
// This class is for testing scenarios where RPCs are cancelled on the server
-// by calling ServerContext::TryCancel()
+// by calling ServerContext::TryCancel(). Server uses AsyncNotifyWhenDone
+// API to check for cancellation
class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
protected:
typedef enum {
@@ -803,13 +818,6 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
CANCEL_AFTER_PROCESSING
} ServerTryCancelRequestPhase;
- void ServerTryCancel(ServerContext* context) {
- EXPECT_FALSE(context->IsCancelled());
- context->TryCancel();
- gpr_log(GPR_INFO, "Server called TryCancel()");
- EXPECT_TRUE(context->IsCancelled());
- }
-
// Helper for testing client-streaming RPCs which are cancelled on the server.
// Depending on the value of server_try_cancel parameter, this will test one
// of the following three scenarios:
@@ -843,6 +851,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
// On the server, request to be notified of 'RequestStream' calls
// and receive the 'RequestStream' call just made by the client
+ srv_ctx.AsyncNotifyWhenDone(tag(11));
service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
tag(2));
Verifier(GetParam()).Expect(2, true).Verify(cq_.get());
@@ -858,9 +867,12 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
bool expected_server_cq_result = true;
bool ignore_cq_result = false;
+ bool want_done_tag = false;
if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
- ServerTryCancel(&srv_ctx);
+ srv_ctx.TryCancel();
+ Verifier(GetParam()).Expect(11, true).Verify(cq_.get());
+ EXPECT_TRUE(srv_ctx.IsCancelled());
// Since cancellation is done before server reads any results, we know
// for sure that all cq results will return false from this point forward
@@ -868,22 +880,39 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
}
std::thread* server_try_cancel_thd = NULL;
+
+ auto verif = Verifier(GetParam());
+
if (server_try_cancel == CANCEL_DURING_PROCESSING) {
- server_try_cancel_thd = new std::thread(
- &AsyncEnd2endServerTryCancelTest::ServerTryCancel, this, &srv_ctx);
+ server_try_cancel_thd =
+ new std::thread(&ServerContext::TryCancel, &srv_ctx);
// Server will cancel the RPC in a parallel thread while reading the
// requests from the client. Since the cancellation can happen at anytime,
// some of the cq results (i.e those until cancellation) might be true but
// its non deterministic. So better to ignore the cq results
ignore_cq_result = true;
+ // Expect that we might possibly see the done tag that
+ // indicates cancellation completion in this case
+ want_done_tag = true;
+ verif.Expect(11, true);
}
// Server reads 3 messages (tags 6, 7 and 8)
+ // But if want_done_tag is true, we might also see tag 11
for (int tag_idx = 6; tag_idx <= 8; tag_idx++) {
srv_stream.Read(&recv_request, tag(tag_idx));
- Verifier(GetParam())
- .Expect(tag_idx, expected_server_cq_result)
- .Verify(cq_.get(), ignore_cq_result);
+ // Note that we'll add something to the verifier and verify that
+ // something was seen, but it might be tag 11 and not what we
+ // just added
+ int got_tag = verif.Expect(tag_idx, expected_server_cq_result)
+ .Next(cq_.get(), ignore_cq_result);
+ GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag));
+ if (got_tag == 11) {
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
+ // Now get the other entry that we were waiting on
+ EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx);
+ }
}
if (server_try_cancel_thd != NULL) {
@@ -892,7 +921,15 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
}
if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
- ServerTryCancel(&srv_ctx);
+ srv_ctx.TryCancel();
+ want_done_tag = true;
+ verif.Expect(11, true);
+ }
+
+ if (want_done_tag) {
+ verif.Verify(cq_.get());
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
}
// The RPC has been cancelled at this point for sure (i.e irrespective of
@@ -945,6 +982,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
Verifier(GetParam()).Expect(1, true).Verify(cq_.get());
// On the server, request to be notified of 'ResponseStream' calls and
// receive the call just made by the client
+ srv_ctx.AsyncNotifyWhenDone(tag(11));
service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream,
cq_.get(), cq_.get(), tag(2));
Verifier(GetParam()).Expect(2, true).Verify(cq_.get());
@@ -952,9 +990,12 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
bool expected_cq_result = true;
bool ignore_cq_result = false;
+ bool want_done_tag = false;
if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
- ServerTryCancel(&srv_ctx);
+ srv_ctx.TryCancel();
+ Verifier(GetParam()).Expect(11, true).Verify(cq_.get());
+ EXPECT_TRUE(srv_ctx.IsCancelled());
// We know for sure that all cq results will be false from this point
// since the server cancelled the RPC
@@ -962,24 +1003,41 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
}
std::thread* server_try_cancel_thd = NULL;
+
+ auto verif = Verifier(GetParam());
+
if (server_try_cancel == CANCEL_DURING_PROCESSING) {
- server_try_cancel_thd = new std::thread(
- &AsyncEnd2endServerTryCancelTest::ServerTryCancel, this, &srv_ctx);
+ server_try_cancel_thd =
+ new std::thread(&ServerContext::TryCancel, &srv_ctx);
// Server will cancel the RPC in a parallel thread while writing responses
// to the client. Since the cancellation can happen at anytime, some of
// the cq results (i.e those until cancellation) might be true but it is
// non deterministic. So better to ignore the cq results
ignore_cq_result = true;
+ // Expect that we might possibly see the done tag that
+ // indicates cancellation completion in this case
+ want_done_tag = true;
+ verif.Expect(11, true);
}
// Server sends three messages (tags 3, 4 and 5)
+ // But if want_done tag is true, we might also see tag 11
for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
send_response.set_message("Pong " + std::to_string(tag_idx));
srv_stream.Write(send_response, tag(tag_idx));
- Verifier(GetParam())
- .Expect(tag_idx, expected_cq_result)
- .Verify(cq_.get(), ignore_cq_result);
+ // Note that we'll add something to the verifier and verify that
+ // something was seen, but it might be tag 11 and not what we
+ // just added
+ int got_tag = verif.Expect(tag_idx, expected_cq_result)
+ .Next(cq_.get(), ignore_cq_result);
+ GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag));
+ if (got_tag == 11) {
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
+ // Now get the other entry that we were waiting on
+ EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx);
+ }
}
if (server_try_cancel_thd != NULL) {
@@ -988,13 +1046,21 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
}
if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
- ServerTryCancel(&srv_ctx);
+ srv_ctx.TryCancel();
+ want_done_tag = true;
+ verif.Expect(11, true);
// Client reads may fail bacause it is notified that the stream is
// cancelled.
ignore_cq_result = true;
}
+ if (want_done_tag) {
+ verif.Verify(cq_.get());
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
+ }
+
// Client attemts to read the three messages from the server
for (int tag_idx = 6; tag_idx <= 8; tag_idx++) {
cli_stream->Read(&recv_response, tag(tag_idx));
@@ -1052,6 +1118,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
// On the server, request to be notified of the 'BidiStream' call and
// receive the call just made by the client
+ srv_ctx.AsyncNotifyWhenDone(tag(11));
service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
tag(2));
Verifier(GetParam()).Expect(2, true).Verify(cq_.get());
@@ -1063,9 +1130,12 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
bool expected_cq_result = true;
bool ignore_cq_result = false;
+ bool want_done_tag = false;
if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
- ServerTryCancel(&srv_ctx);
+ srv_ctx.TryCancel();
+ Verifier(GetParam()).Expect(11, true).Verify(cq_.get());
+ EXPECT_TRUE(srv_ctx.IsCancelled());
// We know for sure that all cq results will be false from this point
// since the server cancelled the RPC
@@ -1073,42 +1143,84 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
}
std::thread* server_try_cancel_thd = NULL;
+
+ auto verif = Verifier(GetParam());
+
if (server_try_cancel == CANCEL_DURING_PROCESSING) {
- server_try_cancel_thd = new std::thread(
- &AsyncEnd2endServerTryCancelTest::ServerTryCancel, this, &srv_ctx);
+ server_try_cancel_thd =
+ new std::thread(&ServerContext::TryCancel, &srv_ctx);
// Since server is going to cancel the RPC in a parallel thread, some of
// the cq results (i.e those until the cancellation) might be true. Since
// that number is non-deterministic, it is better to ignore the cq results
ignore_cq_result = true;
+ // Expect that we might possibly see the done tag that
+ // indicates cancellation completion in this case
+ want_done_tag = true;
+ verif.Expect(11, true);
}
+ int got_tag;
srv_stream.Read(&recv_request, tag(4));
- Verifier(GetParam())
- .Expect(4, expected_cq_result)
- .Verify(cq_.get(), ignore_cq_result);
+ verif.Expect(4, expected_cq_result);
+ got_tag = verif.Next(cq_.get(), ignore_cq_result);
+ GPR_ASSERT((got_tag == 4) || (got_tag == 11 && want_done_tag));
+ if (got_tag == 11) {
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
+ // Now get the other entry that we were waiting on
+ EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 4);
+ }
send_response.set_message("Pong");
srv_stream.Write(send_response, tag(5));
- Verifier(GetParam())
- .Expect(5, expected_cq_result)
- .Verify(cq_.get(), ignore_cq_result);
+ verif.Expect(5, expected_cq_result);
+ got_tag = verif.Next(cq_.get(), ignore_cq_result);
+ GPR_ASSERT((got_tag == 5) || (got_tag == 11 && want_done_tag));
+ if (got_tag == 11) {
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
+ // Now get the other entry that we were waiting on
+ EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 5);
+ }
cli_stream->Read(&recv_response, tag(6));
- Verifier(GetParam())
- .Expect(6, expected_cq_result)
- .Verify(cq_.get(), ignore_cq_result);
+ verif.Expect(6, expected_cq_result);
+ got_tag = verif.Next(cq_.get(), ignore_cq_result);
+ GPR_ASSERT((got_tag == 6) || (got_tag == 11 && want_done_tag));
+ if (got_tag == 11) {
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
+ // Now get the other entry that we were waiting on
+ EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 6);
+ }
// This is expected to succeed in all cases
cli_stream->WritesDone(tag(7));
- Verifier(GetParam()).Expect(7, true).Verify(cq_.get());
+ verif.Expect(7, true);
+ got_tag = verif.Next(cq_.get(), ignore_cq_result);
+ GPR_ASSERT((got_tag == 7) || (got_tag == 11 && want_done_tag));
+ if (got_tag == 11) {
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
+ // Now get the other entry that we were waiting on
+ EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 7);
+ }
// This is expected to fail in all cases i.e for all values of
// server_try_cancel. This is because at this point, either there are no
// more msgs from the client (because client called WritesDone) or the RPC
// is cancelled on the server
srv_stream.Read(&recv_request, tag(8));
- Verifier(GetParam()).Expect(8, false).Verify(cq_.get());
+ verif.Expect(8, false);
+ got_tag = verif.Next(cq_.get(), ignore_cq_result);
+ GPR_ASSERT((got_tag == 8) || (got_tag == 11 && want_done_tag));
+ if (got_tag == 11) {
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
+ // Now get the other entry that we were waiting on
+ EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 8);
+ }
if (server_try_cancel_thd != NULL) {
server_try_cancel_thd->join();
@@ -1116,7 +1228,15 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
}
if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
- ServerTryCancel(&srv_ctx);
+ srv_ctx.TryCancel();
+ want_done_tag = true;
+ verif.Expect(11, true);
+ }
+
+ if (want_done_tag) {
+ verif.Verify(cq_.get());
+ EXPECT_TRUE(srv_ctx.IsCancelled());
+ want_done_tag = false;
}
// The RPC has been cancelled at this point for sure (i.e irrespective of
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index dc2c4f6426..4759818322 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -59,6 +59,7 @@
using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
+using grpc::testing::kTlsCredentialsType;
using std::chrono::system_clock;
namespace grpc {
@@ -1194,6 +1195,8 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorSuccess) {
request.mutable_param()->set_echo_metadata(true);
request.mutable_param()->set_expected_client_identity(
TestAuthMetadataProcessor::kGoodGuy);
+ request.mutable_param()->set_expected_transport_security_type(
+ GetParam().credentials_type);
Status s = stub_->Echo(&context, request, &response);
EXPECT_EQ(request.message(), response.message());
@@ -1301,6 +1304,8 @@ TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginAndProcessorSuccess) {
request.mutable_param()->set_echo_metadata(true);
request.mutable_param()->set_expected_client_identity(
TestAuthMetadataProcessor::kGoodGuy);
+ request.mutable_param()->set_expected_transport_security_type(
+ GetParam().credentials_type);
Status s = stub_->Echo(&context, request, &response);
EXPECT_EQ(request.message(), response.message());
@@ -1349,25 +1354,30 @@ TEST_P(SecureEnd2endTest, ClientAuthContext) {
EchoRequest request;
EchoResponse response;
request.set_message("Hello");
- request.mutable_param()->set_check_auth_context(true);
-
+ request.mutable_param()->set_check_auth_context(GetParam().credentials_type ==
+ kTlsCredentialsType);
+ request.mutable_param()->set_expected_transport_security_type(
+ GetParam().credentials_type);
ClientContext context;
Status s = stub_->Echo(&context, request, &response);
EXPECT_EQ(response.message(), request.message());
EXPECT_TRUE(s.ok());
std::shared_ptr<const AuthContext> auth_ctx = context.auth_context();
- std::vector<grpc::string_ref> ssl =
+ std::vector<grpc::string_ref> tst =
auth_ctx->FindPropertyValues("transport_security_type");
- EXPECT_EQ(1u, ssl.size());
- EXPECT_EQ("ssl", ToString(ssl[0]));
- EXPECT_EQ("x509_subject_alternative_name",
- auth_ctx->GetPeerIdentityPropertyName());
- EXPECT_EQ(3u, auth_ctx->GetPeerIdentity().size());
- EXPECT_EQ("*.test.google.fr", ToString(auth_ctx->GetPeerIdentity()[0]));
- EXPECT_EQ("waterzooi.test.google.be",
- ToString(auth_ctx->GetPeerIdentity()[1]));
- EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2]));
+ EXPECT_EQ(1u, tst.size());
+ EXPECT_EQ(GetParam().credentials_type, ToString(tst[0]));
+ if (GetParam().credentials_type == kTlsCredentialsType) {
+ EXPECT_EQ("x509_subject_alternative_name",
+ auth_ctx->GetPeerIdentityPropertyName());
+ EXPECT_EQ(4u, auth_ctx->GetPeerIdentity().size());
+ EXPECT_EQ("*.test.google.fr", ToString(auth_ctx->GetPeerIdentity()[0]));
+ EXPECT_EQ("waterzooi.test.google.be",
+ ToString(auth_ctx->GetPeerIdentity()[1]));
+ EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2]));
+ EXPECT_EQ("192.168.1.3", ToString(auth_ctx->GetPeerIdentity()[3]));
+ }
}
std::vector<TestScenario> CreateTestScenarios(bool use_proxy,
diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc
index 7c3e514eff..fe29c4afe9 100644
--- a/test/cpp/end2end/test_service_impl.cc
+++ b/test/cpp/end2end/test_service_impl.cc
@@ -62,14 +62,16 @@ void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,
}
}
-void CheckServerAuthContext(const ServerContext* context,
- const grpc::string& expected_client_identity) {
+void CheckServerAuthContext(
+ const ServerContext* context,
+ const grpc::string& expected_transport_security_type,
+ const grpc::string& expected_client_identity) {
std::shared_ptr<const AuthContext> auth_ctx = context->auth_context();
- std::vector<grpc::string_ref> ssl =
+ std::vector<grpc::string_ref> tst =
auth_ctx->FindPropertyValues("transport_security_type");
- EXPECT_EQ(1u, ssl.size());
- EXPECT_EQ("ssl", ToString(ssl[0]));
- if (expected_client_identity.length() == 0) {
+ EXPECT_EQ(1u, tst.size());
+ EXPECT_EQ(expected_transport_security_type, ToString(tst[0]));
+ if (expected_client_identity.empty()) {
EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty());
EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty());
EXPECT_FALSE(auth_ctx->IsPeerAuthenticated());
@@ -139,6 +141,7 @@ Status TestServiceImpl::Echo(ServerContext* context, const EchoRequest* request,
(request->param().expected_client_identity().length() > 0 ||
request->param().check_auth_context())) {
CheckServerAuthContext(context,
+ request->param().expected_transport_security_type(),
request->param().expected_client_identity());
}
if (request->has_param() && request->param().response_message_length() > 0) {
diff --git a/test/cpp/interop/reconnect_interop_server.cc b/test/cpp/interop/reconnect_interop_server.cc
index 3602b8c2b0..1f9147d0ef 100644
--- a/test/cpp/interop/reconnect_interop_server.cc
+++ b/test/cpp/interop/reconnect_interop_server.cc
@@ -31,6 +31,8 @@
*
*/
+// Test description at doc/connection-backoff-interop-test-description.md
+
#include <signal.h>
#include <unistd.h>
@@ -40,17 +42,17 @@
#include <sstream>
#include <gflags/gflags.h>
-#include <grpc/grpc.h>
-#include <grpc/support/log.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
-#include "test/core/util/reconnect_server.h"
-#include "test/cpp/util/test_config.h"
-#include "src/proto/grpc/testing/test.grpc.pb.h"
#include "src/proto/grpc/testing/empty.grpc.pb.h"
#include "src/proto/grpc/testing/messages.grpc.pb.h"
+#include "src/proto/grpc/testing/test.grpc.pb.h"
+#include "test/core/util/reconnect_server.h"
+#include "test/cpp/util/test_config.h"
DEFINE_int32(control_port, 0, "Server port for controlling the server.");
DEFINE_int32(retry_port, 0,
diff --git a/test/cpp/qps/async_streaming_ping_pong_test.cc b/test/cpp/qps/async_streaming_ping_pong_test.cc
index 97499329c1..d9fbb39df7 100644
--- a/test/cpp/qps/async_streaming_ping_pong_test.cc
+++ b/test/cpp/qps/async_streaming_ping_pong_test.cc
@@ -43,7 +43,7 @@ namespace grpc {
namespace testing {
static const int WARMUP = 5;
-static const int BENCHMARK = 10;
+static const int BENCHMARK = 5;
static void RunAsyncStreamingPingPong() {
gpr_log(GPR_INFO, "Running Async Streaming Ping Pong");
diff --git a/test/cpp/qps/async_unary_ping_pong_test.cc b/test/cpp/qps/async_unary_ping_pong_test.cc
index d801bddf4a..5ab86197b0 100644
--- a/test/cpp/qps/async_unary_ping_pong_test.cc
+++ b/test/cpp/qps/async_unary_ping_pong_test.cc
@@ -43,7 +43,7 @@ namespace grpc {
namespace testing {
static const int WARMUP = 5;
-static const int BENCHMARK = 10;
+static const int BENCHMARK = 5;
static void RunAsyncUnaryPingPong() {
gpr_log(GPR_INFO, "Running Async Unary Ping Pong");
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index 2dc83f0f29..92e77eed9b 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -123,15 +123,13 @@ class Client {
if (reset) {
Histogram* to_merge = new Histogram[threads_.size()];
for (size_t i = 0; i < threads_.size(); i++) {
- threads_[i]->BeginSwap(&to_merge[i]);
- }
- std::unique_ptr<UsageTimer> timer(new UsageTimer);
- timer_.swap(timer);
- for (size_t i = 0; i < threads_.size(); i++) {
- threads_[i]->EndSwap();
+ threads_[i]->Swap(&to_merge[i]);
latencies.Merge(to_merge[i]);
}
delete[] to_merge;
+
+ std::unique_ptr<UsageTimer> timer(new UsageTimer);
+ timer_.swap(timer);
timer_result = timer->Mark();
} else {
// merge snapshots of each thread histogram
@@ -227,7 +225,6 @@ class Client {
public:
Thread(Client* client, size_t idx)
: done_(false),
- new_stats_(nullptr),
client_(client),
idx_(idx),
impl_(&Thread::ThreadFunc, this) {}
@@ -240,16 +237,9 @@ class Client {
impl_.join();
}
- void BeginSwap(Histogram* n) {
+ void Swap(Histogram* n) {
std::lock_guard<std::mutex> g(mu_);
- new_stats_ = n;
- }
-
- void EndSwap() {
- std::unique_lock<std::mutex> g(mu_);
- while (new_stats_ != nullptr) {
- cv_.wait(g);
- };
+ n->Swap(&histogram_);
}
void MergeStatsInto(Histogram* hist) {
@@ -263,10 +253,11 @@ class Client {
void ThreadFunc() {
for (;;) {
+ // lock since the thread should only be doing one thing at a time
+ std::lock_guard<std::mutex> g(mu_);
// run the loop body
const bool thread_still_ok = client_->ThreadFunc(&histogram_, idx_);
- // lock, see if we're done
- std::lock_guard<std::mutex> g(mu_);
+ // see if we're done
if (!thread_still_ok) {
gpr_log(GPR_ERROR, "Finishing client thread due to RPC error");
done_ = true;
@@ -274,19 +265,11 @@ class Client {
if (done_) {
return;
}
- // check if we're resetting stats, swap out the histogram if so
- if (new_stats_) {
- new_stats_->Swap(&histogram_);
- new_stats_ = nullptr;
- cv_.notify_one();
- }
}
}
std::mutex mu_;
- std::condition_variable cv_;
bool done_;
- Histogram* new_stats_;
Histogram histogram_;
Client* client_;
const size_t idx_;
diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc
index 1c7fdf8796..6c05799d09 100644
--- a/test/cpp/qps/driver.cc
+++ b/test/cpp/qps/driver.cc
@@ -43,6 +43,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
+#include <gtest/gtest.h>
#include "src/core/support/env.h"
#include "src/proto/grpc/testing/services.grpc.pb.h"
@@ -120,11 +121,9 @@ static deque<string> get_workers(const string& name) {
namespace runsc {
// ClientContext allocator
-template <class T>
-static ClientContext* AllocContext(list<ClientContext>* contexts, T deadline) {
+static ClientContext* AllocContext(list<ClientContext>* contexts) {
contexts->emplace_back();
auto context = &contexts->back();
- context->set_deadline(deadline);
return context;
}
@@ -196,9 +195,6 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Trim to just what we need
workers.resize(num_clients + num_servers);
- gpr_timespec deadline =
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(warmup_seconds + benchmark_seconds + 20);
-
// Start servers
using runsc::ServerData;
// servers is array rather than std::vector to avoid gcc-4.4 issues
@@ -248,7 +244,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
ServerArgs args;
*args.mutable_setup() = server_config;
servers[i].stream =
- servers[i].stub->RunServer(runsc::AllocContext(&contexts, deadline));
+ servers[i].stub->RunServer(runsc::AllocContext(&contexts));
GPR_ASSERT(servers[i].stream->Write(args));
ServerStatus init_status;
GPR_ASSERT(servers[i].stream->Read(&init_status));
@@ -304,7 +300,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
ClientArgs args;
*args.mutable_setup() = per_client_config;
clients[i].stream =
- clients[i].stub->RunClient(runsc::AllocContext(&contexts, deadline));
+ clients[i].stub->RunClient(runsc::AllocContext(&contexts));
GPR_ASSERT(clients[i].stream->Write(args));
ClientStatus init_status;
GPR_ASSERT(clients[i].stream->Read(&init_status));
@@ -342,25 +338,17 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Use gpr_sleep_until rather than this_thread::sleep_until to support
// compilers that don't work with this_thread
gpr_sleep_until(gpr_time_add(
- start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN)));
+ start,
+ gpr_time_from_seconds(warmup_seconds + benchmark_seconds, GPR_TIMESPAN)));
// Finish a run
std::unique_ptr<ScenarioResult> result(new ScenarioResult);
result->client_config = result_client_config;
result->server_config = result_server_config;
- gpr_log(GPR_INFO, "Finishing");
- for (auto server = &servers[0]; server != &servers[num_servers]; server++) {
- GPR_ASSERT(server->stream->Write(server_mark));
- }
+ gpr_log(GPR_INFO, "Finishing clients");
for (auto client = &clients[0]; client != &clients[num_clients]; client++) {
GPR_ASSERT(client->stream->Write(client_mark));
- }
- for (auto server = &servers[0]; server != &servers[num_servers]; server++) {
- GPR_ASSERT(server->stream->Read(&server_status));
- const auto& stats = server_status.stats();
- result->server_resources.emplace_back(
- stats.time_elapsed(), stats.time_user(), stats.time_system(),
- server_status.cores());
+ GPR_ASSERT(client->stream->WritesDone());
}
for (auto client = &clients[0]; client != &clients[num_clients]; client++) {
GPR_ASSERT(client->stream->Read(&client_status));
@@ -368,17 +356,30 @@ std::unique_ptr<ScenarioResult> RunScenario(
result->latencies.MergeProto(stats.latencies());
result->client_resources.emplace_back(
stats.time_elapsed(), stats.time_user(), stats.time_system(), -1);
+ GPR_ASSERT(!client->stream->Read(&client_status));
}
-
for (auto client = &clients[0]; client != &clients[num_clients]; client++) {
- GPR_ASSERT(client->stream->WritesDone());
GPR_ASSERT(client->stream->Finish().ok());
}
+ delete[] clients;
+
+ gpr_log(GPR_INFO, "Finishing servers");
for (auto server = &servers[0]; server != &servers[num_servers]; server++) {
+ GPR_ASSERT(server->stream->Write(server_mark));
GPR_ASSERT(server->stream->WritesDone());
+ }
+ for (auto server = &servers[0]; server != &servers[num_servers]; server++) {
+ GPR_ASSERT(server->stream->Read(&server_status));
+ const auto& stats = server_status.stats();
+ result->server_resources.emplace_back(
+ stats.time_elapsed(), stats.time_user(), stats.time_system(),
+ server_status.cores());
+ GPR_ASSERT(!server->stream->Read(&server_status));
+ }
+ for (auto server = &servers[0]; server != &servers[num_servers]; server++) {
GPR_ASSERT(server->stream->Finish().ok());
}
- delete[] clients;
+
delete[] servers;
return result;
}
diff --git a/test/cpp/qps/generic_async_streaming_ping_pong_test.cc b/test/cpp/qps/generic_async_streaming_ping_pong_test.cc
index d9166ae210..77ed11f287 100644
--- a/test/cpp/qps/generic_async_streaming_ping_pong_test.cc
+++ b/test/cpp/qps/generic_async_streaming_ping_pong_test.cc
@@ -43,7 +43,7 @@ namespace grpc {
namespace testing {
static const int WARMUP = 5;
-static const int BENCHMARK = 10;
+static const int BENCHMARK = 5;
static void RunGenericAsyncStreamingPingPong() {
gpr_log(GPR_INFO, "Running Generic Async Streaming Ping Pong");
diff --git a/test/cpp/qps/qps_openloop_test.cc b/test/cpp/qps/qps_openloop_test.cc
index 27f266b32b..2ae0afbcbe 100644
--- a/test/cpp/qps/qps_openloop_test.cc
+++ b/test/cpp/qps/qps_openloop_test.cc
@@ -44,7 +44,7 @@ namespace grpc {
namespace testing {
static const int WARMUP = 5;
-static const int BENCHMARK = 10;
+static const int BENCHMARK = 5;
static void RunQPS() {
gpr_log(GPR_INFO, "Running QPS test, open-loop");
diff --git a/test/cpp/qps/qps_test.cc b/test/cpp/qps/qps_test.cc
index 27aaf137f6..b6a2e1ef30 100644
--- a/test/cpp/qps/qps_test.cc
+++ b/test/cpp/qps/qps_test.cc
@@ -43,7 +43,7 @@ namespace grpc {
namespace testing {
static const int WARMUP = 20;
-static const int BENCHMARK = 40;
+static const int BENCHMARK = 20;
static void RunQPS() {
gpr_log(GPR_INFO, "Running QPS test");
diff --git a/test/cpp/qps/secure_sync_unary_ping_pong_test.cc b/test/cpp/qps/secure_sync_unary_ping_pong_test.cc
index 359310b856..946c76f747 100644
--- a/test/cpp/qps/secure_sync_unary_ping_pong_test.cc
+++ b/test/cpp/qps/secure_sync_unary_ping_pong_test.cc
@@ -43,7 +43,7 @@ namespace grpc {
namespace testing {
static const int WARMUP = 5;
-static const int BENCHMARK = 10;
+static const int BENCHMARK = 5;
static void RunSynchronousUnaryPingPong() {
gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong");
diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc
index 2024e0bfef..d7b3f76e0e 100644
--- a/test/cpp/qps/server_async.cc
+++ b/test/cpp/qps/server_async.cc
@@ -130,8 +130,7 @@ class AsyncQpsServerTest : public Server {
}
}
~AsyncQpsServerTest() {
- auto deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
- server_->Shutdown(deadline);
+ server_->Shutdown();
for (auto ss = shutdown_state_.begin(); ss != shutdown_state_.end(); ++ss) {
(*ss)->set_shutdown();
}
diff --git a/test/cpp/qps/sync_streaming_ping_pong_test.cc b/test/cpp/qps/sync_streaming_ping_pong_test.cc
index e02c14c926..ee1bbc7a11 100644
--- a/test/cpp/qps/sync_streaming_ping_pong_test.cc
+++ b/test/cpp/qps/sync_streaming_ping_pong_test.cc
@@ -43,7 +43,7 @@ namespace grpc {
namespace testing {
static const int WARMUP = 5;
-static const int BENCHMARK = 10;
+static const int BENCHMARK = 5;
static void RunSynchronousStreamingPingPong() {
gpr_log(GPR_INFO, "Running Synchronous Streaming Ping Pong");
diff --git a/test/cpp/qps/sync_unary_ping_pong_test.cc b/test/cpp/qps/sync_unary_ping_pong_test.cc
index 9d363c04fb..4dccfee190 100644
--- a/test/cpp/qps/sync_unary_ping_pong_test.cc
+++ b/test/cpp/qps/sync_unary_ping_pong_test.cc
@@ -43,7 +43,7 @@ namespace grpc {
namespace testing {
static const int WARMUP = 5;
-static const int BENCHMARK = 10;
+static const int BENCHMARK = 5;
static void RunSynchronousUnaryPingPong() {
gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong");
diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h
index 50fadb53a2..1fb311e556 100644
--- a/test/cpp/util/test_credentials_provider.h
+++ b/test/cpp/util/test_credentials_provider.h
@@ -44,7 +44,10 @@ namespace grpc {
namespace testing {
const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS";
-const char kTlsCredentialsType[] = "TLS_CREDENTIALS";
+
+// For real credentials, like tls/ssl, this name should match the AuthContext
+// property "transport_security_type".
+const char kTlsCredentialsType[] = "ssl";
// Provide test credentials of a particular type.
class CredentialTypeProvider {