aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
Diffstat (limited to 'test/core')
-rw-r--r--test/core/echo/server.c69
1 files changed, 59 insertions, 10 deletions
diff --git a/test/core/echo/server.c b/test/core/echo/server.c
index 57b083779c..6b67334248 100644
--- a/test/core/echo/server.c
+++ b/test/core/echo/server.c
@@ -32,6 +32,8 @@
*/
#include <grpc/grpc.h>
+#include <grpc/grpc_http.h>
+#include <grpc/grpc_security.h>
#include <signal.h>
#include <stdio.h>
@@ -42,10 +44,12 @@
#include "src/core/support/string.h"
#include "test/core/util/test_config.h"
#include <grpc/support/alloc.h>
+#include <grpc/support/cmdline.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "test/core/util/port.h"
+#include "test/core/end2end/data/ssl_test_data.h"
static grpc_completion_queue *cq;
static grpc_server *server;
@@ -83,29 +87,74 @@ static void sigint_handler(int x) { got_sigint = 1; }
int main(int argc, char **argv) {
grpc_event *ev;
- char *addr;
call_state *s;
+ char *addr_buf = NULL;
+ gpr_cmdline *cl;
int shutdown_started = 0;
int shutdown_finished = 0;
- grpc_test_init(argc, argv);
+ int secure = 0;
+ char *addr = NULL;
+
+ char *fake_argv[1];
+
+#define MAX_ARGS 4
+ grpc_arg arge[MAX_ARGS];
+ grpc_arg *e;
+ grpc_channel_args args = {0, NULL};
+
+ grpc_http_server_page home_page = {"/", "text/html",
+ "<head>\n"
+ "<title>Echo Server</title>\n"
+ "</head>\n"
+ "<body>\n"
+ "Welcome to the world of the future!\n"
+ "</body>\n"};
+
+ GPR_ASSERT(argc >= 1);
+ fake_argv[0] = argv[0];
+ grpc_test_init(1, fake_argv);
grpc_init();
srand(clock());
-
- if (argc == 2) {
- addr = gpr_strdup(argv[1]);
- } else {
- gpr_join_host_port(&addr, "::", grpc_pick_unused_port_or_die());
+ memset(arge, 0, sizeof(arge));
+ args.args = arge;
+
+ cl = gpr_cmdline_create("echo server");
+ gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr);
+ gpr_cmdline_add_flag(cl, "secure", "Run with security?", &secure);
+ gpr_cmdline_parse(cl, argc, argv);
+ gpr_cmdline_destroy(cl);
+
+ e = &arge[args.num_args++];
+ e->type = GRPC_ARG_POINTER;
+ e->key = GRPC_ARG_SERVE_OVER_HTTP;
+ e->value.pointer.p = &home_page;
+
+ if (addr == NULL) {
+ gpr_join_host_port(&addr_buf, "::", grpc_pick_unused_port_or_die());
+ addr = addr_buf;
}
gpr_log(GPR_INFO, "creating server on: %s", addr);
cq = grpc_completion_queue_create();
- server = grpc_server_create(cq, NULL);
- GPR_ASSERT(grpc_server_add_http2_port(server, addr));
- gpr_free(addr);
+ if (secure) {
+ grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {test_server1_key,
+ test_server1_cert};
+ grpc_server_credentials *ssl_creds =
+ grpc_ssl_server_credentials_create(NULL, &pem_key_cert_pair, 1);
+ server = grpc_secure_server_create(ssl_creds, cq, &args);
+ GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr));
+ grpc_server_credentials_release(ssl_creds);
+ } else {
+ server = grpc_server_create(cq, &args);
+ GPR_ASSERT(grpc_server_add_http2_port(server, addr));
+ }
grpc_server_start(server);
+ gpr_free(addr_buf);
+ addr = addr_buf = NULL;
+
request_call();
signal(SIGINT, sigint_handler);