fstyp_test.sh revision 312270
1193323Sed#!/bin/sh 2193323Sed# 3193323Sed# Copyright (c) 2015 Alan Somers 4193323Sed# All rights reserved. 5193323Sed# 6193323Sed# Redistribution and use in source and binary forms, with or without 7193323Sed# modification, are permitted provided that the following conditions 8193323Sed# are met: 9193323Sed# 1. Redistributions of source code must retain the above copyright 10193323Sed# notice, this list of conditions and the following disclaimer. 11193323Sed# 2. Redistributions in binary form must reproduce the above copyright 12218893Sdim# notice, this list of conditions and the following disclaimer in the 13218893Sdim# documentation and/or other materials provided with the distribution. 14218893Sdim# 15193323Sed# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16218893Sdim# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17218893Sdim# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18218893Sdim# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19218893Sdim# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20218893Sdim# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21218893Sdim# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22218893Sdim# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23218893Sdim# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24218893Sdim# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25218893Sdim# SUCH DAMAGE. 26193323Sed 27193323Sed# $FreeBSD: stable/10/usr.sbin/fstyp/tests/fstyp_test.sh 312270 2017-01-16 07:11:37Z ngie $ 28193323Sed 29193323Sedatf_test_case cd9660 30193323Sedcd9660_head() { 31234353Sdim atf_set "descr" "fstyp(8) should detect cd9660 filesystems" 32249423Sdim} 33193323Sedcd9660_body() { 34193323Sed atf_check -s exit:0 mkdir -p dir/emptydir # makefs requires a nonempty directory 35193323Sed atf_check -s exit:0 -o ignore makefs -t cd9660 -Z -s 64m cd9660.img dir 36249423Sdim atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img 37249423Sdim atf_check -s exit:0 -o inline:"cd9660\n" fstyp -l cd9660.img 38249423Sdim} 39249423Sdim 40249423Sdimatf_test_case cd9660_label 41249423Sdimcd9660_label_head() { 42249423Sdim atf_set "descr" "fstyp(8) can read the label on a cd9660 filesystem" 43249423Sdim} 44249423Sdimcd9660_label_body() { 45249423Sdim atf_check -s exit:0 mkdir -p dir/emptydir # makefs requires a nonempty directory 46249423Sdim atf_check -s exit:0 -o ignore makefs -t cd9660 -o label=Foo -Z -s 64m cd9660.img dir 47249423Sdim atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img 48193323Sed # Note: cd9660 labels are always upper case 49249423Sdim atf_check -s exit:0 -o inline:"cd9660 FOO\n" fstyp -l cd9660.img 50193323Sed} 51218893Sdim 52193323Sedatf_test_case dir 53193323Seddir_head() { 54193323Sed atf_set "descr" "fstyp(8) should fail on a directory" 55193323Sed} 56193323Seddir_body() { 57193323Sed atf_check -s exit:0 mkdir dir 58193323Sed atf_check -s exit:1 -e match:"not a disk" fstyp dir 59193323Sed} 60193323Sed 61193323Sedatf_test_case empty 62193323Sedempty_head() { 63193323Sed atf_set "descr" "fstyp(8) should fail on an empty file" 64193323Sed} 65193323Sedempty_body() { 66193323Sed atf_check -s exit:0 touch empty 67193323Sed atf_check -s exit:1 -e match:"filesystem not recognized" fstyp empty 68193323Sed} 69193323Sed 70234353Sdimatf_test_case ext2 71234353Sdimext2_head() { 72193323Sed atf_set "descr" "fstyp(8) can detect ext2 filesystems" 73193323Sed} 74193323Sedext2_body() { 75193323Sed bzcat $(atf_get_srcdir)/ext2.img.bz2 > ext2.img 76193323Sed atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext2.img 77193323Sed atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext2.img 78193323Sed} 79193323Sed 80193323Sedatf_test_case ext3 81193323Sedext3_head() { 82193323Sed atf_set "descr" "fstyp(8) can detect ext3 filesystems" 83193323Sed} 84193323Sedext3_body() { 85193323Sed bzcat $(atf_get_srcdir)/ext3.img.bz2 > ext3.img 86193323Sed atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext3.img 87206083Srdivacky atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext3.img 88210299Sed} 89210299Sed 90210299Sedatf_test_case ext4 91226633Sdimext4_head() { 92226633Sdim atf_set "descr" "fstyp(8) can detect ext4 filesystems" 93193323Sed} 94193323Sedext4_body() { 95210299Sed bzcat $(atf_get_srcdir)/ext4.img.bz2 > ext4.img 96193323Sed atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext4.img 97193323Sed atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext4.img 98226633Sdim} 99226633Sdim 100193323Sedatf_test_case ext4_label 101193323Sedext4_label_head() { 102224145Sdim atf_set "descr" "fstyp(8) can read the label on an ext4 filesystem" 103224145Sdim} 104224145Sdimext4_label_body() { 105224145Sdim bzcat $(atf_get_srcdir)/ext4_with_label.img.bz2 > ext4_with_label.img 106224145Sdim atf_check -s exit:0 -o inline:"ext2fs foo\n" fstyp -l ext4_with_label.img 107224145Sdim} 108224145Sdim 109224145Sdimatf_test_case fat12 110224145Sdimfat12_head() { 111224145Sdim atf_set "descr" "fstyp(8) can detect FAT12 filesystems" 112224145Sdim} 113224145Sdimfat12_body() { 114224145Sdim atf_check -s exit:0 truncate -s 64m msdos.img 115224145Sdim atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 12 ./msdos.img 116224145Sdim atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img 117224145Sdim atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img 118193323Sed} 119193323Sed 120193323Sedatf_test_case fat16 121210299Sedfat16_head() { 122193323Sed atf_set "descr" "fstyp(8) can detect FAT16 filesystems" 123193323Sed} 124193323Sedfat16_body() { 125193323Sed atf_check -s exit:0 truncate -s 64m msdos.img 126193323Sed atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 16 ./msdos.img 127193323Sed atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img 128193323Sed atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img 129193323Sed} 130198892Srdivacky 131193323Sedatf_test_case fat32 132193323Sedfat32_head() { 133193323Sed atf_set "descr" "fstyp(8) can detect FAT32 filesystems" 134200581Srdivacky} 135193323Sedfat32_body() { 136193323Sed atf_check -s exit:0 truncate -s 64m msdos.img 137193323Sed atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -c 1 \ 138193323Sed ./msdos.img 139193323Sed atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img 140193323Sed atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img 141193323Sed} 142193323Sed 143193323Sedatf_test_case fat32_label 144193323Sedfat32_label_head() { 145193323Sed atf_set "descr" "fstyp(8) can read the label on an msdos filesystem" 146193323Sed} 147193323Sedfat32_label_body() { 148193323Sed atf_check -s exit:0 truncate -s 64m msdos.img 149193323Sed atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -L Foo -c 1 \ 150193323Sed ./msdos.img 151193323Sed atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img 152193323Sed # Note: msdos labels are always upper case 153198892Srdivacky atf_check -s exit:0 -o inline:"msdosfs FOO\n" fstyp -l msdos.img 154193323Sed} 155193323Sed 156193323Sedatf_test_case ntfs 157193323Sedntfs_head() { 158193323Sed atf_set "descr" "fstyp(8) can detect ntfs filesystems" 159193323Sed} 160193323Sedntfs_body() { 161193323Sed bzcat $(atf_get_srcdir)/ntfs.img.bz2 > ntfs.img 162193323Sed atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs.img 163193323Sed atf_check -s exit:0 -o inline:"ntfs\n" fstyp -l ntfs.img 164193323Sed} 165193323Sed 166193323Sedatf_test_case ntfs_with_label 167193323Sedntfs_with_label_head() { 168193323Sed atf_set "descr" "fstyp(8) can read labels on ntfs filesystems" 169193323Sed} 170193323Sedntfs_with_label_body() { 171193323Sed bzcat $(atf_get_srcdir)/ntfs_with_label.img.bz2 > ntfs_with_label.img 172193323Sed atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs_with_label.img 173193323Sed atf_check -s exit:0 -o inline:"ntfs Foo\n" fstyp -l ntfs_with_label.img 174193323Sed} 175193323Sed 176193323Sedatf_test_case ufs1 177193323Sedufs1_head() { 178193323Sed atf_set "descr" "fstyp(8) should detect UFS version 1 filesystems" 179193323Sed} 180193323Sedufs1_body() { 181193323Sed atf_check -s exit:0 mkdir dir 182193323Sed atf_check -s exit:0 -o ignore makefs -Z -s 64m ufs.img dir 183193323Sed atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img 184193323Sed atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img 185193323Sed} 186193323Sed 187193323Sedatf_test_case ufs2 188193323Sedufs2_head() { 189193323Sed atf_set "descr" "fstyp(8) should detect UFS version 2 filesystems" 190193323Sed} 191193323Sedufs2_body() { 192193323Sed atf_check -s exit:0 mkdir dir 193193323Sed atf_check -s exit:0 -o ignore makefs -o version=2 -Z -s 64m ufs.img dir 194193323Sed atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img 195193323Sed atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img 196193323Sed} 197193323Sed 198193323Sedatf_test_case ufs2_label 199193323Sedufs2_label_head() { 200198892Srdivacky atf_set "descr" "fstyp(8) can read the label on a UFS v2 filesystem" 201193323Sed} 202193323Sedufs2_label_body() { 203193323Sed atf_check -s exit:0 mkdir dir 204193323Sed atf_check -s exit:0 -o ignore makefs -o version=2,label="foo" -Z -s 64m ufs.img dir 205219077Sdim atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l ufs.img 206193323Sed} 207193323Sed 208193323Sedatf_test_case ufs_on_device cleanup 209193323Sedufs_on_device_head() { 210198090Srdivacky atf_set "descr" "fstyp(8) should work on device nodes" 211193323Sed atf_set "require.user" "root" 212193323Sed} 213218893Sdimufs_on_device_body() { 214193323Sed mdconfig -a -t swap -s 64m > mdname 215243830Sdim md=$(cat mdname) 216243830Sdim if [ -z "$md" ]; then 217243830Sdim atf_fail "Failed to create md(4) device" 218243830Sdim fi 219243830Sdim atf_check -s exit:0 -o ignore newfs -L foo /dev/$md 220193323Sed atf_check -s exit:0 -o inline:"ufs\n" fstyp /dev/$md 221243830Sdim atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l /dev/$md 222193323Sed} 223193323Sedufs_on_device_cleanup() { 224193323Sed md=$(cat mdname) 225193323Sed if [ -n "$md" ]; then 226193323Sed mdconfig -d -u "$md" 227193323Sed fi 228193323Sed} 229193323Sed 230193323Sedatf_test_case zeros 231193323Sedzeros_head() { 232193323Sed atf_set "descr" "fstyp(8) should fail on a zero-filled file" 233203954Srdivacky} 234203954Srdivackyzeros_body() { 235203954Srdivacky atf_check -s exit:0 truncate -s 256m zeros 236203954Srdivacky atf_check -s exit:1 -e match:"filesystem not recognized" fstyp zeros 237203954Srdivacky} 238193323Sed 239193323Sed 240193323Sedatf_init_test_cases() { 241193323Sed atf_add_test_case cd9660 242193323Sed atf_add_test_case cd9660_label 243193323Sed atf_add_test_case dir 244193323Sed atf_add_test_case empty 245193323Sed atf_add_test_case ext2 246218893Sdim atf_add_test_case ext3 247218893Sdim atf_add_test_case ext4 248218893Sdim atf_add_test_case ext4_label 249193323Sed atf_add_test_case fat12 250193323Sed atf_add_test_case fat16 251193323Sed atf_add_test_case fat32 252193323Sed atf_add_test_case fat32_label 253218893Sdim atf_add_test_case ntfs 254219077Sdim atf_add_test_case ntfs_with_label 255203954Srdivacky atf_add_test_case ufs1 256219077Sdim atf_add_test_case ufs2 257203954Srdivacky atf_add_test_case ufs2_label 258193323Sed atf_add_test_case ufs_on_device 259193323Sed atf_add_test_case zeros 260193323Sed} 261193323Sed