LCOV - code coverage report
Current view: top level - test/core/end2end/fixtures - h2_sockpair_1byte.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 57 57 100.0 %
Date: 2015-10-10 Functions: 7 7 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 "test/core/end2end/end2end_tests.h"
      35             : 
      36             : #include <string.h>
      37             : 
      38             : #include "src/core/channel/client_channel.h"
      39             : #include "src/core/channel/connected_channel.h"
      40             : #include "src/core/channel/http_client_filter.h"
      41             : #include "src/core/channel/http_server_filter.h"
      42             : #include "src/core/channel/compress_filter.h"
      43             : #include "src/core/iomgr/endpoint_pair.h"
      44             : #include "src/core/iomgr/iomgr.h"
      45             : #include "src/core/surface/channel.h"
      46             : #include "src/core/surface/server.h"
      47             : #include "src/core/transport/chttp2_transport.h"
      48             : #include <grpc/support/alloc.h>
      49             : #include <grpc/support/log.h>
      50             : #include <grpc/support/sync.h>
      51             : #include <grpc/support/thd.h>
      52             : #include <grpc/support/useful.h>
      53             : #include "test/core/util/port.h"
      54             : #include "test/core/util/test_config.h"
      55             : 
      56             : /* chttp2 transport that is immediately available (used for testing
      57             :    connected_channel without a client_channel */
      58             : 
      59         148 : static void server_setup_transport(void *ts, grpc_transport *transport,
      60             :                                    grpc_mdctx *mdctx) {
      61         148 :   grpc_end2end_test_fixture *f = ts;
      62             :   static grpc_channel_filter const *extra_filters[] = {
      63             :       &grpc_http_server_filter};
      64         148 :   grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
      65         148 :   grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters,
      66             :                               GPR_ARRAY_SIZE(extra_filters), mdctx,
      67             :                               grpc_server_get_channel_args(f->server));
      68         148 :   grpc_exec_ctx_finish(&exec_ctx);
      69         148 : }
      70             : 
      71             : typedef struct {
      72             :   grpc_end2end_test_fixture *f;
      73             :   grpc_channel_args *client_args;
      74             : } sp_client_setup;
      75             : 
      76         148 : static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts,
      77             :                                    grpc_transport *transport,
      78             :                                    grpc_mdctx *mdctx) {
      79         148 :   sp_client_setup *cs = ts;
      80             : 
      81         148 :   const grpc_channel_filter *filters[] = {&grpc_http_client_filter,
      82             :                                           &grpc_compress_filter,
      83             :                                           &grpc_connected_channel_filter};
      84         148 :   size_t nfilters = sizeof(filters) / sizeof(*filters);
      85         148 :   grpc_channel *channel =
      86             :       grpc_channel_create_from_filters(exec_ctx, "socketpair-target", filters,
      87         148 :                                        nfilters, cs->client_args, mdctx, 1);
      88             : 
      89         148 :   cs->f->client = channel;
      90             : 
      91         148 :   grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel),
      92             :                                         transport);
      93         148 : }
      94             : 
      95         148 : static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
      96             :     grpc_channel_args *client_args, grpc_channel_args *server_args) {
      97         148 :   grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair));
      98             : 
      99             :   grpc_end2end_test_fixture f;
     100         148 :   memset(&f, 0, sizeof(f));
     101         148 :   f.fixture_data = sfd;
     102         148 :   f.cq = grpc_completion_queue_create(NULL);
     103             : 
     104         148 :   *sfd = grpc_iomgr_create_endpoint_pair("fixture", 1);
     105             : 
     106         148 :   return f;
     107             : }
     108             : 
     109         148 : static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
     110             :                                           grpc_channel_args *client_args) {
     111         148 :   grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
     112         148 :   grpc_endpoint_pair *sfd = f->fixture_data;
     113             :   grpc_transport *transport;
     114         148 :   grpc_mdctx *mdctx = grpc_mdctx_create();
     115             :   sp_client_setup cs;
     116         148 :   cs.client_args = client_args;
     117         148 :   cs.f = f;
     118         148 :   transport = grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client,
     119             :                                            mdctx, 1);
     120         148 :   client_setup_transport(&exec_ctx, &cs, transport, mdctx);
     121         148 :   GPR_ASSERT(f->client);
     122         148 :   grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
     123         148 :   grpc_exec_ctx_finish(&exec_ctx);
     124         148 : }
     125             : 
     126         148 : static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
     127             :                                           grpc_channel_args *server_args) {
     128         148 :   grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
     129         148 :   grpc_endpoint_pair *sfd = f->fixture_data;
     130         148 :   grpc_mdctx *mdctx = grpc_mdctx_create();
     131             :   grpc_transport *transport;
     132         148 :   GPR_ASSERT(!f->server);
     133         148 :   f->server = grpc_server_create_from_filters(NULL, 0, server_args);
     134         148 :   grpc_server_register_completion_queue(f->server, f->cq, NULL);
     135         148 :   grpc_server_start(f->server);
     136         148 :   transport = grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server,
     137             :                                            mdctx, 0);
     138         148 :   server_setup_transport(f, transport, mdctx);
     139         148 :   grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
     140         148 :   grpc_exec_ctx_finish(&exec_ctx);
     141         148 : }
     142             : 
     143         148 : static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
     144         148 :   gpr_free(f->fixture_data);
     145         148 : }
     146             : 
     147             : /* All test configurations */
     148             : static grpc_end2end_test_config configs[] = {
     149             :     {"chttp2/socketpair_one_byte_at_a_time", 0,
     150             :      chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
     151             :      chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
     152             : };
     153             : 
     154          57 : int main(int argc, char **argv) {
     155             :   size_t i;
     156             : 
     157          57 :   grpc_test_init(argc, argv);
     158          57 :   grpc_init();
     159             : 
     160         114 :   for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
     161          57 :     grpc_end2end_tests(configs[i]);
     162             :   }
     163             : 
     164          57 :   grpc_shutdown();
     165             : 
     166          57 :   return 0;
     167             : }

Generated by: LCOV version 1.10