]> CyberLeo.Net >> Repos - FreeBSD/releng/10.3.git/blob - usr.sbin/fstyp/tests/fstyp_test.sh
- Copy stable/10@296371 to releng/10.3 in preparation for 10.3-RC1
[FreeBSD/releng/10.3.git] / usr.sbin / fstyp / tests / fstyp_test.sh
1 # $FreeBSD$
2
3 atf_test_case cd9660
4 cd9660_head() {
5         atf_set "descr" "fstyp(8) should detect cd9660 filesystems"
6 }
7 cd9660_body() {
8         atf_check -s exit:0 mkdir -p dir/emptydir       # makefs requires a nonempty directory
9         atf_check -s exit:0 -o ignore makefs -t cd9660 -Z -s 64m cd9660.img dir
10         atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img
11         atf_check -s exit:0 -o inline:"cd9660\n" fstyp -l cd9660.img
12 }       
13
14 atf_test_case cd9660_label
15 cd9660_label_head() {
16         atf_set "descr" "fstyp(8) can read the label on a cd9660 filesystem"
17 }
18 cd9660_label_body() {
19         atf_check -s exit:0 mkdir -p dir/emptydir       # makefs requires a nonempty directory
20         atf_check -s exit:0 -o ignore makefs -t cd9660 -o label=Foo -Z -s 64m cd9660.img dir
21         atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img
22         # Note: cd9660 labels are always upper case
23         atf_check -s exit:0 -o inline:"cd9660 FOO\n" fstyp -l cd9660.img
24 }       
25
26 atf_test_case dir
27 dir_head() {
28         atf_set "descr" "fstyp(8) should fail on a directory"
29 }
30 dir_body() {
31         atf_check -s exit:0 mkdir dir
32         atf_check -s exit:1 -e match:"not a disk" fstyp dir
33 }
34
35 atf_test_case empty
36 empty_head() {
37         atf_set "descr" "fstyp(8) should fail on an empty file"
38 }
39 empty_body() {
40         atf_check -s exit:0 touch empty
41         atf_check -s exit:1 -e match:"filesystem not recognized" fstyp empty
42 }
43
44 atf_test_case ext2
45 ext2_head() {
46         atf_set "descr" "fstyp(8) can detect ext2 filesystems"
47 }
48 ext2_body() {
49         bzcat $(atf_get_srcdir)/ext2.img.bz2 > ext2.img
50         atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext2.img
51         atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext2.img
52 }
53
54 atf_test_case ext3
55 ext3_head() {
56         atf_set "descr" "fstyp(8) can detect ext3 filesystems"
57 }
58 ext3_body() {
59         bzcat $(atf_get_srcdir)/ext3.img.bz2 > ext3.img
60         atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext3.img
61         atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext3.img
62 }
63
64 atf_test_case ext4
65 ext4_head() {
66         atf_set "descr" "fstyp(8) can detect ext4 filesystems"
67 }
68 ext4_body() {
69         bzcat $(atf_get_srcdir)/ext4.img.bz2 > ext4.img
70         atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext4.img
71         atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext4.img
72 }
73
74 atf_test_case ext4_label
75 ext4_label_head() {
76         atf_set "descr" "fstyp(8) can read the label on an ext4 filesystem"
77 }
78 ext4_label_body() {
79         bzcat $(atf_get_srcdir)/ext4_with_label.img.bz2 > ext4_with_label.img
80         atf_check -s exit:0 -o inline:"ext2fs foo\n" fstyp -l ext4_with_label.img
81 }
82
83 atf_test_case fat12
84 fat12_head() {
85         atf_set "descr" "fstyp(8) can detect FAT12 filesystems"
86 }
87 fat12_body() {
88         atf_check -s exit:0 truncate -s 64m msdos.img
89         atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 12 ./msdos.img
90         atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
91         atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
92 }
93
94 atf_test_case fat16
95 fat16_head() {
96         atf_set "descr" "fstyp(8) can detect FAT16 filesystems"
97 }
98 fat16_body() {
99         atf_check -s exit:0 truncate -s 64m msdos.img
100         atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 16 ./msdos.img
101         atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
102         atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
103 }
104
105 atf_test_case fat32
106 fat32_head() {
107         atf_set "descr" "fstyp(8) can detect FAT32 filesystems"
108 }
109 fat32_body() {
110         atf_check -s exit:0 truncate -s 64m msdos.img
111         atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -c 1 \
112                 ./msdos.img
113         atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
114         atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
115 }
116
117 atf_test_case fat32_label
118 fat32_label_head() {
119         atf_set "descr" "fstyp(8) can read the label on an msdos filesystem"
120 }
121 fat32_label_body() {
122         atf_check -s exit:0 truncate -s 64m msdos.img
123         atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -L Foo -c 1 \
124                 ./msdos.img
125         atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
126         # Note: msdos labels are always upper case
127         atf_check -s exit:0 -o inline:"msdosfs FOO\n" fstyp -l msdos.img
128 }
129
130 atf_test_case ntfs
131 ntfs_head() {
132         atf_set "descr" "fstyp(8) can detect ntfs filesystems"
133 }
134 ntfs_body() {
135         bzcat $(atf_get_srcdir)/ntfs.img.bz2 > ntfs.img
136         atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs.img
137         atf_check -s exit:0 -o inline:"ntfs\n" fstyp -l ntfs.img
138 }
139
140 atf_test_case ntfs_with_label
141 ntfs_with_label_head() {
142         atf_set "descr" "fstyp(8) can read labels on ntfs filesystems"
143 }
144 ntfs_with_label_body() {
145         bzcat $(atf_get_srcdir)/ntfs_with_label.img.bz2 > ntfs_with_label.img
146         atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs_with_label.img
147         atf_check -s exit:0 -o inline:"ntfs Foo\n" fstyp -l ntfs_with_label.img
148 }
149
150 atf_test_case ufs1
151 ufs1_head() {
152         atf_set "descr" "fstyp(8) should detect UFS version 1 filesystems"
153 }
154 ufs1_body() {
155         atf_check -s exit:0 mkdir dir
156         atf_check -s exit:0 -o ignore makefs -Z -s 64m ufs.img dir
157         atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img
158         atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img
159 }
160
161 atf_test_case ufs2
162 ufs2_head() {
163         atf_set "descr" "fstyp(8) should detect UFS version 2 filesystems"
164 }
165 ufs2_body() {
166         atf_check -s exit:0 mkdir dir
167         atf_check -s exit:0 -o ignore makefs -o version=2 -Z -s 64m ufs.img dir
168         atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img
169         atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img
170 }
171
172 atf_test_case ufs2_label
173 ufs2_label_head() {
174         atf_set "descr" "fstyp(8) can read the label on a UFS v2 filesystem"
175 }
176 ufs2_label_body() {
177         atf_check -s exit:0 mkdir dir
178         atf_check -s exit:0 -o ignore makefs -o version=2,label="foo" -Z -s 64m ufs.img dir
179         atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l ufs.img
180 }       
181
182 atf_test_case ufs_on_device cleanup
183 ufs_on_device_head() {
184         atf_set "descr" "fstyp(8) should work on device nodes"
185         atf_set "require.user" "root"
186 }
187 ufs_on_device_body() {
188         mdconfig -a -t swap -s 64m > mdname
189         md=$(cat mdname)
190         if [ -z "$md" ]; then
191                 atf_fail "Failed to create md(4) device"
192         fi
193         atf_check -s exit:0 -o ignore newfs -L foo /dev/$md
194         atf_check -s exit:0 -o inline:"ufs\n" fstyp /dev/$md
195         atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l /dev/$md
196 }
197 ufs_on_device_cleanup() {
198         md=$(cat mdname)
199         if [ -n "$md" ]; then
200                 mdconfig -d -u "$md"
201         fi
202 }
203
204 atf_test_case zeros
205 zeros_head() {
206         atf_set "descr" "fstyp(8) should fail on a zero-filled file"
207 }
208 zeros_body() {
209         atf_check -s exit:0 truncate -s 256m zeros
210         atf_check -s exit:1 -e match:"filesystem not recognized" fstyp zeros
211 }
212
213
214 atf_init_test_cases() {
215         atf_add_test_case cd9660
216         atf_add_test_case cd9660_label
217         atf_add_test_case dir
218         atf_add_test_case empty
219         atf_add_test_case ext2
220         atf_add_test_case ext3
221         atf_add_test_case ext4
222         atf_add_test_case ext4_label
223         atf_add_test_case fat12
224         atf_add_test_case fat16
225         atf_add_test_case fat32
226         atf_add_test_case fat32_label
227         atf_add_test_case ntfs
228         atf_add_test_case ntfs_with_label
229         atf_add_test_case ufs1
230         atf_add_test_case ufs2
231         atf_add_test_case ufs2_label
232         atf_add_test_case ufs_on_device
233         atf_add_test_case zeros
234 }