xref: /freebsd/lib/libproc/tests/proc_test.c (revision 9351ac6d696354f83d368557151fedb18b2670fa)
1*9351ac6dSMark Johnston /*-
2*9351ac6dSMark Johnston  * Copyright (c) 2014 Mark Johnston <markj@FreeBSD.org>
3*9351ac6dSMark Johnston  * All rights reserved.
4*9351ac6dSMark Johnston  *
5*9351ac6dSMark Johnston  * Redistribution and use in source and binary forms, with or without
6*9351ac6dSMark Johnston  * modification, are permitted provided that the following conditions
7*9351ac6dSMark Johnston  * are met:
8*9351ac6dSMark Johnston  * 1. Redistributions of source code must retain the above copyright
9*9351ac6dSMark Johnston  *    notice, this list of conditions and the following disclaimer.
10*9351ac6dSMark Johnston  * 2. Redistributions in binary form must reproduce the above copyright
11*9351ac6dSMark Johnston  *    notice, this list of conditions and the following disclaimer in the
12*9351ac6dSMark Johnston  *    documentation and/or other materials provided with the distribution.
13*9351ac6dSMark Johnston  *
14*9351ac6dSMark Johnston  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*9351ac6dSMark Johnston  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*9351ac6dSMark Johnston  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*9351ac6dSMark Johnston  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*9351ac6dSMark Johnston  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*9351ac6dSMark Johnston  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*9351ac6dSMark Johnston  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*9351ac6dSMark Johnston  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*9351ac6dSMark Johnston  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*9351ac6dSMark Johnston  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*9351ac6dSMark Johnston  * SUCH DAMAGE.
25*9351ac6dSMark Johnston  */
26*9351ac6dSMark Johnston 
27*9351ac6dSMark Johnston #include <sys/cdefs.h>
28*9351ac6dSMark Johnston __FBSDID("$FreeBSD$");
29*9351ac6dSMark Johnston 
30*9351ac6dSMark Johnston #include <sys/types.h>
31*9351ac6dSMark Johnston #include <sys/wait.h>
32*9351ac6dSMark Johnston 
33*9351ac6dSMark Johnston #include <libgen.h>
34*9351ac6dSMark Johnston #include <stdio.h>
35*9351ac6dSMark Johnston #include <stdint.h>
36*9351ac6dSMark Johnston #include <stdlib.h>
37*9351ac6dSMark Johnston #include <string.h>
38*9351ac6dSMark Johnston #include <atf-c.h>
39*9351ac6dSMark Johnston #include <libelf.h>
40*9351ac6dSMark Johnston #include <libproc.h>
41*9351ac6dSMark Johnston 
42*9351ac6dSMark Johnston static const char *aout_object = "a.out";
43*9351ac6dSMark Johnston static const char *ldelf_object = "ld-elf.so.1";
44*9351ac6dSMark Johnston static const char *target_prog_file = "target_prog";
45*9351ac6dSMark Johnston 
46*9351ac6dSMark Johnston /*
47*9351ac6dSMark Johnston  * Run the test program. If the sig parameter is set to true, the test program
48*9351ac6dSMark Johnston  * will deliver SIGUSR1 to itself during execution.
49*9351ac6dSMark Johnston  */
50*9351ac6dSMark Johnston static struct proc_handle *
51*9351ac6dSMark Johnston start_prog(const struct atf_tc *tc, bool sig)
52*9351ac6dSMark Johnston {
53*9351ac6dSMark Johnston 	char *argv[3];
54*9351ac6dSMark Johnston 	struct proc_handle *phdl;
55*9351ac6dSMark Johnston 	int error;
56*9351ac6dSMark Johnston 
57*9351ac6dSMark Johnston 	asprintf(&argv[0], "%s/%s", atf_tc_get_config_var(tc, "srcdir"),
58*9351ac6dSMark Johnston 	    target_prog_file);
59*9351ac6dSMark Johnston 	ATF_REQUIRE(argv[0] != NULL);
60*9351ac6dSMark Johnston 
61*9351ac6dSMark Johnston 	if (sig) {
62*9351ac6dSMark Johnston 		argv[1] = strdup("-s");
63*9351ac6dSMark Johnston 		argv[2] = NULL;
64*9351ac6dSMark Johnston 	} else {
65*9351ac6dSMark Johnston 		argv[1] = NULL;
66*9351ac6dSMark Johnston 	}
67*9351ac6dSMark Johnston 
68*9351ac6dSMark Johnston 	error = proc_create(argv[0], argv, NULL, NULL, &phdl);
69*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to run '%s'", target_prog_file);
70*9351ac6dSMark Johnston 	ATF_REQUIRE(phdl != NULL);
71*9351ac6dSMark Johnston 
72*9351ac6dSMark Johnston 	free(argv[0]);
73*9351ac6dSMark Johnston 	free(argv[1]);
74*9351ac6dSMark Johnston 
75*9351ac6dSMark Johnston 	return (phdl);
76*9351ac6dSMark Johnston }
77*9351ac6dSMark Johnston 
78*9351ac6dSMark Johnston static void
79*9351ac6dSMark Johnston set_bkpt(struct proc_handle *phdl, uintptr_t addr, u_long *saved)
80*9351ac6dSMark Johnston {
81*9351ac6dSMark Johnston 	int error;
82*9351ac6dSMark Johnston 
83*9351ac6dSMark Johnston 	error = proc_bkptset(phdl, addr, saved);
84*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to set breakpoint at 0x%jx",
85*9351ac6dSMark Johnston 	    (uintmax_t)addr);
86*9351ac6dSMark Johnston }
87*9351ac6dSMark Johnston 
88*9351ac6dSMark Johnston static void
89*9351ac6dSMark Johnston remove_bkpt(struct proc_handle *phdl, uintptr_t addr, u_long val)
90*9351ac6dSMark Johnston {
91*9351ac6dSMark Johnston 	int error;
92*9351ac6dSMark Johnston 
93*9351ac6dSMark Johnston 	error = proc_bkptdel(phdl, addr, val);
94*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0,
95*9351ac6dSMark Johnston 	    "failed to delete breakpoint at 0x%jx", (uintmax_t)addr);
96*9351ac6dSMark Johnston 
97*9351ac6dSMark Johnston 	error = proc_regset(phdl, REG_PC, addr);
98*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to reset program counter");
99*9351ac6dSMark Johnston }
100*9351ac6dSMark Johnston 
101*9351ac6dSMark Johnston /*
102*9351ac6dSMark Johnston  * Wait for the specified process to hit a breakpoint at the specified symbol.
103*9351ac6dSMark Johnston  */
104*9351ac6dSMark Johnston static void
105*9351ac6dSMark Johnston verify_bkpt(struct proc_handle *phdl, GElf_Sym *sym, const char *symname,
106*9351ac6dSMark Johnston     const char *mapname)
107*9351ac6dSMark Johnston {
108*9351ac6dSMark Johnston 	char mapbname[MAXPATHLEN], *name;
109*9351ac6dSMark Johnston 	GElf_Sym tsym;
110*9351ac6dSMark Johnston 	prmap_t *map;
111*9351ac6dSMark Johnston 	size_t namesz;
112*9351ac6dSMark Johnston 	u_long addr;
113*9351ac6dSMark Johnston 	int error, state;
114*9351ac6dSMark Johnston 
115*9351ac6dSMark Johnston 	state = proc_wstatus(phdl);
116*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(state, PS_STOP, "process has state %d", state);
117*9351ac6dSMark Johnston 
118*9351ac6dSMark Johnston 	/* Get the program counter and decrement it. */
119*9351ac6dSMark Johnston 	error = proc_regget(phdl, REG_PC, &addr);
120*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to obtain PC for '%s'",
121*9351ac6dSMark Johnston 	    target_prog_file);
122*9351ac6dSMark Johnston 	proc_bkptregadj(&addr);
123*9351ac6dSMark Johnston 
124*9351ac6dSMark Johnston 	/*
125*9351ac6dSMark Johnston 	 * Make sure the PC matches the expected value obtained from the symbol
126*9351ac6dSMark Johnston 	 * definition we looked up earlier.
127*9351ac6dSMark Johnston 	 */
128*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(addr, sym->st_value,
129*9351ac6dSMark Johnston 	    "program counter 0x%lx doesn't match expected value 0x%jx",
130*9351ac6dSMark Johnston 	    addr, (uintmax_t)sym->st_value);
131*9351ac6dSMark Johnston 
132*9351ac6dSMark Johnston 	/*
133*9351ac6dSMark Johnston 	 * Ensure we can look up the r_debug_state symbol using its starting
134*9351ac6dSMark Johnston 	 * address and that the resulting symbol matches the one we found using
135*9351ac6dSMark Johnston 	 * a name lookup.
136*9351ac6dSMark Johnston 	 */
137*9351ac6dSMark Johnston 	namesz = strlen(symname) + 1;
138*9351ac6dSMark Johnston 	name = malloc(namesz);
139*9351ac6dSMark Johnston 	ATF_REQUIRE(name != NULL);
140*9351ac6dSMark Johnston 
141*9351ac6dSMark Johnston 	error = proc_addr2sym(phdl, addr, name, namesz, &tsym);
142*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up symbol at 0x%lx", addr);
143*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ(memcmp(sym, &tsym, sizeof(*sym)), 0);
144*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ(strcmp(symname, name), 0);
145*9351ac6dSMark Johnston 	free(name);
146*9351ac6dSMark Johnston 
147*9351ac6dSMark Johnston 	map = proc_addr2map(phdl, addr);
148*9351ac6dSMark Johnston 	ATF_REQUIRE_MSG(map != NULL, "failed to look up map for address 0x%lx",
149*9351ac6dSMark Johnston 	    addr);
150*9351ac6dSMark Johnston 	basename_r(map->pr_mapname, mapbname);
151*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(strcmp(mapname, mapbname), 0,
152*9351ac6dSMark Johnston 	    "expected map name '%s' doesn't match '%s'", mapname, mapbname);
153*9351ac6dSMark Johnston }
154*9351ac6dSMark Johnston 
155*9351ac6dSMark Johnston ATF_TC(map_alias_obj2map);
156*9351ac6dSMark Johnston ATF_TC_HEAD(map_alias_obj2map, tc)
157*9351ac6dSMark Johnston {
158*9351ac6dSMark Johnston 	atf_tc_set_md_var(tc, "descr",
159*9351ac6dSMark Johnston 	    "Callers are supposed to be able to use \"a.out\" as an alias for "
160*9351ac6dSMark Johnston 	    "the program executable. Make sure that proc_obj2map() handles "
161*9351ac6dSMark Johnston 	    "this properly.");
162*9351ac6dSMark Johnston }
163*9351ac6dSMark Johnston ATF_TC_BODY(map_alias_obj2map, tc)
164*9351ac6dSMark Johnston {
165*9351ac6dSMark Johnston 	struct proc_handle *phdl;
166*9351ac6dSMark Johnston 	prmap_t *map1, *map2;
167*9351ac6dSMark Johnston 
168*9351ac6dSMark Johnston 	phdl = start_prog(tc, false);
169*9351ac6dSMark Johnston 
170*9351ac6dSMark Johnston 	/* Initialize the rtld_db handle. */
171*9351ac6dSMark Johnston 	(void)proc_rdagent(phdl);
172*9351ac6dSMark Johnston 
173*9351ac6dSMark Johnston 	/* Ensure that "target_prog" and "a.out" return the same map. */
174*9351ac6dSMark Johnston 	map1 = proc_obj2map(phdl, target_prog_file);
175*9351ac6dSMark Johnston 	ATF_REQUIRE_MSG(map1 != NULL, "failed to look up map for '%s'",
176*9351ac6dSMark Johnston 	    target_prog_file);
177*9351ac6dSMark Johnston 	map2 = proc_obj2map(phdl, aout_object);
178*9351ac6dSMark Johnston 	ATF_REQUIRE_MSG(map2 != NULL, "failed to look up map for '%s'",
179*9351ac6dSMark Johnston 	    aout_object);
180*9351ac6dSMark Johnston 	ATF_CHECK_EQ(strcmp(map1->pr_mapname, map2->pr_mapname), 0);
181*9351ac6dSMark Johnston 
182*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
183*9351ac6dSMark Johnston 
184*9351ac6dSMark Johnston 	proc_free(phdl);
185*9351ac6dSMark Johnston }
186*9351ac6dSMark Johnston 
187*9351ac6dSMark Johnston ATF_TC(map_alias_name2map);
188*9351ac6dSMark Johnston ATF_TC_HEAD(map_alias_name2map, tc)
189*9351ac6dSMark Johnston {
190*9351ac6dSMark Johnston 	atf_tc_set_md_var(tc, "descr",
191*9351ac6dSMark Johnston 	    "Callers are supposed to be able to use \"a.out\" as an alias for "
192*9351ac6dSMark Johnston 	    "the program executable. Make sure that proc_name2map() handles "
193*9351ac6dSMark Johnston 	    "this properly.");
194*9351ac6dSMark Johnston }
195*9351ac6dSMark Johnston ATF_TC_BODY(map_alias_name2map, tc)
196*9351ac6dSMark Johnston {
197*9351ac6dSMark Johnston 	struct proc_handle *phdl;
198*9351ac6dSMark Johnston 	prmap_t *map1, *map2;
199*9351ac6dSMark Johnston 
200*9351ac6dSMark Johnston 	phdl = start_prog(tc, false);
201*9351ac6dSMark Johnston 
202*9351ac6dSMark Johnston 	/* Initialize the rtld_db handle. */
203*9351ac6dSMark Johnston 	(void)proc_rdagent(phdl);
204*9351ac6dSMark Johnston 
205*9351ac6dSMark Johnston 	/* Ensure that "target_prog" and "a.out" return the same map. */
206*9351ac6dSMark Johnston 	map1 = proc_name2map(phdl, target_prog_file);
207*9351ac6dSMark Johnston 	ATF_REQUIRE_MSG(map1 != NULL, "failed to look up map for '%s'",
208*9351ac6dSMark Johnston 	    target_prog_file);
209*9351ac6dSMark Johnston 	map2 = proc_name2map(phdl, aout_object);
210*9351ac6dSMark Johnston 	ATF_REQUIRE_MSG(map2 != NULL, "failed to look up map for '%s'",
211*9351ac6dSMark Johnston 	    aout_object);
212*9351ac6dSMark Johnston 	ATF_CHECK_EQ(strcmp(map1->pr_mapname, map2->pr_mapname), 0);
213*9351ac6dSMark Johnston 
214*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
215*9351ac6dSMark Johnston 
216*9351ac6dSMark Johnston 	proc_free(phdl);
217*9351ac6dSMark Johnston }
218*9351ac6dSMark Johnston 
219*9351ac6dSMark Johnston ATF_TC(map_alias_name2sym);
220*9351ac6dSMark Johnston ATF_TC_HEAD(map_alias_name2sym, tc)
221*9351ac6dSMark Johnston {
222*9351ac6dSMark Johnston 	atf_tc_set_md_var(tc, "descr",
223*9351ac6dSMark Johnston 	    "Callers are supposed to be able to use \"a.out\" as an alias for "
224*9351ac6dSMark Johnston 	    "the program executable. Make sure that proc_name2sym() handles "
225*9351ac6dSMark Johnston 	    "this properly.");
226*9351ac6dSMark Johnston }
227*9351ac6dSMark Johnston ATF_TC_BODY(map_alias_name2sym, tc)
228*9351ac6dSMark Johnston {
229*9351ac6dSMark Johnston 	GElf_Sym sym1, sym2;
230*9351ac6dSMark Johnston 	struct proc_handle *phdl;
231*9351ac6dSMark Johnston 	int error;
232*9351ac6dSMark Johnston 
233*9351ac6dSMark Johnston 	phdl = start_prog(tc, false);
234*9351ac6dSMark Johnston 
235*9351ac6dSMark Johnston 	/* Initialize the rtld_db handle. */
236*9351ac6dSMark Johnston 	(void)proc_rdagent(phdl);
237*9351ac6dSMark Johnston 
238*9351ac6dSMark Johnston 	/*
239*9351ac6dSMark Johnston 	 * Make sure that "target_prog:main" and "a.out:main" return the same
240*9351ac6dSMark Johnston 	 * symbol.
241*9351ac6dSMark Johnston 	 */
242*9351ac6dSMark Johnston 	error = proc_name2sym(phdl, target_prog_file, "main", &sym1);
243*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main' via %s",
244*9351ac6dSMark Johnston 	    target_prog_file);
245*9351ac6dSMark Johnston 	error = proc_name2sym(phdl, aout_object, "main", &sym2);
246*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main' via %s",
247*9351ac6dSMark Johnston 	    aout_object);
248*9351ac6dSMark Johnston 
249*9351ac6dSMark Johnston 	ATF_CHECK_EQ(memcmp(&sym1, &sym2, sizeof(sym1)), 0);
250*9351ac6dSMark Johnston 
251*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
252*9351ac6dSMark Johnston 
253*9351ac6dSMark Johnston 	proc_free(phdl);
254*9351ac6dSMark Johnston }
255*9351ac6dSMark Johnston 
256*9351ac6dSMark Johnston ATF_TC(symbol_lookup);
257*9351ac6dSMark Johnston ATF_TC_HEAD(symbol_lookup, tc)
258*9351ac6dSMark Johnston {
259*9351ac6dSMark Johnston 	atf_tc_set_md_var(tc, "descr",
260*9351ac6dSMark Johnston 	    "Look up a couple of well-known symbols in the test program, place "
261*9351ac6dSMark Johnston 	    "breakpoints on them, and verify that we hit the breakpoints. Also "
262*9351ac6dSMark Johnston 	    "make sure that we can use the breakpoint address to look up the "
263*9351ac6dSMark Johnston 	    "corresponding symbol.");
264*9351ac6dSMark Johnston }
265*9351ac6dSMark Johnston ATF_TC_BODY(symbol_lookup, tc)
266*9351ac6dSMark Johnston {
267*9351ac6dSMark Johnston 	GElf_Sym main_sym, r_debug_state_sym;
268*9351ac6dSMark Johnston 	struct proc_handle *phdl;
269*9351ac6dSMark Johnston 	u_long saved;
270*9351ac6dSMark Johnston 	int error;
271*9351ac6dSMark Johnston 
272*9351ac6dSMark Johnston 	phdl = start_prog(tc, false);
273*9351ac6dSMark Johnston 
274*9351ac6dSMark Johnston 	error = proc_name2sym(phdl, target_prog_file, "main", &main_sym);
275*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'main'");
276*9351ac6dSMark Johnston 
277*9351ac6dSMark Johnston 	error = proc_name2sym(phdl, ldelf_object, "r_debug_state",
278*9351ac6dSMark Johnston 	    &r_debug_state_sym);
279*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(error, 0, "failed to look up 'r_debug_state'");
280*9351ac6dSMark Johnston 
281*9351ac6dSMark Johnston 	set_bkpt(phdl, r_debug_state_sym.st_value, &saved);
282*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
283*9351ac6dSMark Johnston 	verify_bkpt(phdl, &r_debug_state_sym, "r_debug_state", ldelf_object);
284*9351ac6dSMark Johnston 	remove_bkpt(phdl, r_debug_state_sym.st_value, saved);
285*9351ac6dSMark Johnston 
286*9351ac6dSMark Johnston 	set_bkpt(phdl, main_sym.st_value, &saved);
287*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
288*9351ac6dSMark Johnston 	verify_bkpt(phdl, &main_sym, "main", target_prog_file);
289*9351ac6dSMark Johnston 	remove_bkpt(phdl, main_sym.st_value, saved);
290*9351ac6dSMark Johnston 
291*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
292*9351ac6dSMark Johnston 
293*9351ac6dSMark Johnston 	proc_free(phdl);
294*9351ac6dSMark Johnston }
295*9351ac6dSMark Johnston 
296*9351ac6dSMark Johnston ATF_TC(signal_forward);
297*9351ac6dSMark Johnston ATF_TC_HEAD(signal_forward, tc)
298*9351ac6dSMark Johnston {
299*9351ac6dSMark Johnston 	atf_tc_set_md_var(tc, "descr",
300*9351ac6dSMark Johnston 	    "Run the test program in a mode which causes it to send a signal "
301*9351ac6dSMark Johnston 	    "to itself. Make sure that we intercept the signal and that "
302*9351ac6dSMark Johnston 	    "proc_continue() forwards it to the process.");
303*9351ac6dSMark Johnston }
304*9351ac6dSMark Johnston ATF_TC_BODY(signal_forward, tc)
305*9351ac6dSMark Johnston {
306*9351ac6dSMark Johnston 	struct proc_handle *phdl;
307*9351ac6dSMark Johnston 	int state, status;
308*9351ac6dSMark Johnston 
309*9351ac6dSMark Johnston 	phdl = start_prog(tc, true);
310*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
311*9351ac6dSMark Johnston 
312*9351ac6dSMark Johnston 	/* The process should have been interrupted by a signal. */
313*9351ac6dSMark Johnston 	state = proc_wstatus(phdl);
314*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(state, PS_STOP, "process has unexpected state %d",
315*9351ac6dSMark Johnston 	    state);
316*9351ac6dSMark Johnston 
317*9351ac6dSMark Johnston 	/* Continue execution and allow the signal to be delivered. */
318*9351ac6dSMark Johnston 	ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
319*9351ac6dSMark Johnston 
320*9351ac6dSMark Johnston 	/*
321*9351ac6dSMark Johnston 	 * Make sure the process exited with status 0. If it didn't receive the
322*9351ac6dSMark Johnston 	 * SIGUSR1 that it sent to itself, it'll exit with a non-zero exit
323*9351ac6dSMark Johnston 	 * status, causing the test to fail.
324*9351ac6dSMark Johnston 	 */
325*9351ac6dSMark Johnston 	state = proc_wstatus(phdl);
326*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ_MSG(state, PS_UNDEAD, "process has unexpected state %d",
327*9351ac6dSMark Johnston 	    state);
328*9351ac6dSMark Johnston 
329*9351ac6dSMark Johnston 	status = proc_getwstat(phdl);
330*9351ac6dSMark Johnston 	ATF_REQUIRE(status >= 0);
331*9351ac6dSMark Johnston 	ATF_REQUIRE(WIFEXITED(status));
332*9351ac6dSMark Johnston 	ATF_REQUIRE_EQ(WEXITSTATUS(status), 0);
333*9351ac6dSMark Johnston 
334*9351ac6dSMark Johnston 	proc_free(phdl);
335*9351ac6dSMark Johnston }
336*9351ac6dSMark Johnston 
337*9351ac6dSMark Johnston ATF_TP_ADD_TCS(tp)
338*9351ac6dSMark Johnston {
339*9351ac6dSMark Johnston 
340*9351ac6dSMark Johnston 	ATF_TP_ADD_TC(tp, map_alias_obj2map);
341*9351ac6dSMark Johnston 	ATF_TP_ADD_TC(tp, map_alias_name2map);
342*9351ac6dSMark Johnston 	ATF_TP_ADD_TC(tp, map_alias_name2sym);
343*9351ac6dSMark Johnston 	ATF_TP_ADD_TC(tp, symbol_lookup);
344*9351ac6dSMark Johnston 	ATF_TP_ADD_TC(tp, signal_forward);
345*9351ac6dSMark Johnston 
346*9351ac6dSMark Johnston 	return (atf_no_error());
347*9351ac6dSMark Johnston }
348