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/client_config/lb_policies_test.c18
-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.py3
-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/udp_server_test.c16
-rw-r--r--test/core/security/security_connector_test.c58
-rw-r--r--test/core/support/backoff_test.c107
-rw-r--r--test/core/surface/concurrent_connectivity_test.c34
-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/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/driver.cc15
-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
30 files changed, 810 insertions, 415 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/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/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 e456882a88..3c24440777 100755
--- a/test/core/end2end/gen_build_yaml.py
+++ b/test/core/end2end/gen_build_yaml.py
@@ -55,6 +55,7 @@ END2END_FIXTURES = {
'h2_full': default_unsecure_fixture_options,
'h2_full+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),
@@ -62,7 +63,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_proxy': default_secure_fixture_options._replace(includes_proxy=True,
ci_mac=False),
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/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index ce3c23b4bf..5507f7e961 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -31,19 +31,21 @@
*
*/
-#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>
-#include "test/core/util/test_config.h"
-#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
+#include <sys/socket.h>
#include <unistd.h>
+#include <grpc/support/log.h>
+#include <grpc/support/sync.h>
+#include <grpc/support/time.h>
+
+#include "src/core/iomgr/ev_posix.h"
+#include "src/core/iomgr/iomgr.h"
+#include "test/core/util/test_config.h"
+
#ifdef GRPC_NEED_UDP
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x)
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/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
index 4d3b7bf22a..96761b0502 100644
--- a/test/core/surface/concurrent_connectivity_test.c
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -40,29 +40,27 @@
#include "test/core/util/test_config.h"
#define NUM_THREADS 100
-static grpc_channel* channels[NUM_THREADS];
-static grpc_completion_queue* queues[NUM_THREADS];
+#define NUM_OUTER_LOOPS 10
+#define NUM_INNER_LOOPS 10
+#define DELAY_MILLIS 10
+#define POLL_MILLIS 3000
-void create_loop_destroy(void* actually_an_int) {
- int thread_index = (int)(intptr_t)(actually_an_int);
- for (int i = 0; i < 10; ++i) {
+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);
- channels[thread_index] = chan;
- queues[thread_index] = cq;
-
- for (int j = 0; j < 10; ++j) {
- gpr_timespec later_time = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10);
+ 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_ASSERT(grpc_completion_queue_next(cq,
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3),
- NULL).type == GRPC_OP_COMPLETE);
+ 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(channels[thread_index]);
- grpc_completion_queue_destroy(queues[thread_index]);
+ grpc_channel_destroy(chan);
+ grpc_completion_queue_destroy(cq);
}
}
@@ -70,12 +68,12 @@ int main(int argc, char** argv) {
grpc_test_init(argc, argv);
grpc_init();
gpr_thd_id threads[NUM_THREADS];
- for (intptr_t i = 0; i < NUM_THREADS; ++i) {
+ 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, (void*)i, &options);
+ gpr_thd_new(&threads[i], create_loop_destroy, NULL, &options);
}
- for (int i = 0; i < NUM_THREADS; ++i) {
+ for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
}
grpc_shutdown();
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c
index b69df73c83..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,77 +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);
- gpr_free(p);
-}
-
-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);
- 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);
-
- grpc_shutdown();
-}
-
-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);
}
@@ -206,101 +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);
- 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;
-}
-
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/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/driver.cc b/test/cpp/qps/driver.cc
index bc8780f74d..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,7 +338,8 @@ 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);
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");