• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
23 
24 #include "absl/strings/str_cat.h"
25 
26 #include <grpc/support/alloc.h>
27 
28 #include "src/core/lib/gprpp/host_port.h"
29 #include "test/core/util/port.h"
30 #include "test/core/util/subprocess.h"
31 
main(int,const char ** argv)32 int main(int /*argc*/, const char** argv) {
33   const char* me = argv[0];
34   const char* lslash = strrchr(me, '/');
35   char root[1024];
36   int port = grpc_pick_unused_port_or_die();
37   char* args[10];
38   int status;
39   gpr_subprocess *svr, *cli;
40   /* figure out where we are */
41   if (lslash) {
42     memcpy(root, me, static_cast<size_t>(lslash - me));
43     root[lslash - me] = 0;
44   } else {
45     strcpy(root, ".");
46   }
47   /* start the server */
48   std::string command =
49       absl::StrCat(root, "/fling_server", gpr_subprocess_binary_extension());
50   args[0] = const_cast<char*>(command.c_str());
51   args[1] = const_cast<char*>("--bind");
52   std::string joined = grpc_core::JoinHostPort("::", port);
53   args[2] = const_cast<char*>(joined.c_str());
54   args[3] = const_cast<char*>("--no-secure");
55   svr = gpr_subprocess_create(4, (const char**)args);
56 
57   /* start the client */
58   command =
59       absl::StrCat(root, "/fling_client", gpr_subprocess_binary_extension());
60   args[0] = const_cast<char*>(command.c_str());
61   args[1] = const_cast<char*>("--target");
62   joined = grpc_core::JoinHostPort("127.0.0.1", port);
63   args[2] = const_cast<char*>(joined.c_str());
64   args[3] = const_cast<char*>("--scenario=ping-pong-request");
65   args[4] = const_cast<char*>("--no-secure");
66   args[5] = nullptr;
67   cli = gpr_subprocess_create(6, (const char**)args);
68 
69   /* wait for completion */
70   printf("waiting for client\n");
71   if ((status = gpr_subprocess_join(cli))) {
72     gpr_subprocess_destroy(cli);
73     gpr_subprocess_destroy(svr);
74     return status;
75   }
76   gpr_subprocess_destroy(cli);
77 
78   gpr_subprocess_interrupt(svr);
79   status = gpr_subprocess_join(svr);
80   gpr_subprocess_destroy(svr);
81   return status;
82 }
83