LCOV - code coverage report
Current view: top level - test/core/fling - fling_stream_test.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 23 43 53.5 %
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             : #ifndef _POSIX_SOURCE
      35             : #define _POSIX_SOURCE
      36             : #endif
      37             : 
      38             : #include <unistd.h>
      39             : #include <assert.h>
      40             : #include <stdio.h>
      41             : #include <string.h>
      42             : #include <signal.h>
      43             : #include <stdlib.h>
      44             : #include <sys/types.h>
      45             : #include <sys/wait.h>
      46             : 
      47             : #include "src/core/support/string.h"
      48             : #include <grpc/support/alloc.h>
      49             : #include <grpc/support/host_port.h>
      50             : #include <grpc/support/string_util.h>
      51             : #include "test/core/util/port.h"
      52             : 
      53           1 : int main(int argc, char **argv) {
      54           1 :   char *me = argv[0];
      55           1 :   char *lslash = strrchr(me, '/');
      56             :   char root[1024];
      57           1 :   int port = grpc_pick_unused_port_or_die();
      58             :   char *args[10];
      59             :   int status;
      60             :   pid_t svr, cli;
      61             :   /* seed rng with pid, so we don't end up with the same random numbers as a
      62             :      concurrently running test binary */
      63           1 :   srand((unsigned)getpid());
      64             :   /* figure out where we are */
      65           1 :   if (lslash) {
      66           1 :     memcpy(root, me, (size_t)(lslash - me));
      67           1 :     root[lslash - me] = 0;
      68             :   } else {
      69           0 :     strcpy(root, ".");
      70             :   }
      71             :   /* start the server */
      72           1 :   svr = fork();
      73           1 :   if (svr == 0) {
      74           0 :     gpr_asprintf(&args[0], "%s/fling_server", root);
      75           0 :     args[1] = "--bind";
      76           0 :     gpr_join_host_port(&args[2], "::", port);
      77           0 :     args[3] = "--no-secure";
      78           0 :     args[4] = 0;
      79           0 :     execv(args[0], args);
      80             : 
      81           0 :     gpr_free(args[0]);
      82           0 :     gpr_free(args[2]);
      83           0 :     return 1;
      84             :   }
      85             :   /* wait a little */
      86           1 :   sleep(2);
      87             :   /* start the client */
      88           1 :   cli = fork();
      89           1 :   if (cli == 0) {
      90           0 :     gpr_asprintf(&args[0], "%s/fling_client", root);
      91           0 :     args[1] = "--target";
      92           0 :     gpr_join_host_port(&args[2], "127.0.0.1", port);
      93           0 :     args[3] = "--scenario=ping-pong-stream";
      94           0 :     args[4] = "--no-secure";
      95           0 :     args[5] = 0;
      96           0 :     execv(args[0], args);
      97             : 
      98           0 :     gpr_free(args[0]);
      99           0 :     gpr_free(args[2]);
     100           0 :     return 1;
     101             :   }
     102             :   /* wait for completion */
     103           1 :   printf("waiting for client\n");
     104           1 :   if (waitpid(cli, &status, 0) == -1) return 2;
     105           1 :   if (!WIFEXITED(status)) return 4;
     106           1 :   if (WEXITSTATUS(status)) return WEXITSTATUS(status);
     107           1 :   printf("waiting for server\n");
     108           1 :   kill(svr, SIGINT);
     109           1 :   if (waitpid(svr, &status, 0) == -1) return 2;
     110           1 :   if (!WIFEXITED(status)) return 4;
     111           1 :   if (WEXITSTATUS(status)) return WEXITSTATUS(status);
     112           1 :   return 0;
     113             : }

Generated by: LCOV version 1.10