fling_stream_test.cc 2.4 KB

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