blob: 1d75c359991f2413a9cc86b11519da535cc05d17 [file] [log] [blame] [edit]
#define _LARGEFILE64_SOURCE /* needed to use lseek64 */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <parlib/arch/arch.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <parlib/parlib.h>
#include <utest/utest.h>
TEST_SUITE("FILE POSIX");
/* <--- Begin definition of test cases ---> */
bool test_openat(void)
{
int dfd = open("/dir1", O_RDONLY);
UT_ASSERT(dfd >= 0);
int ffd = openat(dfd, "f1.txt", O_RDWR);
UT_ASSERT(ffd >= 0, close(dfd));
close(ffd);
close(dfd);
return TRUE;
}
/* This tests opening a lot of files, enough to grow our file/chan table, then
* forking/spawning with DUP_FGRP. It caused a panic at one point. */
bool test_open_lots_and_spawn(void)
{
char *p_argv[] = {0, 0, 0};
char *p_envp[] = {"LD_LIBRARY_PATH=/lib", 0};
int fd, 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);
}
pid = sys_proc_create(filename, strlen(filename), p_argv, p_envp,
PROC_DUP_FGRP);
UT_ASSERT(pid > 0);
sys_proc_destroy(pid, 0);
return TRUE;
}
/* <--- End definition of test cases ---> */
struct utest utests[] = {
UTEST_REG(openat),
UTEST_REG(open_lots_and_spawn),
};
int num_utests = sizeof(utests) / sizeof(struct utest);
int main(int argc, char *argv[])
{
// Run test suite passing it all the args as whitelist of what tests to run.
char **whitelist = &argv[1];
int whitelist_len = argc - 1;
RUN_TEST_SUITE(utests, num_utests, whitelist, whitelist_len);
}