Module Name:    src
Committed By:   pooka
Date:           Tue Apr 14 10:19:39 UTC 2009

Modified Files:
        src/tests: h_macros.h
        src/tests/fs/ffs: t_renamerace.c
        src/tests/fs/tmpfs: t_renamerace.c

Log Message:
Add atf_tc_fail_errno(), which appends strerror(errno) to the
message string.  Adding it to h_macros suggested by jmmv


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/h_macros.h
cvs rdiff -u -r1.2 -r1.3 src/tests/fs/ffs/t_renamerace.c
cvs rdiff -u -r1.4 -r1.5 src/tests/fs/tmpfs/t_renamerace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/h_macros.h
diff -u src/tests/h_macros.h:1.1 src/tests/h_macros.h:1.2
--- src/tests/h_macros.h:1.1	Fri Feb 20 21:40:55 2009
+++ src/tests/h_macros.h	Tue Apr 14 10:19:38 2009
@@ -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);
+}

Index: src/tests/fs/ffs/t_renamerace.c
diff -u src/tests/fs/ffs/t_renamerace.c:1.2 src/tests/fs/ffs/t_renamerace.c:1.3
--- src/tests/fs/ffs/t_renamerace.c:1.2	Wed Apr  8 12:29:05 2009
+++ src/tests/fs/ffs/t_renamerace.c	Tue Apr 14 10:19:39 2009
@@ -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 @@
 #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 @@
 	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 @@
 	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);

Index: src/tests/fs/tmpfs/t_renamerace.c
diff -u src/tests/fs/tmpfs/t_renamerace.c:1.4 src/tests/fs/tmpfs/t_renamerace.c:1.5
--- src/tests/fs/tmpfs/t_renamerace.c:1.4	Wed Apr  8 09:11:34 2009
+++ src/tests/fs/tmpfs/t_renamerace.c	Tue Apr 14 10:19:39 2009
@@ -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 @@
 	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);

Reply via email to