t_modload.sh revision 1.9 1 # $NetBSD: t_modload.sh,v 1.9 2011/03/24 21:52:51 jmmv 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 -s eq:0 -o file:expout -e empty sysctl ${1}
31 }
32
33 atf_test_case plain cleanup
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 -s eq:1 -o empty -e ignore modload non-existent.o
43
44 atf_check -s eq:0 -o empty -e empty \
45 modload $(atf_get_srcdir)/k_helper/k_helper.kmod
46 check_sysctl vendor.k_helper.present 1
47 check_sysctl vendor.k_helper.prop_int_ok 0
48 check_sysctl vendor.k_helper.prop_str_ok 0
49 atf_check -s eq:0 -o empty -e empty modunload k_helper
50 touch done
51 }
52 plain_cleanup() {
53 test -f done || modunload k_helper >/dev/null 2>&1
54 }
55
56 atf_test_case bflag cleanup
57 bflag_head() {
58 atf_set "descr" "Test the -b flag"
59 atf_set "require.user" "root"
60 }
61 bflag_body() {
62 echo "Checking error conditions"
63
64 atf_check -s eq:1 -o empty -e save:stderr \
65 modload -b foo k_helper.kmod
66 atf_check -s eq:0 -o ignore -e empty \
67 grep 'Invalid parameter.*foo' stderr
68
69 atf_check -s eq:1 -o empty -e save:stderr \
70 modload -b foo= k_helper.kmod
71 atf_check -s eq:0 -o ignore -e empty \
72 grep 'Invalid boolean value' stderr
73
74 atf_check -s eq:1 -o empty -e save:stderr \
75 modload -b foo=bar k_helper.kmod
76 atf_check -s eq:0 -o ignore -e empty \
77 grep 'Invalid boolean value.*bar' stderr
78
79 atf_check -s eq:1 -o empty -e save:stderr \
80 modload -b foo=falsea k_helper.kmod
81 atf_check -s eq:0 -o ignore -e empty \
82 grep 'Invalid boolean value.*falsea' stderr
83
84 atf_check -s eq:1 -o empty -e save:stderr \
85 modload -b foo=truea k_helper.kmod
86 atf_check -s eq:0 -o ignore -e empty \
87 grep 'Invalid boolean value.*truea' stderr
88
89 # TODO Once sysctl(8) supports CTLTYPE_BOOL nodes.
90 #echo "Checking valid values"
91 }
92 bflag_cleanup() {
93 modunload k_helper >/dev/null 2>&1 || true
94 }
95
96 atf_test_case iflag cleanup
97 iflag_head() {
98 atf_set "descr" "Test the -i flag"
99 atf_set "require.user" "root"
100 }
101 iflag_body() {
102 echo "Checking error conditions"
103
104 atf_check -s eq:1 -o empty -e save:stderr modload -i foo \
105 k_helper/k_helper.kmod
106 atf_check -s eq:0 -o ignore -e empty \
107 grep 'Invalid parameter.*foo' stderr
108
109 atf_check -s eq:1 -o empty -e save:stderr modload -i foo= \
110 k_helper/k_helper.kmod
111 atf_check -s eq:0 -o ignore -e empty \
112 grep 'Invalid integer value' stderr
113
114 atf_check -s eq:1 -o empty -e save:stderr \
115 modload -i foo=bar k_helper/k_helper.kmod
116 atf_check -s eq:0 -o ignore -e empty \
117 grep 'Invalid integer value.*bar' stderr
118
119 atf_check -s eq:1 -o empty -e save:stderr \
120 modload -i foo=123a k_helper/k_helper.kmod
121 atf_check -s eq:0 -o ignore -e empty \
122 grep 'Invalid integer value.*123a' stderr
123
124 echo "Checking valid values"
125
126 for v in 5 10; do
127 atf_check -s eq:0 -o empty -e empty \
128 modload -i prop_int="${v}" \
129 $(atf_get_srcdir)/k_helper/k_helper.kmod
130 check_sysctl vendor.k_helper.prop_int_ok 1
131 check_sysctl vendor.k_helper.prop_int_val "${v}"
132 atf_check -s eq:0 -o empty -e empty modunload k_helper
133 done
134 touch done
135 }
136 iflag_cleanup() {
137 test -f done || modunload k_helper >/dev/null 2>&1
138 }
139
140 atf_test_case sflag cleanup
141 sflag_head() {
142 atf_set "descr" "Test the -s flag"
143 atf_set "require.user" "root"
144 }
145 sflag_body() {
146 echo "Checking error conditions"
147
148 atf_check -s eq:1 -o empty -e save:stderr modload -s foo \
149 k_helper/k_helper.kmod
150 atf_check -s eq:0 -o ignore -e empty \
151 grep 'Invalid parameter.*foo' stderr
152
153 echo "Checking valid values"
154
155 for v in '1st string' '2nd string'; do
156 atf_check -s eq:0 -o empty -e empty \
157 modload -s prop_str="${v}" \
158 $(atf_get_srcdir)/k_helper/k_helper.kmod
159 check_sysctl vendor.k_helper.prop_str_ok 1
160 check_sysctl vendor.k_helper.prop_str_val "${v}"
161 atf_check -s eq:0 -o empty -e empty modunload k_helper
162 done
163 touch done
164 }
165 sflag_cleanup() {
166 test -f done || modunload k_helper >/dev/null 2>&1
167 }
168
169 atf_init_test_cases()
170 {
171 atf_add_test_case plain
172 atf_add_test_case bflag
173 atf_add_test_case iflag
174 atf_add_test_case sflag
175 }
176