LCOV - code coverage report
Current view: top level - test/core/fling - fling_test.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 30 34 88.2 %
Date: 2015-10-10 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       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             : 
      34             : #include <string.h>
      35             : #include <stdio.h>
      36             : 
      37             : #include <grpc/support/alloc.h>
      38             : #include <grpc/support/host_port.h>
      39             : #include <grpc/support/string_util.h>
      40             : #include <grpc/support/subprocess.h>
      41             : #include "src/core/support/string.h"
      42             : #include "test/core/util/port.h"
      43             : 
      44           1 : int main(int argc, char **argv) {
      45           1 :   char *me = argv[0];
      46           1 :   char *lslash = strrchr(me, '/');
      47             :   char root[1024];
      48           1 :   int port = grpc_pick_unused_port_or_die();
      49             :   char *args[10];
      50             :   int status;
      51             :   gpr_subprocess *svr, *cli;
      52             :   /* figure out where we are */
      53           1 :   if (lslash) {
      54           1 :     memcpy(root, me, (size_t)(lslash - me));
      55           1 :     root[lslash - me] = 0;
      56             :   } else {
      57           0 :     strcpy(root, ".");
      58             :   }
      59             :   /* start the server */
      60           1 :   gpr_asprintf(&args[0], "%s/fling_server%s", root,
      61             :                gpr_subprocess_binary_extension());
      62           1 :   args[1] = "--bind";
      63           1 :   gpr_join_host_port(&args[2], "::", port);
      64           1 :   args[3] = "--no-secure";
      65           1 :   svr = gpr_subprocess_create(4, (const char **)args);
      66           1 :   gpr_free(args[0]);
      67           1 :   gpr_free(args[2]);
      68             : 
      69             :   /* start the client */
      70           1 :   gpr_asprintf(&args[0], "%s/fling_client%s", root,
      71             :                gpr_subprocess_binary_extension());
      72           1 :   args[1] = "--target";
      73           1 :   gpr_join_host_port(&args[2], "127.0.0.1", port);
      74           1 :   args[3] = "--scenario=ping-pong-request";
      75           1 :   args[4] = "--no-secure";
      76           1 :   args[5] = 0;
      77           1 :   cli = gpr_subprocess_create(6, (const char **)args);
      78           1 :   gpr_free(args[0]);
      79           1 :   gpr_free(args[2]);
      80             : 
      81             :   /* wait for completion */
      82           1 :   printf("waiting for client\n");
      83           1 :   if ((status = gpr_subprocess_join(cli))) {
      84           0 :     gpr_subprocess_destroy(cli);
      85           0 :     gpr_subprocess_destroy(svr);
      86           0 :     return status;
      87             :   }
      88           1 :   gpr_subprocess_destroy(cli);
      89             : 
      90           1 :   gpr_subprocess_interrupt(svr);
      91           1 :   status = gpr_subprocess_join(svr);
      92           1 :   gpr_subprocess_destroy(svr);
      93           1 :   return status;
      94             : }

Generated by: LCOV version 1.10