Debian Codegraph @

test/core/end2end/tests/no_op.cc

raw
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 <stdint.h>
20
21 #include <grpc/grpc.h>
22 #include <grpc/support/log.h>
23
24 #include "test/core/end2end/end2end_tests.h"
25 #include "test/core/util/test_config.h"
26
27 static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
28
29 static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
30 const char* test_name,
31 grpc_channel_args* client_args,
32 grpc_channel_args* server_args) {
33 grpc_end2end_test_fixture f;
34 gpr_log(GPR_INFO, "Running test: %s/%s", test_name, config.name);
35 f = config.create_fixture(client_args, server_args);
36 config.init_server(&f, server_args);
37 config.init_client(&f, client_args);
38 return f;
39 }
40
41 static gpr_timespec n_seconds_from_now(int n) {
42 return grpc_timeout_seconds_to_deadline(n);
43 }
44
45 static gpr_timespec five_seconds_from_now(void) {
46 return n_seconds_from_now(5);
47 }
48
49 static void drain_cq(grpc_completion_queue* cq) {
50 grpc_event ev;
51 do {
52 ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
53 } while (ev.type != GRPC_QUEUE_SHUTDOWN);
54 }
55
56 static void shutdown_server(grpc_end2end_test_fixture* f) {
57 if (!f->server) return;
58 grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
59 grpc_event ev;
60 do {
61 ev = grpc_completion_queue_next(f->cq, grpc_timeout_seconds_to_deadline(5),
62 nullptr);
63 } while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
64 grpc_server_destroy(f->server);
65 f->server = nullptr;
66 }
67
68 static void shutdown_client(grpc_end2end_test_fixture* f) {
69 if (!f->client) return;
70 grpc_channel_destroy(f->client);
71 f->client = nullptr;
72 }
73
74 static void end_test(grpc_end2end_test_fixture* f) {
75 shutdown_server(f);
76 shutdown_client(f);
77
78 grpc_completion_queue_shutdown(f->cq);
79 drain_cq(f->cq);
80 grpc_completion_queue_destroy(f->cq);
81 }
82
83 static void test_no_op(grpc_end2end_test_config config) {
84 grpc_end2end_test_fixture f = begin_test(config, "no-op", nullptr, nullptr);
85 end_test(&f);
86 config.tear_down_data(&f);
87 }
88
89 void no_op(grpc_end2end_test_config config) { test_no_op(config); }
90
91 void no_op_pre_init(void) {}