Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/kernel Simplify code, prefer strerror(3) over sys_errl...
details: https://anonhg.NetBSD.org/src/rev/e27e7d5bc92d
branches: trunk
changeset: 348713:e27e7d5bc92d
user: kamil <kamil%NetBSD.org@localhost>
date: Thu Nov 03 18:54:16 2016 +0000
description:
Simplify code, prefer strerror(3) over sys_errlist(3)
No functional change intended.
strerror(3) change requested by <kre>.
Sponsored by <The NetBSD Foundation>.
diffstat:
tests/kernel/t_ptrace.c | 454 +++++++++++++++++++++++------------------------
1 files changed, 218 insertions(+), 236 deletions(-)
diffs (truncated from 605 to 300 lines):
diff -r a2585a66f986 -r e27e7d5bc92d tests/kernel/t_ptrace.c
--- a/tests/kernel/t_ptrace.c Thu Nov 03 18:25:54 2016 +0000
+++ b/tests/kernel/t_ptrace.c Thu Nov 03 18:54:16 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace.c,v 1.5 2016/11/03 18:25:54 kamil Exp $ */
+/* $NetBSD: t_ptrace.c,v 1.6 2016/11/03 18:54:16 kamil Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace.c,v 1.5 2016/11/03 18:25:54 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace.c,v 1.6 2016/11/03 18:54:16 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -67,8 +67,7 @@
/* "2: Before calling ptrace(PT_TRACE_ME, ...)\n" */
if (ptrace(PT_TRACE_ME, 0, NULL, 0) == -1) {
/* XXX: Is it safe to use ATF functions in a child? */
- err(EXIT_FAILURE, "2: ptrace(2) call failed with "
- "status %s", sys_errlist[errno]);
+ err(EXIT_FAILURE, "2: ptrace(2) call failed");
}
/* "2: Before raising SIGSTOP\n" */
@@ -76,72 +75,70 @@
/* "2: Before calling _exit(%d)\n", exitval */
_exit(exitval);
- } else {
- printf("1: Parent process PID=%d, child's PID=%d\n", getpid(),
- child);
+ }
+ printf("1: Parent process PID=%d, child's PID=%d\n", getpid(), child);
- printf("1: Before calling waitpid() for the child\n");
- wpid = waitpid(child, &status, 0);
+ printf("1: Before calling waitpid() for the child\n");
+ wpid = waitpid(child, &status, 0);
- printf("1: Validating child's PID (expected %d, got %d)\n",
- child, wpid);
- ATF_REQUIRE(child == wpid);
+ printf("1: Validating child's PID (expected %d, got %d)\n", child,
+ wpid);
+ ATF_REQUIRE(child == wpid);
- printf("1: Ensuring that the child has not been exited\n");
- ATF_REQUIRE(!WIFEXITED(status));
+ printf("1: Ensuring that the child has not been exited\n");
+ ATF_REQUIRE(!WIFEXITED(status));
+
+ printf("1: Ensuring that the child has not been continued\n");
+ ATF_REQUIRE(!WIFCONTINUED(status));
- printf("1: Ensuring that the child has not been continued\n");
- ATF_REQUIRE(!WIFCONTINUED(status));
+ printf("1: Ensuring that the child has not been terminated with a "
+ "signal\n");
+ ATF_REQUIRE(!WIFSIGNALED(status));
- printf("1: Ensuring that the child has not been terminated "
- "with a signal\n");
- ATF_REQUIRE(!WIFSIGNALED(status));
+ printf("1: Ensuring that the child has been stopped\n");
+ ATF_REQUIRE(WIFSTOPPED(status));
- printf("1: Ensuring that the child has been stopped\n");
- ATF_REQUIRE(WIFSTOPPED(status));
+ printf("1: Verifying that he child has been stopped with the %s "
+ "signal (received %s)\n", sys_signame[sigval],
+ sys_signame[WSTOPSIG(status)]);
+ ATF_REQUIRE(WSTOPSIG(status) == sigval);
- printf("1: Verifying that he child has been stopped with the"
- " %s signal (received %s)\n", sys_signame[sigval],
- sys_signame[WSTOPSIG(status)]);
- ATF_REQUIRE(WSTOPSIG(status) == sigval);
-
- printf("1: Before resuming the child process where it left "
- "off and without signal to be sent\n");
- ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
+ printf("1: Before resuming the child process where it left off and "
+ "without signal to be sent\n");
+ ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
- printf("1: Before calling waitpid() for the child\n");
- wpid = waitpid(child, &status, 0);
+ printf("1: Before calling waitpid() for the child\n");
+ wpid = waitpid(child, &status, 0);
- printf("1: Validating that child's PID is still there\n");
- ATF_REQUIRE(wpid == child);
+ printf("1: Validating that child's PID is still there\n");
+ ATF_REQUIRE(wpid == child);
- printf("1: Ensuring that the child has been exited\n");
- ATF_REQUIRE(WIFEXITED(status));
+ printf("1: Ensuring that the child has been exited\n");
+ ATF_REQUIRE(WIFEXITED(status));
- printf("1: Ensuring that the child has not been continued\n");
- ATF_REQUIRE(!WIFCONTINUED(status));
+ printf("1: Ensuring that the child has not been continued\n");
+ ATF_REQUIRE(!WIFCONTINUED(status));
- printf("1: Ensuring that the child has not been terminated "
- "with a signal\n");
- ATF_REQUIRE(!WIFSIGNALED(status));
+ printf("1: Ensuring that the child has not been terminated with a "
+ "signal\n");
+ ATF_REQUIRE(!WIFSIGNALED(status));
- printf("1: Ensuring that the child has not been stopped\n");
- ATF_REQUIRE(!WIFSTOPPED(status));
+ printf("1: Ensuring that the child has not been stopped\n");
+ ATF_REQUIRE(!WIFSTOPPED(status));
- printf("1: Verifying that he child has exited with the "
- "%d status (received %d)\n", exitval, WEXITSTATUS(status));
- ATF_REQUIRE(WEXITSTATUS(status) == exitval);
+ printf("1: Verifying that he child has exited with the %d status "
+ "(received %d)\n", exitval, WEXITSTATUS(status));
+ ATF_REQUIRE(WEXITSTATUS(status) == exitval);
- printf("1: Before calling waitpid() for the exited child\n");
- wpid = waitpid(child, &status, 0);
+ printf("1: Before calling waitpid() for the exited child\n");
+ wpid = waitpid(child, &status, 0);
- printf("1: Validating that child's PID no longer exists\n");
- ATF_REQUIRE(wpid == -1);
+ printf("1: Validating that child's PID no longer exists\n");
+ ATF_REQUIRE(wpid == -1);
- printf("1: Validating that errno is set to %s (got %s)\n",
- sys_errlist[ECHILD], sys_errlist[errno]);
- ATF_REQUIRE(errno == ECHILD);
- }
+ printf("1: Validating that errno is set to %s (got %s)\n",
+ strerror(ECHILD), strerror(errno));
+ ATF_REQUIRE(errno == ECHILD);
}
ATF_TC(traceme2);
@@ -180,8 +177,7 @@
/* "2: Before calling ptrace(PT_TRACE_ME, ...)\n" */
if (ptrace(PT_TRACE_ME, 0, NULL, 0) == -1) {
/* XXX: Is it safe to use ATF functions in a child? */
- err(EXIT_FAILURE, "2: ptrace(2) call failed with "
- "status %s", sys_errlist[errno]);
+ err(EXIT_FAILURE, "2: ptrace(2) call failed");
}
/* "2: Setup sigaction(2) in the child" */
@@ -190,8 +186,7 @@
sigemptyset(&sa.sa_mask);
if (sigaction(sigsent, &sa, NULL) == -1)
- err(EXIT_FAILURE, "2: sigaction(2) call failed with "
- "status %s", sys_errlist[errno]);
+ err(EXIT_FAILURE, "2: sigaction(2) call failed");
/* "2: Before raising SIGSTOP\n" */
raise(sigval);
@@ -203,74 +198,70 @@
/* "2: Before calling _exit(%d)\n", exitval */
_exit(exitval);
- } else {
- printf("1: Parent process PID=%d, child's PID=%d\n", getpid(),
- child);
+ }
+ printf("1: Parent process PID=%d, child's PID=%d\n", getpid(), child);
- printf("1: Before calling waitpid() for the child\n");
- wpid = waitpid(child, &status, 0);
+ printf("1: Before calling waitpid() for the child\n");
+ wpid = waitpid(child, &status, 0);
- printf("1: Validating child's PID (expected %d, got %d)\n",
- child, wpid);
- ATF_REQUIRE(child == wpid);
+ printf("1: Validating child's PID (expected %d, got %d)\n", child,
+ wpid);
+ ATF_REQUIRE(child == wpid);
- printf("1: Ensuring that the child has not been exited\n");
- ATF_REQUIRE(!WIFEXITED(status));
+ printf("1: Ensuring that the child has not been exited\n");
+ ATF_REQUIRE(!WIFEXITED(status));
+
+ printf("1: Ensuring that the child has not been continued\n");
+ ATF_REQUIRE(!WIFCONTINUED(status));
- printf("1: Ensuring that the child has not been continued\n");
- ATF_REQUIRE(!WIFCONTINUED(status));
+ printf("1: Ensuring that the child has not been terminated with a "
+ "signal\n");
+ ATF_REQUIRE(!WIFSIGNALED(status));
- printf("1: Ensuring that the child has not been terminated "
- "with a signal\n");
- ATF_REQUIRE(!WIFSIGNALED(status));
+ printf("1: Ensuring that the child has been stopped\n");
+ ATF_REQUIRE(WIFSTOPPED(status));
- printf("1: Ensuring that the child has been stopped\n");
- ATF_REQUIRE(WIFSTOPPED(status));
+ printf("1: Verifying that he child has been stopped with the %s "
+ "signal (received %s)\n", sys_signame[sigval],
+ sys_signame[WSTOPSIG(status)]);
+ ATF_REQUIRE(WSTOPSIG(status) == sigval);
- printf("1: Verifying that he child has been stopped with the"
- " %s signal (received %s)\n", sys_signame[sigval],
- sys_signame[WSTOPSIG(status)]);
- ATF_REQUIRE(WSTOPSIG(status) == sigval);
+ printf("1: Before resuming the child process where it left off and "
+ "with signal %s to be sent\n", sys_signame[sigsent]);
+ ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1);
- printf("1: Before resuming the child process where it left "
- "off and with signal %s to be sent\n",
- sys_signame[sigsent]);
- ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent)
- != -1);
+ printf("1: Before calling waitpid() for the child\n");
+ wpid = waitpid(child, &status, 0);
- printf("1: Before calling waitpid() for the child\n");
- wpid = waitpid(child, &status, 0);
+ printf("1: Validating that child's PID is still there\n");
+ ATF_REQUIRE(wpid == child);
- printf("1: Validating that child's PID is still there\n");
- ATF_REQUIRE(wpid == child);
+ printf("1: Ensuring that the child has been exited\n");
+ ATF_REQUIRE(WIFEXITED(status));
- printf("1: Ensuring that the child has been exited\n");
- ATF_REQUIRE(WIFEXITED(status));
+ printf("1: Ensuring that the child has not been continued\n");
+ ATF_REQUIRE(!WIFCONTINUED(status));
- printf("1: Ensuring that the child has not been continued\n");
- ATF_REQUIRE(!WIFCONTINUED(status));
+ printf("1: Ensuring that the child has not been terminated with a "
+ "signal\n");
+ ATF_REQUIRE(!WIFSIGNALED(status));
- printf("1: Ensuring that the child has not been terminated "
- "with a signal\n");
- ATF_REQUIRE(!WIFSIGNALED(status));
+ printf("1: Ensuring that the child has not been stopped\n");
+ ATF_REQUIRE(!WIFSTOPPED(status));
- printf("1: Ensuring that the child has not been stopped\n");
- ATF_REQUIRE(!WIFSTOPPED(status));
-
- printf("1: Verifying that he child has exited with the "
- "%d status (received %d)\n", exitval, WEXITSTATUS(status));
- ATF_REQUIRE(WEXITSTATUS(status) == exitval);
+ printf("1: Verifying that he child has exited with the %d status "
+ "(received %d)\n", exitval, WEXITSTATUS(status));
+ ATF_REQUIRE(WEXITSTATUS(status) == exitval);
- printf("1: Before calling waitpid() for the exited child\n");
- wpid = waitpid(child, &status, 0);
+ printf("1: Before calling waitpid() for the exited child\n");
+ wpid = waitpid(child, &status, 0);
- printf("1: Validating that child's PID no longer exists\n");
- ATF_REQUIRE(wpid == -1);
+ printf("1: Validating that child's PID no longer exists\n");
+ ATF_REQUIRE(wpid == -1);
- printf("1: Validating that errno is set to %s (got %s)\n",
- sys_errlist[ECHILD], sys_errlist[errno]);
- ATF_REQUIRE(errno == ECHILD);
- }
+ printf("1: Validating that errno is set to %s (got %s)\n",
+ strerror(ECHILD), strerror(errno));
+ ATF_REQUIRE(errno == ECHILD);
}
ATF_TC(traceme3);
@@ -295,8 +286,7 @@
/* "2: Before calling ptrace(PT_TRACE_ME, ...)\n" */
if (ptrace(PT_TRACE_ME, 0, NULL, 0) == -1) {
/* XXX: Is it safe to use ATF functions in a child? */
- err(EXIT_FAILURE, "2: ptrace(2) call failed with "
- "status %s", sys_errlist[errno]);
+ err(EXIT_FAILURE, "2: ptrace(2) call failed");
}
/* "2: Before raising SIGSTOP\n" */
Home |
Main Index |
Thread Index |
Old Index