From e4e1e6e4f53d942de7f5627377bd3b4adce89394 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 18 Aug 2022 13:57:08 -0400 Subject: [PATCH] tests: Add fifo_test. Creates, opens, tries to open as directory, then unlinks. The attempt to open as a directory triggers an assertion in the kernel at present (this is #17870.) The next commit will fix that. --- src/tests/system/libroot/posix/Jamfile | 1 + src/tests/system/libroot/posix/fifo_test.cpp | 38 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/tests/system/libroot/posix/fifo_test.cpp diff --git a/src/tests/system/libroot/posix/Jamfile b/src/tests/system/libroot/posix/Jamfile index 8974881f00..68b4cb1e2c 100644 --- a/src/tests/system/libroot/posix/Jamfile +++ b/src/tests/system/libroot/posix/Jamfile @@ -14,6 +14,7 @@ SimpleTest calloc_test : calloc_test.c ; SimpleTest chmod : chmod.cpp ; SimpleTest clearenv : clearenv.cpp ; SimpleTest dirent_test : dirent_test.cpp ; +SimpleTest fifo_test : fifo_test.cpp ; SimpleTest flock_test : flock_test.cpp ; SimpleTest fseek_test : fseek_test.cpp ; SimpleTest getsubopt_test : getsubopt_test.cpp ; diff --git a/src/tests/system/libroot/posix/fifo_test.cpp b/src/tests/system/libroot/posix/fifo_test.cpp new file mode 100644 index 0000000000..b65c661e83 --- /dev/null +++ b/src/tests/system/libroot/posix/fifo_test.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include + +int +main(int argc, char** argv) +{ + const char* filename = "temp.fifo"; + + if (mkfifo("temp.fifo", S_IRWXU) != 0) { + perror("mkfifo error"); + return 1; + } + + int rfd = open(filename, O_RDONLY | O_NONBLOCK); + if (rfd < 0) { + perror("open() error"); + return 1; + } + + DIR* dir = opendir(filename); + if (dir != NULL) { + perror("opendir succeeded"); + return 1; + } + + dir = fdopendir(rfd); + if (dir != NULL) { + perror("fdopendir succeeded"); + return 1; + } + + unlink(filename); + return 0; +}