Home | History | Annotate | Line # | Download | only in modules
t_modload.sh revision 1.1.6.1
      1 # $NetBSD: t_modload.sh,v 1.1.6.1 2008/05/18 12:36:01 yamt Exp $
      2 #
      3 # Copyright (c) 2008 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 check_sysctl() {
     29 	echo "${1} = ${2}" >expout
     30 	atf_check "sysctl ${1}" 0 expout null
     31 }
     32 
     33 atf_test_case plain
     34 plain_head() {
     35 	atf_set "descr" "Test load without arguments"
     36 	atf_set "require.user" "root"
     37 }
     38 plain_body() {
     39 	cat >experr <<EOF
     40 modload: No such file or directory
     41 EOF
     42 	atf_check "modload non-existent.o" 1 null experr
     43 
     44 	atf_check "modload $(atf_get_srcdir)/k_helper.kmod" 0 null null
     45 	check_sysctl vendor.k_helper.present 1
     46 	check_sysctl vendor.k_helper.prop_int_ok 0
     47 	check_sysctl vendor.k_helper.prop_str_ok 0
     48 	atf_check "modunload k_helper" 0 null null
     49 }
     50 plain_cleanup() {
     51 	modunload k_helper >/dev/null 2>&1
     52 }
     53 
     54 atf_test_case bflag
     55 bflag_head() {
     56 	atf_set "descr" "Test the -b flag"
     57 	atf_set "require.user" "root"
     58 }
     59 bflag_body() {
     60 	echo "Checking error conditions"
     61 
     62 	atf_check "modload -b foo k_helper.kmod" 1 null stderr
     63 	atf_check "grep 'Invalid parameter.*foo' stderr" 0 ignore null
     64 
     65 	atf_check "modload -b foo= k_helper.kmod" 1 null stderr
     66 	atf_check "grep 'Invalid boolean value' stderr" 0 ignore null
     67 
     68 	atf_check "modload -b foo=bar k_helper.kmod" 1 null stderr
     69 	atf_check "grep 'Invalid boolean value.*bar' stderr" 0 ignore null
     70 
     71 	atf_check "modload -b foo=falsea k_helper.kmod" 1 null stderr
     72 	atf_check "grep 'Invalid boolean value.*falsea' stderr" 0 ignore null
     73 
     74 	atf_check "modload -b foo=truea k_helper.kmod" 1 null stderr
     75 	atf_check "grep 'Invalid boolean value.*truea' stderr" 0 ignore null
     76 
     77 	# TODO Once sysctl(8) supports CTLTYPE_BOOL nodes.
     78 	#echo "Checking valid values"
     79 }
     80 bflag_cleanup() {
     81 	modunload k_helper >/dev/null 2>&1
     82 }
     83 
     84 atf_test_case iflag
     85 iflag_head() {
     86 	atf_set "descr" "Test the -i flag"
     87 	atf_set "require.user" "root"
     88 }
     89 iflag_body() {
     90 	echo "Checking error conditions"
     91 
     92 	atf_check "modload -i foo k_helper.kmod" 1 null stderr
     93 	atf_check "grep 'Invalid parameter.*foo' stderr" 0 ignore null
     94 
     95 	atf_check "modload -i foo= k_helper.kmod" 1 null stderr
     96 	atf_check "grep 'Invalid integer value' stderr" 0 ignore null
     97 
     98 	atf_check "modload -i foo=bar k_helper.kmod" 1 null stderr
     99 	atf_check "grep 'Invalid integer value.*bar' stderr" 0 ignore null
    100 
    101 	atf_check "modload -i foo=123a k_helper.kmod" 1 null stderr
    102 	atf_check "grep 'Invalid integer value.*123a' stderr" 0 ignore null
    103 
    104 	echo "Checking valid values"
    105 
    106 	for v in 5 10; do
    107 		atf_check "modload -i prop_int='${v}' \
    108 			   $(atf_get_srcdir)/k_helper.kmod" 0 null null
    109 		check_sysctl vendor.k_helper.prop_int_ok 1
    110 		check_sysctl vendor.k_helper.prop_int_val "${v}"
    111 		atf_check "modunload k_helper" 0 null null
    112 	done
    113 }
    114 iflag_cleanup() {
    115 	modunload k_helper >/dev/null 2>&1
    116 }
    117 
    118 atf_test_case sflag
    119 sflag_head() {
    120 	atf_set "descr" "Test the -s flag"
    121 	atf_set "require.user" "root"
    122 }
    123 sflag_body() {
    124 	echo "Checking error conditions"
    125 
    126 	atf_check "modload -s foo k_helper.kmod" 1 null stderr
    127 	atf_check "grep 'Invalid parameter.*foo' stderr" 0 ignore null
    128 
    129 	echo "Checking valid values"
    130 
    131 	for v in '1st string' '2nd string'; do
    132 		atf_check "modload -s prop_str='${v}' \
    133 			   $(atf_get_srcdir)/k_helper.kmod" 0 null null
    134 		check_sysctl vendor.k_helper.prop_str_ok 1
    135 		check_sysctl vendor.k_helper.prop_str_val "${v}"
    136 		atf_check "modunload k_helper" 0 null null
    137 	done
    138 }
    139 sflag_cleanup() {
    140 	modunload k_helper >/dev/null 2>&1
    141 }
    142 
    143 atf_init_test_cases()
    144 {
    145 	atf_add_test_case plain
    146 	atf_add_test_case bflag
    147 	atf_add_test_case iflag
    148 	atf_add_test_case sflag
    149 }
    150