Close FDs in test_open_lots_and_spawn()
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 16 Oct 2017 17:48:09 +0000 (13:48 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 16 Oct 2017 17:48:09 +0000 (13:48 -0400)
This allows the following tests to assume a reasonable number of FDs alread
open.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/utest/file-posix.c

index 1d75c35..f4ff473 100644 (file)
@@ -37,18 +37,22 @@ bool test_open_lots_and_spawn(void)
 {
        char *p_argv[] = {0, 0, 0};
        char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
-       int fd, pid;
+       #define NR_LOOPS 128
+       int fd[NR_LOOPS];
+       int pid;
        const char *filename = "/bin/hello";
 
        /* the kernel-internal number is 32 at the moment. */
-       for (int i = 0; i < 128; i++) {
-               fd = open("hello.txt", O_RDONLY);
-               UT_ASSERT(fd >= 0);
+       for (int i = 0; i < NR_LOOPS; i++) {
+               fd[i] = open("hello.txt", O_RDONLY);
+               UT_ASSERT(fd[i] >= 0);
        }
        pid = sys_proc_create(filename, strlen(filename), p_argv, p_envp,
                              PROC_DUP_FGRP);
        UT_ASSERT(pid > 0);
        sys_proc_destroy(pid, 0);
+       for (int i = 0; i < NR_LOOPS; i++)
+               close(fd[i]);
        return TRUE;
 }