diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile | 32 | ||||
-rw-r--r-- | tests/abort.c | 7 | ||||
-rw-r--r-- | tests/cont.c | 8 | ||||
-rw-r--r-- | tests/exec.c | 7 | ||||
-rw-r--r-- | tests/exit.c | 5 | ||||
-rw-r--r-- | tests/fork-stop.c | 10 | ||||
-rw-r--r-- | tests/fork.c | 15 | ||||
-rw-r--r-- | tests/kill.c | 8 | ||||
-rw-r--r-- | tests/raise.c | 8 | ||||
-rw-r--r-- | tests/siginfo.c | 64 | ||||
-rw-r--r-- | tests/signal.c | 18 | ||||
-rw-r--r-- | tests/stop.c | 8 | ||||
-rw-r--r-- | tests/threads.c | 21 | ||||
-rw-r--r-- | tests/tstp.c | 8 | ||||
-rw-r--r-- | tests/vfork-exec.c | 18 | ||||
-rw-r--r-- | tests/vfork.c | 14 |
17 files changed, 252 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..a8d6b6c --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +*.t diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..db5caa7 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,32 @@ +.POSIX: + +BIN =\ + abort.t\ + cont.t\ + exec.t\ + exit.t\ + fork.t\ + fork-stop.t\ + kill.t\ + raise.t\ + siginfo.t\ + signal.t\ + stop.t\ + threads.t\ + tstp.t\ + vfork.t\ + vfork-exec.t + +all: $(BIN) +$(BIN): $(@:.t=.c) + +.c.t: + $(CC) -static -pthread -Og -g -o $@ $< -D_XOPEN_SOURCE=700 + +clean: + -rm -f -- $(BIN) + +.SUFFIXES: +.SUFFIXES: .t .c + +.PHONY: all clean diff --git a/tests/abort.c b/tests/abort.c new file mode 100644 index 0000000..3afda7b --- /dev/null +++ b/tests/abort.c @@ -0,0 +1,7 @@ +#include <stdlib.h> + +int +main(void) +{ + abort(); +} diff --git a/tests/cont.c b/tests/cont.c new file mode 100644 index 0000000..8eed336 --- /dev/null +++ b/tests/cont.c @@ -0,0 +1,8 @@ +#include <signal.h> +#include <unistd.h> + +int +main(void) +{ + return kill(getpid(), SIGCONT); +} diff --git a/tests/exec.c b/tests/exec.c new file mode 100644 index 0000000..f9705d1 --- /dev/null +++ b/tests/exec.c @@ -0,0 +1,7 @@ +#include <unistd.h> + +int +main(void) +{ + return execlp("printf", "printf", "hello world\n", NULL); +} diff --git a/tests/exit.c b/tests/exit.c new file mode 100644 index 0000000..adfbe65 --- /dev/null +++ b/tests/exit.c @@ -0,0 +1,5 @@ +int +main(void) +{ + return 3; +} diff --git a/tests/fork-stop.c b/tests/fork-stop.c new file mode 100644 index 0000000..0682848 --- /dev/null +++ b/tests/fork-stop.c @@ -0,0 +1,10 @@ +#include <signal.h> +#include <unistd.h> + +int +main(void) +{ + if (fork() == -1) + return -1; + return kill(getpid(), SIGSTOP); +} diff --git a/tests/fork.c b/tests/fork.c new file mode 100644 index 0000000..7bbc4c2 --- /dev/null +++ b/tests/fork.c @@ -0,0 +1,15 @@ +#include <unistd.h> + +int +main(void) +{ + switch (fork()) { + case -1: + return -1; + case 0: + return 2; + default: + usleep(100000U); + return 1; + } +} diff --git a/tests/kill.c b/tests/kill.c new file mode 100644 index 0000000..67e8e24 --- /dev/null +++ b/tests/kill.c @@ -0,0 +1,8 @@ +#include <signal.h> +#include <unistd.h> + +int +main(void) +{ + return kill(getpid(), SIGKILL); +} diff --git a/tests/raise.c b/tests/raise.c new file mode 100644 index 0000000..555ad21 --- /dev/null +++ b/tests/raise.c @@ -0,0 +1,8 @@ +#include <signal.h> + +int +main(void) +{ + raise(SIGTERM); + return 0; +} diff --git a/tests/siginfo.c b/tests/siginfo.c new file mode 100644 index 0000000..9672870 --- /dev/null +++ b/tests/siginfo.c @@ -0,0 +1,64 @@ +#include <signal.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +const char * +strsigcode(int code) +{ + switch (code) { + case SI_USER: + return "SIG_USER"; + case SI_KERNEL: + return "SIG_KERNEL"; + case SI_QUEUE: + return "SIG_QUEUE"; + case SI_TIMER: + return "SIG_TIMER"; + case SI_MESGQ: + return "SIG_MESGQ"; + case SI_ASYNCIO: + return "SIG_ASYNCIO"; + case SI_SIGIO: + return "SIG_SIGIO"; + case SI_TKILL: + return "SIG_TKILL"; + default: + return "???"; + } +} + +void +handler(int signo, siginfo_t *info, void *frame) +{ + (void) signo; + (void) frame; + fprintf(stderr, ".si_signo: %i (%s)\n", info->si_signo, strsignal(info->si_signo)); + fprintf(stderr, ".si_code: %i (%s)\n", info->si_code, strsigcode(info->si_code)); + fprintf(stderr, ".si_errno: %i\n", info->si_errno); + if (info->si_code == SI_USER || info->si_code == SI_TKILL || info->si_code == SI_QUEUE) { + fprintf(stderr, ".si_pid: %ju\n", info->si_pid); + fprintf(stderr, ".si_uid: %ju\n", info->si_uid); + if (info->si_code == SI_QUEUE) { + fprintf(stderr, ".si_value.sival_int: %i\n", info->si_value.sival_int); + fprintf(stderr, ".si_value.sival_ptr: %p\n", info->si_value.sival_ptr); + } + } + _exit(1); +} + +int +main(void) +{ + static union sigval value; + static struct sigaction sa; + sa.sa_sigaction = handler; + sa.sa_flags = SA_SIGINFO; + sigaction(SIGRTMAX, &sa, 0); + value.sival_int = 1444; + sigqueue(getpid(), SIGRTMAX, value); + pause(); + return 0; +} diff --git a/tests/signal.c b/tests/signal.c new file mode 100644 index 0000000..e4862cd --- /dev/null +++ b/tests/signal.c @@ -0,0 +1,18 @@ +#include <signal.h> +#include <unistd.h> + +static void +interrupt() +{ + write(-2, "xyzzy\n", 6); +} + +int +main(void) +{ + signal(SIGINT, interrupt); + kill(getpid(), SIGINT); + usleep(100000U); + write(-1, "qwerty\n", 7); + return 0; +} diff --git a/tests/stop.c b/tests/stop.c new file mode 100644 index 0000000..05c0e61 --- /dev/null +++ b/tests/stop.c @@ -0,0 +1,8 @@ +#include <signal.h> +#include <unistd.h> + +int +main(void) +{ + return kill(getpid(), SIGSTOP); +} diff --git a/tests/threads.c b/tests/threads.c new file mode 100644 index 0000000..18b0145 --- /dev/null +++ b/tests/threads.c @@ -0,0 +1,21 @@ +#include <pthread.h> +#include <unistd.h> + +static int x; + +static void * +thread_main(void *data) +{ + sleep(1); + return data; +} + +int +main(void) +{ + pthread_t thread; + if (pthread_create(&thread, NULL, thread_main, &x)) + return 2; + sleep(2); + return 1; +} diff --git a/tests/tstp.c b/tests/tstp.c new file mode 100644 index 0000000..ca999a9 --- /dev/null +++ b/tests/tstp.c @@ -0,0 +1,8 @@ +#include <signal.h> +#include <unistd.h> + +int +main(void) +{ + return kill(getpid(), SIGTSTP); +} diff --git a/tests/vfork-exec.c b/tests/vfork-exec.c new file mode 100644 index 0000000..2974ed6 --- /dev/null +++ b/tests/vfork-exec.c @@ -0,0 +1,18 @@ +#include <unistd.h> + +int +main(int argc, char *argv[], char *envp[]) +{ + (void) argc; + argv = (void *)(const char *[]){"/usr/bin/sleep", "1", NULL}; + switch (vfork()) { + case -1: + return -1; + case 0: + execve("", argv, envp); + execve(*argv, argv, envp); + _exit(2); + default: + return 1; + } +} diff --git a/tests/vfork.c b/tests/vfork.c new file mode 100644 index 0000000..d8c61ba --- /dev/null +++ b/tests/vfork.c @@ -0,0 +1,14 @@ +#include <unistd.h> + +int +main(void) +{ + switch (vfork()) { + case -1: + return -1; + case 0: + _exit(2); + default: + return 1; + } +} |