Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * 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 Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 34 | #include <string.h> |
Craig Tiller | c21a809 | 2015-05-15 10:03:40 -0700 | [diff] [blame] | 35 | #include <stdio.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
| 37 | #include <grpc/support/alloc.h> |
| 38 | #include <grpc/support/host_port.h> |
Masood Malekghassemi | 701af60 | 2015-06-03 15:01:17 -0700 | [diff] [blame] | 39 | #include <grpc/support/string_util.h> |
| 40 | #include <grpc/support/subprocess.h> |
Craig Tiller | 485d776 | 2015-01-23 12:54:05 -0800 | [diff] [blame] | 41 | #include "src/core/support/string.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 42 | #include "test/core/util/port.h" |
| 43 | |
| 44 | int 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 Tiller | c21a809 | 2015-05-15 10:03:40 -0700 | [diff] [blame] | 51 | gpr_subprocess *svr, *cli; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 52 | /* figure out where we are */ |
| 53 | if (lslash) { |
Craig Tiller | 32ca48c | 2015-09-10 11:47:15 -0700 | [diff] [blame] | 54 | memcpy(root, me, (size_t)(lslash - me)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 55 | root[lslash - me] = 0; |
| 56 | } else { |
| 57 | strcpy(root, "."); |
| 58 | } |
| 59 | /* start the server */ |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 60 | gpr_asprintf(&args[0], "%s/fling_server%s", root, |
| 61 | gpr_subprocess_binary_extension()); |
Craig Tiller | c21a809 | 2015-05-15 10:03:40 -0700 | [diff] [blame] | 62 | args[1] = "--bind"; |
| 63 | gpr_join_host_port(&args[2], "::", port); |
| 64 | args[3] = "--no-secure"; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 65 | svr = gpr_subprocess_create(4, (const char **)args); |
Craig Tiller | c21a809 | 2015-05-15 10:03:40 -0700 | [diff] [blame] | 66 | gpr_free(args[0]); |
| 67 | gpr_free(args[2]); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 68 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 69 | /* start the client */ |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 70 | gpr_asprintf(&args[0], "%s/fling_client%s", root, |
| 71 | gpr_subprocess_binary_extension()); |
Craig Tiller | c21a809 | 2015-05-15 10:03:40 -0700 | [diff] [blame] | 72 | 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 Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 77 | cli = gpr_subprocess_create(6, (const char **)args); |
Craig Tiller | c21a809 | 2015-05-15 10:03:40 -0700 | [diff] [blame] | 78 | gpr_free(args[0]); |
| 79 | gpr_free(args[2]); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 80 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 81 | /* wait for completion */ |
| 82 | printf("waiting for client\n"); |
Craig Tiller | c21a809 | 2015-05-15 10:03:40 -0700 | [diff] [blame] | 83 | 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 Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 94 | } |