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.
This commit is contained in:
Augustin Cavalier
2022-08-18 13:57:08 -04:00
parent 0b19ba0ad9
commit e4e1e6e4f5
2 changed files with 39 additions and 0 deletions
+1
View File
@@ -14,6 +14,7 @@ SimpleTest calloc_test : calloc_test.c ;
SimpleTest <test>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 ;
@@ -0,0 +1,38 @@
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
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;
}