1170809Sdelphij#!/bin/sh
2170809Sdelphij#
3170809Sdelphij# $NetBSD: t_vnd,v 1.1 2006/11/09 15:25:37 jmmv Exp $
4170809Sdelphij#
5170809Sdelphij# Copyright (c) 2006 The NetBSD Foundation, Inc.
6170809Sdelphij# All rights reserved.
7170809Sdelphij#
8170809Sdelphij# This code is derived from software contributed to The NetBSD Foundation
9170809Sdelphij# by Julio M. Merino Vidal.
10170809Sdelphij#
11170809Sdelphij# Redistribution and use in source and binary forms, with or without
12170809Sdelphij# modification, are permitted provided that the following conditions
13170809Sdelphij# are met:
14170809Sdelphij# 1. Redistributions of source code must retain the above copyright
15170809Sdelphij#    notice, this list of conditions and the following disclaimer.
16170809Sdelphij# 2. Redistributions in binary form must reproduce the above copyright
17170809Sdelphij#    notice, this list of conditions and the following disclaimer in the
18170809Sdelphij#    documentation and/or other materials provided with the distribution.
19170809Sdelphij#
20170809Sdelphij# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21170809Sdelphij# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22170809Sdelphij# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23170809Sdelphij# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24170809Sdelphij# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25170809Sdelphij# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26170809Sdelphij# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27170809Sdelphij# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28170809Sdelphij# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29170809Sdelphij# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30170809Sdelphij# POSSIBILITY OF SUCH DAMAGE.
31170809Sdelphij#
32170809Sdelphij# $FreeBSD$
33170809Sdelphij#
34170809Sdelphij
35170809Sdelphij#
36170809Sdelphij# Verifies that vnd works with files stored in tmpfs.
37170809Sdelphij#
38170809Sdelphij
39170809Sdelphijdie_mounted() {
40170809Sdelphij	umount mnt
41170809Sdelphij	die_configured
42170809Sdelphij}
43170809Sdelphij
44170809Sdelphijdie_configured() {
45170809Sdelphij	mdconfig -d -u 3	
46170809Sdelphij	die
47170809Sdelphij}
48170809Sdelphij
49170809Sdelphijtest_run() {
50170809Sdelphij	test_mount
51170809Sdelphij
52170809Sdelphij	test_name "Creation of disk image"
53170809Sdelphij	dd if=/dev/zero of=disk.img bs=1m count=10 >/dev/null 2>&1 || die
54170809Sdelphij
55170809Sdelphij	test_name "Configuration of vnd"
56170809Sdelphij	mdconfig -a -f disk.img -u 3 -x 32 -y 2 ||die
57170809Sdelphij
58170809Sdelphij	test_name "Labelling the md"
59170809Sdelphij	bsdlabel -m i386 -w /dev/md3 || die_configured
60170809Sdelphij	
61170809Sdelphij	test_name "Formatting of disk image"
62170809Sdelphij	newfs -n -U -m 0 -O 1 /dev/md3a >/dev/null 2>&1 || die_configured
63170809Sdelphij
64170809Sdelphij	test_name "Mounting of disk image"
65170809Sdelphij	mkdir mnt || die
66170809Sdelphij	mount /dev/md3a mnt || die_configured
67170809Sdelphij
68170809Sdelphij	test_name "Creation of several files"
69170809Sdelphij	for f in $(jot 100); do
70170809Sdelphij		jot 1000 >mnt/$f || die_mounted
71170809Sdelphij	done
72170809Sdelphij
73170809Sdelphij	test_name "Verification of created files"
74170809Sdelphij	for f in $(jot 100); do
75170809Sdelphij		[ $(md5 mnt/$f | cut -d ' ' -f 4) = \
76170809Sdelphij		    53d025127ae99ab79e8502aae2d9bea6 ] || die_mounted
77170809Sdelphij	done
78170809Sdelphij
79170809Sdelphij	test_name "Unmounting of disk image"
80170809Sdelphij	umount mnt || die_configured
81170809Sdelphij
82170809Sdelphij	test_name "Deconfiguration of vnd"
83170809Sdelphij	mdconfig -d -u 3 || die
84170809Sdelphij
85170809Sdelphij	test_unmount
86170809Sdelphij}
87170809Sdelphij
88170809Sdelphij. ${SUBRDIR}/h_funcs.subr
89