diff options
author | pmarks <pmarks@google.com> | 2014-12-10 18:09:25 -0800 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2014-12-11 15:11:44 -0800 |
commit | 465554e5b6672998aecbd9bee12e831b613e185e (patch) | |
tree | 462d47ba5ff8acd1015b3d9e4d109be9c8143547 /test/core/echo | |
parent | c9e80fb26a0b9325f06da3e5827db17c85dc2efe (diff) |
Add a grpc_ipv6_loopback_available() test utility, and only run IPv6-specific
tests on machines that support AF_INET6 sockets bound to ::1.
Listening on :: or connecting to a mapped address should always work.
Change on 2014/12/10 by pmarks <pmarks@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81837056
Diffstat (limited to 'test/core/echo')
-rw-r--r-- | test/core/echo/echo_test.c | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/test/core/echo/echo_test.c b/test/core/echo/echo_test.c index bbce9da846..cc265cadbf 100644 --- a/test/core/echo/echo_test.c +++ b/test/core/echo/echo_test.c @@ -42,12 +42,33 @@ #include <grpc/support/alloc.h> #include <grpc/support/host_port.h> +#include <grpc/support/log.h> #include <grpc/support/string.h> +#include "test/core/util/ipv6.h" #include "test/core/util/port.h" -static const char *const kHosts[] = { - "127.0.0.1", "::1", "::ffff:127.0.0.1", "localhost", -}; +int test_client(const char *root, const char *host, int port) { + char *args[3]; + int status; + pid_t cli; + cli = fork(); + if (cli == 0) { + gpr_asprintf(&args[0], "%s/echo_client", root); + gpr_join_host_port(&args[1], host, port); + args[2] = 0; + execv(args[0], args); + + gpr_free(args[0]); + gpr_free(args[1]); + 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]; @@ -56,8 +77,13 @@ int main(int argc, char **argv) { int port = grpc_pick_unused_port_or_die(); char *args[3]; int status; - pid_t svr, cli; - int i; + pid_t svr; + int ret; + int do_ipv6 = 1; + 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); @@ -80,26 +106,18 @@ int main(int argc, char **argv) { /* wait a little */ sleep(2); /* start the clients */ - for (i = 0; i < sizeof(kHosts) / sizeof(*kHosts); i++) { - cli = fork(); - if (cli == 0) { - gpr_asprintf(&args[0], "%s/echo_client", root); - gpr_join_host_port(&args[1], kHosts[i], port); - args[2] = 0; - execv(args[0], args); - - gpr_free(args[0]); - gpr_free(args[1]); - return 1; - } - /* wait for client */ - printf("waiting for client: %s\n", kHosts[i]); - if (waitpid(cli, &status, 0) == -1) return 2; - if (!WIFEXITED(status)) return 4; - if (WEXITSTATUS(status)) return WEXITSTATUS(status); + 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 */ - printf("waiting for server\n"); + gpr_log(GPR_INFO, "Waiting for server"); kill(svr, SIGINT); if (waitpid(svr, &status, 0) == -1) return 2; if (!WIFEXITED(status)) return 4; |