Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/kernel Turn err() into atf_tc_fail_errno() for parent ...
details: https://anonhg.NetBSD.org/src/rev/ef56c689bd2e
branches: trunk
changeset: 935071:ef56c689bd2e
user: rin <rin%NetBSD.org@localhost>
date: Wed Jun 24 05:59:18 2020 +0000
description:
Turn err() into atf_tc_fail_errno() for parent process, so that
atf can catch failures correctly.
diffstat:
tests/kernel/t_pty.c | 41 +++++++++++++++++++++--------------------
1 files changed, 21 insertions(+), 20 deletions(-)
diffs (140 lines):
diff -r 06535fa85337 -r ef56c689bd2e tests/kernel/t_pty.c
--- a/tests/kernel/t_pty.c Wed Jun 24 05:06:08 2020 +0000
+++ b/tests/kernel/t_pty.c Wed Jun 24 05:59:18 2020 +0000
@@ -1,4 +1,4 @@
-/* $Id: t_pty.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */
+/* $Id: t_pty.c,v 1.3 2020/06/24 05:59:18 rin Exp $ */
/*
* Allocates a pty(4) device, and sends the specified number of packets of the
@@ -9,7 +9,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_pty.c,v 1.2 2017/01/13 21:30:41 christos Exp $");
+__RCSID("$NetBSD: t_pty.c,v 1.3 2020/06/24 05:59:18 rin Exp $");
#include <errno.h>
#include <err.h>
@@ -31,6 +31,8 @@
#include <sys/wait.h>
#ifdef STANDALONE
+#define atf_tc_fail_errno(fmt, ...) err(EXIT_FAILURE, fmt, ## __VA_ARGS__)
+#define atf_tc_fail(fmt, ...) errx(EXIT_FAILURE, fmt, ## __VA_ARGS__)
static __dead void usage(const char *);
static void parse_args(int, char **);
#else
@@ -59,7 +61,7 @@
int status;
pid_t child;
if ((dbuf = calloc(1, buffer_size)) == NULL)
- err(EXIT_FAILURE, "malloc(%zu)", buffer_size);
+ atf_tc_fail_errno("malloc(%zu)", buffer_size);
if (verbose)
(void)printf(
@@ -84,7 +86,7 @@
"parent: attempting to write %zu bytes to PTY\n",
buffer_size);
if ((size = write(pty, dbuf, buffer_size)) == -1) {
- err(EXIT_FAILURE, "parent: write()");
+ atf_tc_fail_errno("parent: write()");
break;
}
if (verbose)
@@ -94,9 +96,9 @@
if (verbose)
(void)printf("parent: waiting for child to exit\n");
if (waitpid(child, &status, 0) == -1)
- err(EXIT_FAILURE, "waitpid");
+ atf_tc_fail_errno("waitpid");
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
- errx(EXIT_FAILURE, "child failed");
+ atf_tc_fail("child failed");
if (verbose)
(void)printf("parent: closing PTY\n");
@@ -113,19 +115,18 @@
if (qsize) {
int opt = qsize;
if (ioctl(fd, TIOCSQSIZE, &opt) == -1)
- err(EXIT_FAILURE, "Couldn't set tty(4) buffer size");
+ atf_tc_fail_errno("Couldn't set tty(4) buffer size");
if (ioctl(fd, TIOCGQSIZE, &opt) == -1)
- err(EXIT_FAILURE, "Couldn't get tty(4) buffer size");
+ atf_tc_fail_errno("Couldn't get tty(4) buffer size");
if (opt != qsize)
- errx(EXIT_FAILURE, "Wrong qsize %d != %d\n",
- qsize, opt);
+ atf_tc_fail_errno("Wrong qsize %d != %d\n", qsize, opt);
}
if (tcgetattr(fd, &tios) == -1)
- err(EXIT_FAILURE, "tcgetattr()");
+ atf_tc_fail_errno("tcgetattr()");
cfmakeraw(&tios);
cfsetspeed(&tios, B921600);
if (tcsetattr(fd, TCSANOW, &tios) == -1)
- err(EXIT_FAILURE, "tcsetattr()");
+ atf_tc_fail_errno("tcsetattr()");
}
static int
@@ -134,17 +135,17 @@
int fd;
if ((fd = posix_openpt(O_RDWR)) == -1)
- err(EXIT_FAILURE, "Couldn't pty(4) device");
+ atf_tc_fail_errno("Couldn't pty(4) device");
condition(fd);
if (grantpt(fd) == -1)
- err(EXIT_FAILURE,
+ atf_tc_fail_errno(
"Couldn't grant permissions on tty(4) device");
condition(fd);
if (unlockpt(fd) == -1)
- err(EXIT_FAILURE, "unlockpt()");
+ atf_tc_fail_errno("unlockpt()");
return fd;
}
@@ -155,13 +156,13 @@
int fd;
if ((fd = open(ttydev, O_RDWR, 0)) == -1)
- err(EXIT_FAILURE, "Couldn't open tty(4) device");
+ atf_tc_fail_errno("Couldn't open tty(4) device");
#ifdef USE_PPP_DISCIPLINE
{
int opt = PPPDISC;
if (ioctl(fd, TIOCSETD, &opt) == -1)
- err(EXIT_FAILURE,
+ atf_tc_fail_errno(
"Couldn't set tty(4) discipline to PPP");
}
#endif
@@ -177,9 +178,9 @@
int opt;
if ((opt = fcntl(fd, F_GETFL, NULL)) == -1)
- err(EXIT_FAILURE, "fcntl()");
+ atf_tc_fail_errno("fcntl()");
if (fcntl(fd, F_SETFL, opt | O_NONBLOCK) == -1)
- err(EXIT_FAILURE, "fcntl()");
+ atf_tc_fail_errno("fcntl()");
}
static pid_t
@@ -191,7 +192,7 @@
size_t total = 0;
if ((pid = fork()) == -1)
- err(EXIT_FAILURE, "fork()");
+ atf_tc_fail_errno("fork()");
(void)setsid();
if (pid != 0)
return pid;
Home |
Main Index |
Thread Index |
Old Index