Files
RedBear-OS/local/patches/relibc/P3-fd-event-tests.patch
T

127 lines
3.5 KiB
Diff

diff --git a/tests/sys_eventfd/eventfd.c b/tests/sys_eventfd/eventfd.c
new file mode 100644
--- /dev/null
+++ b/tests/sys_eventfd/eventfd.c
@@ -0,0 +1,27 @@
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <sys/eventfd.h>
+#include <unistd.h>
+
+int main(void) {
+ int fd = eventfd(2, 0);
+ assert(fd >= 0);
+ eventfd_t value = 0;
+ assert(eventfd_read(fd, &value) == 0);
+ assert(value == 2);
+ assert(eventfd_write(fd, 5) == 0);
+ assert(eventfd_read(fd, &value) == 0);
+ assert(value == 5);
+ assert(close(fd) == 0);
+
+ int semfd = eventfd(2, EFD_SEMAPHORE);
+ assert(semfd >= 0);
+ assert(eventfd_read(semfd, &value) == 0);
+ assert(value == 1);
+ assert(eventfd_read(semfd, &value) == 0);
+ assert(value == 1);
+ assert(close(semfd) == 0);
+ puts("eventfd ok");
+ return 0;
+}
diff --git a/tests/sys_signalfd/signalfd.c b/tests/sys_signalfd/signalfd.c
new file mode 100644
--- /dev/null
+++ b/tests/sys_signalfd/signalfd.c
@@ -0,0 +1,23 @@
+#include <assert.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/signalfd.h>
+#include <unistd.h>
+
+int main(void) {
+ sigset_t mask;
+ assert(sigemptyset(&mask) == 0);
+ assert(sigaddset(&mask, SIGUSR1) == 0);
+ assert(sigprocmask(SIG_BLOCK, &mask, NULL) == 0);
+ int fd = signalfd(-1, &mask, sizeof(mask));
+ assert(fd >= 0);
+ assert(kill(getpid(), SIGUSR1) == 0);
+ struct signalfd_siginfo info;
+ assert(read(fd, &info, sizeof(info)) == (ssize_t)sizeof(info));
+ assert(info.ssi_signo == SIGUSR1);
+ assert(info.ssi_pid == (uint32_t)getpid());
+ assert(close(fd) == 0);
+ puts("signalfd ok");
+ return 0;
+}
diff --git a/tests/sys_signalfd/header_only.c b/tests/sys_signalfd/header_only.c
new file mode 100644
--- /dev/null
+++ b/tests/sys_signalfd/header_only.c
@@ -0,0 +1,12 @@
+#include <stdint.h>
+#include <sys/signalfd.h>
+
+int main(void) {
+ struct signalfd_siginfo info = {0};
+ int (*fn1)(int, const sigset_t *, size_t) = signalfd;
+ int (*fn2)(int, const sigset_t *, size_t, int) = signalfd4;
+
+ return (int)sizeof(info)
+ + (fn1 == 0)
+ + (fn2 == 0);
+}
diff --git a/tests/sys_timerfd/timerfd.c b/tests/sys_timerfd/timerfd.c
new file mode 100644
--- /dev/null
+++ b/tests/sys_timerfd/timerfd.c
@@ -0,0 +1,29 @@
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/timerfd.h>
+#include <unistd.h>
+
+int main(void) {
+ int fd = timerfd_create(CLOCK_REALTIME, 0);
+ assert(fd >= 0);
+ struct itimerspec spec;
+ memset(&spec, 0, sizeof(spec));
+ spec.it_value.tv_nsec = 1000000;
+ assert(timerfd_settime(fd, 0, &spec, NULL) == 0);
+
+ uint64_t expirations = 0;
+ assert(read(fd, &expirations, sizeof(expirations)) == (ssize_t)sizeof(expirations));
+ assert(expirations >= 1);
+
+ struct itimerspec cur;
+ assert(timerfd_gettime(fd, &cur) == 0);
+
+ memset(&spec, 0, sizeof(spec));
+ spec.it_value.tv_sec = 1;
+ assert(timerfd_settime(fd, TFD_TIMER_ABSTIME, &spec, NULL) == 0);
+ assert(close(fd) == 0);
+ puts("timerfd ok");
+ return 0;
+}
diff --git a/tests/Makefile.tests.mk b/tests/Makefile.tests.mk
--- a/tests/Makefile.tests.mk
+++ b/tests/Makefile.tests.mk
@@ -314,8 +314,12 @@ VARIED_NAMES=\
grp/gr_iter \
semaphore/named \
semaphore/unnamed \
+ sys_eventfd/eventfd \
+ sys_signalfd/header_only \
+ sys_signalfd/signalfd \
+ sys_timerfd/timerfd \
waitid \
waitpid \
waitpid_multiple \
$(FAILING_TESTS)