2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
28 #include <sys/types.h>
30 #include <sys/resource.h>
36 #include "ioctl_wrappers.h"
41 int fd_arr[FD_ARR_SZ];
48 FILE *file_max = fopen("/proc/sys/fs/file-max", "r");
49 igt_assert(fscanf(file_max, "%u", &nofile_rlim) == 1);
52 igt_info("System limit for open files is %u\n", nofile_rlim);
54 igt_assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0);
55 rlim.rlim_cur = nofile_rlim;
56 rlim.rlim_max = nofile_rlim;
57 igt_assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0);
61 igt_assert(open("/dev/null", O_RDONLY) >= 0);
67 int tmp_fd = open("/dev/null", O_RDONLY);
70 if (tmp_fd >= 0 && i < FD_ARR_SZ)
73 handle = __gem_create(fd, 4096);
75 gem_close(fd, handle);
79 /* Ensure we actually hit the failure path ... */
80 igt_assert(handle == 0);
81 igt_info("fd exhaustion after %i rounds.\n", i);
86 /* The child will free all the fds when exiting, so no need to
87 * clean up to mess to ensure that the parent can at least run
88 * the exit handlers. */