summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile9
-rw-r--r--test/fork.c10
-rw-r--r--test/procpollable.c33
-rw-r--r--test/sfd.c32
-rw-r--r--test/sig.c16
5 files changed, 100 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..36670cb
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,9 @@
+#
+# $Id$
+#
+
+all: fork sig
+
+clean distclean:
+ rm -f fork sig *.o core
+
diff --git a/test/fork.c b/test/fork.c
new file mode 100644
index 0000000..3f68f67
--- /dev/null
+++ b/test/fork.c
@@ -0,0 +1,10 @@
+main()
+{
+ if (fork() == 0)
+ write(1, "child\n", 6);
+ else {
+ wait(0);
+ write(1, "parent\n", 7);
+ }
+ exit(0);
+}
diff --git a/test/procpollable.c b/test/procpollable.c
new file mode 100644
index 0000000..fc599b5
--- /dev/null
+++ b/test/procpollable.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <signal.h>
+#include <sys/procfs.h>
+#include <sys/stropts.h>
+#include <poll.h>
+main()
+{
+ int pid;
+ char proc[32];
+ FILE *pfp;
+ struct pollfd pfd;
+
+ if ((pid = fork()) == 0) {
+ pause();
+ exit(0);
+ }
+ sprintf(proc, "/proc/%d", pid);
+ if ((pfp = fopen(proc, "r+")) == NULL)
+ goto fail;
+ if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
+ goto fail;
+ pfd.fd = fileno(pfp);
+ pfd.events = POLLPRI;
+ if (poll(&pfd, 1, 0) < 0)
+ goto fail;
+ if (!(pfd.revents & POLLPRI))
+ goto fail;
+ kill(pid, SIGKILL);
+ exit(0);
+fail:
+ kill(pid, SIGKILL);
+ exit(1);
+}
diff --git a/test/sfd.c b/test/sfd.c
new file mode 100644
index 0000000..081de01
--- /dev/null
+++ b/test/sfd.c
@@ -0,0 +1,32 @@
+#include <fcntl.h>
+#include <stdio.h>
+main(int argc, char *argv[])
+{
+ int pid = atoi(argv[1]);
+ int sfd;
+ char sname[32];
+ char buf[1024];
+ char *s;
+ int i;
+ int signal, blocked, ignore, caught;
+
+ sprintf(sname, "/proc/%d/stat", pid);
+ if ((sfd = open(sname, O_RDONLY)) == -1) {
+ perror(sname);
+ return 1;
+ }
+ i = read(sfd, buf, 1024);
+ buf[i] = '\0';
+ for (i = 0, s = buf; i < 30; i++) {
+ while (*++s != ' ') {
+ if (!*s)
+ break;
+ }
+ }
+ if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) {
+ fprintf(stderr, "/proc/pid/stat format error\n");
+ return 1;
+ }
+ printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);
+ return 1;
+}
diff --git a/test/sig.c b/test/sig.c
new file mode 100644
index 0000000..930a177
--- /dev/null
+++ b/test/sig.c
@@ -0,0 +1,16 @@
+#include <signal.h>
+main()
+{
+ char buf[1024];
+ void interrupt();
+
+ signal(SIGINT, interrupt);
+ read(0, buf, 1024);
+ write(2, "qwerty\n", 7);
+ exit(0);
+}
+
+interrupt()
+{
+ write(2, "xyzzy\n", 6);
+}