| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_ptrace_wait.c,v 1.3 2016/11/11 12:01:14 kamil Exp $ */ | | 1 | /* $NetBSD: t_ptrace_wait.c,v 1.4 2016/11/11 17:08:54 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2016 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2016 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __RCSID("$NetBSD: t_ptrace_wait.c,v 1.3 2016/11/11 12:01:14 kamil Exp $"); | | 30 | __RCSID("$NetBSD: t_ptrace_wait.c,v 1.4 2016/11/11 17:08:54 christos Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/types.h> | | 33 | #include <sys/types.h> |
34 | #include <sys/ptrace.h> | | 34 | #include <sys/ptrace.h> |
35 | #include <sys/resource.h> | | 35 | #include <sys/resource.h> |
36 | #include <sys/sysctl.h> | | 36 | #include <sys/sysctl.h> |
37 | #include <sys/wait.h> | | 37 | #include <sys/wait.h> |
38 | #include <err.h> | | 38 | #include <err.h> |
39 | #include <errno.h> | | 39 | #include <errno.h> |
40 | #include <signal.h> | | 40 | #include <signal.h> |
41 | #include <stdint.h> | | 41 | #include <stdint.h> |
42 | #include <stdio.h> | | 42 | #include <stdio.h> |
43 | #include <stdlib.h> | | 43 | #include <stdlib.h> |
| @@ -193,27 +193,28 @@ do { \ | | | @@ -193,27 +193,28 @@ do { \ |
193 | /* | | 193 | /* |
194 | * Helper tools to verify whether status reports exited value | | 194 | * Helper tools to verify whether status reports exited value |
195 | */ | | 195 | */ |
196 | #if TWAIT_HAVE_STATUS | | 196 | #if TWAIT_HAVE_STATUS |
197 | static void __used | | 197 | static void __used |
198 | validate_status_exited(int status, int expected) | | 198 | validate_status_exited(int status, int expected) |
199 | { | | 199 | { |
200 | ATF_REQUIRE_MSG(WIFEXITED(status), "Reported exited process"); | | 200 | ATF_REQUIRE_MSG(WIFEXITED(status), "Reported exited process"); |
201 | ATF_REQUIRE_MSG(!WIFCONTINUED(status), "Reported continued process"); | | 201 | ATF_REQUIRE_MSG(!WIFCONTINUED(status), "Reported continued process"); |
202 | ATF_REQUIRE_MSG(!WIFSIGNALED(status), "Reported signaled process"); | | 202 | ATF_REQUIRE_MSG(!WIFSIGNALED(status), "Reported signaled process"); |
203 | ATF_REQUIRE_MSG(!WIFSTOPPED(status), "Reported stopped process"); | | 203 | ATF_REQUIRE_MSG(!WIFSTOPPED(status), "Reported stopped process"); |
204 | | | 204 | |
205 | ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), expected, | | 205 | ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), expected, |
206 | "The process has exited with invalid value"); | | 206 | "The process has exited with invalid value %d != %d", |
| | | 207 | WEXITSTATUS(status), expected); |
207 | } | | 208 | } |
208 | | | 209 | |
209 | static void __used | | 210 | static void __used |
210 | forkee_status_exited(int status, int expected) | | 211 | forkee_status_exited(int status, int expected) |
211 | { | | 212 | { |
212 | FORKEE_ASSERTX(WIFEXITED(status)); | | 213 | FORKEE_ASSERTX(WIFEXITED(status)); |
213 | FORKEE_ASSERTX(!WIFCONTINUED(status)); | | 214 | FORKEE_ASSERTX(!WIFCONTINUED(status)); |
214 | FORKEE_ASSERTX(!WIFSIGNALED(status)); | | 215 | FORKEE_ASSERTX(!WIFSIGNALED(status)); |
215 | FORKEE_ASSERTX(!WIFSTOPPED(status)); | | 216 | FORKEE_ASSERTX(!WIFSTOPPED(status)); |
216 | | | 217 | |
217 | FORKEE_ASSERTX(WEXITSTATUS(status) == expected); | | 218 | FORKEE_ASSERTX(WEXITSTATUS(status) == expected); |
218 | } | | 219 | } |
219 | | | 220 | |
| @@ -260,28 +261,32 @@ forkee_status_signaled(int status, int e | | | @@ -260,28 +261,32 @@ forkee_status_signaled(int status, int e |
260 | | | 261 | |
261 | FORKEE_ASSERTX(WTERMSIG(status) == expected_termsig); | | 262 | FORKEE_ASSERTX(WTERMSIG(status) == expected_termsig); |
262 | FORKEE_ASSERTX(WCOREDUMP(status) == expected_core); | | 263 | FORKEE_ASSERTX(WCOREDUMP(status) == expected_core); |
263 | } | | 264 | } |
264 | | | 265 | |
265 | static void __used | | 266 | static void __used |
266 | validate_status_stopped(int status, int expected) | | 267 | validate_status_stopped(int status, int expected) |
267 | { | | 268 | { |
268 | ATF_REQUIRE_MSG(!WIFEXITED(status), "Reported exited process"); | | 269 | ATF_REQUIRE_MSG(!WIFEXITED(status), "Reported exited process"); |
269 | ATF_REQUIRE_MSG(!WIFCONTINUED(status), "Reported continued process"); | | 270 | ATF_REQUIRE_MSG(!WIFCONTINUED(status), "Reported continued process"); |
270 | ATF_REQUIRE_MSG(!WIFSIGNALED(status), "Reported signaled process"); | | 271 | ATF_REQUIRE_MSG(!WIFSIGNALED(status), "Reported signaled process"); |
271 | ATF_REQUIRE_MSG(WIFSTOPPED(status), "Reported stopped process"); | | 272 | ATF_REQUIRE_MSG(WIFSTOPPED(status), "Reported stopped process"); |
272 | | | 273 | |
| | | 274 | char st[128], ex[128]; |
| | | 275 | strlcpy(st, strsignal(WSTOPSIG(status)), sizeof(st)); |
| | | 276 | strlcpy(ex, strsignal(expected), sizeof(ex)); |
| | | 277 | |
273 | ATF_REQUIRE_EQ_MSG(WSTOPSIG(status), expected, | | 278 | ATF_REQUIRE_EQ_MSG(WSTOPSIG(status), expected, |
274 | "Unexpected stop signal received"); | | 279 | "Unexpected stop signal received [%s] != [%s]", st, ex); |
275 | } | | 280 | } |
276 | | | 281 | |
277 | static void __used | | 282 | static void __used |
278 | forkee_status_stopped(int status, int expected) | | 283 | forkee_status_stopped(int status, int expected) |
279 | { | | 284 | { |
280 | FORKEE_ASSERTX(!WIFEXITED(status)); | | 285 | FORKEE_ASSERTX(!WIFEXITED(status)); |
281 | FORKEE_ASSERTX(!WIFCONTINUED(status)); | | 286 | FORKEE_ASSERTX(!WIFCONTINUED(status)); |
282 | FORKEE_ASSERTX(!WIFSIGNALED(status)); | | 287 | FORKEE_ASSERTX(!WIFSIGNALED(status)); |
283 | FORKEE_ASSERTX(WIFSTOPPED(status)); | | 288 | FORKEE_ASSERTX(WIFSTOPPED(status)); |
284 | | | 289 | |
285 | FORKEE_ASSERTX(WSTOPSIG(status) == expected); | | 290 | FORKEE_ASSERTX(WSTOPSIG(status) == expected); |
286 | } | | 291 | } |
287 | #else | | 292 | #else |
| @@ -816,29 +821,26 @@ ATF_TC_HEAD(attach3, tc) | | | @@ -816,29 +821,26 @@ ATF_TC_HEAD(attach3, tc) |
816 | } | | 821 | } |
817 | | | 822 | |
818 | ATF_TC_BODY(attach3, tc) | | 823 | ATF_TC_BODY(attach3, tc) |
819 | { | | 824 | { |
820 | int fds_totracee[2], fds_fromtracee[2]; | | 825 | int fds_totracee[2], fds_fromtracee[2]; |
821 | int rv; | | 826 | int rv; |
822 | const int exitval_tracee = 5; | | 827 | const int exitval_tracee = 5; |
823 | pid_t tracee, wpid; | | 828 | pid_t tracee, wpid; |
824 | uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ | | 829 | uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ |
825 | #if defined(TWAIT_HAVE_STATUS) | | 830 | #if defined(TWAIT_HAVE_STATUS) |
826 | int status; | | 831 | int status; |
827 | #endif | | 832 | #endif |
828 | | | 833 | |
829 | /* PT_ATTACH from a parent is unreliable */ | | | |
830 | atf_tc_expect_fail("PR kern/51621"); | | | |
831 | | | | |
832 | printf("Spawn tracee\n"); | | 834 | printf("Spawn tracee\n"); |
833 | ATF_REQUIRE(pipe(fds_totracee) == 0); | | 835 | ATF_REQUIRE(pipe(fds_totracee) == 0); |
834 | ATF_REQUIRE(pipe(fds_fromtracee) == 0); | | 836 | ATF_REQUIRE(pipe(fds_fromtracee) == 0); |
835 | tracee = atf_utils_fork(); | | 837 | tracee = atf_utils_fork(); |
836 | if (tracee == 0) { | | 838 | if (tracee == 0) { |
837 | FORKEE_ASSERT(close(fds_totracee[1]) == 0); | | 839 | FORKEE_ASSERT(close(fds_totracee[1]) == 0); |
838 | FORKEE_ASSERT(close(fds_fromtracee[0]) == 0); | | 840 | FORKEE_ASSERT(close(fds_fromtracee[0]) == 0); |
839 | | | 841 | |
840 | /* Wait for message from the parent */ | | 842 | /* Wait for message from the parent */ |
841 | rv = read(fds_totracee[0], &msg, sizeof(msg)); | | 843 | rv = read(fds_totracee[0], &msg, sizeof(msg)); |
842 | FORKEE_ASSERT(rv == sizeof(msg)); | | 844 | FORKEE_ASSERT(rv == sizeof(msg)); |
843 | | | 845 | |
844 | printf("Parent should now attach to tracee\n"); | | 846 | printf("Parent should now attach to tracee\n"); |