aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/surface
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/surface')
-rw-r--r--test/core/surface/byte_buffer_reader_test.c36
-rw-r--r--test/core/surface/completion_queue_test.c32
-rw-r--r--test/core/surface/concurrent_connectivity_test.c81
-rw-r--r--test/core/surface/lame_client_test.c13
-rw-r--r--test/core/surface/public_headers_must_be_c89.c1
-rw-r--r--test/core/surface/secure_channel_create_test.c4
-rw-r--r--test/core/surface/sequential_connectivity_test.c179
-rw-r--r--test/core/surface/server_chttp2_test.c11
-rw-r--r--test/core/surface/server_test.c81
9 files changed, 370 insertions, 68 deletions
diff --git a/test/core/surface/byte_buffer_reader_test.c b/test/core/surface/byte_buffer_reader_test.c
index 9c6734e179..1ab1a06211 100644
--- a/test/core/surface/byte_buffer_reader_test.c
+++ b/test/core/surface/byte_buffer_reader_test.c
@@ -59,7 +59,8 @@ static void test_read_one_slice(void) {
slice = gpr_slice_from_copied_string("test");
buffer = grpc_raw_byte_buffer_create(&slice, 1);
gpr_slice_unref(slice);
- grpc_byte_buffer_reader_init(&reader, buffer);
+ GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, buffer) &&
+ "Couldn't init byte buffer reader");
first_code = grpc_byte_buffer_reader_next(&reader, &first_slice);
GPR_ASSERT(first_code != 0);
GPR_ASSERT(memcmp(GPR_SLICE_START_PTR(first_slice), "test", 4) == 0);
@@ -81,7 +82,8 @@ static void test_read_one_slice_malloc(void) {
memcpy(GPR_SLICE_START_PTR(slice), "test", 4);
buffer = grpc_raw_byte_buffer_create(&slice, 1);
gpr_slice_unref(slice);
- grpc_byte_buffer_reader_init(&reader, buffer);
+ GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, buffer) &&
+ "Couldn't init byte buffer reader");
first_code = grpc_byte_buffer_reader_next(&reader, &first_slice);
GPR_ASSERT(first_code != 0);
GPR_ASSERT(memcmp(GPR_SLICE_START_PTR(first_slice), "test", 4) == 0);
@@ -102,7 +104,8 @@ static void test_read_none_compressed_slice(void) {
slice = gpr_slice_from_copied_string("test");
buffer = grpc_raw_byte_buffer_create(&slice, 1);
gpr_slice_unref(slice);
- grpc_byte_buffer_reader_init(&reader, buffer);
+ GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, buffer) &&
+ "Couldn't init byte buffer reader");
first_code = grpc_byte_buffer_reader_next(&reader, &first_slice);
GPR_ASSERT(first_code != 0);
GPR_ASSERT(memcmp(GPR_SLICE_START_PTR(first_slice), "test", 4) == 0);
@@ -112,6 +115,20 @@ static void test_read_none_compressed_slice(void) {
grpc_byte_buffer_destroy(buffer);
}
+static void test_read_corrupted_slice(void) {
+ gpr_slice slice;
+ grpc_byte_buffer *buffer;
+ grpc_byte_buffer_reader reader;
+
+ LOG_TEST("test_read_corrupted_slice");
+ slice = gpr_slice_from_copied_string("test");
+ buffer = grpc_raw_byte_buffer_create(&slice, 1);
+ buffer->data.raw.compression = GRPC_COMPRESS_GZIP; /* lies! */
+ gpr_slice_unref(slice);
+ GPR_ASSERT(!grpc_byte_buffer_reader_init(&reader, buffer));
+ grpc_byte_buffer_destroy(buffer);
+}
+
static void read_compressed_slice(grpc_compression_algorithm algorithm,
size_t input_size) {
gpr_slice input_slice;
@@ -132,7 +149,8 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm,
buffer = grpc_raw_compressed_byte_buffer_create(sliceb_out.slices,
sliceb_out.count, algorithm);
- grpc_byte_buffer_reader_init(&reader, buffer);
+ GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, buffer) &&
+ "Couldn't init byte buffer reader");
while (grpc_byte_buffer_reader_next(&reader, &read_slice)) {
GPR_ASSERT(memcmp(GPR_SLICE_START_PTR(read_slice),
@@ -170,7 +188,8 @@ static void test_byte_buffer_from_reader(void) {
memcpy(GPR_SLICE_START_PTR(slice), "test", 4);
buffer = grpc_raw_byte_buffer_create(&slice, 1);
gpr_slice_unref(slice);
- grpc_byte_buffer_reader_init(&reader, buffer);
+ GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, buffer) &&
+ "Couldn't init byte buffer reader");
buffer_from_reader = grpc_raw_byte_buffer_from_reader(&reader);
GPR_ASSERT(buffer->type == buffer_from_reader->type);
@@ -206,7 +225,8 @@ static void test_readall(void) {
gpr_slice_unref(slices[0]);
gpr_slice_unref(slices[1]);
- grpc_byte_buffer_reader_init(&reader, buffer);
+ GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, buffer) &&
+ "Couldn't init byte buffer reader");
slice_out = grpc_byte_buffer_reader_readall(&reader);
GPR_ASSERT(GPR_SLICE_LENGTH(slice_out) == 512 + 1024);
@@ -241,7 +261,8 @@ static void test_byte_buffer_copy(void) {
gpr_slice_unref(slices[1]);
copied_buffer = grpc_byte_buffer_copy(buffer);
- grpc_byte_buffer_reader_init(&reader, copied_buffer);
+ GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, buffer) &&
+ "Couldn't init byte buffer reader");
slice_out = grpc_byte_buffer_reader_readall(&reader);
GPR_ASSERT(GPR_SLICE_LENGTH(slice_out) == 512 + 1024);
@@ -260,6 +281,7 @@ int main(int argc, char **argv) {
test_read_none_compressed_slice();
test_read_gzip_compressed_slice();
test_read_deflate_compressed_slice();
+ test_read_corrupted_slice();
test_byte_buffer_from_reader();
test_byte_buffer_copy();
test_readall();
diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c
index d62d5a93b1..1486d2508f 100644
--- a/test/core/surface/completion_queue_test.c
+++ b/test/core/surface/completion_queue_test.c
@@ -63,6 +63,12 @@ static void test_no_op(void) {
shutdown_and_destroy(grpc_completion_queue_create(NULL));
}
+static void test_pollset_conversion(void) {
+ grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
+ GPR_ASSERT(grpc_cq_from_pollset(grpc_cq_pollset(cq)) == cq);
+ shutdown_and_destroy(cq);
+}
+
static void test_wait_empty(void) {
grpc_completion_queue *cc;
grpc_event event;
@@ -90,8 +96,8 @@ static void test_cq_end_op(void) {
cc = grpc_completion_queue_create(NULL);
grpc_cq_begin_op(cc, tag);
- grpc_cq_end_op(&exec_ctx, cc, tag, 1, do_nothing_end_completion, NULL,
- &completion);
+ grpc_cq_end_op(&exec_ctx, cc, tag, GRPC_ERROR_NONE, do_nothing_end_completion,
+ NULL, &completion);
ev = grpc_completion_queue_next(cc, gpr_inf_past(GPR_CLOCK_REALTIME), NULL);
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
@@ -149,8 +155,8 @@ static void test_pluck(void) {
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
grpc_cq_begin_op(cc, tags[i]);
- grpc_cq_end_op(&exec_ctx, cc, tags[i], 1, do_nothing_end_completion, NULL,
- &completions[i]);
+ grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE,
+ do_nothing_end_completion, NULL, &completions[i]);
}
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
@@ -161,8 +167,8 @@ static void test_pluck(void) {
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
grpc_cq_begin_op(cc, tags[i]);
- grpc_cq_end_op(&exec_ctx, cc, tags[i], 1, do_nothing_end_completion, NULL,
- &completions[i]);
+ grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE,
+ do_nothing_end_completion, NULL, &completions[i]);
}
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
@@ -234,8 +240,8 @@ static void test_too_many_plucks(void) {
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
grpc_cq_begin_op(cc, tags[i]);
- grpc_cq_end_op(&exec_ctx, cc, tags[i], 1, do_nothing_end_completion, NULL,
- &completions[i]);
+ grpc_cq_end_op(&exec_ctx, cc, tags[i], GRPC_ERROR_NONE,
+ do_nothing_end_completion, NULL, &completions[i]);
}
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
@@ -288,8 +294,9 @@ static void producer_thread(void *arg) {
gpr_log(GPR_INFO, "producer %d phase 2", opt->id);
for (i = 0; i < TEST_THREAD_EVENTS; i++) {
- grpc_cq_end_op(&exec_ctx, opt->cc, (void *)(intptr_t)1, 1, free_completion,
- NULL, gpr_malloc(sizeof(grpc_cq_completion)));
+ grpc_cq_end_op(&exec_ctx, opt->cc, (void *)(intptr_t)1, GRPC_ERROR_NONE,
+ free_completion, NULL,
+ gpr_malloc(sizeof(grpc_cq_completion)));
opt->events_triggered++;
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -342,8 +349,8 @@ static void test_threading(size_t producers, size_t consumers) {
size_t total_consumed = 0;
static int optid = 101;
- gpr_log(GPR_INFO, "%s: %d producers, %d consumers", "test_threading",
- producers, consumers);
+ gpr_log(GPR_INFO, "%s: %" PRIuPTR " producers, %" PRIuPTR " consumers",
+ "test_threading", producers, consumers);
/* start all threads: they will wait for phase1 */
for (i = 0; i < producers + consumers; i++) {
@@ -408,6 +415,7 @@ int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_init();
test_no_op();
+ test_pollset_conversion();
test_wait_empty();
test_shutdown_then_next_polling();
test_shutdown_then_next_with_timeout();
diff --git a/test/core/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
index 28ddf58cc8..f7567f350d 100644
--- a/test/core/surface/concurrent_connectivity_test.c
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -1,35 +1,35 @@
/*
-*
-* 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.
-*
-*/
+ *
+ * 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 <memory.h>
#include <stdio.h>
@@ -96,12 +96,13 @@ void server_thread(void *vargs) {
}
static void on_connect(grpc_exec_ctx *exec_ctx, void *vargs, grpc_endpoint *tcp,
+ grpc_pollset *accepting_pollset,
grpc_tcp_server_acceptor *acceptor) {
struct server_thread_args *args = (struct server_thread_args *)vargs;
(void)acceptor;
grpc_endpoint_shutdown(exec_ctx, tcp);
grpc_endpoint_destroy(exec_ctx, tcp);
- grpc_pollset_kick(args->pollset, NULL);
+ GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, NULL));
}
void bad_server_thread(void *vargs) {
@@ -111,10 +112,14 @@ void bad_server_thread(void *vargs) {
struct sockaddr_storage addr;
socklen_t addr_len = sizeof(addr);
int port;
- grpc_tcp_server *s = grpc_tcp_server_create(NULL);
+ grpc_tcp_server *s;
+ grpc_error *error = grpc_tcp_server_create(NULL, NULL, &s);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
memset(&addr, 0, sizeof(addr));
addr.ss_family = AF_INET;
- port = grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len);
+ error =
+ grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len, &port);
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("grpc_tcp_server_add_port", error));
GPR_ASSERT(port > 0);
gpr_asprintf(&args->addr, "localhost:%d", port);
@@ -128,7 +133,11 @@ void bad_server_thread(void *vargs) {
gpr_time_add(now, gpr_time_from_millis(100, GPR_TIMESPAN));
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, args->pollset, &worker, now, deadline);
+ if (!GRPC_LOG_IF_ERROR("pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker,
+ now, deadline))) {
+ gpr_atm_rel_store(&args->stop, 1);
+ }
gpr_mu_unlock(args->mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(args->mu);
@@ -143,7 +152,7 @@ void bad_server_thread(void *vargs) {
}
static void done_pollset_shutdown(grpc_exec_ctx *exec_ctx, void *pollset,
- bool success) {
+ grpc_error *error) {
grpc_pollset_destroy(pollset);
gpr_free(pollset);
}
diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c
index 12fa9de6cf..f36f980575 100644
--- a/test/core/surface/lame_client_test.c
+++ b/test/core/surface/lame_client_test.c
@@ -47,13 +47,14 @@ grpc_closure transport_op_cb;
static void *tag(intptr_t x) { return (void *)x; }
-void verify_connectivity(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
+void verify_connectivity(grpc_exec_ctx *exec_ctx, void *arg,
+ grpc_error *error) {
grpc_transport_op *op = arg;
- GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE == *op->connectivity_state);
- GPR_ASSERT(success);
+ GPR_ASSERT(GRPC_CHANNEL_SHUTDOWN == *op->connectivity_state);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
}
-void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, bool success) {}
+void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {}
void test_transport_op(grpc_channel *channel) {
grpc_transport_op op;
@@ -104,7 +105,7 @@ int main(int argc, char **argv) {
test_transport_op(chan);
- GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE ==
+ GPR_ASSERT(GRPC_CHANNEL_SHUTDOWN ==
grpc_channel_check_connectivity_state(chan, 0));
cq = grpc_completion_queue_create(NULL);
@@ -115,6 +116,7 @@ int main(int argc, char **argv) {
GPR_ASSERT(call);
cqv = cq_verifier_create(cq);
+ memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
@@ -133,6 +135,7 @@ int main(int argc, char **argv) {
cq_expect_completion(cqv, tag(1), 0);
cq_verify(cqv);
+ memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c
index 0eede6c23b..3eeb55d033 100644
--- a/test/core/surface/public_headers_must_be_c89.c
+++ b/test/core/surface/public_headers_must_be_c89.c
@@ -41,6 +41,7 @@
#include <grpc/impl/codegen/alloc.h>
#include <grpc/impl/codegen/atm.h>
#include <grpc/impl/codegen/byte_buffer.h>
+#include <grpc/impl/codegen/byte_buffer_reader.h>
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/connectivity_state.h>
#include <grpc/impl/codegen/grpc_types.h>
diff --git a/test/core/surface/secure_channel_create_test.c b/test/core/surface/secure_channel_create_test.c
index 80419efce4..b952503167 100644
--- a/test/core/surface/secure_channel_create_test.c
+++ b/test/core/surface/secure_channel_create_test.c
@@ -37,8 +37,8 @@
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include "src/core/ext/client_config/resolver_registry.h"
-#include "src/core/lib/security/credentials.h"
-#include "src/core/lib/security/security_connector.h"
+#include "src/core/lib/security/credentials/fake/fake_credentials.h"
+#include "src/core/lib/security/transport/security_connector.h"
#include "src/core/lib/surface/channel.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/surface/sequential_connectivity_test.c b/test/core/surface/sequential_connectivity_test.c
new file mode 100644
index 0000000000..fe87f119f2
--- /dev/null
+++ b/test/core/surface/sequential_connectivity_test.c
@@ -0,0 +1,179 @@
+/*
+ *
+ * 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 <grpc/grpc.h>
+#include <grpc/grpc_security.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/host_port.h>
+#include <grpc/support/log.h>
+#include <grpc/support/thd.h>
+
+#include "src/core/lib/channel/channel_args.h"
+#include "test/core/end2end/data/ssl_test_data.h"
+#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
+
+typedef struct test_fixture {
+ const char *name;
+ void (*add_server_port)(grpc_server *server, const char *addr);
+ grpc_channel *(*create_channel)(const char *addr);
+} test_fixture;
+
+#define NUM_CONNECTIONS 1000
+
+typedef struct {
+ grpc_server *server;
+ grpc_completion_queue *cq;
+} server_thread_args;
+
+static void server_thread_func(void *args) {
+ server_thread_args *a = args;
+ grpc_event ev = grpc_completion_queue_next(
+ a->cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+ GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
+ GPR_ASSERT(ev.tag == NULL);
+ GPR_ASSERT(ev.success == true);
+}
+
+static void run_test(const test_fixture *fixture) {
+ gpr_log(GPR_INFO, "TEST: %s", fixture->name);
+
+ grpc_init();
+
+ char *addr;
+ gpr_join_host_port(&addr, "localhost", grpc_pick_unused_port_or_die());
+
+ grpc_server *server = grpc_server_create(NULL, NULL);
+ fixture->add_server_port(server, addr);
+ grpc_completion_queue *server_cq = grpc_completion_queue_create(NULL);
+ grpc_server_register_completion_queue(server, server_cq, NULL);
+ grpc_server_start(server);
+
+ server_thread_args sta = {server, server_cq};
+ gpr_thd_id server_thread;
+ gpr_thd_options thdopt = gpr_thd_options_default();
+ gpr_thd_options_set_joinable(&thdopt);
+ gpr_thd_new(&server_thread, server_thread_func, &sta, &thdopt);
+
+ grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
+ grpc_channel *channels[NUM_CONNECTIONS];
+ for (size_t i = 0; i < NUM_CONNECTIONS; i++) {
+ channels[i] = fixture->create_channel(addr);
+
+ gpr_timespec connect_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(30);
+ grpc_connectivity_state state;
+ while ((state = grpc_channel_check_connectivity_state(channels[i], 1)) !=
+ GRPC_CHANNEL_READY) {
+ grpc_channel_watch_connectivity_state(channels[i], state,
+ connect_deadline, cq, NULL);
+ grpc_event ev = grpc_completion_queue_next(
+ cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+ GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
+ GPR_ASSERT(ev.tag == NULL);
+ GPR_ASSERT(ev.success == true);
+ }
+ }
+
+ grpc_server_shutdown_and_notify(server, server_cq, NULL);
+ gpr_thd_join(server_thread);
+
+ grpc_completion_queue_shutdown(server_cq);
+ grpc_completion_queue_shutdown(cq);
+
+ while (grpc_completion_queue_next(server_cq,
+ gpr_inf_future(GPR_CLOCK_REALTIME), NULL)
+ .type != GRPC_QUEUE_SHUTDOWN)
+ ;
+ while (
+ grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL)
+ .type != GRPC_QUEUE_SHUTDOWN)
+ ;
+
+ for (size_t i = 0; i < NUM_CONNECTIONS; i++) {
+ grpc_channel_destroy(channels[i]);
+ }
+
+ grpc_server_destroy(server);
+ grpc_completion_queue_destroy(server_cq);
+ grpc_completion_queue_destroy(cq);
+
+ grpc_shutdown();
+ gpr_free(addr);
+}
+
+static void insecure_test_add_port(grpc_server *server, const char *addr) {
+ grpc_server_add_insecure_http2_port(server, addr);
+}
+
+static grpc_channel *insecure_test_create_channel(const char *addr) {
+ return grpc_insecure_channel_create(addr, NULL, NULL);
+}
+
+static const test_fixture insecure_test = {
+ "insecure", insecure_test_add_port, insecure_test_create_channel,
+};
+
+static void secure_test_add_port(grpc_server *server, const char *addr) {
+ grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key,
+ test_server1_cert};
+ grpc_server_credentials *ssl_creds =
+ grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
+ grpc_server_add_secure_http2_port(server, addr, ssl_creds);
+ grpc_server_credentials_release(ssl_creds);
+}
+
+static grpc_channel *secure_test_create_channel(const char *addr) {
+ grpc_channel_credentials *ssl_creds =
+ grpc_ssl_credentials_create(test_root_cert, NULL, NULL);
+ grpc_arg ssl_name_override = {GRPC_ARG_STRING,
+ GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
+ {"foo.test.google.fr"}};
+ grpc_channel_args *new_client_args =
+ grpc_channel_args_copy_and_add(NULL, &ssl_name_override, 1);
+ grpc_channel *channel =
+ grpc_secure_channel_create(ssl_creds, addr, new_client_args, NULL);
+ grpc_channel_args_destroy(new_client_args);
+ grpc_channel_credentials_release(ssl_creds);
+ return channel;
+}
+
+static const test_fixture secure_test = {
+ "secure", secure_test_add_port, secure_test_create_channel,
+};
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+
+ run_test(&insecure_test);
+ run_test(&secure_test);
+}
diff --git a/test/core/surface/server_chttp2_test.c b/test/core/surface/server_chttp2_test.c
index d22c164972..6310b6f00b 100644
--- a/test/core/surface/server_chttp2_test.c
+++ b/test/core/surface/server_chttp2_test.c
@@ -37,7 +37,8 @@
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
-#include "src/core/lib/security/credentials.h"
+#include "src/core/lib/security/credentials/credentials.h"
+#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "src/core/lib/tsi/fake_transport_security.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -48,10 +49,16 @@ void test_unparsable_target(void) {
}
void test_add_same_port_twice() {
+ grpc_arg a;
+ a.type = GRPC_ARG_INTEGER;
+ a.key = GRPC_ARG_ALLOW_REUSEPORT;
+ a.value.integer = 0;
+ grpc_channel_args args = {1, &a};
+
int port = grpc_pick_unused_port_or_die();
char *addr = NULL;
grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
- grpc_server *server = grpc_server_create(NULL, NULL);
+ grpc_server *server = grpc_server_create(&args, NULL);
grpc_server_credentials *fake_creds =
grpc_fake_transport_security_server_credentials_create();
gpr_join_host_port(&addr, "localhost", port);
diff --git a/test/core/surface/server_test.c b/test/core/surface/server_test.c
index 3d2e25379a..3fd1c2c266 100644
--- a/test/core/surface/server_test.c
+++ b/test/core/surface/server_test.c
@@ -32,9 +32,13 @@
*/
#include <grpc/grpc.h>
+#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
+#include "src/core/lib/iomgr/resolve_address.h"
+#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -67,25 +71,38 @@ void test_register_method_fail(void) {
void test_request_call_on_no_server_cq(void) {
grpc_completion_queue *cc = grpc_completion_queue_create(NULL);
+ grpc_server *server = grpc_server_create(NULL, NULL);
GPR_ASSERT(GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE ==
- grpc_server_request_call(NULL, NULL, NULL, NULL, cc, cc, NULL));
+ grpc_server_request_call(server, NULL, NULL, NULL, cc, cc, NULL));
GPR_ASSERT(GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE ==
- grpc_server_request_registered_call(NULL, NULL, NULL, NULL, NULL,
+ grpc_server_request_registered_call(server, NULL, NULL, NULL, NULL,
NULL, cc, cc, NULL));
grpc_completion_queue_destroy(cc);
+ grpc_server_destroy(server);
}
void test_bind_server_twice(void) {
+ grpc_arg a;
+ a.type = GRPC_ARG_INTEGER;
+ a.key = GRPC_ARG_ALLOW_REUSEPORT;
+ a.value.integer = 0;
+ grpc_channel_args args = {1, &a};
+
char *addr;
- grpc_server *server1 = grpc_server_create(NULL, NULL);
- grpc_server *server2 = grpc_server_create(NULL, NULL);
+ grpc_server *server1 = grpc_server_create(&args, NULL);
+ grpc_server *server2 = grpc_server_create(&args, NULL);
grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
int port = grpc_pick_unused_port_or_die();
gpr_asprintf(&addr, "[::]:%d", port);
grpc_server_register_completion_queue(server1, cq, NULL);
grpc_server_register_completion_queue(server2, cq, NULL);
+ GPR_ASSERT(0 == grpc_server_add_secure_http2_port(server2, addr, NULL));
GPR_ASSERT(port == grpc_server_add_insecure_http2_port(server1, addr));
GPR_ASSERT(0 == grpc_server_add_insecure_http2_port(server2, addr));
+ grpc_server_credentials *fake_creds =
+ grpc_fake_transport_security_server_credentials_create();
+ GPR_ASSERT(0 == grpc_server_add_secure_http2_port(server2, addr, fake_creds));
+ grpc_server_credentials_release(fake_creds);
grpc_server_shutdown_and_notify(server1, cq, NULL);
grpc_server_shutdown_and_notify(server2, cq, NULL);
grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL);
@@ -96,12 +113,68 @@ void test_bind_server_twice(void) {
gpr_free(addr);
}
+void test_bind_server_to_addr(const char *host, bool secure) {
+ int port = grpc_pick_unused_port_or_die();
+ char *addr;
+ gpr_join_host_port(&addr, host, port);
+ gpr_log(GPR_INFO, "Test bind to %s", addr);
+
+ grpc_server *server = grpc_server_create(NULL, NULL);
+ if (secure) {
+ grpc_server_credentials *fake_creds =
+ grpc_fake_transport_security_server_credentials_create();
+ GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, fake_creds));
+ grpc_server_credentials_release(fake_creds);
+ } else {
+ GPR_ASSERT(grpc_server_add_insecure_http2_port(server, addr));
+ }
+ grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
+ grpc_server_register_completion_queue(server, cq, NULL);
+ grpc_server_start(server);
+ grpc_server_shutdown_and_notify(server, cq, NULL);
+ grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL);
+ grpc_server_destroy(server);
+ grpc_completion_queue_destroy(cq);
+ gpr_free(addr);
+}
+
+static int external_dns_works(const char *host) {
+ grpc_resolved_addresses *res = NULL;
+ grpc_error *error = grpc_blocking_resolve_address(host, "80", &res);
+ GRPC_ERROR_UNREF(error);
+ if (res != NULL) {
+ grpc_resolved_addresses_destroy(res);
+ return 1;
+ }
+ return 0;
+}
+
+static void test_bind_server_to_addrs(const char **addrs, size_t n) {
+ for (size_t i = 0; i < n; i++) {
+ test_bind_server_to_addr(addrs[i], false);
+ test_bind_server_to_addr(addrs[i], true);
+ }
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_init();
test_register_method_fail();
test_request_call_on_no_server_cq();
test_bind_server_twice();
+
+ static const char *addrs[] = {
+ "::1", "127.0.0.1", "::ffff:127.0.0.1", "localhost", "0.0.0.0", "::",
+ };
+ test_bind_server_to_addrs(addrs, GPR_ARRAY_SIZE(addrs));
+
+ if (external_dns_works("loopback46.unittest.grpc.io")) {
+ static const char *dns_addrs[] = {
+ "loopback46.unittest.grpc.io", "loopback4.unittest.grpc.io",
+ };
+ test_bind_server_to_addrs(dns_addrs, GPR_ARRAY_SIZE(dns_addrs));
+ }
+
grpc_shutdown();
return 0;
}