Home | History | Annotate | Line # | Download | only in opencrypto
t_opencrypto.sh revision 1.2
      1 #	$NetBSD: t_opencrypto.sh,v 1.2 2014/01/17 14:14:54 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 	atf_skip "ARC4 not implemented by swcrypto"
     79 	common_body h_arc4
     80 }
     81 
     82 arc4_cleanup() {
     83 	common_cleanup
     84 }
     85 
     86 atf_test_case camellia cleanup
     87 camellia_head() {
     88 	common_head "Test CAMELLIA_CBC crypto"
     89 }
     90 
     91 camellia_body() {
     92 	common_body h_camellia
     93 }
     94 
     95 camellia_cleanup() {
     96 	common_cleanup
     97 }
     98 
     99 atf_test_case cbcdes cleanup
    100 cbcdes_head() {
    101 	common_head "Test ARC4 crypto"
    102 }
    103 
    104 cbcdes_body() {
    105 	common_body h_cbcdes
    106 }
    107 
    108 cbcdes_cleanup() {
    109 	common_cleanup
    110 }
    111 
    112 atf_test_case comp cleanup
    113 comp_head() {
    114 	common_head "Test GZIP_COMP Compression"
    115 }
    116 
    117 comp_body() {
    118 	common_body h_comp
    119 }
    120 
    121 comp_cleanup() {
    122 	common_cleanup
    123 }
    124 
    125 atf_test_case comp_deflate cleanup
    126 comp_deflate_head() {
    127 	common_head "Test DEFLATE_COMP Compression"
    128 }
    129 
    130 comp_deflate_body() {
    131 	common_body h_comp_zlib
    132 }
    133 
    134 comp_deflate_cleanup() {
    135 	common_cleanup
    136 }
    137 
    138 atf_test_case comp_zlib_rnd cleanup
    139 comp_zlib_rnd_head() {
    140 	common_head "Test DEFLATE_COMP Compression with random data"
    141 }
    142 
    143 comp_zlib_rnd_body() {
    144 	common_body h_comp_zlib_rnd
    145 }
    146 
    147 comp_zlib_rnd_cleanup() {
    148 	common_cleanup
    149 }
    150 
    151 atf_test_case aesctr1 cleanup
    152 aesctr1_head() {
    153 	common_head "Test AES_CTR crypto"
    154 }
    155 
    156 aesctr1_body() {
    157 	common_body h_aesctr1
    158 }
    159 
    160 aesctr1_cleanup() {
    161 	common_cleanup
    162 }
    163 
    164 atf_test_case aesctr2 cleanup
    165 aesctr2_head() {
    166 	common_head "Test AES_CTR crypto"
    167 }
    168 
    169 aesctr2_body() {
    170 	common_body h_aesctr2
    171 }
    172 
    173 aesctr2_cleanup() {
    174 	common_cleanup
    175 }
    176 
    177 atf_test_case gcm cleanup
    178 gcm_head() {
    179 	common_head "Test AES_GCM_16 crypto"
    180 }
    181 
    182 gcm_body() {
    183 	common_body h_gcm
    184 }
    185 
    186 gcm_cleanup() {
    187 	common_cleanup
    188 }
    189 
    190 atf_test_case md5 cleanup
    191 md5_head() {
    192 	common_head "Test MD5 crypto"
    193 }
    194 
    195 md5_body() {
    196 	common_body h_md5
    197 }
    198 
    199 md5_cleanup() {
    200 	common_cleanup
    201 }
    202 
    203 atf_test_case md5_hmac cleanup
    204 md5_hmac_head() {
    205 	common_head "Test MD5_HMAC crypto"
    206 }
    207 
    208 md5_hmac_body() {
    209 	common_body h_md5hmac
    210 }
    211 
    212 md5_hmac_cleanup() {
    213 	common_cleanup
    214 }
    215 
    216 atf_test_case null cleanup
    217 null_head() {
    218 	atf_skip "NULL_CBC not implemented by swcrypto"
    219 	common_head "Test NULL_CBC crypto"
    220 }
    221 
    222 null_body() {
    223 	common_body h_null
    224 }
    225 
    226 null_cleanup() {
    227 	common_cleanup
    228 }
    229 
    230 atf_test_case xcbcmac cleanup
    231 xcbcmac_head() {
    232 	common_head "Test XCBC_MAC_96 crypto"
    233 }
    234 
    235 xcbcmac_body() {
    236 	common_body h_xcbcmac
    237 }
    238 
    239 xcbcmac_cleanup() {
    240 	common_cleanup
    241 }
    242 
    243 atf_init_test_cases() {
    244 	RUMP_SERVER="unix://t_opencrypto_socket" ; export RUMP_SERVER
    245 
    246 	atf_add_test_case arc4
    247 	atf_add_test_case camellia
    248 	atf_add_test_case cbcdes
    249 	atf_add_test_case comp
    250 	atf_add_test_case comp_deflate
    251 	atf_add_test_case comp_zlib_rnd
    252 	atf_add_test_case aesctr1
    253 	atf_add_test_case aesctr2
    254 	atf_add_test_case gcm
    255 	atf_add_test_case md5
    256 	atf_add_test_case md5_hmac
    257 	atf_add_test_case null
    258 	atf_add_test_case xcbcmac
    259 }
    260