git: 4e71258227d6 - main - newfs_msdos: connect the ATF test from NetBSD

From: Eric van Gyzen <vangyzen_at_FreeBSD.org>
Date: Wed, 16 Feb 2022 15:59:15 UTC
The branch main has been updated by vangyzen:

URL: https://cgit.FreeBSD.org/src/commit/?id=4e71258227d6a0d7ae5adadb0f3672bfce2bc906

commit 4e71258227d6a0d7ae5adadb0f3672bfce2bc906
Author:     Eric van Gyzen <vangyzen@FreeBSD.org>
AuthorDate: 2022-01-31 20:43:04 +0000
Commit:     Eric van Gyzen <vangyzen@FreeBSD.org>
CommitDate: 2022-02-16 15:56:16 +0000

    newfs_msdos: connect the ATF test from NetBSD
    
    NetBSD has an ATF test for newfs_msdos.  Connect it to the build.
    Adapt it for FreeBSD.  This would have caught the bug fixed by my
    previous commit.
    
    Reviewed by:    delphij, emaste
    MFC after:      1 week
    Sponsored by:   Dell EMC Isilon
    Differential Revision:  https://reviews.freebsd.org/D34116
---
 contrib/netbsd-tests/sbin/newfs_msdos/t_create.sh | 14 ++++++++++++--
 etc/mtree/BSD.tests.dist                          |  2 ++
 sbin/newfs_msdos/Makefile                         |  5 +++++
 sbin/newfs_msdos/tests/Makefile                   |  6 ++++++
 4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/contrib/netbsd-tests/sbin/newfs_msdos/t_create.sh b/contrib/netbsd-tests/sbin/newfs_msdos/t_create.sh
index dc431166a469..61ed927b8889 100755
--- a/contrib/netbsd-tests/sbin/newfs_msdos/t_create.sh
+++ b/contrib/netbsd-tests/sbin/newfs_msdos/t_create.sh
@@ -31,11 +31,21 @@ validfat32_head() {
 }
 validfat32_body() {
 
-	atf_check -s eq:0 -o ignore -e ignore \
+	if true; then
+		# FreeBSD
+		exp_err=empty
+		fsck=fsck_msdosfs
+	else
+		# NetBSD
+		exp_err=ignore
+		fsck=fsck_msdos
+	fi
+
+	atf_check -s eq:0 -o ignore -e $exp_err \
 	    newfs_msdos -b 512 -C 33m -F 32 msdos.img
 #	fsck_msdos/newfs_msdos have been fixed
 #	atf_expect_fail "PR bin/46743"
-	atf_check -s eq:0 -o not-match:FIXED -e empty fsck_msdos -p msdos.img
+	atf_check -s eq:0 -o not-match:FIXED -e empty $fsck -p msdos.img
 	atf_expect_pass
 }
 
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index 08ad8e41a527..ec487eb1124a 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -442,6 +442,8 @@
         ..
         mdconfig
         ..
+        newfs_msdos
+        ..
         nvmecontrol
         ..
         pfctl
diff --git a/sbin/newfs_msdos/Makefile b/sbin/newfs_msdos/Makefile
index d12cf0245df2..0123f4dd7a8a 100644
--- a/sbin/newfs_msdos/Makefile
+++ b/sbin/newfs_msdos/Makefile
@@ -1,5 +1,7 @@
 # $FreeBSD$
 
+.include <src.opts.mk>
+
 PACKAGE=runtime
 PROG=	newfs_msdos
 MAN=	newfs_msdos.8
@@ -11,4 +13,7 @@ WARNS?= 3
 .endif
 CSTD=	c11
 
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
 .include <bsd.prog.mk>
diff --git a/sbin/newfs_msdos/tests/Makefile b/sbin/newfs_msdos/tests/Makefile
new file mode 100644
index 000000000000..3f112c7f4710
--- /dev/null
+++ b/sbin/newfs_msdos/tests/Makefile
@@ -0,0 +1,6 @@
+TESTSRC=${SRCTOP}/contrib/netbsd-tests/sbin/newfs_msdos
+
+NETBSD_ATF_TESTS_SH+=	create
+
+.include <netbsd-tests.test.mk>
+.include <bsd.test.mk>