| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2015 gRPC authors. |
| 4 |
* |
| 5 |
* 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 |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* 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. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <inttypes.h> |
| 20 |
#include <string.h> |
| 21 |
#include <unistd.h> |
| 22 |
|
| 23 |
#include <atomic> |
| 24 |
#include <string> |
| 25 |
#include <utility> |
| 26 |
|
| 27 |
#include "absl/strings/str_format.h" |
| 28 |
|
| 29 |
#include <grpc/grpc.h> |
| 30 |
#include <grpc/grpc_security.h> |
| 31 |
#include <grpc/support/log.h> |
| 32 |
#include <grpc/support/time.h> |
| 33 |
|
| 34 |
#include "test/core/end2end/end2end_tests.h" |
| 35 |
#include "test/core/util/test_config.h" |
| 36 |
|
| 37 |
struct fullstack_fixture_data { |
| 38 |
std::string localaddr; |
| 39 |
}; |
| 40 |
|
| 41 |
static std::atomic<int> unique{1}; |
| 42 |
|
| 43 |
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_base( |
| 44 |
std::string addr) { |
| 45 |
fullstack_fixture_data* ffd = new fullstack_fixture_data; |
| 46 |
ffd->localaddr = std::move(addr); |
| 47 |
|
| 48 |
grpc_end2end_test_fixture f; |
| 49 |
memset(&f, 0, sizeof(f)); |
| 50 |
f.fixture_data = ffd; |
| 51 |
f.cq = grpc_completion_queue_create_for_next(nullptr); |
| 52 |
|
| 53 |
return f; |
| 54 |
} |
| 55 |
|
| 56 |
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( |
| 57 |
const grpc_channel_args* /*client_args*/, |
| 58 |
const grpc_channel_args* /*server_args*/) { |
| 59 |
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); |
| 60 |
const std::string localaddr = absl::StrFormat( |
| 61 |
"unix:/tmp/grpc_fullstack_test.%d.%" PRId64 ".%" PRId32 ".%d", getpid(), |
| 62 |
now.tv_sec, now.tv_nsec, unique++); |
| 63 |
return chttp2_create_fixture_fullstack_base(localaddr); |
| 64 |
} |
| 65 |
|
| 66 |
void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, |
| 67 |
const grpc_channel_args* client_args) { |
| 68 |
fullstack_fixture_data* ffd = |
| 69 |
static_cast<fullstack_fixture_data*>(f->fixture_data); |
| 70 |
grpc_channel_credentials* creds = grpc_insecure_credentials_create(); |
| 71 |
f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args); |
| 72 |
grpc_channel_credentials_release(creds); |
| 73 |
} |
| 74 |
|
| 75 |
void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, |
| 76 |
const grpc_channel_args* server_args) { |
| 77 |
fullstack_fixture_data* ffd = |
| 78 |
static_cast<fullstack_fixture_data*>(f->fixture_data); |
| 79 |
if (f->server) { |
| 80 |
grpc_server_destroy(f->server); |
| 81 |
} |
| 82 |
f->server = grpc_server_create(server_args, nullptr); |
| 83 |
grpc_server_register_completion_queue(f->server, f->cq, nullptr); |
| 84 |
grpc_server_credentials* server_creds = |
| 85 |
grpc_insecure_server_credentials_create(); |
| 86 |
GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(), |
| 87 |
server_creds)); |
| 88 |
grpc_server_credentials_release(server_creds); |
| 89 |
grpc_server_start(f->server); |
| 90 |
} |
| 91 |
|
| 92 |
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { |
| 93 |
fullstack_fixture_data* ffd = |
| 94 |
static_cast<fullstack_fixture_data*>(f->fixture_data); |
| 95 |
delete ffd; |
| 96 |
} |
| 97 |
|
| 98 |
/* All test configurations */ |
| 99 |
static grpc_end2end_test_config configs[] = { |
| 100 |
{"chttp2/fullstack_uds", |
| 101 |
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | |
| 102 |
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | |
| 103 |
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, |
| 104 |
nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, |
| 105 |
chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, |
| 106 |
}; |
| 107 |
|
| 108 |
int main(int argc, char** argv) { |
| 109 |
size_t i; |
| 110 |
|
| 111 |
grpc::testing::TestEnvironment env(&argc, argv); |
| 112 |
grpc_end2end_tests_pre_init(); |
| 113 |
grpc_init(); |
| 114 |
|
| 115 |
for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
| 116 |
grpc_end2end_tests(argc, argv, configs[i]); |
| 117 |
} |
| 118 |
|
| 119 |
grpc_shutdown(); |
| 120 |
|
| 121 |
return 0; |
| 122 |
} |