t_cgd.sh revision 272343
1129906Sbmilekic#	$NetBSD: t_cgd.sh,v 1.11 2013/02/19 21:08:24 joerg Exp $
2141991Sbmilekic#
3243995Spjd# Copyright (c) 2010 The NetBSD Foundation, Inc.
4129906Sbmilekic# All rights reserved.
5129906Sbmilekic#
6129906Sbmilekic# Redistribution and use in source and binary forms, with or without
7129906Sbmilekic# modification, are permitted provided that the following conditions
8129906Sbmilekic# are met:
9129906Sbmilekic# 1. Redistributions of source code must retain the above copyright
10129906Sbmilekic#    notice, this list of conditions and the following disclaimer.
11129906Sbmilekic# 2. Redistributions in binary form must reproduce the above copyright
12129906Sbmilekic#    notice, this list of conditions and the following disclaimer in the
13129906Sbmilekic#    documentation and/or other materials provided with the distribution.
14129906Sbmilekic#
15129906Sbmilekic# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16129906Sbmilekic# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17129906Sbmilekic# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18129906Sbmilekic# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19129906Sbmilekic# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20129906Sbmilekic# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21129906Sbmilekic# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22129906Sbmilekic# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23129906Sbmilekic# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24129906Sbmilekic# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25129906Sbmilekic# POSSIBILITY OF SUCH DAMAGE.
26129906Sbmilekic#
27129906Sbmilekic
28129906Sbmilekicrawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'`
29129906Sbmilekicrawcgd=/dev/rcgd0${rawpart}
30129906Sbmilekiccgdserver=\
31129906Sbmilekic"rump_server -lrumpvfs -lrumpkern_crypto -lrumpdev -lrumpdev_disk -lrumpdev_cgd"
32129906Sbmilekic
33129906Sbmilekicatf_test_case basic cleanup
34129906Sbmilekicbasic_head()
35129906Sbmilekic{
36129906Sbmilekic
37129906Sbmilekic	atf_set "descr" "Tests that encrypt/decrypt works"
38129906Sbmilekic	atf_set "require.progs" "rump_server"
39129906Sbmilekic}
40129906Sbmilekic
41129906Sbmilekicbasic_body()
42129906Sbmilekic{
43129906Sbmilekic
44163606Srwatson	d=$(atf_get_srcdir)
45163606Srwatson	atf_check -s exit:0 \
46129906Sbmilekic	    ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock
47194454Salc
48194454Salc	export RUMP_SERVER=unix://csock
49129906Sbmilekic	atf_check -s exit:0 -x "echo 12345 | \
50245575Sandre	    rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile"
51129906Sbmilekic	atf_check -s exit:0 -e ignore -x \
52147537Ssilby	    "dd if=${d}/t_cgd count=2 | rump.dd of=${rawcgd}"
53147537Ssilby	atf_check -s exit:0 -e ignore dd if=${d}/t_cgd of=testfile count=2
54129906Sbmilekic	atf_check -s exit:0 -e ignore -o file:testfile \
55129906Sbmilekic	    rump.dd if=${rawcgd} count=2
56129906Sbmilekic}
57129906Sbmilekic
58129906Sbmilekicbasic_cleanup()
59129906Sbmilekic{
60129906Sbmilekic
61129906Sbmilekic	env RUMP_SERVER=unix://csock rump.halt || true
62129906Sbmilekic}
63129906Sbmilekic
64129906Sbmilekicatf_test_case wrongpass cleanup
65129906Sbmilekicwrongpass_head()
66129906Sbmilekic{
67129906Sbmilekic
68129906Sbmilekic	atf_set "descr" "Tests that wrong password does not give original " \
69129906Sbmilekic	    "plaintext"
70129906Sbmilekic	atf_set "require.progs" "rump_server"
71129906Sbmilekic}
72129906Sbmilekic
73129906Sbmilekicwrongpass_body()
74129906Sbmilekic{
75129906Sbmilekic
76129906Sbmilekic	d=$(atf_get_srcdir)
77129906Sbmilekic	atf_check -s exit:0 \
78129906Sbmilekic	    ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock
79129906Sbmilekic
80243995Spjd	export RUMP_SERVER=unix://csock
81129906Sbmilekic	atf_check -s exit:0 -x "echo 12345 | \
82129906Sbmilekic	    rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile"
83129906Sbmilekic	atf_check -s exit:0 -e ignore -x \
84151976Sandre	    "dd if=${d}/t_cgd | rump.dd of=${rawcgd} count=2"
85151976Sandre
86156023Sglebius	# unconfig and reconfig cgd
87151976Sandre	atf_check -s exit:0 rump.cgdconfig -u cgd0
88156023Sglebius	atf_check -s exit:0 -x "echo 54321 | \
89151976Sandre	    rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile"
90156023Sglebius
91151976Sandre	atf_check -s exit:0 -e ignore dd if=${d}/t_cgd of=testfile count=2
92151976Sandre	atf_check -s exit:0 -e ignore -o not-file:testfile \
93156023Sglebius	    rump.dd if=${rawcgd} count=2
94151976Sandre}
95151976Sandre
96151976Sandrewrongpass_cleanup()
97151976Sandre{
98129906Sbmilekic
99129906Sbmilekic	env RUMP_SERVER=unix://csock rump.halt || true
100243631Sandre}
101151976Sandre
102155780Sandre
103151976Sandreatf_test_case unaligned_write cleanup
104151976Sandreunaligned_write_head()
105129906Sbmilekic{
106253204Sandre
107253204Sandre	atf_set "descr" "Attempt unaligned writes to a raw cgd device"
108253204Sandre	atf_set "require.progs" "rump_server"
109253204Sandre}
110253204Sandre
111185893Sbzunaligned_write_body()
112245575Sandre{
113185893Sbz	d=$(atf_get_srcdir)
114129906Sbmilekic	atf_check -s exit:0 \
115129906Sbmilekic	    ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock
116129906Sbmilekic
117253204Sandre	export RUMP_SERVER=unix://csock
118129906Sbmilekic	atf_check -s exit:0 -x "echo 12345 | \
119245575Sandre	    rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile"
120245575Sandre
121245575Sandre	# Check that cgd rejects writes of totally bogus lengths.
122245575Sandre	atf_check -s not-exit:0 -e ignore -x \
123245575Sandre	    "echo die hard | rump.dd of=${rawcgd} bs=123 conv=sync"
124254025Sjeff
125245575Sandre	# Check that cgd rejects non-sector-length writes even if they
126253204Sandre	# are integral multiples of the block size.
127245575Sandre	atf_check -s not-exit:0 -e ignore -x \
128245575Sandre	    "echo die hard | rump.dd of=${rawcgd} bs=64 conv=sync"
129245575Sandre	atf_check -s not-exit:0 -e ignore -x \
130239624Snp	    "echo die hard | rump.dd of=${rawcgd} bs=256 conv=sync"
131243639Sandre
132243639Sandre	# Check that cgd rejects misaligned buffers, produced by
133239624Snp	# packetizing the input on bogus boundaries and using the
134239624Snp	# bizarre behaviour of `bs=N' in dd.
135239624Snp	atf_check -s not-exit:0 -e ignore -x \
136243639Sandre	    "(echo -n x && sleep 1 && head -c 511 </dev/zero) \
137239624Snp		| rump.dd of=${rawcgd} bs=512"
138239624Snp
139239624Snp	# Check that cgd rejects sector-length writes if they are not
140243639Sandre	# on sector boundaries.  Doesn't work because dd can't be
141239624Snp	# persuaded to seek a non-integral multiple of the output
142239624Snp	# buffer size and I can't be arsed to find the another way to
143239624Snp	# do that.
144243639Sandre	#atf_check -s not-exit:0 -e ignore -x \
145243639Sandre	#    "echo die hard | rump.dd of=${rawcgd} seek=1 bs=512 conv=sync"
146243639Sandre}
147243639Sandre
148243639Sandreunaligned_write_cleanup()
149243639Sandre{
150243639Sandre	env RUMP_SERVER=unix://csock rump.halt || true
151243639Sandre}
152243639Sandre
153243996Spjdatf_init_test_cases()
154129906Sbmilekic{
155245575Sandre
156129906Sbmilekic	atf_add_test_case basic
157157927Sps	atf_add_test_case wrongpass
158157927Sps	atf_add_test_case unaligned_write
159157927Sps}
160157927Sps