t_opencrypto.sh revision 272343
1272343Sngie#	$NetBSD: t_opencrypto.sh,v 1.4 2014/01/18 15:15:16 pgoyette Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2014 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
28272343Sngie# Start a rumpserver, load required modules, and set requires sysctl vars
29272343Sngie
30272343Sngiestart_rump() {
31272343Sngie	rump_libs="-l rumpvfs -l rumpdev -l rumpdev_opencrypto"
32272343Sngie	rump_libs="${rump_libs} -l rumpkern_z -l rumpkern_crypto"
33272343Sngie
34272343Sngie	rump_server ${rump_libs} ${RUMP_SERVER} || \
35272343Sngie	    return 1
36272343Sngie
37272343Sngie	rump.sysctl -w kern.cryptodevallowsoft=-1 && \
38272343Sngie	    return 0
39272343Sngie
40272343Sngie	rump.halt
41272343Sngie
42272343Sngie	return 1
43272343Sngie}
44272343Sngie
45272343Sngiecommon_head() {
46272343Sngie	atf_set	descr		"$1"
47272343Sngie	atf_set	timeout		10
48272343Sngie	atf_set	require.progs	rump_server	rump.sysctl	rump.halt
49272343Sngie}
50272343Sngie
51272343Sngiecommon_body() {
52272343Sngie	local status
53272343Sngie
54272343Sngie	start_rump || atf_skip "Cannot set-up rump environment"
55272343Sngie	LD_PRELOAD="/usr/lib/librumphijack.so" ; export LD_PRELOAD
56272343Sngie	RUMPHIJACK="blanket=/dev/crypto" ; export RUMPHIJACK
57272343Sngie	$(atf_get_srcdir)/$1
58272343Sngie	status=$?
59272343Sngie	unset RUMPHIJACK
60272343Sngie	unset LD_PRELOAD
61272343Sngie	if [ $status -ne 0 ] ; then
62272343Sngie		atf_fail "$1 returned non-zero status, check output/error"
63272343Sngie	fi
64272343Sngie}
65272343Sngie
66272343Sngiecommon_cleanup() {
67272343Sngie	unset RUMPHIJACK
68272343Sngie	unset LD_PRELOAD
69272343Sngie	rump.halt
70272343Sngie}
71272343Sngie
72272343Sngieatf_test_case arc4 cleanup
73272343Sngiearc4_head() {
74272343Sngie	common_head "Test ARC4 crypto"
75272343Sngie}
76272343Sngie
77272343Sngiearc4_body() {
78272343Sngie	atf_skip "ARC4 not implemented by swcrypto"
79272343Sngie	common_body h_arc4
80272343Sngie}
81272343Sngie
82272343Sngiearc4_cleanup() {
83272343Sngie	common_cleanup
84272343Sngie}
85272343Sngie
86272343Sngieatf_test_case camellia cleanup
87272343Sngiecamellia_head() {
88272343Sngie	common_head "Test CAMELLIA_CBC crypto"
89272343Sngie}
90272343Sngie
91272343Sngiecamellia_body() {
92272343Sngie	common_body h_camellia
93272343Sngie}
94272343Sngie
95272343Sngiecamellia_cleanup() {
96272343Sngie	common_cleanup
97272343Sngie}
98272343Sngie
99272343Sngieatf_test_case cbcdes cleanup
100272343Sngiecbcdes_head() {
101272343Sngie	common_head "Test ARC4 crypto"
102272343Sngie}
103272343Sngie
104272343Sngiecbcdes_body() {
105272343Sngie	common_body h_cbcdes
106272343Sngie}
107272343Sngie
108272343Sngiecbcdes_cleanup() {
109272343Sngie	common_cleanup
110272343Sngie}
111272343Sngie
112272343Sngieatf_test_case comp cleanup
113272343Sngiecomp_head() {
114272343Sngie	common_head "Test GZIP_COMP Compression"
115272343Sngie}
116272343Sngie
117272343Sngiecomp_body() {
118272343Sngie	common_body h_comp
119272343Sngie}
120272343Sngie
121272343Sngiecomp_cleanup() {
122272343Sngie	common_cleanup
123272343Sngie}
124272343Sngie
125272343Sngieatf_test_case comp_deflate cleanup
126272343Sngiecomp_deflate_head() {
127272343Sngie	common_head "Test DEFLATE_COMP Compression"
128272343Sngie}
129272343Sngie
130272343Sngiecomp_deflate_body() {
131272343Sngie	common_body h_comp_zlib
132272343Sngie}
133272343Sngie
134272343Sngiecomp_deflate_cleanup() {
135272343Sngie	common_cleanup
136272343Sngie}
137272343Sngie
138272343Sngieatf_test_case comp_zlib_rnd cleanup
139272343Sngiecomp_zlib_rnd_head() {
140272343Sngie	common_head "Test DEFLATE_COMP Compression with random data"
141272343Sngie}
142272343Sngie
143272343Sngiecomp_zlib_rnd_body() {
144272343Sngie	common_body h_comp_zlib_rnd
145272343Sngie}
146272343Sngie
147272343Sngiecomp_zlib_rnd_cleanup() {
148272343Sngie	common_cleanup
149272343Sngie}
150272343Sngie
151272343Sngieatf_test_case aesctr1 cleanup
152272343Sngieaesctr1_head() {
153272343Sngie	common_head "Test AES_CTR crypto"
154272343Sngie}
155272343Sngie
156272343Sngieaesctr1_body() {
157272343Sngie	common_body h_aesctr1
158272343Sngie}
159272343Sngie
160272343Sngieaesctr1_cleanup() {
161272343Sngie	common_cleanup
162272343Sngie}
163272343Sngie
164272343Sngieatf_test_case aesctr2 cleanup
165272343Sngieaesctr2_head() {
166272343Sngie	common_head "Test AES_CTR crypto"
167272343Sngie}
168272343Sngie
169272343Sngieaesctr2_body() {
170272343Sngie	common_body h_aesctr2
171272343Sngie}
172272343Sngie
173272343Sngieaesctr2_cleanup() {
174272343Sngie	common_cleanup
175272343Sngie}
176272343Sngie
177272343Sngieatf_test_case gcm cleanup
178272343Sngiegcm_head() {
179272343Sngie	common_head "Test AES_GCM_16 crypto"
180272343Sngie}
181272343Sngie
182272343Sngiegcm_body() {
183272343Sngie	common_body h_gcm
184272343Sngie}
185272343Sngie
186272343Sngiegcm_cleanup() {
187272343Sngie	common_cleanup
188272343Sngie}
189272343Sngie
190272343Sngieatf_test_case md5 cleanup
191272343Sngiemd5_head() {
192272343Sngie	common_head "Test MD5 crypto"
193272343Sngie}
194272343Sngie
195272343Sngiemd5_body() {
196272343Sngie	common_body h_md5
197272343Sngie}
198272343Sngie
199272343Sngiemd5_cleanup() {
200272343Sngie	common_cleanup
201272343Sngie}
202272343Sngie
203272343Sngieatf_test_case md5_hmac cleanup
204272343Sngiemd5_hmac_head() {
205272343Sngie	common_head "Test MD5_HMAC crypto"
206272343Sngie}
207272343Sngie
208272343Sngiemd5_hmac_body() {
209272343Sngie	common_body h_md5hmac
210272343Sngie}
211272343Sngie
212272343Sngiemd5_hmac_cleanup() {
213272343Sngie	common_cleanup
214272343Sngie}
215272343Sngie
216272343Sngieatf_test_case null cleanup
217272343Sngienull_head() {
218272343Sngie	common_head "Test NULL_CBC crypto"
219272343Sngie}
220272343Sngie
221272343Sngienull_body() {
222272343Sngie	common_body h_null
223272343Sngie}
224272343Sngie
225272343Sngienull_cleanup() {
226272343Sngie	common_cleanup
227272343Sngie}
228272343Sngie
229272343Sngieatf_test_case sha1_hmac cleanup
230272343Sngiesha1_hmac_head() {
231272343Sngie	common_head "Test SHA1_HMAC crypto"
232272343Sngie}
233272343Sngie
234272343Sngiesha1_hmac_body() {
235272343Sngie	common_body h_sha1hmac
236272343Sngie}
237272343Sngie
238272343Sngiesha1_hmac_cleanup() {
239272343Sngie	common_cleanup
240272343Sngie}
241272343Sngie
242272343Sngieatf_test_case xcbcmac cleanup
243272343Sngiexcbcmac_head() {
244272343Sngie	common_head "Test XCBC_MAC_96 crypto"
245272343Sngie}
246272343Sngie
247272343Sngiexcbcmac_body() {
248272343Sngie	common_body h_xcbcmac
249272343Sngie}
250272343Sngie
251272343Sngiexcbcmac_cleanup() {
252272343Sngie	common_cleanup
253272343Sngie}
254272343Sngie
255272343Sngieatf_init_test_cases() {
256272343Sngie	RUMP_SERVER="unix://t_opencrypto_socket" ; export RUMP_SERVER
257272343Sngie
258272343Sngie	atf_add_test_case arc4
259272343Sngie	atf_add_test_case camellia
260272343Sngie	atf_add_test_case cbcdes
261272343Sngie	atf_add_test_case comp
262272343Sngie	atf_add_test_case comp_deflate
263272343Sngie	atf_add_test_case comp_zlib_rnd
264272343Sngie	atf_add_test_case aesctr1
265272343Sngie	atf_add_test_case aesctr2
266272343Sngie	atf_add_test_case gcm
267272343Sngie	atf_add_test_case md5
268272343Sngie	atf_add_test_case md5_hmac
269272343Sngie	atf_add_test_case null
270272343Sngie	atf_add_test_case sha1_hmac
271272343Sngie	atf_add_test_case xcbcmac
272272343Sngie}
273