| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2017 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 <string.h> |
| 20 |
|
| 21 |
#include <grpc/grpc.h> |
| 22 |
#include <grpc/support/alloc.h> |
| 23 |
#include <grpc/support/log.h> |
| 24 |
|
| 25 |
#include "src/core/ext/transport/inproc/inproc_transport.h" |
| 26 |
#include "test/core/end2end/end2end_tests.h" |
| 27 |
#include "test/core/util/test_config.h" |
| 28 |
|
| 29 |
typedef struct inproc_fixture_data { |
| 30 |
bool phony; // reserved for future expansion. Struct can't be empty |
| 31 |
} inproc_fixture_data; |
| 32 |
|
| 33 |
static grpc_end2end_test_fixture inproc_create_fixture( |
| 34 |
const grpc_channel_args* /*client_args*/, |
| 35 |
const grpc_channel_args* /*server_args*/) { |
| 36 |
grpc_end2end_test_fixture f; |
| 37 |
inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>( |
| 38 |
gpr_malloc(sizeof(inproc_fixture_data))); |
| 39 |
memset(&f, 0, sizeof(f)); |
| 40 |
|
| 41 |
f.fixture_data = ffd; |
| 42 |
f.cq = grpc_completion_queue_create_for_next(nullptr); |
| 43 |
|
| 44 |
return f; |
| 45 |
} |
| 46 |
|
| 47 |
void inproc_init_client(grpc_end2end_test_fixture* f, |
| 48 |
const grpc_channel_args* client_args) { |
| 49 |
f->client = grpc_inproc_channel_create(f->server, client_args, nullptr); |
| 50 |
GPR_ASSERT(f->client); |
| 51 |
} |
| 52 |
|
| 53 |
void inproc_init_server(grpc_end2end_test_fixture* f, |
| 54 |
const grpc_channel_args* server_args) { |
| 55 |
if (f->server) { |
| 56 |
grpc_server_destroy(f->server); |
| 57 |
} |
| 58 |
f->server = grpc_server_create(server_args, nullptr); |
| 59 |
grpc_server_register_completion_queue(f->server, f->cq, nullptr); |
| 60 |
grpc_server_start(f->server); |
| 61 |
} |
| 62 |
|
| 63 |
void inproc_tear_down(grpc_end2end_test_fixture* f) { |
| 64 |
inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>(f->fixture_data); |
| 65 |
gpr_free(ffd); |
| 66 |
} |
| 67 |
|
| 68 |
/* All test configurations */ |
| 69 |
static grpc_end2end_test_config configs[] = { |
| 70 |
{"inproc", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr, |
| 71 |
inproc_create_fixture, inproc_init_client, inproc_init_server, |
| 72 |
inproc_tear_down}, |
| 73 |
}; |
| 74 |
|
| 75 |
int main(int argc, char** argv) { |
| 76 |
size_t i; |
| 77 |
|
| 78 |
grpc::testing::TestEnvironment env(&argc, argv); |
| 79 |
grpc_end2end_tests_pre_init(); |
| 80 |
grpc_init(); |
| 81 |
|
| 82 |
for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
| 83 |
grpc_end2end_tests(argc, argv, configs[i]); |
| 84 |
} |
| 85 |
|
| 86 |
grpc_shutdown(); |
| 87 |
|
| 88 |
return 0; |
| 89 |
} |