blob: 0c826b6836809cf238cbef36baf3050512bb7693 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080016 *
17 */
18
19#include "test/core/end2end/end2end_tests.h"
20
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080021#include <string.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080022
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080023#include <grpc/support/alloc.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080024#include <grpc/support/log.h>
25#include <grpc/support/sync.h>
Vijay Paid4d0a302018-01-25 13:24:03 -080026
Craig Tiller9eb0fde2017-03-31 16:59:30 -070027#include "src/core/ext/filters/client_channel/client_channel.h"
Craig Tillere3593d92017-04-03 14:51:02 -070028#include "src/core/ext/filters/http/server/http_server_filter.h"
Craig Tilleradcb92d2016-03-28 10:14:05 -070029#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
Craig Tiller9533d042016-03-25 17:11:06 -070030#include "src/core/lib/channel/connected_channel.h"
Vijay Paiae376bf2018-01-25 22:54:02 -080031#include "src/core/lib/gpr/host_port.h"
Craig Tiller9533d042016-03-25 17:11:06 -070032#include "src/core/lib/surface/channel.h"
33#include "src/core/lib/surface/server.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080034#include "test/core/util/port.h"
35#include "test/core/util/test_config.h"
36
37typedef struct fullstack_fixture_data {
Craig Tillerbaa14a92017-11-03 09:09:36 -070038 char* localaddr;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080039} fullstack_fixture_data;
40
41static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
Craig Tillerbaa14a92017-11-03 09:09:36 -070042 grpc_channel_args* client_args, grpc_channel_args* server_args) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080043 grpc_end2end_test_fixture f;
44 int port = grpc_pick_unused_port_or_die();
Yash Tibrewal40422d52017-11-06 14:39:17 -080045 fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
Yash Tibrewal34a57d02017-10-23 15:33:21 -070046 gpr_malloc(sizeof(fullstack_fixture_data)));
ctillerc6d61c42014-12-15 14:52:08 -080047 memset(&f, 0, sizeof(f));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080048
49 gpr_join_host_port(&ffd->localaddr, "localhost", port);
50
51 f.fixture_data = ffd;
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080052 f.cq = grpc_completion_queue_create_for_next(nullptr);
53 f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080054
55 return f;
56}
57
Craig Tillerbaa14a92017-11-03 09:09:36 -070058void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
59 grpc_channel_args* client_args) {
Yash Tibrewal40422d52017-11-06 14:39:17 -080060 fullstack_fixture_data* ffd =
61 static_cast<fullstack_fixture_data*>(f->fixture_data);
Craig Tillerbe98d242017-11-10 15:26:57 -080062 f->client =
63 grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
Craig Tillereb3b12e2015-06-26 14:42:49 -070064 GPR_ASSERT(f->client);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080065}
66
Craig Tillerbaa14a92017-11-03 09:09:36 -070067void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
68 grpc_channel_args* server_args) {
Yash Tibrewal40422d52017-11-06 14:39:17 -080069 fullstack_fixture_data* ffd =
70 static_cast<fullstack_fixture_data*>(f->fixture_data);
ctillerc6d61c42014-12-15 14:52:08 -080071 if (f->server) {
72 grpc_server_destroy(f->server);
73 }
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080074 f->server = grpc_server_create(server_args, nullptr);
75 grpc_server_register_completion_queue(f->server, f->cq, nullptr);
Craig Tillerc5ae3eb2015-08-03 10:42:22 -070076 GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080077 grpc_server_start(f->server);
78}
79
Craig Tillerbaa14a92017-11-03 09:09:36 -070080void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
Yash Tibrewal40422d52017-11-06 14:39:17 -080081 fullstack_fixture_data* ffd =
82 static_cast<fullstack_fixture_data*>(f->fixture_data);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080083 gpr_free(ffd->localaddr);
84 gpr_free(ffd);
85}
86
87/* All test configurations */
88static grpc_end2end_test_config configs[] = {
Craig Tillerbaa14a92017-11-03 09:09:36 -070089 {"chttp2/fullstack",
90 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
91 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
92 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
David Garcia Quintas02879242018-03-23 18:14:12 -070093 nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
Craig Tiller8ad8a412015-02-25 08:36:40 -080094 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
95};
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080096
Craig Tillerbaa14a92017-11-03 09:09:36 -070097int main(int argc, char** argv) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080098 size_t i;
99
100 grpc_test_init(argc, argv);
Craig Tiller9e9edbc2016-04-04 10:38:49 -0700101 grpc_end2end_tests_pre_init();
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800102 grpc_init();
103
104 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800105 grpc_end2end_tests(argc, argv, configs[i]);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800106 }
107
108 grpc_shutdown();
109
110 return 0;
Craig Tiller190d3602015-02-18 09:23:38 -0800111}