|
|
1.1 root 1: /* The Plum Hall Validation Suite for C
2: * Unpublished copyright (c) 1986-1991, Chiron Systems Inc and Plum Hall Inc.
3: * VERSION: 4
4: * DATE: 1993-01-01
5: * The "ANSI" mode of this suite corresponds to official ANSI C, X3.159-1989.
6: * As per your license agreement, your distribution is not to be moved or copied outside the Designated Site
7: * without specific permission from Plum Hall Inc.
8: */
9:
10:
11: #include "flags.h"
12: #define LIB_TEST 1
13: #include "defs.h" /* 92/05/04 moved here from line 18 */
14: #ifndef SKIP47
15: /*
16: * 4.7 - Signal handling. Both signal() and raise() are tested here.
17: * This file is not relevant for pre ANSI C.
18: */
19:
20: #if !ANSI
21: void d4_7() { }
22: #else
23:
24: #include <signal.h>
25: void d4_7x(int);
26: void d4_7y(void);
27: static volatile sig_atomic_t flag = 0;
28: volatile sig_atomic_t flag_sig = 0;
29: void (*prev_fn)(int) = SIG_DFL;
30: static int num_sig[] = {SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM};
31: typedef void (*PIF)(int);
32: PIF d4_7b(int);
33: void d4_7b_2(int);
34:
35: void d4_7()
36: {
37: int i, j;
38:
39: Filename = "d47.c";
40:
41: /* make sure that these are actually macros */
42: #if !defined(SIG_DFL) || !defined(SIG_ERR) || !defined(SIG_IGN)
43: complain(__LINE__);
44: #elif !defined(SIGABRT) || !defined(SIGFPE) || !defined(SIGILL)
45: complain(__LINE__);
46: #elif !defined(SIGINT) || !defined(SIGSEGV) || !defined(SIGTERM)
47: complain(__LINE__);
48: #endif
49:
50:
51:
52:
53: /* test that SIG modes are distinct and of type void (*)(int) */
54: checkthat(__LINE__, SIG_DFL != SIG_ERR && SIG_DFL != SIG_IGN && SIG_ERR != SIG_IGN);
55: {void (*p)(int) = SIG_DFL; checkthat(__LINE__, sizeof(void (*)(int)) == sizeof(SIG_DFL));}
56: {void (*p)(int) = SIG_ERR; checkthat(__LINE__, sizeof(void (*)(int)) == sizeof(SIG_ERR));}
57: {void (*p)(int) = SIG_IGN; checkthat(__LINE__, sizeof(void (*)(int)) == sizeof(SIG_IGN));}
58:
59: /* test that SIG numbers are positive and distinct */
60: for (i = 0; i < 6; ++i)
61: {
62: checkthat(__LINE__, num_sig[i] > 0);
63: for (j = 0; j < i; ++j)
64: inotequals(__LINE__, num_sig[i], num_sig[j]);
65: }
66:
67:
68:
69: /* 4.7.1.1 signal
70: * it can be set to a user function ... raise should change the flag
71: */
72: signal(SIGINT, d4_7x);
73: /* 4.7.2.1 raise
74: */
75: iequals(__LINE__, raise(SIGINT), 0);
76: iequals(__LINE__, flag, 2);
77:
78: /* after the raise, the signal handler MAY have set SIG_DFL */
79: checkthat( - __LINE__, signal(SIGINT, d4_7x) == SIG_DFL);
80:
81: /* the signal can be set to ignore the raise */
82: flag = 0;
83: signal(SIGINT, SIG_IGN);
84: iequals(__LINE__, raise(SIGINT), 0);
85: iequals(__LINE__, flag, 0);
86:
87: /* the return from signal should be the "previous" value */
88: signal(SIGINT, d4_7x);
89: checkthat(__LINE__, d4_7x == signal(SIGINT, SIG_DFL));
90:
91: /* more extensive raise tests, with externally-linked subfunctions */
92: checkthat(__LINE__, d4_7b(SIGABRT) != SIG_ERR);
93: flag_sig = 0;
94: raise(SIGABRT);
95: checkthat(__LINE__, flag_sig == (sig_atomic_t)SIGABRT);
96: prev_fn = signal(SIGABRT, SIG_DFL);
97: checkthat( - __LINE__, prev_fn == SIG_DFL);
98:
99:
100:
101:
102:
103: checkthat(__LINE__, d4_7b(SIGTERM) != SIG_ERR);
104: flag_sig = 0;
105: raise(SIGTERM);
106: checkthat(__LINE__, flag_sig == (sig_atomic_t)SIGTERM);
107: prev_fn = signal(SIGTERM, SIG_DFL);
108: checkthat( - __LINE__, prev_fn == SIG_DFL);
109:
110: /* test that signal returns the previous handler */
111: prev_fn = signal(SIGTERM, SIG_IGN);
112: prev_fn = signal(SIGTERM, SIG_DFL);
113: checkthat(__LINE__, prev_fn == SIG_IGN);
114:
115: /* test that we can longjmp out of the signal handler */
116: d4_7y();
117:
118: /* test that bad SIG numbers are diagnosed */
119: /* (But test is only a warning, because signal numbers are implem-def'ed.) */
120: checkthat( - __LINE__, SIG_ERR == signal(100+SIGABRT+SIGFPE+SIGILL+SIGINT+SIGSEGV+SIGTERM, SIG_IGN));
121: }
122:
123:
124:
125:
126: void d4_7x(signo)
127: int signo;
128: {
129: iequals(__LINE__, signo, SIGINT);
130: flag = 2;
131: }
132:
133: /* make sure that a signal handler can do a longjmp */
134: #include <setjmp.h>
135: jmp_buf d7jbuf = {0};
136: void d4_7y()
137: {
138: signal(SIGINT, d4_7b_2);
139: if (setjmp(d7jbuf) == 0)
140: {
141: raise(SIGINT);
142: /* this line should never be reached */
143: complain(__LINE__);
144: }
145: }
146:
147: #endif
148:
149: #else /* if SKIP47 */
150: void d4_7() { pr_skip("d4_7: SKIPPED ENTIRELY\n"); }
151: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.