blob: cf43ecfd2ded28eb40e81ac48313cb2e5c69cb6e [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
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
15 * distribution.
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.
19 *
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.
31 *
32 */
33
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080034#include <string.h>
Craig Tillerc21a8092015-05-15 10:03:40 -070035#include <stdio.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
37#include <grpc/support/alloc.h>
38#include <grpc/support/host_port.h>
Masood Malekghassemi701af602015-06-03 15:01:17 -070039#include <grpc/support/string_util.h>
40#include <grpc/support/subprocess.h>
Craig Tiller485d7762015-01-23 12:54:05 -080041#include "src/core/support/string.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080042#include "test/core/util/port.h"
43
44int main(int argc, char **argv) {
45 char *me = argv[0];
46 char *lslash = strrchr(me, '/');
47 char root[1024];
48 int port = grpc_pick_unused_port_or_die();
49 char *args[10];
50 int status;
Craig Tillerc21a8092015-05-15 10:03:40 -070051 gpr_subprocess *svr, *cli;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080052 /* figure out where we are */
53 if (lslash) {
Craig Tiller32ca48c2015-09-10 11:47:15 -070054 memcpy(root, me, (size_t)(lslash - me));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080055 root[lslash - me] = 0;
56 } else {
57 strcpy(root, ".");
58 }
59 /* start the server */
Craig Tillerd6c98df2015-08-18 09:33:44 -070060 gpr_asprintf(&args[0], "%s/fling_server%s", root,
61 gpr_subprocess_binary_extension());
Craig Tillerc21a8092015-05-15 10:03:40 -070062 args[1] = "--bind";
63 gpr_join_host_port(&args[2], "::", port);
64 args[3] = "--no-secure";
Craig Tillerd6c98df2015-08-18 09:33:44 -070065 svr = gpr_subprocess_create(4, (const char **)args);
Craig Tillerc21a8092015-05-15 10:03:40 -070066 gpr_free(args[0]);
67 gpr_free(args[2]);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080068
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080069 /* start the client */
Craig Tillerd6c98df2015-08-18 09:33:44 -070070 gpr_asprintf(&args[0], "%s/fling_client%s", root,
71 gpr_subprocess_binary_extension());
Craig Tillerc21a8092015-05-15 10:03:40 -070072 args[1] = "--target";
73 gpr_join_host_port(&args[2], "127.0.0.1", port);
74 args[3] = "--scenario=ping-pong-request";
75 args[4] = "--no-secure";
76 args[5] = 0;
Craig Tillerd6c98df2015-08-18 09:33:44 -070077 cli = gpr_subprocess_create(6, (const char **)args);
Craig Tillerc21a8092015-05-15 10:03:40 -070078 gpr_free(args[0]);
79 gpr_free(args[2]);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080080
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080081 /* wait for completion */
82 printf("waiting for client\n");
Craig Tillerc21a8092015-05-15 10:03:40 -070083 if ((status = gpr_subprocess_join(cli))) {
84 gpr_subprocess_destroy(cli);
85 gpr_subprocess_destroy(svr);
86 return status;
87 }
88 gpr_subprocess_destroy(cli);
89
90 gpr_subprocess_interrupt(svr);
91 status = gpr_subprocess_join(svr);
92 gpr_subprocess_destroy(svr);
93 return status;
Craig Tiller190d3602015-02-18 09:23:38 -080094}