tests/gem_fd_exhaustion: Make it work

- We need to drop root to actually hit the limits. This requires us to
  fork the actual test since otherwise the exit handlers (which
  require root) fail the entire test.
- Don't assert that the gem create ioctl succeeds, it won't on the
  final run of the loop.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Daniel Vetter 2014-01-19 22:15:13 +01:00
parent 7d2ba073ad
commit 5b91475130

View File

@ -57,6 +57,9 @@ igt_simple_main
igt_assert(open("/dev/null", O_RDONLY) >= 0); igt_assert(open("/dev/null", O_RDONLY) >= 0);
igt_fork(n, 1) {
igt_drop_root();
for (i = 0; ; i++) { for (i = 0; ; i++) {
int tmp_fd = open("/dev/null", O_RDONLY); int tmp_fd = open("/dev/null", O_RDONLY);
uint32_t handle; uint32_t handle;
@ -64,20 +67,25 @@ igt_simple_main
if (tmp_fd >= 0 && i < FD_ARR_SZ) if (tmp_fd >= 0 && i < FD_ARR_SZ)
fd_arr[i] = tmp_fd; fd_arr[i] = tmp_fd;
handle = gem_create(fd, 4096); handle = __gem_create(fd, 4096);
if (handle) if (handle)
gem_close(fd, handle); gem_close(fd, handle);
if (!handle || tmp_fd < 0) { if (tmp_fd < 0) {
/* Ensure we actually hit the failure path ... */
igt_assert(handle == 0);
printf("fd exhaustion after %i rounds.\n", i); printf("fd exhaustion after %i rounds.\n", i);
break; break;
} }
} }
/* free a few fd so that the exit handlers can at least run. */ /* The child will free all the fds when exiting, so no need to
for (i = 0; i < FD_ARR_SZ; i++) * clean up to mess to ensure that the parent can at least run
close(fd_arr[i]); * the exit handlers. */
}
igt_waitchildren();
close(fd); close(fd);
} }