OSDN Git Service

Make all the uClibc tests use the --uclibc-use-build-dir flag
[uclinux-h8/uclibc-ng.git] / test / signal / signal.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * signal testing function for uClibc
4  *
5  * Copyright (C) 2000 by Lineo, inc.  Written by Erik Andersen
6  * <andersen@lineo.com>, <andersee@debian.org>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Library General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
16  * for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  */
23
24
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <strings.h>
30 #include <fcntl.h>
31 #include <signal.h>
32
33
34 /* -------------------------------------------------*/
35 /* This stuff is common to all the testing routines */
36 /* -------------------------------------------------*/
37 const char *it = "<UNSET>";             /* Routine name for message routines. */
38 size_t errors = 0;
39
40 void check(int thing, int number)
41 {
42         if (!thing) {
43                 printf("%s: flunked test %d\n", it, number);
44                 ++errors;
45         }
46 }
47
48 void equal(const char *a, const char *b, int number)
49 {
50         check(a != NULL && b != NULL && (strcmp(a, b) == 0), number);
51 }
52
53
54 /* -------------------------------------------------*/
55 /* Let the tests begin....                          */
56 /* -------------------------------------------------*/
57
58 int global_int = 0;
59
60 void set_global_int_to_one(int signum)
61 {
62         printf ("Received signal %d (%s).\n", signum, strsignal(signum));
63         global_int = 1;
64         return;
65 }
66
67 void signal_test_1(void)
68 {
69         global_int = 0;
70
71         it = "global variable set from signal handler";
72         signal(SIGUSR1, set_global_int_to_one);
73         raise(SIGUSR1);
74
75         /* This should already have jumped to the signal handler */
76         check((global_int == 1), 1);
77
78         global_int = 0;
79         signal(SIGUSR1, SIG_IGN);
80         raise(SIGUSR1);
81         /* This should not go to the signal handler this time since we  */
82         check((global_int == 0), 1);
83 }
84
85
86 int main(void)
87 {
88         int status;
89
90         signal_test_1();
91
92         if (errors == 0) {
93                 status = EXIT_SUCCESS;
94                 printf("No errors.\n");
95         } else {
96                 status = EXIT_FAILURE;
97                 printf("%d errors.\n", errors);
98         }
99         exit(status);
100 }