1 #!/bin/sh 2 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 # Use is subject to license terms. 24 # 25 # ident "@(#)test_ipmievd 1.1 08/12/17 SMI" 26 27 # ---------------------------------------------------------------------------- 28 # test_ipmievd confirm basic ipmievd functionality works 29 # 30 # exercise syslog event reporting via event injection via ipmitool 31 # ---------------------------------------------------------------------------- 32 33 cmd_name="`basename $0`" # the name of this command 34 35 cmd_err="${cmd_name}: error:" # the (fatal) error header 36 cmd_warn="${cmd_name}: warning:" # the warning header 37 cmd_info="${cmd_name}: info:" # the informational header 38 cmd_query="${cmd_name}: query:" # the interrogative header 39 40 bin_path="/usr/sbin:/usr/lib" # path(s) to needed binary executable(s) 41 proto_root="" # path to proto root from build 42 state_fn="/tmp/$cnd_name.$$.db" # state file for cleanup 43 44 # Design_Note: typically it takes about 4 seconds for an event to be syslogged, 45 # let's allow at least 12 seconds for it to be syslogged. 46 47 SYSLOG_DELAY_SEC=12 # max wait in sec for event to be syslogged 48 49 # ---------------------------------------------------------------------------- 50 51 usage() 52 { 53 echo "usage: $cmd_name [-r <proto_root>]" 54 echo " -r path to proto root of recent build of tool+daemon" 55 echo "purpose: confirm basic ipmievd functionality works;" 56 echo " this is NOT a comprehensive test" 57 echo "examples:" 58 echo " $cmd_name -r \$CODEMGR_WS/proto/root_\`uname -p\`" 59 echo "caveats: installs and leaves installed new tool+daemon on error" 60 } # usage() 61 62 # ---------------------------------------------------------------------------- 63 64 show_env() 65 { 66 echo "$cmd_info general environment:" 67 date ; id ; uname -a ; pwd ; echo "$PATH" 68 [ -r /etc/release ] && cat /etc/release 69 [ -r /etc/motd ] && grep bfu /etc/motd 70 ipmievd -V 71 ipmitool -V 72 } # usage() 73 74 # ---------------------------------------------------------------------------- 75 76 enforce_i386() 77 { 78 proctype=`uname -p` 79 [ "$proctype" != "i386" ] && { 80 echo "$cmd_err processor type $proctype != i386" 81 exit 1 82 } 83 } # enforce_i386() 84 85 # ---------------------------------------------------------------------------- 86 87 install_proto() 88 { 89 [ "$proto_root" = "" ] && { 90 echo "$cmd_info skipping install of unset proto_root" ; return 0 91 } 92 [ ! -r /usr/sbin/ipmitool.orig ] && { 93 cp -p /usr/sbin/ipmitool /usr/sbin/ipmitool.orig 94 } 95 [ ! -r /usr/lib/ipmievd.orig ] && { 96 cp -p /usr/lib/ipmievd /usr/lib/ipmievd.orig 97 } 98 99 # disable/kill ipmievd before overwriting binary 100 101 sstate=`svcs | grep '/ipmievd:' | awk '{print $1}'` 102 echo "ipmievd_svc_state: $sstate" > $state_fn 103 [ "$sstate" = "online" ] && { 104 echo "$cmd_info disabling ipmievd service per proto_root" 105 svcadm disable -ts ipmievd 106 } 107 pkill -x ipmievd # may or may not have been running as a service 108 109 echo "$cmd_info installing proto_root tool+daemon" 110 cp $proto_root/usr/sbin/ipmitool /usr/sbin/ipmitool 111 cp $proto_root/usr/lib/ipmievd /usr/lib/ipmievd 112 113 } # install_proto() 114 115 # ---------------------------------------------------------------------------- 116 117 uninstall_proto() 118 { 119 [ "$proto_root" = "" ] && { 120 echo "$cmd_info skipping uninstall of unset proto_root" ; return 0 121 } 122 123 # disable/kill ipmievd before overwriting binary 124 125 sstate=`svcs | grep '/ipmievd:' | awk '{print $1}'` 126 [ "$sstate" = "online" ] && { 127 echo "$cmd_info disabling ipmievd service per proto_root" 128 svcadm disable -ts ipmievd 129 } 130 pkill -x ipmievd # may or may not have been running as a service 131 132 echo "$cmd_info uninstalling proto_root tool+daemon" 133 [ -r /usr/sbin/ipmitool.orig ] && { 134 cp -p /usr/sbin/ipmitool.orig /usr/sbin/ipmitool 135 } 136 [ -r /usr/lib/ipmievd.orig ] && { 137 cp -p /usr/lib/ipmievd.orig /usr/lib/ipmievd 138 } 139 140 # restore initial state of ipmievd svc if known 141 142 [ ! -r $state_fn ] && return 0 143 144 was_online=`grep -c "ipmievd_svc_state.*online" $state_fn` 145 [ $was_online -ne 0 ] && { 146 echo "$cmd_info enabling ipmievd service per initial state" 147 svcadm enable -s ipmievd 148 } 149 } # uninstall_proto() 150 151 # ---------------------------------------------------------------------------- 152 153 test_opt_version() 154 { 155 tnm="version option" 156 ipmievd -V > ipmievd_V.out 157 rc=$? 158 [ $rc -ne 0 ] && { 159 echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc 160 } 161 cnt=`grep -i -c 'version.*[0-9][0-9]*\.[0-9]' ipmievd_V.out` 162 [ $cnt -le 0 ] && { 163 echo "$cmd_err $tnm output missing version" ; exit 1 164 } 165 echo "$cmd_info $tnm passed" 166 } # test_opt_version() 167 168 # ---------------------------------------------------------------------------- 169 170 test_opt_help() 171 { 172 tnm="help option" 173 ipmievd -h > ipmievd_h.out 2>&1 174 rc=$? 175 [ $rc -ne 0 ] && { 176 echo "$cmd_err $tnm failed with exit code $rc" ; exit $rc 177 } 178 cnt=`grep -i 'interface' ipmievd_h.out | grep -i -c 'bmc'` 179 [ $cnt -le 0 ] && { 180 echo "$cmd_err $tnm output missing bmc interface" ; exit 1 181 } 182 echo "$cmd_info $tnm passed" 183 } # test_opt_help() 184 185 # ---------------------------------------------------------------------------- 186 187 test_svc_online() 188 { 189 tnm="service online check" 190 sstate=`svcs | grep '/ipmievd:' | awk '{print $1}'` 191 [ "$sstate" = "online" ] && { 192 echo "$cmd_info disabling ipmievd service" 193 svcadm disable -ts ipmievd 194 } 195 196 echo "$cmd_info enabling ipmievd service" 197 svcadm enable -ts ipmievd 198 sstate=`svcs | grep '/ipmievd:' | awk '{print $1}'` 199 [ "$sstate" != "online" ] && { 200 echo "$cmd_err $tnm ipmievd service state $sstate != online" ; exit 1 201 } 202 echo "$cmd_info $tnm passed" 203 } # test_svc_online() 204 205 # ---------------------------------------------------------------------------- 206 207 test_syslog_init() 208 { 209 tnm="syslog initial entries" 210 # Reading|Waiting events below are generated by bringing svc online; 211 # wait some for them to be syslogged. 212 echo "$cmd_info may wait $SYSLOG_DELAY_SEC sec per expected syslog entry" 213 sleep $SYSLOG_DELAY_SEC 214 cnt1=`grep -i -c 'ipmievd.*Reading' /var/adm/messages` 215 cnt2=`grep -i -c 'ipmievd.*Waiting' /var/adm/messages` 216 grep ipmievd /var/adm/messages > ipmievd.syslog_init.out 217 [ $cnt1 -lt 1 ] || [ $cnt2 -lt 1 ] && { 218 echo "$cmd_err $tnm ipmievd too few initial syslog entries" ; exit 1 219 } 220 echo "$cmd_info $tnm passed" 221 } # test_syslog_init() 222 223 # ---------------------------------------------------------------------------- 224 225 test_syslog_event() 226 { 227 num="$1" # event number being tested 228 229 tnm="syslog event $num entry" 230 now=`date | awk '{print $2 " " $3}'` 231 cnt1=`grep -i -c "$now.*ipmievd" /var/adm/messages` 232 ipmitool event $num > ipmitool.syslog_event_$num.out 233 rc=$? 234 [ $rc -ne 0 ] && { 235 echo "$cmd_warn $tnm ipmitool exit code $rc" 236 } 237 sleep $SYSLOG_DELAY_SEC 238 cnt2=`grep -i -c "$now.*ipmievd" /var/adm/messages` 239 cnt3=`expr $cnt1 + 1` # expected val 240 [ $cnt2 -lt $cnt3 ] && { 241 echo "$cmd_err $tnm not syslogged in $SYSLOG_DELAY_SEC sec" ; exit 1 242 } 243 [ $cnt2 -gt $cnt3 ] && { 244 echo "$cmd_warn $tnm more syslog entries seen than expected" 245 } 246 echo "$cmd_info $tnm passed" 247 } # test_syslog_event() 248 249 # ---------------------------------------------------------------------------- 250 251 # main() 252 253 while getopts r: opt; do # { 254 case $opt in 255 r) proto_root="$OPTARG";; 256 -) break;; 257 \?) echo "$cmd_err bad option(s)" ; usage ; exit 22;; 258 esac 259 done # } while grabbing cmd line args 260 261 shift `expr $OPTIND - 1` 262 263 too_much="$1" 264 [ "$too_much" != "" ] && { 265 echo "$cmd_err too few/many args" ; usage ; exit 7 266 } 267 [ "$proto_root" != "" ] && [ ! -d $proto_root ] && { 268 echo "$cmd_err proto_root $proto_root not a dir" ; usage ; exit 20 269 } 270 271 PATH="${bin_path}:$PATH" 272 export PATH 273 274 # ---------------------------------------------------------------------------- 275 276 enforce_i386 277 install_proto 278 show_env 279 280 test_opt_version 281 test_opt_help 282 test_svc_online 283 test_syslog_init 284 # Design_Note: not all platforms appear to support event 3 (ECC); 285 # so skip it and just do events 1 and 2. 286 for n in 1 2; do 287 test_syslog_event $n 288 done 289 290 uninstall_proto 291 292 echo "$cmd_info all tests passed" # if reach here then aok 293