xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_vnd.sh (revision ea1e967cbf9a3e1bbf964b01859c4d37965548d4)
1# $NetBSD: t_vnd.sh,v 1.9 2016/07/29 05:23:24 pgoyette Exp $
2#
3# Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
4# All rights reserved.
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
15# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
18# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24# POSSIBILITY OF SUCH DAMAGE.
25#
26
27#
28# Verifies that vnd works with files stored in tmpfs.
29#
30
31# Begin FreeBSD
32MD_DEVICE_FILE=md.device
33# End FreeBSD
34
35atf_test_case basic cleanup
36basic_head() {
37	atf_set "descr" "Verifies that vnd works with files stored in tmpfs"
38	atf_set "require.user" "root"
39}
40basic_body() {
41	test_mount
42
43	atf_check -s eq:0 -o ignore -e ignore \
44	    dd if=/dev/zero of=disk.img bs=1m count=10
45	# Begin FreeBSD
46	if true; then
47		atf_check -s eq:0 -o empty -e empty mkdir mnt
48		atf_check -s eq:0 -o empty -e empty mdmfs -F disk.img md mnt
49		md_dev=$(df mnt | awk 'NR != 1 { print $1 }' | xargs basename)
50		atf_check test -c /dev/$md_dev # Sanity check
51		echo -n $md_dev > $TMPDIR/$MD_DEVICE_FILE
52	else
53	# End FreeBSD
54	atf_check -s eq:0 -o empty -e empty vndconfig /dev/vnd3 disk.img
55
56	atf_check -s eq:0 -o ignore -e ignore newfs /dev/rvnd3a
57
58	atf_check -s eq:0 -o empty -e empty mkdir mnt
59	atf_check -s eq:0 -o empty -e empty mount /dev/vnd3a mnt
60	# Begin FreeBSD
61	fi
62	# End FreeBSD
63
64	echo "Creating test files"
65	for f in $(jot -w %u 100 | uniq); do
66		jot 1000 >mnt/${f} || atf_fail "Failed to create file ${f}"
67	done
68
69	echo "Verifying created files"
70	for f in $(jot -w %u 100 | uniq); do
71		[ $(md5 mnt/${f} | cut -d ' ' -f 4) = \
72		    53d025127ae99ab79e8502aae2d9bea6 ] || \
73		    atf_fail "Invalid checksum for file ${f}"
74	done
75
76	atf_check -s eq:0 -o empty -e empty umount mnt
77	atf_check -s eq:0 -o empty -e empty vndconfig -u /dev/vnd3
78
79	test_unmount
80	touch done
81}
82basic_cleanup() {
83	# Begin FreeBSD
84	if md_dev=$(cat $TMPDIR/$MD_DEVICE_FILE); then
85		echo "Will try disconnecting $md_dev"
86	else
87		echo "$MD_DEVICE_FILE doesn't exist in $TMPDIR; returning early"
88		return 0
89	fi
90	# End FreeBSD
91	if [ ! -f done ]; then
92		umount mnt 2>/dev/null 1>&2
93		vndconfig -u /dev/vnd3 2>/dev/null 1>&2
94	fi
95}
96
97atf_init_test_cases() {
98	. $(atf_get_srcdir)/../h_funcs.subr
99	. $(atf_get_srcdir)/h_funcs.subr
100
101	atf_add_test_case basic
102}
103