1272343Sngie#	$NetBSD: t_disk.sh,v 1.5 2013/02/19 21:08:25 joerg Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2011 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngieserver='rump_server -lrumpvfs'
29272343Sngieexport RUMP_SERVER='unix://commsock'
30272343Sngie
31272343Sngiestartsrv()
32272343Sngie{
33272343Sngie
34272343Sngie	atf_check -s exit:0 ${server} $@ ${RUMP_SERVER}
35272343Sngie}
36272343Sngie
37272343Sngietest_case()
38272343Sngie{
39272343Sngie	local name="${1}"; shift
40272343Sngie
41272343Sngie	atf_test_case "${name}" cleanup
42272343Sngie	eval "${name}_head() {  \
43272343Sngie		atf_set "require.progs" "rump_server" ; \
44272343Sngie	}"
45272343Sngie	eval "${name}_body() { \
46272343Sngie		${name}_prefun ; \
47272343Sngie		startsrv $@ ; \
48272343Sngie		${name} ; \
49272343Sngie	}"
50272343Sngie	eval "${name}_cleanup() { \
51272343Sngie		[ -f halted ] && return 0 ; rump.halt ;
52272343Sngie	}"
53272343Sngie}
54272343Sngie
55272343Sngietest_case size -d key=/img,hostpath=the.img,size=32k
56272343Sngiesize()
57272343Sngie{
58272343Sngie	atf_check -s exit:0 -o inline:'32768\n' stat -f %z the.img
59272343Sngie}
60272343Sngie
61272343Sngietest_case offset -d key=/img,hostpath=the.img,size=32k,offset=16k
62272343Sngieoffset()
63272343Sngie{
64272343Sngie	atf_check -s exit:0 -o inline:'49152\n' stat -f %z the.img
65272343Sngie}
66272343Sngie
67272343Sngietest_case notrunc -d key=/img,hostpath=the.img,size=8k,offset=16k
68272343Sngienotrunc_prefun()
69272343Sngie{
70272343Sngie	dd if=/dev/zero of=the.img bs=1 oseek=65535 count=1 
71272343Sngie}
72272343Sngienotrunc()
73272343Sngie{
74272343Sngie	atf_check -s exit:0 -o inline:'65536\n' stat -f %z the.img
75272343Sngie}
76272343Sngie
77272343Sngietest_case data -d key=/img,hostpath=the.img,size=8k,offset=16k
78272343Sngiedata()
79272343Sngie{
80272343Sngie	echo 'test string' | dd of=testfile ibs=512 count=1 conv=sync
81272343Sngie	atf_check -s exit:0 -e ignore -x \
82272343Sngie	    "dd if=testfile | rump.dd of=/img bs=512 count=1"
83272343Sngie
84272343Sngie	# cheap fsync
85272343Sngie	atf_check -s exit:0 rump.halt
86272343Sngie	touch halted
87272343Sngie	atf_check -s exit:0 -e ignore -o file:testfile \
88272343Sngie	    dd if=the.img iseek=16k bs=1 count=512
89272343Sngie}
90272343Sngie
91272343Sngietest_case type_chr -d key=/img,hostpath=the.img,size=32k,type=chr
92272343Sngietype_chr()
93272343Sngie{
94272343Sngie	atf_check -s exit:0 -o inline:'Character Device\n' \
95272343Sngie	    env LD_PRELOAD=/usr/lib/librumphijack.so stat -f %HT /rump/img
96272343Sngie}
97272343Sngie
98272343Sngietest_case type_reg -d key=/img,hostpath=the.img,size=32k,type=reg
99272343Sngietype_reg()
100272343Sngie{
101272343Sngie	atf_check -s exit:0 -o inline:'Regular File\n' \
102272343Sngie	    env LD_PRELOAD=/usr/lib/librumphijack.so stat -f %HT /rump/img
103272343Sngie}
104272343Sngie
105272343Sngietest_case type_blk -d key=/img,hostpath=the.img,size=32k,type=blk
106272343Sngietype_blk()
107272343Sngie{
108272343Sngie	atf_check -s exit:0 -o inline:'Block Device\n' \
109272343Sngie	    env LD_PRELOAD=/usr/lib/librumphijack.so stat -f %HT /rump/img
110272343Sngie}
111272343Sngie
112272343Sngietest_case type_blk_default -d key=/img,hostpath=the.img,size=32k
113272343Sngietype_blk_default()
114272343Sngie{
115272343Sngie	atf_check -s exit:0 -o inline:'Block Device\n' \
116272343Sngie	    env LD_PRELOAD=/usr/lib/librumphijack.so stat -f %HT /rump/img
117272343Sngie}
118272343Sngie
119272343Sngieatf_init_test_cases()
120272343Sngie{
121272343Sngie
122272343Sngie	atf_add_test_case size
123272343Sngie	atf_add_test_case offset
124272343Sngie	atf_add_test_case notrunc
125272343Sngie	atf_add_test_case data
126272343Sngie	atf_add_test_case type_chr
127272343Sngie	atf_add_test_case type_reg
128272343Sngie	atf_add_test_case type_blk
129272343Sngie	atf_add_test_case type_blk_default
130272343Sngie}
131