From 0ced984233c06d20b76974ad2303534df596dcad Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 29 Apr 2015 15:02:07 -0700 Subject: Kill echo test --- test/core/echo/client.c | 138 ---------------------------- test/core/echo/echo_test.c | 135 --------------------------- test/core/echo/server.c | 223 --------------------------------------------- 3 files changed, 496 deletions(-) delete mode 100644 test/core/echo/client.c delete mode 100644 test/core/echo/echo_test.c delete mode 100644 test/core/echo/server.c (limited to 'test/core') diff --git a/test/core/echo/client.c b/test/core/echo/client.c deleted file mode 100644 index f2b69ec320..0000000000 --- a/test/core/echo/client.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * - * Copyright 2015, 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 - -#include - -#include -#include -#include -#include "test/core/util/test_config.h" - -enum { WRITE_SLICE_LENGTH = 1024, TOTAL_BYTES = 102400 }; - -/* Start write the next slice, fill slice.data[0..length - 1] with first % 256, - (first + 1) % 256, ... (first + length - 1) % 256. - Produce a GRPC_WRITE_ACCEPTED event */ -static void start_write_next_slice(grpc_call *call, int first, int length) { - int i = 0; - grpc_byte_buffer *byte_buffer = NULL; - gpr_slice slice = gpr_slice_malloc(length); - for (i = 0; i < length; i++) - GPR_SLICE_START_PTR(slice)[i] = (first + i) % 256; - byte_buffer = grpc_byte_buffer_create(&slice, 1); - GPR_ASSERT(grpc_call_start_write_old(call, byte_buffer, (void *)1, 0) == - GRPC_CALL_OK); - gpr_slice_unref(slice); - grpc_byte_buffer_destroy(byte_buffer); -} - -int main(int argc, char **argv) { - grpc_channel *channel = NULL; - grpc_call *call = NULL; - grpc_event *ev = NULL; - grpc_byte_buffer_reader *bb_reader = NULL; - grpc_completion_queue *cq = NULL; - int bytes_written = 0; - int bytes_read = 0; - unsigned i = 0; - int waiting_finishes; - gpr_slice read_slice; - - grpc_test_init(argc, argv); - - grpc_init(); - - cq = grpc_completion_queue_create(); - - GPR_ASSERT(argc == 2); - channel = grpc_channel_create(argv[1], NULL); - call = grpc_channel_create_call_old(channel, "/foo", "localhost", - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)); - GPR_ASSERT(grpc_call_invoke_old(call, cq, (void *)1, (void *)1, 0) == - GRPC_CALL_OK); - - start_write_next_slice(call, bytes_written, WRITE_SLICE_LENGTH); - bytes_written += WRITE_SLICE_LENGTH; - GPR_ASSERT(grpc_call_start_read_old(call, (void *)1) == GRPC_CALL_OK); - waiting_finishes = 2; - while (waiting_finishes) { - ev = grpc_completion_queue_next(cq, gpr_inf_future); - switch (ev->type) { - case GRPC_WRITE_ACCEPTED: - if (bytes_written < TOTAL_BYTES) { - start_write_next_slice(call, bytes_written, WRITE_SLICE_LENGTH); - bytes_written += WRITE_SLICE_LENGTH; - } else { - GPR_ASSERT(grpc_call_writes_done_old(call, (void *)1) == - GRPC_CALL_OK); - } - break; - case GRPC_CLIENT_METADATA_READ: - break; - case GRPC_READ: - bb_reader = grpc_byte_buffer_reader_create(ev->data.read); - while (grpc_byte_buffer_reader_next(bb_reader, &read_slice)) { - for (i = 0; i < GPR_SLICE_LENGTH(read_slice); i++) { - GPR_ASSERT(GPR_SLICE_START_PTR(read_slice)[i] == bytes_read % 256); - bytes_read++; - } - gpr_slice_unref(read_slice); - } - grpc_byte_buffer_reader_destroy(bb_reader); - if (bytes_read < TOTAL_BYTES) { - GPR_ASSERT(grpc_call_start_read_old(call, (void *)1) == GRPC_CALL_OK); - } - break; - case GRPC_FINISHED: - case GRPC_FINISH_ACCEPTED: - waiting_finishes--; - break; - default: - GPR_ASSERT(0 && "unexpected event"); - break; - } - grpc_event_finish(ev); - } - GPR_ASSERT(bytes_read == TOTAL_BYTES); - gpr_log(GPR_INFO, "All data have been successfully echoed"); - - grpc_call_destroy(call); - grpc_channel_destroy(channel); - grpc_completion_queue_destroy(cq); - - grpc_shutdown(); - - return 0; -} diff --git a/test/core/echo/echo_test.c b/test/core/echo/echo_test.c deleted file mode 100644 index e2c4d22ef5..0000000000 --- a/test/core/echo/echo_test.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * - * Copyright 2015, 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 _POSIX_SOURCE -#define _POSIX_SOURCE -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "src/core/iomgr/socket_utils_posix.h" -#include "src/core/support/string.h" -#include -#include -#include -#include "test/core/util/port.h" - -int test_client(const char *root, const char *host, int port) { - int status; - pid_t cli; - cli = fork(); - if (cli == 0) { - char *binary_path; - char *binding; - gpr_asprintf(&binary_path, "%s/echo_client", root); - gpr_join_host_port(&binding, host, port); - - execl(binary_path, binary_path, binding, NULL); - - gpr_free(binary_path); - gpr_free(binding); - return 1; - } - /* wait for client */ - gpr_log(GPR_INFO, "Waiting for client: %s", host); - if (waitpid(cli, &status, 0) == -1) return 2; - if (!WIFEXITED(status)) return 4; - if (WEXITSTATUS(status)) return WEXITSTATUS(status); - return 0; -} - -int main(int argc, char **argv) { - char *me = argv[0]; - char *lslash = strrchr(me, '/'); - char root[1024]; - int port = grpc_pick_unused_port_or_die(); - int status; - pid_t svr; - int ret; - int do_ipv6 = 1; - /* seed rng with pid, so we don't end up with the same random numbers as a - concurrently running test binary */ - srand(getpid()); - if (!grpc_ipv6_loopback_available()) { - gpr_log(GPR_INFO, "Can't bind to ::1. Skipping IPv6 tests."); - do_ipv6 = 0; - } - /* figure out where we are */ - if (lslash) { - memcpy(root, me, lslash - me); - root[lslash - me] = 0; - } else { - strcpy(root, "."); - } - /* start the server */ - svr = fork(); - if (svr == 0) { - char *binary_path; - char *binding; - gpr_asprintf(&binary_path, "%s/echo_server", root); - gpr_join_host_port(&binding, "::", port); - - execl(binary_path, binary_path, "-bind", binding, NULL); - - gpr_free(binary_path); - gpr_free(binding); - return 1; - } - /* wait a little */ - sleep(2); - /* start the clients */ - ret = test_client(root, "127.0.0.1", port); - if (ret != 0) return ret; - ret = test_client(root, "::ffff:127.0.0.1", port); - if (ret != 0) return ret; - ret = test_client(root, "localhost", port); - if (ret != 0) return ret; - if (do_ipv6) { - ret = test_client(root, "::1", port); - if (ret != 0) return ret; - } - /* wait for server */ - gpr_log(GPR_INFO, "Waiting for server"); - kill(svr, SIGINT); - if (waitpid(svr, &status, 0) == -1) return 2; - if (!WIFEXITED(status)) return 4; - if (WEXITSTATUS(status)) return WEXITSTATUS(status); - return 0; -} diff --git a/test/core/echo/server.c b/test/core/echo/server.c deleted file mode 100644 index e888a0c877..0000000000 --- a/test/core/echo/server.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * - * Copyright 2015, 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 -#include -#include - -#include -#include -#include -#include -#include - -#include "src/core/support/string.h" -#include "test/core/util/test_config.h" -#include -#include -#include -#include -#include -#include "test/core/util/port.h" -#include "test/core/end2end/data/ssl_test_data.h" - -static grpc_completion_queue *cq; -static grpc_server *server; -static int got_sigint = 0; - -typedef struct { - gpr_refcount pending_ops; - gpr_intmax bytes_read; -} call_state; - -static void request_call(void) { - call_state *tag = gpr_malloc(sizeof(*tag)); - gpr_ref_init(&tag->pending_ops, 2); - tag->bytes_read = 0; - grpc_server_request_call_old(server, tag); -} - -static void assert_read_ok(call_state *s, grpc_byte_buffer *b) { - grpc_byte_buffer_reader *bb_reader = NULL; - gpr_slice read_slice; - unsigned i; - - bb_reader = grpc_byte_buffer_reader_create(b); - while (grpc_byte_buffer_reader_next(bb_reader, &read_slice)) { - for (i = 0; i < GPR_SLICE_LENGTH(read_slice); i++) { - GPR_ASSERT(GPR_SLICE_START_PTR(read_slice)[i] == s->bytes_read % 256); - s->bytes_read++; - } - gpr_slice_unref(read_slice); - } - grpc_byte_buffer_reader_destroy(bb_reader); -} - -static void sigint_handler(int x) { got_sigint = 1; } - -int main(int argc, char **argv) { - grpc_event *ev; - call_state *s; - char *addr_buf = NULL; - gpr_cmdline *cl; - int shutdown_started = 0; - int shutdown_finished = 0; - - 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", - "\n" - "Echo Server\n" - "\n" - "\n" - "Welcome to the world of the future!\n" - "\n"}; - - GPR_ASSERT(argc >= 1); - fake_argv[0] = argv[0]; - grpc_test_init(1, fake_argv); - - grpc_init(); - srand(clock()); - 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(); - 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_server_create(cq, &args); - GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, ssl_creds)); - 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); - while (!shutdown_finished) { - if (got_sigint && !shutdown_started) { - gpr_log(GPR_INFO, "Shutting down due to SIGINT"); - grpc_server_shutdown(server); - grpc_completion_queue_shutdown(cq); - shutdown_started = 1; - } - ev = grpc_completion_queue_next( - cq, gpr_time_add(gpr_now(), gpr_time_from_seconds(1))); - if (!ev) continue; - s = ev->tag; - switch (ev->type) { - case GRPC_SERVER_RPC_NEW: - if (ev->call != NULL) { - /* initial ops are already started in request_call */ - grpc_call_server_accept_old(ev->call, cq, s); - grpc_call_server_end_initial_metadata_old(ev->call, - GRPC_WRITE_BUFFER_HINT); - GPR_ASSERT(grpc_call_start_read_old(ev->call, s) == GRPC_CALL_OK); - request_call(); - } else { - GPR_ASSERT(shutdown_started); - gpr_free(s); - } - break; - case GRPC_WRITE_ACCEPTED: - GPR_ASSERT(ev->data.write_accepted == GRPC_OP_OK); - GPR_ASSERT(grpc_call_start_read_old(ev->call, s) == GRPC_CALL_OK); - break; - case GRPC_READ: - if (ev->data.read) { - assert_read_ok(ev->tag, ev->data.read); - GPR_ASSERT(grpc_call_start_write_old(ev->call, ev->data.read, s, - GRPC_WRITE_BUFFER_HINT) == - GRPC_CALL_OK); - } else { - GPR_ASSERT(grpc_call_start_write_status_old(ev->call, GRPC_STATUS_OK, - NULL, s) == GRPC_CALL_OK); - } - break; - case GRPC_FINISH_ACCEPTED: - case GRPC_FINISHED: - if (gpr_unref(&s->pending_ops)) { - grpc_call_destroy(ev->call); - gpr_free(s); - } - break; - case GRPC_QUEUE_SHUTDOWN: - GPR_ASSERT(shutdown_started); - shutdown_finished = 1; - break; - default: - GPR_ASSERT(0); - } - grpc_event_finish(ev); - } - - grpc_server_destroy(server); - grpc_completion_queue_destroy(cq); - grpc_shutdown(); - - return 0; -} -- cgit v1.2.3