1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <stdio.h>
20 #include <string.h>
21
22 #include <grpc/support/alloc.h>
23 #include <grpc/support/string_util.h>
24
25 #include "src/core/lib/gpr/host_port.h"
26 #include "src/core/lib/gpr/string.h"
27 #include "test/core/util/port.h"
28 #include "test/core/util/subprocess.h"
29
main(int argc,char ** argv)30 int main(int argc, char** argv) {
31 char* me = argv[0];
32 char* lslash = strrchr(me, '/');
33 char root[1024];
34 int port = grpc_pick_unused_port_or_die();
35 char* args[10];
36 int status;
37 gpr_subprocess *svr, *cli;
38 /* figure out where we are */
39 if (lslash) {
40 memcpy(root, me, static_cast<size_t>(lslash - me));
41 root[lslash - me] = 0;
42 } else {
43 strcpy(root, ".");
44 }
45 /* start the server */
46 gpr_asprintf(&args[0], "%s/fling_server%s", root,
47 gpr_subprocess_binary_extension());
48 args[1] = const_cast<char*>("--bind");
49 gpr_join_host_port(&args[2], "::", port);
50 args[3] = const_cast<char*>("--no-secure");
51 svr = gpr_subprocess_create(4, (const char**)args);
52 gpr_free(args[0]);
53 gpr_free(args[2]);
54
55 /* start the client */
56 gpr_asprintf(&args[0], "%s/fling_client%s", root,
57 gpr_subprocess_binary_extension());
58 args[1] = const_cast<char*>("--target");
59 gpr_join_host_port(&args[2], "127.0.0.1", port);
60 args[3] = const_cast<char*>("--scenario=ping-pong-stream");
61 args[4] = const_cast<char*>("--no-secure");
62 args[5] = nullptr;
63 cli = gpr_subprocess_create(6, (const char**)args);
64 gpr_free(args[0]);
65 gpr_free(args[2]);
66
67 /* wait for completion */
68 printf("waiting for client\n");
69 if ((status = gpr_subprocess_join(cli))) {
70 gpr_subprocess_destroy(cli);
71 gpr_subprocess_destroy(svr);
72 return status;
73 }
74 gpr_subprocess_destroy(cli);
75
76 gpr_subprocess_interrupt(svr);
77 status = gpr_subprocess_join(svr);
78 gpr_subprocess_destroy(svr);
79 return status;
80 }
81