t_opencrypto.sh revision 1.1 1 # $NetBSD: t_opencrypto.sh,v 1.1 2014/01/14 17:51:39 pgoyette Exp $
2 #
3 # Copyright (c) 2014 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 # Start a rumpserver, load required modules, and set requires sysctl vars
29
30 start_rump() {
31 rump_libs="-l rumpvfs -l rumpdev -l rumpdev_opencrypto"
32 rump_libs="${rump_libs} -l rumpkern_z -l rumpkern_crypto"
33
34 rump_server ${rump_libs} ${RUMP_SERVER} || \
35 return 1
36
37 rump.sysctl -w kern.cryptodevallowsoft=-1 && \
38 return 0
39
40 rump.halt
41
42 return 1
43 }
44
45 common_head() {
46 atf_set descr "$1"
47 atf_set timeout 10
48 atf_set require.progs rump_server rump.sysctl rump.halt
49 }
50
51 common_body() {
52 local status
53
54 start_rump || atf_skip "Cannot set-up rump environment"
55 LD_PRELOAD="/usr/lib/librumphijack.so" ; export LD_PRELOAD
56 RUMPHIJACK="blanket=/dev/crypto" ; export RUMPHIJACK
57 $(atf_get_srcdir)/$1
58 status=$?
59 unset RUMPHIJACK
60 unset LD_PRELOAD
61 if [ $status -ne 0 ] ; then
62 atf_fail "$1 returned non-zero status, check output/error"
63 fi
64 }
65
66 common_cleanup() {
67 unset RUMPHIJACK
68 unset LD_PRELOAD
69 rump.halt
70 }
71
72 atf_test_case arc4 cleanup
73 arc4_head() {
74 common_head "Test ARC4 crypto"
75 }
76
77 arc4_body() {
78 common_body h_arc4
79 }
80
81 arc4_cleanup() {
82 common_cleanup
83 }
84
85 atf_test_case camellia cleanup
86 camellia_head() {
87 common_head "Test CAMELLIA_CBC crypto"
88 }
89
90 camellia_body() {
91 common_body h_camellia
92 }
93
94 camellia_cleanup() {
95 common_cleanup
96 }
97
98 atf_test_case cbcdes cleanup
99 cbcdes_head() {
100 common_head "Test ARC4 crypto"
101 }
102
103 cbcdes_body() {
104 common_body h_cbcdes
105 }
106
107 cbcdes_cleanup() {
108 common_cleanup
109 }
110
111 atf_test_case comp cleanup
112 comp_head() {
113 common_head "Test GZIP_COMP Compression"
114 }
115
116 comp_body() {
117 common_body h_comp
118 }
119
120 comp_cleanup() {
121 common_cleanup
122 }
123
124 atf_test_case comp_deflate cleanup
125 comp_deflate_head() {
126 common_head "Test DEFLATE_COMP Compression"
127 }
128
129 comp_deflate_body() {
130 common_body h_comp_zlib
131 }
132
133 comp_deflate_cleanup() {
134 common_cleanup
135 }
136
137 atf_test_case comp_zlib_rnd cleanup
138 comp_zlib_rnd_head() {
139 common_head "Test DEFLATE_COMP Compression with random data"
140 }
141
142 comp_zlib_rnd_body() {
143 common_body h_comp_zlib_rnd
144 }
145
146 comp_zlib_rnd_cleanup() {
147 common_cleanup
148 }
149
150 atf_test_case aesctr1 cleanup
151 aesctr1_head() {
152 common_head "Test AES_CTR crypto"
153 }
154
155 aesctr1_body() {
156 common_body h_aesctr1
157 }
158
159 aesctr1_cleanup() {
160 common_cleanup
161 }
162
163 atf_test_case aesctr2 cleanup
164 aesctr2_head() {
165 common_head "Test AES_CTR crypto"
166 }
167
168 aesctr2_body() {
169 common_body h_aesctr2
170 }
171
172 aesctr2_cleanup() {
173 common_cleanup
174 }
175
176 atf_test_case gcm cleanup
177 gcm_head() {
178 common_head "Test AES_GCM_16 crypto"
179 }
180
181 gcm_body() {
182 common_body h_gcm
183 }
184
185 gcm_cleanup() {
186 common_cleanup
187 }
188
189 atf_test_case md5 cleanup
190 md5_head() {
191 common_head "Test MD5 crypto"
192 }
193
194 md5_body() {
195 common_body h_md5
196 }
197
198 md5_cleanup() {
199 common_cleanup
200 }
201
202 atf_test_case md5_hmac cleanup
203 md5_hmac_head() {
204 common_head "Test MD5_HMAC crypto"
205 }
206
207 md5_hmac_body() {
208 common_body h_md5hmac
209 }
210
211 md5_hmac_cleanup() {
212 common_cleanup
213 }
214
215 atf_test_case null cleanup
216 null_head() {
217 common_head "Test NULL_CBC crypto"
218 }
219
220 null_body() {
221 common_body h_null
222 }
223
224 null_cleanup() {
225 common_cleanup
226 }
227
228 atf_test_case xcbcmac cleanup
229 xcbcmac_head() {
230 common_head "Test XCBC_MAC_96 crypto"
231 }
232
233 xcbcmac_body() {
234 common_body h_xcbcmac
235 }
236
237 xcbcmac_cleanup() {
238 common_cleanup
239 }
240
241 atf_init_test_cases() {
242 RUMP_SERVER="unix://t_opencrypto_socket" ; export RUMP_SERVER
243
244 atf_add_test_case arc4
245 atf_add_test_case camellia
246 atf_add_test_case cbcdes
247 atf_add_test_case comp
248 atf_add_test_case comp_deflate
249 atf_add_test_case comp_zlib_rnd
250 atf_add_test_case aesctr1
251 atf_add_test_case aesctr2
252 atf_add_test_case gcm
253 atf_add_test_case md5
254 atf_add_test_case md5_hmac
255 atf_add_test_case null
256 atf_add_test_case xcbcmac
257 }
258