[git commit] test/signal: Add tst-signalfd

Mike Frysinger vapier at gentoo.org
Sun Apr 8 21:00:56 UTC 2012


commit: http://git.uclibc.org/uClibc/commit/?id=8272dea0feba7910d7e38fa09c7b35886d88d4c9
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
 test/.gitignore            |    1 +
 test/signal/tst-signalfd.c |   63 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/test/.gitignore b/test/.gitignore
index a39fbec..a86135d 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -247,6 +247,7 @@ signal/sigchld
 signal/signal
 signal/tst-raise
 signal/tst-signal
+signal/tst-signalfd
 signal/tst-sigset
 signal/tst-sigsimple
 silly/hello
diff --git a/test/signal/tst-signalfd.c b/test/signal/tst-signalfd.c
new file mode 100644
index 0000000..1fbb748
--- /dev/null
+++ b/test/signal/tst-signalfd.c
@@ -0,0 +1,63 @@
+/* vi: set sw=4 ts=4 sts=4: */
+/*
+ * signalfd test for uClibc
+ * Copyright (C) 2012 by Kevin Cernekee <cernekee at gmail.com>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <error.h>
+#include <signal.h>
+#include <sys/signalfd.h>
+#include <sys/fcntl.h>
+
+static int
+do_test(void)
+{
+	int fd, ret, result = 0;
+	struct signalfd_siginfo ssi;
+	sigset_t mask;
+
+	sigemptyset(&mask);
+	sigaddset(&mask, SIGUSR1);
+	sigprocmask(SIG_BLOCK, &mask, NULL);
+
+	fd = signalfd(-1, &mask, SFD_NONBLOCK);
+	if (fd < 0) {
+		printf("signalfd() failed: %s\n", strerror(errno));
+		result = 1;
+	}
+
+	/* this should return immediately with EAGAIN due to SFD_NONBLOCK */
+	memset(&ssi, 0, sizeof(ssi));
+	ret = read(fd, &ssi, sizeof(ssi));
+	if (ret != -1 || errno != EAGAIN) {
+		error(0, 0, "first read() returned %d", ret);
+		result = 1;
+	}
+
+	kill(getpid(), SIGUSR1);
+
+	/* this should return a struct ssi indicating receipt of SIGUSR1 */
+	ret = read(fd, &ssi, sizeof(ssi));
+	if (ret != sizeof(ssi)) {
+		error(0, 0, "second read() returned %d", ret);
+		result = 1;
+	}
+
+	if (ssi.ssi_signo != SIGUSR1) {
+		error(0, 0, "ssi contains bogus signo");
+		result = 1;
+	}
+
+	return result;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"


More information about the uClibc-cvs mailing list