t_modload.sh revision 1.10 1 # $NetBSD: t_modload.sh,v 1.10 2012/03/20 05:50:11 jruoho 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
40 # XXX: There should be a reliable way to detect MODULAR.
41 #
42 sysctl machdep.xen > /dev/null 2>&1
43
44 if [ $? -eq 0 ]; then
45 atf_skip "host does not support modules"
46 fi
47
48 cat >experr <<EOF
49 modload: No such file or directory
50 EOF
51 atf_check -s eq:1 -o empty -e ignore modload non-existent.o
52
53 atf_check -s eq:0 -o empty -e empty \
54 modload $(atf_get_srcdir)/k_helper/k_helper.kmod
55 check_sysctl vendor.k_helper.present 1
56 check_sysctl vendor.k_helper.prop_int_ok 0
57 check_sysctl vendor.k_helper.prop_str_ok 0
58 atf_check -s eq:0 -o empty -e empty modunload k_helper
59 touch done
60 }
61 plain_cleanup() {
62 test -f done || modunload k_helper >/dev/null 2>&1
63 }
64
65 atf_test_case bflag cleanup
66 bflag_head() {
67 atf_set "descr" "Test the -b flag"
68 atf_set "require.user" "root"
69 }
70 bflag_body() {
71 echo "Checking error conditions"
72
73 atf_check -s eq:1 -o empty -e save:stderr \
74 modload -b foo k_helper.kmod
75 atf_check -s eq:0 -o ignore -e empty \
76 grep 'Invalid parameter.*foo' stderr
77
78 atf_check -s eq:1 -o empty -e save:stderr \
79 modload -b foo= k_helper.kmod
80 atf_check -s eq:0 -o ignore -e empty \
81 grep 'Invalid boolean value' stderr
82
83 atf_check -s eq:1 -o empty -e save:stderr \
84 modload -b foo=bar k_helper.kmod
85 atf_check -s eq:0 -o ignore -e empty \
86 grep 'Invalid boolean value.*bar' stderr
87
88 atf_check -s eq:1 -o empty -e save:stderr \
89 modload -b foo=falsea k_helper.kmod
90 atf_check -s eq:0 -o ignore -e empty \
91 grep 'Invalid boolean value.*falsea' stderr
92
93 atf_check -s eq:1 -o empty -e save:stderr \
94 modload -b foo=truea k_helper.kmod
95 atf_check -s eq:0 -o ignore -e empty \
96 grep 'Invalid boolean value.*truea' stderr
97
98 # TODO Once sysctl(8) supports CTLTYPE_BOOL nodes.
99 #echo "Checking valid values"
100 }
101 bflag_cleanup() {
102 modunload k_helper >/dev/null 2>&1 || true
103 }
104
105 atf_test_case iflag cleanup
106 iflag_head() {
107 atf_set "descr" "Test the -i flag"
108 atf_set "require.user" "root"
109 }
110 iflag_body() {
111
112 # XXX: There should be a reliable way to detect MODULAR.
113 #
114 sysctl machdep.xen > /dev/null 2>&1
115
116 if [ $? -eq 0 ]; then
117 atf_skip "host does not support modules"
118 fi
119
120 echo "Checking error conditions"
121
122 atf_check -s eq:1 -o empty -e save:stderr modload -i foo \
123 k_helper/k_helper.kmod
124 atf_check -s eq:0 -o ignore -e empty \
125 grep 'Invalid parameter.*foo' stderr
126
127 atf_check -s eq:1 -o empty -e save:stderr modload -i foo= \
128 k_helper/k_helper.kmod
129 atf_check -s eq:0 -o ignore -e empty \
130 grep 'Invalid integer value' stderr
131
132 atf_check -s eq:1 -o empty -e save:stderr \
133 modload -i foo=bar k_helper/k_helper.kmod
134 atf_check -s eq:0 -o ignore -e empty \
135 grep 'Invalid integer value.*bar' stderr
136
137 atf_check -s eq:1 -o empty -e save:stderr \
138 modload -i foo=123a k_helper/k_helper.kmod
139 atf_check -s eq:0 -o ignore -e empty \
140 grep 'Invalid integer value.*123a' stderr
141
142 echo "Checking valid values"
143
144 for v in 5 10; do
145 atf_check -s eq:0 -o empty -e empty \
146 modload -i prop_int="${v}" \
147 $(atf_get_srcdir)/k_helper/k_helper.kmod
148 check_sysctl vendor.k_helper.prop_int_ok 1
149 check_sysctl vendor.k_helper.prop_int_val "${v}"
150 atf_check -s eq:0 -o empty -e empty modunload k_helper
151 done
152 touch done
153 }
154 iflag_cleanup() {
155 test -f done || modunload k_helper >/dev/null 2>&1
156 }
157
158 atf_test_case sflag cleanup
159 sflag_head() {
160 atf_set "descr" "Test the -s flag"
161 atf_set "require.user" "root"
162 }
163 sflag_body() {
164
165 # XXX: There should be a reliable way to detect MODULAR.
166 #
167 sysctl machdep.xen > /dev/null 2>&1
168
169 if [ $? -eq 0 ]; then
170 atf_skip "host does not support modules"
171 fi
172
173 echo "Checking error conditions"
174
175 atf_check -s eq:1 -o empty -e save:stderr modload -s foo \
176 k_helper/k_helper.kmod
177 atf_check -s eq:0 -o ignore -e empty \
178 grep 'Invalid parameter.*foo' stderr
179
180 echo "Checking valid values"
181
182 for v in '1st string' '2nd string'; do
183 atf_check -s eq:0 -o empty -e empty \
184 modload -s prop_str="${v}" \
185 $(atf_get_srcdir)/k_helper/k_helper.kmod
186 check_sysctl vendor.k_helper.prop_str_ok 1
187 check_sysctl vendor.k_helper.prop_str_val "${v}"
188 atf_check -s eq:0 -o empty -e empty modunload k_helper
189 done
190 touch done
191 }
192 sflag_cleanup() {
193 test -f done || modunload k_helper >/dev/null 2>&1
194 }
195
196 atf_init_test_cases()
197 {
198 atf_add_test_case plain
199 atf_add_test_case bflag
200 atf_add_test_case iflag
201 atf_add_test_case sflag
202 }
203