fstyp_test.sh revision 286964
1# $FreeBSD: head/usr.sbin/fstyp/tests/fstyp_test.sh 286964 2015-08-20 15:37:47Z asomers $
2
3atf_test_case cd9660
4cd9660_head() {
5	atf_set "descr" "fstyp(8) should detect cd9660 filesystems"
6}
7cd9660_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
14atf_test_case cd9660_label
15cd9660_label_head() {
16	atf_set "descr" "fstyp(8) can read the label on a cd9660 filesystem"
17}
18cd9660_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
26atf_test_case dir
27dir_head() {
28	atf_set "descr" "fstyp(8) should fail on a directory"
29}
30dir_body() {
31	atf_check -s exit:0 mkdir dir
32	atf_check -s exit:1 -e match:"not a disk" fstyp dir
33}
34
35atf_test_case empty
36empty_head() {
37	atf_set "descr" "fstyp(8) should fail on an empty file"
38}
39empty_body() {
40	atf_check -s exit:0 touch empty
41	atf_check -s exit:1 -e match:"filesystem not recognized" fstyp empty
42}
43
44atf_test_case ext2
45ext2_head() {
46	atf_set "descr" "fstyp(8) can detect ext2 filesystems"
47}
48ext2_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
54atf_test_case ext3
55ext3_head() {
56	atf_set "descr" "fstyp(8) can detect ext3 filesystems"
57}
58ext3_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
64atf_test_case ext4
65ext4_head() {
66	atf_set "descr" "fstyp(8) can detect ext4 filesystems"
67}
68ext4_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
74atf_test_case ext4_label
75ext4_label_head() {
76	atf_set "descr" "fstyp(8) can read the label on an ext4 filesystem"
77}
78ext4_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
83atf_test_case fat12
84fat12_head() {
85	atf_set "descr" "fstyp(8) can detect FAT12 filesystems"
86}
87fat12_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
94atf_test_case fat16
95fat16_head() {
96	atf_set "descr" "fstyp(8) can detect FAT16 filesystems"
97}
98fat16_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
105atf_test_case fat32
106fat32_head() {
107	atf_set "descr" "fstyp(8) can detect FAT32 filesystems"
108}
109fat32_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
117atf_test_case fat32_label
118fat32_label_head() {
119	atf_set "descr" "fstyp(8) can read the label on an msdos filesystem"
120}
121fat32_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
130atf_test_case ntfs
131ntfs_head() {
132	atf_set "descr" "fstyp(8) can detect ntfs filesystems"
133}
134ntfs_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
140atf_test_case ntfs_with_label
141ntfs_with_label_head() {
142	atf_set "descr" "fstyp(8) can read labels on ntfs filesystems"
143}
144ntfs_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
150atf_test_case ufs1
151ufs1_head() {
152	atf_set "descr" "fstyp(8) should detect UFS version 1 filesystems"
153}
154ufs1_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
161atf_test_case ufs2
162ufs2_head() {
163	atf_set "descr" "fstyp(8) should detect UFS version 2 filesystems"
164}
165ufs2_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
172atf_test_case ufs2_label
173ufs2_label_head() {
174	atf_set "descr" "fstyp(8) can read the label on a UFS v2 filesystem"
175}
176ufs2_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
182atf_test_case ufs_on_device cleanup
183ufs_on_device_head() {
184	atf_set "descr" "fstyp(8) should work on device nodes"
185	atf_set "require.user" "root"
186}
187ufs_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}
197ufs_on_device_cleanup() {
198	md=$(cat mdname)
199	if [ -n "$md" ]; then
200		mdconfig -d -u "$md"
201	fi
202}
203
204atf_test_case zeros
205zeros_head() {
206	atf_set "descr" "fstyp(8) should fail on a zero-filled file"
207}
208zeros_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
214atf_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}
235