aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/bad_ssl/server_common.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-10-23 15:33:21 -0700
committerGravatar Yash Tibrewal <yashkt@google.com>2017-10-25 16:23:01 -0700
commit34a57d0346afe95e11104462c30dc468b0cb0b89 (patch)
tree67db15f7b8b361e0618199dc55215f3b4d626201 /test/core/bad_ssl/server_common.cc
parentc563b583cb9b7fecc33971581368796d2df4759d (diff)
rename all test core files to cc and a lot of C++ style conversions
Diffstat (limited to 'test/core/bad_ssl/server_common.cc')
-rw-r--r--test/core/bad_ssl/server_common.cc103
1 files changed, 103 insertions, 0 deletions
diff --git a/test/core/bad_ssl/server_common.cc b/test/core/bad_ssl/server_common.cc
new file mode 100644
index 0000000000..5def618257
--- /dev/null
+++ b/test/core/bad_ssl/server_common.cc
@@ -0,0 +1,103 @@
+/*
+ *
+ * Copyright 2015 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <grpc/support/cmdline.h>
+#include <grpc/support/log.h>
+#include <signal.h>
+
+#include "test/core/bad_ssl/server_common.h"
+#include "test/core/util/test_config.h"
+
+/* Common server implementation details for all servers in servers/.
+ * There's nothing *wrong* with these servers per-se, but they are
+ * configured to cause some failure case in the SSL connection path.
+ */
+
+static int got_sigint = 0;
+
+static void sigint_handler(int x) { got_sigint = 1; }
+
+const char *bad_ssl_addr(int argc, char **argv) {
+ gpr_cmdline *cl;
+ const char *addr = NULL;
+ cl = gpr_cmdline_create("test server");
+ gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr);
+ gpr_cmdline_parse(cl, argc, argv);
+ gpr_cmdline_destroy(cl);
+ GPR_ASSERT(addr);
+ return addr;
+}
+
+void bad_ssl_run(grpc_server *server) {
+ int shutdown_started = 0;
+ int shutdown_finished = 0;
+ grpc_event ev;
+ grpc_call_error error;
+ grpc_call *s = NULL;
+ grpc_call_details call_details;
+ grpc_metadata_array request_metadata_recv;
+
+ grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
+ grpc_completion_queue *shutdown_cq;
+
+ grpc_call_details_init(&call_details);
+ grpc_metadata_array_init(&request_metadata_recv);
+
+ grpc_server_register_completion_queue(server, cq, NULL);
+ grpc_server_start(server);
+
+ error = grpc_server_request_call(server, &s, &call_details,
+ &request_metadata_recv, cq, cq, (void *)1);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ signal(SIGINT, sigint_handler);
+ while (!shutdown_finished) {
+ if (got_sigint && !shutdown_started) {
+ gpr_log(GPR_INFO, "Shutting down due to SIGINT");
+ shutdown_cq = grpc_completion_queue_create_for_pluck(NULL);
+ grpc_server_shutdown_and_notify(server, shutdown_cq, NULL);
+ GPR_ASSERT(
+ grpc_completion_queue_pluck(shutdown_cq, NULL,
+ grpc_timeout_seconds_to_deadline(5), NULL)
+ .type == GRPC_OP_COMPLETE);
+ grpc_completion_queue_destroy(shutdown_cq);
+ grpc_completion_queue_shutdown(cq);
+ shutdown_started = 1;
+ }
+ ev = grpc_completion_queue_next(
+ cq, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_micros(1000000, GPR_TIMESPAN)),
+ NULL);
+ switch (ev.type) {
+ case GRPC_OP_COMPLETE:
+ GPR_ASSERT(ev.tag == (void *)1);
+ GPR_ASSERT(ev.success == 0);
+ break;
+ case GRPC_QUEUE_SHUTDOWN:
+ GPR_ASSERT(shutdown_started);
+ shutdown_finished = 1;
+ break;
+ case GRPC_QUEUE_TIMEOUT:
+ break;
+ }
+ }
+
+ GPR_ASSERT(s == NULL);
+ grpc_call_details_destroy(&call_details);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+}