LCOV - code coverage report
Current view: top level - test/core/end2end/fixtures - h2_compress.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 42 43 97.7 %
Date: 2015-10-10 Functions: 5 5 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/channel_args.h"
      39             : #include "src/core/channel/client_channel.h"
      40             : #include "src/core/channel/connected_channel.h"
      41             : #include "src/core/channel/http_server_filter.h"
      42             : #include "src/core/surface/channel.h"
      43             : #include "src/core/surface/server.h"
      44             : #include "src/core/transport/chttp2_transport.h"
      45             : #include <grpc/support/alloc.h>
      46             : #include <grpc/support/host_port.h>
      47             : #include <grpc/support/log.h>
      48             : #include <grpc/support/sync.h>
      49             : #include <grpc/support/thd.h>
      50             : #include <grpc/support/useful.h>
      51             : #include "test/core/util/port.h"
      52             : #include "test/core/util/test_config.h"
      53             : 
      54             : typedef struct fullstack_compression_fixture_data {
      55             :   char *localaddr;
      56             :   grpc_channel_args *client_args_compression;
      57             :   grpc_channel_args *server_args_compression;
      58             : } fullstack_compression_fixture_data;
      59             : 
      60         158 : static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression(
      61             :     grpc_channel_args *client_args, grpc_channel_args *server_args) {
      62             :   grpc_end2end_test_fixture f;
      63         158 :   int port = grpc_pick_unused_port_or_die();
      64         158 :   fullstack_compression_fixture_data *ffd =
      65             :       gpr_malloc(sizeof(fullstack_compression_fixture_data));
      66         158 :   memset(ffd, 0, sizeof(fullstack_compression_fixture_data));
      67             : 
      68         158 :   gpr_join_host_port(&ffd->localaddr, "localhost", port);
      69             : 
      70         158 :   memset(&f, 0, sizeof(f));
      71         158 :   f.fixture_data = ffd;
      72         158 :   f.cq = grpc_completion_queue_create(NULL);
      73             : 
      74         158 :   return f;
      75             : }
      76             : 
      77         158 : void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture *f,
      78             :                                               grpc_channel_args *client_args) {
      79         158 :   fullstack_compression_fixture_data *ffd = f->fixture_data;
      80         158 :   if (ffd->client_args_compression != NULL) {
      81           0 :     grpc_channel_args_destroy(ffd->client_args_compression);
      82             :   }
      83         158 :   ffd->client_args_compression = grpc_channel_args_set_compression_algorithm(
      84             :       client_args, GRPC_COMPRESS_GZIP);
      85         158 :   f->client = grpc_insecure_channel_create(ffd->localaddr,
      86         158 :                                            ffd->client_args_compression, NULL);
      87         158 : }
      88             : 
      89         160 : void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f,
      90             :                                               grpc_channel_args *server_args) {
      91         160 :   fullstack_compression_fixture_data *ffd = f->fixture_data;
      92         160 :   if (ffd->server_args_compression != NULL) {
      93           2 :     grpc_channel_args_destroy(ffd->server_args_compression);
      94             :   }
      95         160 :   ffd->server_args_compression = grpc_channel_args_set_compression_algorithm(
      96             :       server_args, GRPC_COMPRESS_GZIP);
      97         160 :   if (f->server) {
      98           2 :     grpc_server_destroy(f->server);
      99             :   }
     100         160 :   f->server = grpc_server_create(ffd->server_args_compression, NULL);
     101         160 :   grpc_server_register_completion_queue(f->server, f->cq, NULL);
     102         160 :   GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
     103         160 :   grpc_server_start(f->server);
     104         160 : }
     105             : 
     106         158 : void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture *f) {
     107         158 :   fullstack_compression_fixture_data *ffd = f->fixture_data;
     108         158 :   grpc_channel_args_destroy(ffd->client_args_compression);
     109         158 :   grpc_channel_args_destroy(ffd->server_args_compression);
     110         158 :   gpr_free(ffd->localaddr);
     111         158 :   gpr_free(ffd);
     112         158 : }
     113             : 
     114             : /* All test configurations */
     115             : static grpc_end2end_test_config configs[] = {
     116             :     {"chttp2/fullstack_compression", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION,
     117             :      chttp2_create_fixture_fullstack_compression,
     118             :      chttp2_init_client_fullstack_compression,
     119             :      chttp2_init_server_fullstack_compression,
     120             :      chttp2_tear_down_fullstack_compression},
     121             : };
     122             : 
     123          65 : int main(int argc, char **argv) {
     124             :   size_t i;
     125             : 
     126          65 :   grpc_test_init(argc, argv);
     127          65 :   grpc_init();
     128             : 
     129         130 :   for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
     130          65 :     grpc_end2end_tests(configs[i]);
     131             :   }
     132             : 
     133          65 :   grpc_shutdown();
     134             : 
     135          65 :   return 0;
     136             : }

Generated by: LCOV version 1.10