1# $OpenBSD: Makefile,v 1.2 2020/12/17 00:51:12 bluhm Exp $
2
3PROG =		sigpthread
4WARNINGS =	yes
5LDADD =		-lpthread
6DPADD =		${LIBPTHREAD}
7CLEANFILES +=	out
8
9# first test signal delivery while they are blocked
10
11.for t in 0 1 2
12
13REGRESS_TARGETS +=	run-block-thread-3-unblock-$t
14run-block-thread-3-unblock-$t:
15	# block signal
16	# run 3 threads
17	# kill process
18	# suspend threads until signaled
19	# unblock thread $t
20	# handle signal
21	./sigpthread -b -t 3 -u $t >out
22	grep 'signal $t' out
23	test `wc -l <out` = 1
24
25REGRESS_TARGETS +=	run-block-thread-3-sleep-main-unblock-$t
26run-block-thread-3-sleep-main-unblock-$t:
27	# block signal
28	# run 3 threads
29	# suspend threads until signaled
30	# sleep in main thread, signal should be received while suspended
31	# kill process
32	# unblock thread $t
33	# handle signal
34	./sigpthread -b -s -t 3 -u $t >out
35	grep 'signal $t' out
36	test `wc -l <out` = 1
37
38REGRESS_TARGETS +=	run-block-thread-3-unblock-$t-sleep-thread
39run-block-thread-3-sleep-thread-unblock-$t:
40	# block signal
41	# run 3 threads
42	# kill process
43	# sleep in threads, signal should be pending when suspending
44	# suspend threads until signaled
45	# unblock thread $t
46	# handle signal
47	./sigpthread -b -S -t 3 -u $t >out
48	grep 'signal $t' out
49	test `wc -l <out` = 1
50
51REGRESS_TARGETS +=	run-block-thread-3-sleep-unblock-unblock-$t
52run-block-thread-3-sleep-unblock-unblock-$t:
53	# block signal
54	# run 3 threads
55	# kill process
56	# suspend threads until signaled
57	# sleep in thread $t, others should be exited when unblocking
58	# unblock thread $t
59	# handle signal
60	./sigpthread -b -t 3 -U -u $t >out
61	grep 'signal $t' out
62	test `wc -l <out` = 1
63
64REGRESS_TARGETS +=	run-block-thread-3-kill-$t-unblock-$t
65run-block-thread-3-kill-$t-unblock-$t:
66	# block signal
67	# run 3 threads
68	# kill thread $t
69	# suspend threads until signaled
70	# unblock thread $t
71	# handle signal
72	./sigpthread -b -k $t -t 3 -u $t >out
73	grep 'signal $t' out
74	test `wc -l <out` = 1
75
76REGRESS_TARGETS +=	run-block-thread-3-sleep-main-kill-$t-unblock-$t
77run-block-thread-3-sleep-main-kill-$t-unblock-$t:
78	# block signal
79	# run 3 threads
80	# suspend threads until signaled
81	# sleep in main thread, signal should be received while suspended
82	# kill thread $t
83	# unblock thread $t
84	# handle signal
85	./sigpthread -b -k $t -s -t 3 -u $t >out
86	grep 'signal $t' out
87	test `wc -l <out` = 1
88
89REGRESS_TARGETS +=	run-block-thread-3-kill-$t-sleep-thread-unblock-$t
90run-block-thread-3-kill-$t-sleep-thread-unblock-$t:
91	# block signal
92	# run 3 threads
93	# kill thread $t
94	# sleep in threads, signal should be pending when suspending
95	# suspend threads until signaled
96	# unblock thread $t
97	# handle signal
98	./sigpthread -b -k $t -S -t 3 -u $t >out
99	grep 'signal $t' out
100	test `wc -l <out` = 1
101
102REGRESS_TARGETS +=	run-block-thread-3-kill-$t-unblock-$t-sleep-unblock
103run-block-thread-3-kill-$t-unblock-$t-sleep-unblock:
104	# block signal
105	# run 3 threads
106	# kill thread $t
107	# suspend threads until signaled
108	# sleep in thread $t, others should be exited when unblocking
109	# unblock thread $t
110	# handle signal
111	./sigpthread -b -k $t -t 3 -U -u $t >out
112	grep 'signal $t' out
113	test `wc -l <out` = 1
114
115REGRESS_TARGETS +=	run-block-thread-3-kill-$t
116run-block-thread-3-kill-$t:
117	# block signal
118	# run 3 threads
119	# kill thread $t
120	# suspend threads until signaled
121	# unblock all threads
122	# handle signal
123	./sigpthread -b -k $t -t 3 >out
124	grep 'signal $t' out
125	test `wc -l <out` = 1
126
127REGRESS_TARGETS +=	run-block-thread-3-sleep-main-kill-$t
128run-block-thread-3-sleep-main-kill-$t:
129	# block signal
130	# run 3 threads
131	# suspend threads until signaled
132	# sleep in main thread, signal should be received while suspended
133	# kill thread $t
134	# unblock all threads
135	# handle signal
136	./sigpthread -b -k $t -s -t 3 >out
137	grep 'signal $t' out
138	test `wc -l <out` = 1
139
140REGRESS_TARGETS +=	run-block-thread-3-kill-$t-sleep-thread
141run-block-thread-3-kill-$t-sleep-thread:
142	# block signal
143	# run 3 threads
144	# kill thread $t
145	# sleep in threads, signal should be pending when suspending
146	# suspend threads until signaled
147	# unblock all threads
148	# handle signal
149	./sigpthread -b -k $t -S -t 3 >out
150	grep 'signal $t' out
151	test `wc -l <out` = 1
152
153REGRESS_TARGETS +=	run-block-thread-3-kill-$t-sleep-unblock
154run-block-thread-3-kill-$t-sleep-unblock:
155	# block signal
156	# run 3 threads
157	# kill thread $t
158	# suspend threads until signaled
159	# sleep in all threads
160	# unblock all threads
161	# handle signal
162	./sigpthread -b -k $t -t 3 -U >out
163	grep 'signal $t' out
164	test `wc -l <out` = 1
165
166.endfor
167
168REGRESS_TARGETS +=	run-block-thread-3
169run-block-thread-3:
170	# block signal
171	# run 3 threads
172	# kill process
173	# suspend threads until signaled
174	# unblock all threads
175	# handle signal
176	./sigpthread -b -t 3 >out
177	grep 'signal [0-2]' out
178	test `wc -l <out` = 1
179
180REGRESS_TARGETS +=	run-block-thread-3-sleep-main
181run-block-thread-3-sleep-main:
182	# block signal
183	# run 3 threads
184	# suspend threads until signaled
185	# sleep in main thread, signal should be received while suspended
186	# kill process
187	# unblock all threads
188	# handle signal
189	./sigpthread -b -s -t 3 >out
190	grep 'signal [0-2]' out
191	test `wc -l <out` = 1
192
193REGRESS_TARGETS +=	run-block-thread-3-sleep-thread
194run-block-thread-3-sleep-thread:
195	# block signal
196	# run 3 threads
197	# kill process
198	# sleep in threads, signal should be pending when suspending
199	# suspend threads until signaled
200	# unblock all threads
201	# handle signal
202	./sigpthread -b -S -t 3 >out
203	grep 'signal [0-2]' out
204	test `wc -l <out` = 1
205
206REGRESS_TARGETS +=	run-block-thread-3-sleep-unblock
207run-block-thread-3-sleep-unblock:
208	# block signal
209	# run 3 threads
210	# kill process
211	# suspend threads until signaled
212	# sleep in all threads
213	# unblock all threads
214	# handle signal
215	./sigpthread -b -t 3 -U >out
216	grep 'signal [0-2]' out
217	test `wc -l <out` = 1
218
219# check what happens if signals are not blocked but delivered immediately
220
221.for t in 0 1 2
222
223REGRESS_TARGETS +=	run-thread-3-kill-$t
224run-thread-3-kill-$t:
225	# run 3 threads
226	# kill thread $t
227	# handle signal
228	# suspend threads until signaled
229	./sigpthread -k $t -t 3 >out
230	grep 'signal $t' out
231	test `wc -l <out` = 1
232
233REGRESS_TARGETS +=	run-thread-3-sleep-main-kill-$t
234run-thread-3-sleep-main-kill-$t:
235	# run 3 threads
236	# suspend threads until signaled
237	# sleep in main thread, signal should be received while suspended
238	# kill thread $t
239	# handle signal
240	./sigpthread -k $t -s -t 3 >out
241	grep 'signal $t' out
242	test `wc -l <out` = 1
243
244REGRESS_TARGETS +=	run-thread-3-kill-$t-sleep-thread
245run-thread-3-kill-$t-sleep-thread:
246	# run 3 threads
247	# kill thread $t
248	# sleep in threads, signal should be received while sleeping
249	# handle signal
250	# suspend threads until signaled
251	./sigpthread -k $t -S -t 3 >out
252	grep 'signal $t' out
253	test `wc -l <out` = 1
254
255REGRESS_TARGETS +=	run-thread-3-kill-$t-sleep-unblock
256run-thread-3-kill-$t-sleep-unblock:
257	# run 3 threads
258	# kill thread $t
259	# handle signal
260	# suspend threads until signaled
261	# sleep in all threads
262	./sigpthread -k $t -t 3 -U >out
263	grep 'signal $t' out
264	test `wc -l <out` = 1
265
266.endfor
267
268REGRESS_TARGETS +=	run-thread-3
269run-thread-3:
270	# run 3 threads
271	# kill process
272	# handle signal
273	# suspend threads until signaled
274	./sigpthread -t 3 >out
275	grep 'signal [0-2]' out
276	test `wc -l <out` = 1
277
278REGRESS_TARGETS +=	run-thread-3-sleep-main
279run-thread-3-sleep-main:
280	# block signal
281	# run 3 threads
282	# suspend threads until signaled
283	# sleep in main thread, signal should be received while suspended
284	# kill process
285	# handle signal
286	./sigpthread -s -t 3 >out
287	grep 'signal [0-2]' out
288	test `wc -l <out` = 1
289
290REGRESS_TARGETS +=	run-thread-3-sleep-thread
291run-thread-3-sleep-thread:
292	# run 3 threads
293	# kill process
294	# sleep in threads, signal should be received while sleeping
295	# handle signal
296	# suspend threads until signaled
297	./sigpthread -S -t 3 >out
298	grep 'signal [0-2]' out
299	test `wc -l <out` = 1
300
301REGRESS_TARGETS +=	run-thread-3-sleep-unblock
302run-thread-3-sleep-unblock:
303	# run 3 threads
304	# kill process
305	# handle signal
306	# suspend threads until signaled
307	# sleep in all threads
308	./sigpthread -t 3 -U >out
309	grep 'signal [0-2]' out
310	test `wc -l <out` = 1
311
312# signals are blocked and received by sigwait
313
314.for t in 0 1 2
315
316REGRESS_TARGETS +=	run-block-thread-3-waiter-$t
317run-block-thread-3-waiter-$t:
318	# block signal
319	# run 3 threads
320	# kill process
321	# wait for signal in thread $t
322	# suspend threads until signaled
323	./sigpthread -b -t 3 -w $t >out
324	grep 'signal $t' out
325	test `wc -l <out` = 1
326
327REGRESS_TARGETS +=	run-block-thread-3-sleep-main-waiter-$t
328run-block-thread-3-sleep-main-waiter-$t:
329	# block signal
330	# run 3 threads
331	# wait for signal in thread $t
332	# suspend threads until signaled
333	# sleep in main thread, signal should be received while waiting
334	# kill process
335	./sigpthread -b -s -t 3 -w $t >out
336	grep 'signal $t' out
337	test `wc -l <out` = 1
338
339REGRESS_TARGETS +=	run-block-thread-3-waiter-$t-sleep-thread
340run-block-thread-3-sleep-thread-waiter-$t:
341	# block signal
342	# run 3 threads
343	# kill process
344	# sleep in threads, signal should be pending when waiting
345	# wait for signal in thread $t
346	# suspend threads until signaled
347	./sigpthread -b -S -t 3 -w $t >out
348	grep 'signal $t' out
349	test `wc -l <out` = 1
350
351REGRESS_TARGETS +=	run-block-thread-3-kill-$t-waiter-$t
352run-block-thread-3-kill-$t-waiter-$t:
353	# block signal
354	# run 3 threads
355	# kill thread $t
356	# wait for signal in thread $t
357	# suspend threads until signaled
358	./sigpthread -b -k $t -t 3 -w $t >out
359	grep 'signal $t' out
360	test `wc -l <out` = 1
361
362REGRESS_TARGETS +=	run-block-thread-3-sleep-main-kill-$t-waiter-$t
363run-block-thread-3-sleep-main-kill-$t-waiter-$t:
364	# block signal
365	# run 3 threads
366	# wait for signal in thread $t
367	# suspend threads until signaled
368	# sleep in main thread, signal should be received while waiting
369	# kill thread $t
370	./sigpthread -b -k $t -s -t 3 -w $t >out
371	grep 'signal $t' out
372	test `wc -l <out` = 1
373
374REGRESS_TARGETS +=	run-block-thread-3-kill-$t-sleep-thread-waiter-$t
375run-block-thread-3-kill-$t-sleep-thread-waiter-$t:
376	# block signal
377	# run 3 threads
378	# kill thread $t
379	# sleep in threads, signal should be pending when waiting
380	# wait for signal in thread $t
381	# suspend threads until signaled
382	./sigpthread -b -k $t -S -t 3 -w $t >out
383	grep 'signal $t' out
384	test `wc -l <out` = 1
385
386.endfor
387
388# simple tests with much more threads
389
390REGRESS_TARGETS +=	run-block-thread-100-unblock-23
391run-block-thread-100-unblock-23:
392	# block signal
393	# run 100 threads
394	# kill process
395	# suspend threads until signaled
396	# unblock thread 23
397	# handle signal
398	./sigpthread -b -t 100 -u 23 >out
399	grep 'signal 23' out
400	test `wc -l <out` = 1
401
402REGRESS_TARGETS +=	run-block-thread-100-waiter-42
403run-block-thread-100-waiter-42:
404	# block signal
405	# run 100 threads
406	# kill process
407	# wait for signal in thread 42
408	# suspend threads until signaled
409	./sigpthread -b -t 100 -w 42 >out
410	grep 'signal 42' out
411	test `wc -l <out` = 1
412
413${REGRESS_TARGETS}: ${PROG}
414
415.include <bsd.regress.mk>
416