| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: t_cgd.sh,v 1.12 2019/04/10 06:09:39 kre Exp $ | | 1 | # $NetBSD: t_cgd.sh,v 1.13 2019/04/10 06:13:21 kre Exp $ |
2 | # | | 2 | # |
3 | # Copyright (c) 2010 The NetBSD Foundation, Inc. | | 3 | # Copyright (c) 2010 The NetBSD Foundation, Inc. |
4 | # All rights reserved. | | 4 | # All rights reserved. |
5 | # | | 5 | # |
6 | # Redistribution and use in source and binary forms, with or without | | 6 | # Redistribution and use in source and binary forms, with or without |
7 | # modification, are permitted provided that the following conditions | | 7 | # modification, are permitted provided that the following conditions |
8 | # are met: | | 8 | # are met: |
9 | # 1. Redistributions of source code must retain the above copyright | | 9 | # 1. Redistributions of source code must retain the above copyright |
10 | # notice, this list of conditions and the following disclaimer. | | 10 | # notice, this list of conditions and the following disclaimer. |
11 | # 2. Redistributions in binary form must reproduce the above copyright | | 11 | # 2. Redistributions in binary form must reproduce the above copyright |
12 | # notice, this list of conditions and the following disclaimer in the | | 12 | # notice, this list of conditions and the following disclaimer in the |
13 | # documentation and/or other materials provided with the distribution. | | 13 | # documentation and/or other materials provided with the distribution. |
14 | # | | 14 | # |
| @@ -24,179 +24,173 @@ | | | @@ -24,179 +24,173 @@ |
24 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 24 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 | # POSSIBILITY OF SUCH DAMAGE. | | 25 | # POSSIBILITY OF SUCH DAMAGE. |
26 | # | | 26 | # |
27 | | | 27 | |
28 | rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'` | | 28 | rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'` |
29 | rawcgd=/dev/rcgd0${rawpart} | | 29 | rawcgd=/dev/rcgd0${rawpart} |
30 | cgdserver=\ | | 30 | cgdserver=\ |
31 | "rump_server -lrumpvfs -lrumpkern_crypto -lrumpdev -lrumpdev_disk -lrumpdev_cgd" | | 31 | "rump_server -lrumpvfs -lrumpkern_crypto -lrumpdev -lrumpdev_disk -lrumpdev_cgd" |
32 | | | 32 | |
33 | atf_test_case basic cleanup | | 33 | atf_test_case basic cleanup |
34 | basic_head() | | 34 | basic_head() |
35 | { | | 35 | { |
36 | | | 36 | |
37 | atf_set "descr" "Tests that encrypt/decrypt works" | | 37 | atf_set descr "Tests that encrypt/decrypt works" |
38 | atf_set "require.progs" "rump_server" | | 38 | atf_set require.progs rump_server |
39 | } | | 39 | } |
40 | | | 40 | |
41 | basic_body() | | 41 | basic_body() |
42 | { | | 42 | { |
43 | | | | |
44 | d=$(atf_get_srcdir) | | 43 | d=$(atf_get_srcdir) |
45 | atf_check -s exit:0 \ | | 44 | atf_check -s exit:0 \ |
46 | ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock | | 45 | ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock |
47 | | | 46 | |
48 | export RUMP_SERVER=unix://csock | | 47 | export RUMP_SERVER=unix://csock |
49 | atf_check -s exit:0 -x "echo 12345 | \ | | 48 | atf_check -s exit:0 -x "echo 12345 | \ |
50 | rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" | | 49 | rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" |
51 | atf_check -s exit:0 -e ignore -x \ | | 50 | atf_check -s exit:0 -e ignore -x \ |
52 | "dd if=${d}/t_cgd count=2 | rump.dd of=${rawcgd}" | | 51 | "dd if=${d}/t_cgd count=2 | rump.dd of=${rawcgd}" |
53 | atf_check -s exit:0 -e ignore dd if=${d}/t_cgd of=testfile count=2 | | 52 | atf_check -s exit:0 -e ignore dd if=${d}/t_cgd of=testfile count=2 |
54 | atf_check -s exit:0 -e ignore -o file:testfile \ | | 53 | atf_check -s exit:0 -e ignore -o file:testfile \ |
55 | rump.dd if=${rawcgd} count=2 | | 54 | rump.dd if=${rawcgd} count=2 |
56 | } | | 55 | } |
57 | | | 56 | |
58 | basic_cleanup() | | 57 | basic_cleanup() |
59 | { | | 58 | { |
60 | | | | |
61 | env RUMP_SERVER=unix://csock rump.halt || true | | 59 | env RUMP_SERVER=unix://csock rump.halt || true |
62 | } | | 60 | } |
63 | | | 61 | |
64 | atf_test_case wrongpass cleanup | | 62 | atf_test_case wrongpass cleanup |
65 | wrongpass_head() | | 63 | wrongpass_head() |
66 | { | | 64 | { |
67 | | | 65 | |
68 | atf_set "descr" "Tests that wrong password does not give original " \ | | 66 | atf_set descr \ |
69 | "plaintext" | | 67 | "Tests that wrong password does not give original plaintext" |
70 | atf_set "require.progs" "rump_server" | | 68 | atf_set require.progs rump_server |
71 | } | | 69 | } |
72 | | | 70 | |
73 | wrongpass_body() | | 71 | wrongpass_body() |
74 | { | | 72 | { |
75 | | | | |
76 | d=$(atf_get_srcdir) | | 73 | d=$(atf_get_srcdir) |
77 | atf_check -s exit:0 \ | | 74 | atf_check -s exit:0 \ |
78 | ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock | | 75 | ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock |
79 | | | 76 | |
80 | export RUMP_SERVER=unix://csock | | 77 | export RUMP_SERVER=unix://csock |
81 | atf_check -s exit:0 -x "echo 12345 | \ | | 78 | atf_check -s exit:0 -x \ |
82 | rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" | | 79 | "echo 12345 | rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" |
83 | atf_check -s exit:0 -e ignore -x \ | | 80 | atf_check -s exit:0 -e ignore -x \ |
84 | "dd if=${d}/t_cgd | rump.dd of=${rawcgd} count=2" | | 81 | "dd if=${d}/t_cgd | rump.dd of=${rawcgd} count=2" |
85 | | | 82 | |
86 | # unconfig and reconfig cgd | | 83 | # unconfig and reconfig cgd |
87 | atf_check -s exit:0 rump.cgdconfig -u cgd0 | | 84 | atf_check -s exit:0 rump.cgdconfig -u cgd0 |
88 | atf_check -s exit:0 -x "echo 54321 | \ | | 85 | atf_check -s exit:0 -x \ |
89 | rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" | | 86 | "echo 54321 | rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" |
90 | | | 87 | |
91 | atf_check -s exit:0 -e ignore dd if=${d}/t_cgd of=testfile count=2 | | 88 | atf_check -s exit:0 -e ignore dd if=${d}/t_cgd of=testfile count=2 |
92 | atf_check -s exit:0 -e ignore -o not-file:testfile \ | | 89 | atf_check -s exit:0 -e ignore -o not-file:testfile \ |
93 | rump.dd if=${rawcgd} count=2 | | 90 | rump.dd if=${rawcgd} count=2 |
94 | } | | 91 | } |
95 | | | 92 | |
96 | wrongpass_cleanup() | | 93 | wrongpass_cleanup() |
97 | { | | 94 | { |
98 | | | | |
99 | env RUMP_SERVER=unix://csock rump.halt || true | | 95 | env RUMP_SERVER=unix://csock rump.halt || true |
100 | } | | 96 | } |
101 | | | 97 | |
102 | | | 98 | |
103 | atf_test_case unaligned_write cleanup | | 99 | atf_test_case unaligned_write cleanup |
104 | unaligned_write_head() | | 100 | unaligned_write_head() |
105 | { | | 101 | { |
106 | | | 102 | atf_set descr "Attempt unaligned writes to a raw cgd device" |
107 | atf_set "descr" "Attempt unaligned writes to a raw cgd device" | | 103 | atf_set require.progs rump_server |
108 | atf_set "require.progs" "rump_server" | | | |
109 | } | | 104 | } |
110 | | | 105 | |
111 | unaligned_write_body() | | 106 | unaligned_write_body() |
112 | { | | 107 | { |
113 | d=$(atf_get_srcdir) | | 108 | d=$(atf_get_srcdir) |
114 | atf_check -s exit:0 \ | | 109 | atf_check -s exit:0 \ |
115 | ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock | | 110 | ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock |
116 | | | 111 | |
117 | export RUMP_SERVER=unix://csock | | 112 | export RUMP_SERVER=unix://csock |
118 | atf_check -s exit:0 -x "echo 12345 | \ | | 113 | atf_check -s exit:0 -x \ |
119 | rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" | | 114 | "echo 12345 | rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" |
120 | | | 115 | |
121 | # Check that cgd rejects writes of totally bogus lengths. | | 116 | # Check that cgd rejects writes of totally bogus lengths. |
122 | atf_check -s not-exit:0 -e ignore -x \ | | 117 | atf_check -s not-exit:0 -e ignore -x \ |
123 | "echo die hard | rump.dd of=${rawcgd} bs=123 conv=sync" | | 118 | "echo die hard | rump.dd of=${rawcgd} bs=123 conv=sync" |
124 | | | 119 | |
125 | # Check that cgd rejects non-sector-length writes even if they | | 120 | # Check that cgd rejects non-sector-length writes even if they |
126 | # are integral multiples of the block size. | | 121 | # are integral multiples of the block size. |
127 | atf_check -s not-exit:0 -e ignore -x \ | | 122 | atf_check -s not-exit:0 -e ignore -x \ |
128 | "echo die hard | rump.dd of=${rawcgd} bs=64 conv=sync" | | 123 | "echo die hard | rump.dd of=${rawcgd} bs=64 conv=sync" |
129 | atf_check -s not-exit:0 -e ignore -x \ | | 124 | atf_check -s not-exit:0 -e ignore -x \ |
130 | "echo die hard | rump.dd of=${rawcgd} bs=256 conv=sync" | | 125 | "echo die hard | rump.dd of=${rawcgd} bs=256 conv=sync" |
131 | | | 126 | |
132 | # Check that cgd rejects misaligned buffers, produced by | | 127 | # Check that cgd rejects misaligned buffers, produced by |
133 | # packetizing the input on bogus boundaries and using the | | 128 | # packetizing the input on bogus boundaries and using the |
134 | # bizarre behaviour of `bs=N' in dd. | | 129 | # bizarre behaviour of `bs=N' in dd. |
135 | atf_check -s not-exit:0 -e ignore -x \ | | 130 | atf_check -s not-exit:0 -e ignore -x \ |
136 | "(echo -n x && sleep 1 && head -c 511 </dev/zero) \ | | 131 | "(echo -n x && sleep 1 && head -c 511 </dev/zero) | |
137 | | rump.dd of=${rawcgd} bs=512" | | 132 | rump.dd of=${rawcgd} bs=512" |
138 | | | 133 | |
139 | # Check that cgd rejects sector-length writes if they are not | | 134 | # Check that cgd rejects sector-length writes if they are not |
140 | # on sector boundaries. Doesn't work because dd can't be | | 135 | # on sector boundaries. Doesn't work because dd can't be |
141 | # persuaded to seek a non-integral multiple of the output | | 136 | # persuaded to seek a non-integral multiple of the output |
142 | # buffer size and I can't be arsed to find the another way to | | 137 | # buffer size and I can't be arsed to find the another way to |
143 | # do that. | | 138 | # do that. |
144 | #atf_check -s not-exit:0 -e ignore -x \ | | 139 | #atf_check -s not-exit:0 -e ignore -x \ |
145 | # "echo die hard | rump.dd of=${rawcgd} seek=1 bs=512 conv=sync" | | 140 | # "echo die hard | rump.dd of=${rawcgd} seek=1 bs=512 conv=sync" |
146 | } | | 141 | } |
147 | | | 142 | |
148 | unaligned_write_cleanup() | | 143 | unaligned_write_cleanup() |
149 | { | | 144 | { |
150 | env RUMP_SERVER=unix://csock rump.halt || true | | 145 | env RUMP_SERVER=unix://csock rump.halt || true |
151 | } | | 146 | } |
152 | | | 147 | |
153 | vmeth_failure_body() | | 148 | vmeth_failure_body() |
154 | { | | 149 | { |
155 | | | | |
156 | local vmeth="$1" | | 150 | local vmeth="$1" |
157 | local d=$(atf_get_srcdir) | | 151 | local d=$(atf_get_srcdir) |
158 | | | 152 | |
159 | atf_check -s exit:0 \ | | 153 | atf_check -s exit:0 \ |
160 | ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock | | 154 | ${cgdserver} -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock |
161 | export RUMP_SERVER=unix://csock | | 155 | export RUMP_SERVER=unix://csock |
162 | atf_check -s not-exit:0 -e ignore -x "echo 12345 | \ | | 156 | atf_check -s not-exit:0 -e ignore -x \ |
163 | rump.cgdconfig -V "${vmeth}" -p cgd0 /dev/dk ${d}/paramsfile" | | 157 | "echo 12345 | |
164 | atf_check -s exit:0 -o not-match:"(^| )cgd0( |$)" rump.sysctl -n hw.disknames | | 158 | rump.cgdconfig -V '${vmeth}' -p cgd0 /dev/dk ${d}/paramsfile" |
| | | 159 | atf_check -s exit:0 -o not-match:'(^| )cgd0( |$)' \ |
| | | 160 | rump.sysctl -n hw.disknames |
165 | } | | 161 | } |
166 | | | 162 | |
167 | test_case_vmeth_failure() | | 163 | test_case_vmeth_failure() |
168 | { | | 164 | { |
169 | | | | |
170 | local vmeth="${1}" | | 165 | local vmeth="${1}" |
171 | local name="vmeth_failure_${vmeth}" | | 166 | local name="vmeth_failure_${vmeth}" |
172 | | | 167 | |
173 | atf_test_case "${name}" cleanup | | 168 | atf_test_case "${name}" cleanup |
174 | eval "${name}_head() { \ | | 169 | eval "${name}_head() { |
175 | atf_set "descr" "Tests verification method \"${vmeth}\" failure" ; \ | | 170 | atf_set descr 'Tests verification method \"${vmeth}\" failure' |
176 | atf_set "require.progs" "rump_server" ; \ | | 171 | atf_set require.progs rump_server |
177 | }" | | 172 | }" |
178 | eval "${name}_body() { \ | | 173 | eval "${name}_body() { |
179 | vmeth_failure_body "${vmeth}" ; \ | | 174 | vmeth_failure_body '${vmeth}' |
180 | }" | | 175 | }" |
181 | eval "${name}_cleanup() { \ | | 176 | eval "${name}_cleanup() { |
182 | rump.cgdconfig -u cgd0 2>/dev/null ; \ | | 177 | rump.cgdconfig -u cgd0 2>/dev/null |
183 | env RUMP_SERVER=unix://csock rump.halt || true ; \ | | 178 | env RUMP_SERVER=unix://csock rump.halt || true |
184 | }" | | 179 | }" |
185 | } | | 180 | } |
186 | | | 181 | |
187 | test_case_vmeth_failure disklabel | | 182 | test_case_vmeth_failure disklabel |
188 | test_case_vmeth_failure ffs | | 183 | test_case_vmeth_failure ffs |
189 | test_case_vmeth_failure gpt | | 184 | test_case_vmeth_failure gpt |
190 | test_case_vmeth_failure mbr | | 185 | test_case_vmeth_failure mbr |
191 | | | 186 | |
192 | atf_init_test_cases() | | 187 | atf_init_test_cases() |
193 | { | | 188 | { |
194 | | | | |
195 | atf_add_test_case basic | | 189 | atf_add_test_case basic |
196 | atf_add_test_case wrongpass | | 190 | atf_add_test_case wrongpass |
197 | atf_add_test_case unaligned_write | | 191 | atf_add_test_case unaligned_write |
198 | atf_add_test_case vmeth_failure_disklabel | | 192 | atf_add_test_case vmeth_failure_disklabel |
199 | atf_add_test_case vmeth_failure_ffs | | 193 | atf_add_test_case vmeth_failure_ffs |
200 | atf_add_test_case vmeth_failure_gpt | | 194 | atf_add_test_case vmeth_failure_gpt |
201 | atf_add_test_case vmeth_failure_mbr | | 195 | atf_add_test_case vmeth_failure_mbr |
202 | } | | 196 | } |