1 /*
2  * Copyright (c) 2022 Meta
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "_common.h"
8 
9 #include <stdlib.h>
10 
11 #ifdef CONFIG_POSIX_API
12 #include <signal.h>
13 #else
14 #include <zephyr/posix/signal.h>
15 #endif
16 
17 /**
18  * @brief existence test for `<signal.h>`
19  *
20  * @see <a href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html">signal.h</a>
21  */
ZTEST(posix_headers,test_signal_h)22 ZTEST(posix_headers, test_signal_h)
23 {
24 	typedef void *(*my_sig_handler_t)(int signo);
25 
26 	my_sig_handler_t handler;
27 
28 	handler = SIG_DFL;
29 	handler = SIG_ERR;
30 	handler = SIG_IGN;
31 	/* zassert_not_equal(-1, SIG_HOLD); */ /* not implemented */
32 
33 	zassert_not_equal((sig_atomic_t)-1, (sig_atomic_t)0);
34 	zassert_not_equal((pid_t)-1, (pid_t)0);
35 
36 	zassert_not_equal(-1, offsetof(struct sigevent, sigev_notify));
37 	zassert_not_equal(-1, offsetof(struct sigevent, sigev_signo));
38 	zassert_not_equal(-1, offsetof(struct sigevent, sigev_value));
39 	zassert_not_equal(-1, offsetof(struct sigevent, sigev_notify_function));
40 	zassert_not_equal(-1, offsetof(struct sigevent, sigev_notify_attributes));
41 
42 	zassert_not_equal(-1, SIGEV_NONE);
43 	zassert_not_equal(-1, SIGEV_SIGNAL);
44 	zassert_not_equal(-1, SIGEV_THREAD);
45 
46 	zassert_not_equal(-1, offsetof(union sigval, sival_int));
47 	zassert_not_equal(-1, offsetof(union sigval, sival_ptr));
48 
49 	zassert_not_equal(-1, RTSIG_MAX);
50 	zassert_true(SIGRTMAX - SIGRTMIN >= RTSIG_MAX);
51 
52 	zassert_not_equal(-1, SIG_BLOCK);
53 	zassert_not_equal(-1, SIG_UNBLOCK);
54 	zassert_not_equal(-1, SIG_SETMASK);
55 
56 	zassert_not_equal(-1, offsetof(struct sigaction, sa_handler));
57 	zassert_not_equal(-1, offsetof(struct sigaction, sa_mask));
58 	zassert_not_equal(-1, offsetof(struct sigaction, sa_flags));
59 	zassert_not_equal(-1, offsetof(struct sigaction, sa_sigaction));
60 
61 	zassert_not_equal(-1, offsetof(siginfo_t, si_signo));
62 	zassert_not_equal(-1, offsetof(siginfo_t, si_code));
63 	zassert_not_equal(-1, offsetof(siginfo_t, si_value));
64 
65 	/* zassert_not_equal(-1, SA_NOCLDSTOP); */ /* not implemented */
66 	/* zassert_not_equal(-1, SA_ONSTACK); */ /* not implemented */
67 	/* zassert_not_equal(-1, SA_RESETHAND); */ /* not implemented */
68 	/* zassert_not_equal(-1, SA_RESTART); */ /* not implemented */
69 	/* zassert_not_equal(-1, SA_SIGINFO); */ /* not implemented */
70 	/* zassert_not_equal(-1, SA_NOCLDWAIT); */ /* not implemented */
71 	/* zassert_not_equal(-1, SA_NODEFER); */ /* not implemented */
72 
73 	/* zassert_not_equal(-1, SS_ONSTACK); */ /* not implemented */
74 	/* zassert_not_equal(-1, SS_DISABLE); */ /* not implemented */
75 
76 	/* zassert_not_equal(-1, MINSIGSTKSZ); */ /* not implemented */
77 	/* zassert_not_equal(-1, SIGSTKSZ); */ /* not implemented */
78 
79 	/* mcontext_t mctx = {0}; */ /* not implemented */
80 
81 	/* zassert_not_equal(-1, offsetof(ucontext_t, uc_link)); */ /* not implemented */
82 	/* zassert_not_equal(-1, offsetof(ucontext_t, uc_sigmask)); */ /* not implemented */
83 	/* zassert_not_equal(-1, offsetof(ucontext_t, uc_stack)); */ /* not implemented */
84 	/* zassert_not_equal(-1, offsetof(ucontext_t, uc_mcontext)); */ /* not implemented */
85 
86 	/* zassert_not_equal(-1, offsetof(stack_t, ss_sp)); */ /* not implemented */
87 	/* zassert_not_equal(-1, offsetof(stack_t, ss_size)); */ /* not implemented */
88 	/* zassert_not_equal(-1, offsetof(stack_t, ss_flags)); */ /* not implemented */
89 
90 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_signo)); */ /* not implemented */
91 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_code)); */ /* not implemented */
92 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_errno)); */ /* not implemented */
93 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_pid)); */ /* not implemented */
94 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_uid)); */ /* not implemented */
95 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_addr)); */ /* not implemented */
96 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_status)); */ /* not implemented */
97 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_band)); */ /* not implemented */
98 	/* zassert_not_equal(-1, offsetof(siginfo_t, si_value)); */ /* not implemented */
99 
100 	/* zassert_not_equal(-1, ILL_ILLOPC); */ /* not implemented */
101 	/* zassert_not_equal(-1, ILL_ILLOPN); */ /* not implemented */
102 	/* zassert_not_equal(-1, ILL_ILLADR); */ /* not implemented */
103 	/* zassert_not_equal(-1, ILL_ILLTRP); */ /* not implemented */
104 	/* zassert_not_equal(-1, ILL_PRVOPC); */ /* not implemented */
105 	/* zassert_not_equal(-1, ILL_PRVREG); */ /* not implemented */
106 	/* zassert_not_equal(-1, ILL_COPROC); */ /* not implemented */
107 	/* zassert_not_equal(-1, ILL_BADSTK); */ /* not implemented */
108 
109 	/* zassert_not_equal(-1, FPE_INTDIV); */ /* not implemented */
110 	/* zassert_not_equal(-1, FPE_INTOVF); */ /* not implemented */
111 	/* zassert_not_equal(-1, FPE_FLTDIV); */ /* not implemented */
112 	/* zassert_not_equal(-1, FPE_FLTOVF); */ /* not implemented */
113 	/* zassert_not_equal(-1, FPE_FLTUND); */ /* not implemented */
114 	/* zassert_not_equal(-1, FPE_FLTRES); */ /* not implemented */
115 	/* zassert_not_equal(-1, FPE_FLTINV); */ /* not implemented */
116 	/* zassert_not_equal(-1, FPE_FLTSUB); */ /* not implemented */
117 
118 	/* zassert_not_equal(-1, SEGV_MAPERR); */ /* not implemented */
119 	/* zassert_not_equal(-1, SEGV_ACCERR); */ /* not implemented */
120 
121 	/* zassert_not_equal(-1, BUS_ADRALN); */ /* not implemented */
122 	/* zassert_not_equal(-1, BUS_ADRERR); */ /* not implemented */
123 	/* zassert_not_equal(-1, BUS_OBJERR); */ /* not implemented */
124 
125 	/* zassert_not_equal(-1, TRAP_BRKPT); */ /* not implemented */
126 	/* zassert_not_equal(-1, TRAP_TRACE); */ /* not implemented */
127 
128 	/* zassert_not_equal(-1, CLD_EXITED); */ /* not implemented */
129 	/* zassert_not_equal(-1, CLD_KILLED); */ /* not implemented */
130 	/* zassert_not_equal(-1, CLD_DUMPED); */ /* not implemented */
131 	/* zassert_not_equal(-1, CLD_TRAPPED); */ /* not implemented */
132 	/* zassert_not_equal(-1, CLD_STOPPED); */ /* not implemented */
133 	/* zassert_not_equal(-1, CLD_CONTINUED); */ /* not implemented */
134 
135 	zassert_not_equal(-1, SI_USER);
136 	zassert_not_equal(-1, SI_QUEUE);
137 	zassert_not_equal(-1, SI_TIMER);
138 	zassert_not_equal(-1, SI_ASYNCIO);
139 	zassert_not_equal(-1, SI_MESGQ);
140 
141 #ifdef CONFIG_POSIX_SIGNALS
142 	zassert_true(SIGRTMIN >= 0);
143 	zassert_true(SIGRTMAX >= SIGRTMIN);
144 	zassert_not_equal(-1, SIGABRT);
145 	zassert_not_equal(-1, SIGALRM);
146 	zassert_not_equal(-1, SIGBUS);
147 	zassert_not_equal(-1, SIGCHLD);
148 	zassert_not_equal(-1, SIGCONT);
149 	zassert_not_equal(-1, SIGFPE);
150 	zassert_not_equal(-1, SIGHUP);
151 	zassert_not_equal(-1, SIGILL);
152 	zassert_not_equal(-1, SIGINT);
153 	zassert_not_equal(-1, SIGKILL);
154 	zassert_not_equal(-1, SIGPIPE);
155 	zassert_not_equal(-1, SIGQUIT);
156 	zassert_not_equal(-1, SIGSEGV);
157 	zassert_not_equal(-1, SIGSTOP);
158 	zassert_not_equal(-1, SIGTERM);
159 	zassert_not_equal(-1, SIGTSTP);
160 	zassert_not_equal(-1, SIGTTIN);
161 	zassert_not_equal(-1, SIGTTOU);
162 	zassert_not_equal(-1, SIGUSR1);
163 	zassert_not_equal(-1, SIGUSR2);
164 	zassert_not_equal(-1, SIGTRAP);
165 	zassert_not_equal(-1, SIGURG);
166 	zassert_not_equal(-1, SIGXCPU);
167 	zassert_not_equal(-1, SIGXFSZ);
168 	zassert_not_equal(((sigset_t){.sig[0] = 0}).sig[0], ((sigset_t){.sig[0] = -1}).sig[0]);
169 	zassert_not_null(abort);
170 	zassert_not_null(alarm);
171 	zassert_not_null(kill);
172 	zassert_not_null(pause);
173 	zassert_not_null(pthread_sigmask);
174 	zassert_not_null(raise);
175 	zassert_not_null(sigaction);
176 	zassert_not_null(sigaddset);
177 	zassert_not_null(sigdelset);
178 	zassert_not_null(sigemptyset);
179 	zassert_not_null(sigfillset);
180 	zassert_not_null(sigismember);
181 	zassert_not_null(signal);
182 	zassert_not_null(sigpending);
183 	zassert_not_null(sigprocmask);
184 	zassert_not_null(sigsuspend);
185 	zassert_not_null(sigwait);
186 	zassert_not_null(strsignal);
187 #endif /* CONFIG_POSIX_SIGNALS */
188 
189 	if (IS_ENABLED(CONFIG_POSIX_API)) {
190 		/* zassert_not_null(killpg); */ /* not implemented */
191 		/* zassert_not_null(psiginfo); */ /* not implemented */
192 		/* zassert_not_null(psignal); */ /* not implemented */
193 		/* zassert_not_null(pthread_kill); */ /* not implemented */
194 		/* zassert_not_null(sigaltstack); */ /* not implemented */
195 		/* zassert_not_null(sighold); */ /* not implemented */
196 		/* zassert_not_null(sigignore); */ /* not implemented */
197 		/* zassert_not_null(siginterrupt); */ /* not implemented */
198 		/* zassert_not_null(sigpause); */ /* not implemented */
199 		/* zassert_not_null(sigqueue); */ /* not implemented */
200 		/* zassert_not_null(sigrelse); */ /* not implemented */
201 		/* zassert_not_null(sigset); */ /* not implemented */
202 		/* zassert_not_null(sigtimedwait); */ /* not implemented */
203 		/* zassert_not_null(sigwaitinfo); */ /* not implemented */
204 	}
205 }
206