From owner-svn-src-all@freebsd.org Thu Aug 20 15:37:49 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8C6839BE07E; Thu, 20 Aug 2015 15:37:49 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6FEB91847; Thu, 20 Aug 2015 15:37:49 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7KFbn8e001315; Thu, 20 Aug 2015 15:37:49 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7KFbmK6001309; Thu, 20 Aug 2015 15:37:48 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201508201537.t7KFbmK6001309@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Thu, 20 Aug 2015 15:37:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286964 - in head: etc/mtree usr.sbin/fstyp usr.sbin/fstyp/tests X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Aug 2015 15:37:49 -0000 Author: asomers Date: Thu Aug 20 15:37:47 2015 New Revision: 286964 URL: https://svnweb.freebsd.org/changeset/base/286964 Log: Add ATF functional tests for fstyp(8). No ZFS or GELI tests yet. Reviewed by: trasz, ngie MFC after: 2 weeks Sponsored by: SpectraLogic Differential Revision: https://reviews.freebsd.org/D2801 Added: head/usr.sbin/fstyp/tests/ head/usr.sbin/fstyp/tests/Makefile (contents, props changed) head/usr.sbin/fstyp/tests/ext2.img.bz2 (contents, props changed) head/usr.sbin/fstyp/tests/ext3.img.bz2 (contents, props changed) head/usr.sbin/fstyp/tests/ext4.img.bz2 (contents, props changed) head/usr.sbin/fstyp/tests/ext4_with_label.img.bz2 (contents, props changed) head/usr.sbin/fstyp/tests/fstyp_test.sh (contents, props changed) head/usr.sbin/fstyp/tests/ntfs.img.bz2 (contents, props changed) head/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2 (contents, props changed) Modified: head/etc/mtree/BSD.tests.dist head/usr.sbin/fstyp/Makefile Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Thu Aug 20 14:51:11 2015 (r286963) +++ head/etc/mtree/BSD.tests.dist Thu Aug 20 15:37:47 2015 (r286964) @@ -574,6 +574,8 @@ usr.sbin etcupdate .. + fstyp + .. newsyslog .. nmtree Modified: head/usr.sbin/fstyp/Makefile ============================================================================== --- head/usr.sbin/fstyp/Makefile Thu Aug 20 14:51:11 2015 (r286963) +++ head/usr.sbin/fstyp/Makefile Thu Aug 20 15:37:47 2015 (r286964) @@ -13,6 +13,12 @@ MAN= fstyp.8 WARNS?= 0 +.include + +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .if ${MK_ZFS} != "no" IGNORE_PRAGMA= YES Added: head/usr.sbin/fstyp/tests/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/fstyp/tests/Makefile Thu Aug 20 15:37:47 2015 (r286964) @@ -0,0 +1,15 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/usr.sbin/fstyp + +ATF_TESTS_SH= fstyp_test + +FILES= ext2.img.bz2 +FILES+= ext3.img.bz2 +FILES+= ext4.img.bz2 +FILES+= ext4_with_label.img.bz2 +FILES+= ntfs.img.bz2 +FILES+= ntfs_with_label.img.bz2 +FILESDIR= ${TESTSDIR} + +.include Added: head/usr.sbin/fstyp/tests/ext2.img.bz2 ============================================================================== Binary file. No diff available. Added: head/usr.sbin/fstyp/tests/ext3.img.bz2 ============================================================================== Binary file. No diff available. Added: head/usr.sbin/fstyp/tests/ext4.img.bz2 ============================================================================== Binary file. No diff available. Added: head/usr.sbin/fstyp/tests/ext4_with_label.img.bz2 ============================================================================== Binary file. No diff available. Added: head/usr.sbin/fstyp/tests/fstyp_test.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/fstyp/tests/fstyp_test.sh Thu Aug 20 15:37:47 2015 (r286964) @@ -0,0 +1,234 @@ +# $FreeBSD$ + +atf_test_case cd9660 +cd9660_head() { + atf_set "descr" "fstyp(8) should detect cd9660 filesystems" +} +cd9660_body() { + atf_check -s exit:0 mkdir -p dir/emptydir # makefs requires a nonempty directory + atf_check -s exit:0 -o ignore makefs -t cd9660 -Z -s 64m cd9660.img dir + atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img + atf_check -s exit:0 -o inline:"cd9660\n" fstyp -l cd9660.img +} + +atf_test_case cd9660_label +cd9660_label_head() { + atf_set "descr" "fstyp(8) can read the label on a cd9660 filesystem" +} +cd9660_label_body() { + atf_check -s exit:0 mkdir -p dir/emptydir # makefs requires a nonempty directory + atf_check -s exit:0 -o ignore makefs -t cd9660 -o label=Foo -Z -s 64m cd9660.img dir + atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img + # Note: cd9660 labels are always upper case + atf_check -s exit:0 -o inline:"cd9660 FOO\n" fstyp -l cd9660.img +} + +atf_test_case dir +dir_head() { + atf_set "descr" "fstyp(8) should fail on a directory" +} +dir_body() { + atf_check -s exit:0 mkdir dir + atf_check -s exit:1 -e match:"not a disk" fstyp dir +} + +atf_test_case empty +empty_head() { + atf_set "descr" "fstyp(8) should fail on an empty file" +} +empty_body() { + atf_check -s exit:0 touch empty + atf_check -s exit:1 -e match:"filesystem not recognized" fstyp empty +} + +atf_test_case ext2 +ext2_head() { + atf_set "descr" "fstyp(8) can detect ext2 filesystems" +} +ext2_body() { + bzcat $(atf_get_srcdir)/ext2.img.bz2 > ext2.img + atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext2.img + atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext2.img +} + +atf_test_case ext3 +ext3_head() { + atf_set "descr" "fstyp(8) can detect ext3 filesystems" +} +ext3_body() { + bzcat $(atf_get_srcdir)/ext3.img.bz2 > ext3.img + atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext3.img + atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext3.img +} + +atf_test_case ext4 +ext4_head() { + atf_set "descr" "fstyp(8) can detect ext4 filesystems" +} +ext4_body() { + bzcat $(atf_get_srcdir)/ext4.img.bz2 > ext4.img + atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext4.img + atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext4.img +} + +atf_test_case ext4_label +ext4_label_head() { + atf_set "descr" "fstyp(8) can read the label on an ext4 filesystem" +} +ext4_label_body() { + bzcat $(atf_get_srcdir)/ext4_with_label.img.bz2 > ext4_with_label.img + atf_check -s exit:0 -o inline:"ext2fs foo\n" fstyp -l ext4_with_label.img +} + +atf_test_case fat12 +fat12_head() { + atf_set "descr" "fstyp(8) can detect FAT12 filesystems" +} +fat12_body() { + atf_check -s exit:0 truncate -s 64m msdos.img + atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 12 ./msdos.img + atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img + atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img +} + +atf_test_case fat16 +fat16_head() { + atf_set "descr" "fstyp(8) can detect FAT16 filesystems" +} +fat16_body() { + atf_check -s exit:0 truncate -s 64m msdos.img + atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 16 ./msdos.img + atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img + atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img +} + +atf_test_case fat32 +fat32_head() { + atf_set "descr" "fstyp(8) can detect FAT32 filesystems" +} +fat32_body() { + atf_check -s exit:0 truncate -s 64m msdos.img + atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -c 1 \ + ./msdos.img + atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img + atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img +} + +atf_test_case fat32_label +fat32_label_head() { + atf_set "descr" "fstyp(8) can read the label on an msdos filesystem" +} +fat32_label_body() { + atf_check -s exit:0 truncate -s 64m msdos.img + atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -L Foo -c 1 \ + ./msdos.img + atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img + # Note: msdos labels are always upper case + atf_check -s exit:0 -o inline:"msdosfs FOO\n" fstyp -l msdos.img +} + +atf_test_case ntfs +ntfs_head() { + atf_set "descr" "fstyp(8) can detect ntfs filesystems" +} +ntfs_body() { + bzcat $(atf_get_srcdir)/ntfs.img.bz2 > ntfs.img + atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs.img + atf_check -s exit:0 -o inline:"ntfs\n" fstyp -l ntfs.img +} + +atf_test_case ntfs_with_label +ntfs_with_label_head() { + atf_set "descr" "fstyp(8) can read labels on ntfs filesystems" +} +ntfs_with_label_body() { + bzcat $(atf_get_srcdir)/ntfs_with_label.img.bz2 > ntfs_with_label.img + atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs_with_label.img + atf_check -s exit:0 -o inline:"ntfs Foo\n" fstyp -l ntfs_with_label.img +} + +atf_test_case ufs1 +ufs1_head() { + atf_set "descr" "fstyp(8) should detect UFS version 1 filesystems" +} +ufs1_body() { + atf_check -s exit:0 mkdir dir + atf_check -s exit:0 -o ignore makefs -Z -s 64m ufs.img dir + atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img + atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img +} + +atf_test_case ufs2 +ufs2_head() { + atf_set "descr" "fstyp(8) should detect UFS version 2 filesystems" +} +ufs2_body() { + atf_check -s exit:0 mkdir dir + atf_check -s exit:0 -o ignore makefs -o version=2 -Z -s 64m ufs.img dir + atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img + atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img +} + +atf_test_case ufs2_label +ufs2_label_head() { + atf_set "descr" "fstyp(8) can read the label on a UFS v2 filesystem" +} +ufs2_label_body() { + atf_check -s exit:0 mkdir dir + atf_check -s exit:0 -o ignore makefs -o version=2,label="foo" -Z -s 64m ufs.img dir + atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l ufs.img +} + +atf_test_case ufs_on_device cleanup +ufs_on_device_head() { + atf_set "descr" "fstyp(8) should work on device nodes" + atf_set "require.user" "root" +} +ufs_on_device_body() { + mdconfig -a -t swap -s 64m > mdname + md=$(cat mdname) + if [ -z "$md" ]; then + atf_fail "Failed to create md(4) device" + fi + atf_check -s exit:0 -o ignore newfs -L foo /dev/$md + atf_check -s exit:0 -o inline:"ufs\n" fstyp /dev/$md + atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l /dev/$md +} +ufs_on_device_cleanup() { + md=$(cat mdname) + if [ -n "$md" ]; then + mdconfig -d -u "$md" + fi +} + +atf_test_case zeros +zeros_head() { + atf_set "descr" "fstyp(8) should fail on a zero-filled file" +} +zeros_body() { + atf_check -s exit:0 truncate -s 256m zeros + atf_check -s exit:1 -e match:"filesystem not recognized" fstyp zeros +} + + +atf_init_test_cases() { + atf_add_test_case cd9660 + atf_add_test_case cd9660_label + atf_add_test_case dir + atf_add_test_case empty + atf_add_test_case ext2 + atf_add_test_case ext3 + atf_add_test_case ext4 + atf_add_test_case ext4_label + atf_add_test_case fat12 + atf_add_test_case fat16 + atf_add_test_case fat32 + atf_add_test_case fat32_label + atf_add_test_case ntfs + atf_add_test_case ntfs_with_label + atf_add_test_case ufs1 + atf_add_test_case ufs2 + atf_add_test_case ufs2_label + atf_add_test_case ufs_on_device + atf_add_test_case zeros +} Added: head/usr.sbin/fstyp/tests/ntfs.img.bz2 ============================================================================== Binary file. No diff available. Added: head/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2 ============================================================================== Binary file. No diff available.