Add atf_tc_fail_errno(), which appends strerror(errno) to the
message string. Adding it to h_macros suggested by jmmv
This commit is contained in:
parent
238e973f29
commit
3df59b06ac
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: t_renamerace.c,v 1.2 2009/04/08 12:29:05 pooka Exp $ */
|
||||
/* $NetBSD: t_renamerace.c,v 1.3 2009/04/14 10:19:39 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Modified for rump and atf from a program supplied
|
||||
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <ufs/ufs/ufsmount.h>
|
||||
|
||||
#include "../../h_macros.h"
|
||||
|
||||
ATF_TC_WITH_CLEANUP(renamerace);
|
||||
ATF_TC_HEAD(renamerace, tc)
|
||||
{
|
||||
|
@ -70,8 +72,7 @@ ATF_TC_BODY(renamerace, tc)
|
|||
#if 0
|
||||
strcpy(image, TMPPATH);
|
||||
if (mkdtemp(image) == NULL)
|
||||
atf_tc_fail("can't create tmpdir %s: %d (%s)",
|
||||
TMPPATH, errno, strerror(errno));
|
||||
atf_tc_fail_errno("can't create tmpdir %s", TMPPATH);
|
||||
strcat(image, "/ffsatf.img");
|
||||
#else
|
||||
strcpy(image, IMAGENAME);
|
||||
|
@ -81,7 +82,7 @@ ATF_TC_BODY(renamerace, tc)
|
|||
strcat(cmd, image);
|
||||
|
||||
if (system(cmd) == -1)
|
||||
atf_tc_fail("newfs failed: %d (%s)", errno, strerror(errno));
|
||||
atf_tc_fail_errno("newfs failed");
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.fspec = image;
|
||||
|
@ -90,8 +91,7 @@ ATF_TC_BODY(renamerace, tc)
|
|||
fs = ukfs_mount(MOUNT_FFS, "ffs", UKFS_DEFAULTMP,
|
||||
MNT_LOG, &args, sizeof(args));
|
||||
if (fs == NULL)
|
||||
atf_tc_fail("ukfs_mount failed: %d (%s)",
|
||||
errno, strerror(errno));
|
||||
atf_tc_fail_errno("ukfs_mount failed");
|
||||
|
||||
pthread_create(&pt1, NULL, w1, fs);
|
||||
pthread_create(&pt2, NULL, w2, fs);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: t_renamerace.c,v 1.4 2009/04/08 09:11:34 pooka Exp $ */
|
||||
/* $NetBSD: t_renamerace.c,v 1.5 2009/04/14 10:19:39 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Modified for rump and atf from a program supplied
|
||||
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include <fs/tmpfs/tmpfs_args.h>
|
||||
|
||||
#include "../../h_macros.h"
|
||||
|
||||
ATF_TC(renamerace);
|
||||
ATF_TC_HEAD(renamerace, tc)
|
||||
{
|
||||
|
@ -67,8 +69,7 @@ ATF_TC_BODY(renamerace, tc)
|
|||
fs = ukfs_mount(MOUNT_TMPFS, "tmpfs", UKFS_DEFAULTMP, 0,
|
||||
&args, sizeof(args));
|
||||
if (fs == NULL)
|
||||
atf_tc_fail("could not mount tmpfs: %d (%s)",
|
||||
errno, strerror(errno));
|
||||
atf_tc_fail_errno("could not mount tmpfs");
|
||||
|
||||
pthread_create(&pt1, NULL, w1, fs);
|
||||
pthread_create(&pt2, NULL, w2, fs);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: h_macros.h,v 1.1 2009/02/20 21:40:55 jmmv Exp $ */
|
||||
/* $NetBSD: h_macros.h,v 1.2 2009/04/14 10:19:38 pooka Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
|
||||
|
@ -33,6 +33,8 @@
|
|||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
@ -44,3 +46,20 @@
|
|||
ATF_CHECK_MSG((x) != (v), "%s: %s", #x, strerror(errno))
|
||||
|
||||
#define RL(x) REQUIRE_LIBC(x, -1)
|
||||
|
||||
static __inline void
|
||||
atf_tc_fail_errno(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buf[1024];
|
||||
int sverrno = errno;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
strlcat(buf, ": ", sizeof(buf));
|
||||
strlcat(buf, strerror(sverrno), sizeof(buf));
|
||||
|
||||
atf_tc_fail(buf);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue