blob: 39ae34aa0565e0de03a3378b28b26c0fa30d1311 [file] [log] [blame]
Craig Tiller1ada6ad2015-07-16 16:19:14 -07001/*
2 *
Craig Tiller69b093b2016-02-25 19:04:07 -08003 * Copyright 2015-2016, Google Inc.
Craig Tiller1ada6ad2015-07-16 16:19:14 -07004 * 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 <stdlib.h>
37#include <string.h>
38#include <unistd.h>
39
Craig Tiller1ada6ad2015-07-16 16:19:14 -070040#include <grpc/support/alloc.h>
41#include <grpc/support/host_port.h>
42#include <grpc/support/log.h>
43#include <grpc/support/string_util.h>
44#include <grpc/support/sync.h>
45#include <grpc/support/thd.h>
46#include <grpc/support/useful.h>
Craig Tiller69b093b2016-02-25 19:04:07 -080047
Craig Tilleradcb92d2016-03-28 10:14:05 -070048#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
Craig Tiller9533d042016-03-25 17:11:06 -070049#include "src/core/lib/channel/client_channel.h"
50#include "src/core/lib/channel/connected_channel.h"
51#include "src/core/lib/channel/http_server_filter.h"
52#include "src/core/lib/iomgr/pollset_posix.h"
53#include "src/core/lib/support/string.h"
54#include "src/core/lib/surface/channel.h"
55#include "src/core/lib/surface/server.h"
Craig Tiller1ada6ad2015-07-16 16:19:14 -070056#include "test/core/util/port.h"
57#include "test/core/util/test_config.h"
58
59typedef struct fullstack_fixture_data {
60 char *localaddr;
61} fullstack_fixture_data;
62
63static int unique = 1;
64
65static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
66 grpc_channel_args *client_args, grpc_channel_args *server_args) {
67 grpc_end2end_test_fixture f;
68 fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data));
69 memset(&f, 0, sizeof(f));
70
71 gpr_asprintf(&ffd->localaddr, "unix:/tmp/grpc_fullstack_test.%d.%d", getpid(),
72 unique++);
73
74 f.fixture_data = ffd;
Nicolas "Pixel" Noble9d72b142015-08-08 01:45:38 +020075 f.cq = grpc_completion_queue_create(NULL);
Craig Tiller1ada6ad2015-07-16 16:19:14 -070076
77 return f;
78}
79
80void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f,
81 grpc_channel_args *client_args) {
82 fullstack_fixture_data *ffd = f->fixture_data;
Nicolas "Pixel" Noble9d72b142015-08-08 01:45:38 +020083 f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL);
Craig Tiller1ada6ad2015-07-16 16:19:14 -070084}
85
86void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f,
87 grpc_channel_args *server_args) {
88 fullstack_fixture_data *ffd = f->fixture_data;
89 if (f->server) {
90 grpc_server_destroy(f->server);
91 }
Nicolas "Pixel" Noble9d72b142015-08-08 01:45:38 +020092 f->server = grpc_server_create(server_args, NULL);
93 grpc_server_register_completion_queue(f->server, f->cq, NULL);
Craig Tillerc5ae3eb2015-08-03 10:42:22 -070094 GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
Craig Tiller1ada6ad2015-07-16 16:19:14 -070095 grpc_server_start(f->server);
96}
97
98void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) {
99 fullstack_fixture_data *ffd = f->fixture_data;
100 gpr_free(ffd->localaddr);
101 gpr_free(ffd);
102}
103
104/* All test configurations */
105static grpc_end2end_test_config configs[] = {
106 {"chttp2/fullstack_uds", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION,
107 chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
108 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
109};
110
111int main(int argc, char **argv) {
112 size_t i;
113
114 grpc_platform_become_multipoller = grpc_poll_become_multipoller;
115
116 grpc_test_init(argc, argv);
117 grpc_init();
118
119 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800120 grpc_end2end_tests(argc, argv, configs[i]);
Craig Tiller1ada6ad2015-07-16 16:19:14 -0700121 }
122
123 grpc_shutdown();
124
125 return 0;
126}