3
* Copyright 2015, Google Inc.
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are
10
* * Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* * Redistributions in binary form must reproduce the above
13
* copyright notice, this list of conditions and the following disclaimer
14
* in the documentation and/or other materials provided with the
16
* * Neither the name of Google Inc. nor the names of its
17
* contributors may be used to endorse or promote products derived from
18
* this software without specific prior written permission.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
#include <sys/types.h>
48
#include "src/core/iomgr/socket_utils_posix.h"
49
#include "src/core/support/string.h"
52
#include <grpc/support/alloc.h>
53
#include <grpc/support/host_port.h>
54
#include <grpc/support/log.h>
55
#include <grpc/support/string_util.h>
56
#include "test/core/util/port.h"
58
int test_client(const char* root, const char* host, int port) {
65
gpr_asprintf(&binary_path, "%s/interop_client", root);
66
gpr_asprintf(&port_arg, "--server_port=%d", port);
68
execl(binary_path, binary_path, port_arg, NULL);
70
gpr_free(binary_path);
75
gpr_log(GPR_INFO, "Waiting for client: %s", host);
76
if (waitpid(cli, &status, 0) == -1) return 2;
77
if (!WIFEXITED(status)) return 4;
78
if (WEXITSTATUS(status)) return WEXITSTATUS(status);
82
int main(int argc, char** argv) {
84
char* lslash = strrchr(me, '/');
86
int port = grpc_pick_unused_port_or_die();
91
/* seed rng with pid, so we don't end up with the same random numbers as a
92
concurrently running test binary */
94
if (!grpc_ipv6_loopback_available()) {
95
gpr_log(GPR_INFO, "Can't bind to ::1. Skipping IPv6 tests.");
98
/* figure out where we are */
100
memcpy(root, me, lslash - me);
101
root[lslash - me] = 0;
105
/* start the server */
110
gpr_asprintf(&binary_path, "%s/interop_server", root);
111
gpr_asprintf(&port_arg, "--port=%d", port);
113
execl(binary_path, binary_path, port_arg, NULL);
115
gpr_free(binary_path);
121
/* start the clients */
122
ret = test_client(root, "127.0.0.1", port);
123
if (ret != 0) return ret;
124
ret = test_client(root, "::ffff:127.0.0.1", port);
125
if (ret != 0) return ret;
126
ret = test_client(root, "localhost", port);
127
if (ret != 0) return ret;
129
ret = test_client(root, "::1", port);
130
if (ret != 0) return ret;
132
/* wait for server */
133
gpr_log(GPR_INFO, "Waiting for server");
135
if (waitpid(svr, &status, 0) == -1) return 2;
136
if (!WIFEXITED(status)) return 4;
137
if (WEXITSTATUS(status)) return WEXITSTATUS(status);