Debian Codegraph @

test/core/iomgr/fd_conservation_posix_test.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 <sys/resource.h>
20
21 #include <grpc/grpc.h>
22 #include <grpc/support/log.h>
23
24 #include "src/core/lib/iomgr/endpoint_pair.h"
25 #include "src/core/lib/iomgr/iomgr.h"
26 #include "test/core/util/test_config.h"
27
28 int main(int argc, char** argv) {
29 int i;
30 struct rlimit rlim;
31 grpc_endpoint_pair p;
32
33 grpc::testing::TestEnvironment env(&argc, argv);
34 grpc_init();
35 {
36 grpc_core::ExecCtx exec_ctx;
37
38 /* set max # of file descriptors to a low value, and
39 verify we can create and destroy many more than this number
40 of descriptors */
41 rlim.rlim_cur = rlim.rlim_max = 10;
42 GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim));
43 for (i = 0; i < 100; i++) {
44 p = grpc_iomgr_create_endpoint_pair("test", nullptr);
45 grpc_endpoint_destroy(p.client);
46 grpc_endpoint_destroy(p.server);
47 grpc_core::ExecCtx::Get()->Flush();
48 }
49 }
50
51 grpc_shutdown();
52 return 0;
53 }