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