• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <grpc/grpc.h>
20 #include <grpc/support/log.h>
21 #include "test/core/util/test_config.h"
22 
23 static int g_flag;
24 
test(int rounds)25 static void test(int rounds) {
26   int i;
27   for (i = 0; i < rounds; i++) {
28     grpc_init();
29   }
30   for (i = 0; i < rounds; i++) {
31     grpc_shutdown();
32   }
33 }
34 
test_mixed(void)35 static void test_mixed(void) {
36   grpc_init();
37   grpc_init();
38   grpc_shutdown();
39   grpc_init();
40   grpc_shutdown();
41   grpc_shutdown();
42 }
43 
plugin_init(void)44 static void plugin_init(void) { g_flag = 1; }
plugin_destroy(void)45 static void plugin_destroy(void) { g_flag = 2; }
46 
test_plugin()47 static void test_plugin() {
48   grpc_register_plugin(plugin_init, plugin_destroy);
49   grpc_init();
50   GPR_ASSERT(g_flag == 1);
51   grpc_shutdown();
52   GPR_ASSERT(g_flag == 2);
53 }
54 
test_repeatedly()55 static void test_repeatedly() {
56   for (int i = 0; i < 1000; i++) {
57     grpc_init();
58     grpc_shutdown();
59   }
60 }
61 
main(int argc,char ** argv)62 int main(int argc, char** argv) {
63   grpc_test_init(argc, argv);
64   test(1);
65   test(2);
66   test(3);
67   test_mixed();
68   test_plugin();
69   test_repeatedly();
70   return 0;
71 }
72