17c478bd9Sstevel@tonic-gate# 27c478bd9Sstevel@tonic-gate# CDDL HEADER START 37c478bd9Sstevel@tonic-gate# 47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 5*00d0963fSdilpreet# Common Development and Distribution License (the "License"). 6*00d0963fSdilpreet# You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate# 87c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate# and limitations under the License. 127c478bd9Sstevel@tonic-gate# 137c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate# 197c478bd9Sstevel@tonic-gate# CDDL HEADER END 207c478bd9Sstevel@tonic-gate# 217c478bd9Sstevel@tonic-gate# 22*00d0963fSdilpreet# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*00d0963fSdilpreet# Use is subject to license terms. 247c478bd9Sstevel@tonic-gate# 257c478bd9Sstevel@tonic-gate#pragma ident "%Z%%M% %I% %E% SMI" 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate# 287c478bd9Sstevel@tonic-gate# usage: force_state_change <path> <target state> 297c478bd9Sstevel@tonic-gate# 307c478bd9Sstevel@tonic-gateforce_state_change() 317c478bd9Sstevel@tonic-gate{ 327c478bd9Sstevel@tonic-gate [[ $2 != "online" && $2 != "offline" ]] && exit 1 337c478bd9Sstevel@tonic-gate th_manage $1 getstate | read path state busy 347c478bd9Sstevel@tonic-gate [[ $? != 0 ]] && exit 1 357c478bd9Sstevel@tonic-gate [[ "$state" = "$2" ]] && return 0 367c478bd9Sstevel@tonic-gate th_manage $1 $2 377c478bd9Sstevel@tonic-gate [[ $? != 0 ]] && exit 1 387c478bd9Sstevel@tonic-gate th_manage $1 getstate | read path state busy 397c478bd9Sstevel@tonic-gate [[ $? != 0 ]] && exit 1 407c478bd9Sstevel@tonic-gate [[ "$state" != "$2" ]] && exit 1 417c478bd9Sstevel@tonic-gate return 0 427c478bd9Sstevel@tonic-gate} 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gatescript_pid=0 467c478bd9Sstevel@tonic-gatetrap ' terminate $script_pid ' 1 2 3 15 477c478bd9Sstevel@tonic-gateterminate() 487c478bd9Sstevel@tonic-gate{ 497c478bd9Sstevel@tonic-gate [[ $1 -gt 0 ]] && kill $1 > /dev/null 2>&1 507c478bd9Sstevel@tonic-gate exit 1 517c478bd9Sstevel@tonic-gate} 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate# 547c478bd9Sstevel@tonic-gate# usage: control_workload <path> <pid> 557c478bd9Sstevel@tonic-gate# The following function is called (as a background task) prior to taking a 567c478bd9Sstevel@tonic-gate# driver instance offline and immediately after it is brought online. If the 577c478bd9Sstevel@tonic-gate# th_define process which created this script did not specify a script with the 587c478bd9Sstevel@tonic-gate# -e option then the default action is to run in the background this script 597c478bd9Sstevel@tonic-gate# which will continuously offline and online the instance until the injected 607c478bd9Sstevel@tonic-gate# error is detected by the driver or until the errdef is aborted. 617c478bd9Sstevel@tonic-gate# 627c478bd9Sstevel@tonic-gatecontrol_workload() 637c478bd9Sstevel@tonic-gate{ 647c478bd9Sstevel@tonic-gate fixup_script 1 657c478bd9Sstevel@tonic-gate if [ $? == 0 ]; then 667c478bd9Sstevel@tonic-gate return 677c478bd9Sstevel@tonic-gate fi 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate # 707c478bd9Sstevel@tonic-gate # Default workload - continuously offline and online the driver instance 717c478bd9Sstevel@tonic-gate # while injecting errors 727c478bd9Sstevel@tonic-gate # 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate if [[ $2 -gt 0 ]]; then 757c478bd9Sstevel@tonic-gate kill $2 > /dev/null 2>&1 767c478bd9Sstevel@tonic-gate fi 777c478bd9Sstevel@tonic-gate if [ $# -lt 2 ]; then 787c478bd9Sstevel@tonic-gate echo syntax: $0 path pid 797c478bd9Sstevel@tonic-gate elif [ $DRIVER_UNCONFIGURE = 1 ]; then 807c478bd9Sstevel@tonic-gate : no unconfigure action required ; 817c478bd9Sstevel@tonic-gate elif [ $DRIVER_CONFIGURE = 1 ]; then 827c478bd9Sstevel@tonic-gate while [ 1 ]; do 837c478bd9Sstevel@tonic-gate sleep 2 847c478bd9Sstevel@tonic-gate force_state_change $1 offline 857c478bd9Sstevel@tonic-gate force_state_change $1 online 867c478bd9Sstevel@tonic-gate done & 877c478bd9Sstevel@tonic-gate script_pid=$! 887c478bd9Sstevel@tonic-gate fi 897c478bd9Sstevel@tonic-gate} 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate# 927c478bd9Sstevel@tonic-gate# usage: prepare_for_errdef <path> <driver> <instance> <do_unconfigure> 937c478bd9Sstevel@tonic-gate# 947c478bd9Sstevel@tonic-gateprepare_for_errdef() 957c478bd9Sstevel@tonic-gate{ 967c478bd9Sstevel@tonic-gate export DRIVER_PATH=$1 977c478bd9Sstevel@tonic-gate export DRIVER_NAME=$2 987c478bd9Sstevel@tonic-gate export DRIVER_INSTANCE=$3 997c478bd9Sstevel@tonic-gate export DRIVER_UNCONFIGURE=1 1007c478bd9Sstevel@tonic-gate export DRIVER_CONFIGURE=0 1017c478bd9Sstevel@tonic-gate control_workload $1 $script_pid 1027c478bd9Sstevel@tonic-gate script_pid=0 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate th_manage $2 $3 get_handles >/dev/null 2>&1 1057c478bd9Sstevel@tonic-gate [[ $? != 0 ]] && exit 1 1067c478bd9Sstevel@tonic-gate force_state_change $1 offline 1077c478bd9Sstevel@tonic-gate force_state_change $1 online 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate export DRIVER_UNCONFIGURE=0 1107c478bd9Sstevel@tonic-gate export DRIVER_CONFIGURE=1 1117c478bd9Sstevel@tonic-gate [[ $4 == 1 ]] && 1127c478bd9Sstevel@tonic-gate control_workload $1 $script_pid 1137c478bd9Sstevel@tonic-gate} 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate# usage: monitor_edef <driver> <instance> <nsteps> 1167c478bd9Sstevel@tonic-gatemonitor_edef() 1177c478bd9Sstevel@tonic-gate{ 1187c478bd9Sstevel@tonic-gate let aborted=0 1197c478bd9Sstevel@tonic-gate trap ' (( aborted += 1 )) ' 16 1207c478bd9Sstevel@tonic-gate sleep 2 # Wait for the errdef to be added 1217c478bd9Sstevel@tonic-gate th_manage $1 $2 start 1227c478bd9Sstevel@tonic-gate [[ $? != 0 ]] && exit 1 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate let s=0 1257c478bd9Sstevel@tonic-gate let x=$3 1267c478bd9Sstevel@tonic-gate set -A stats 0 0 1 0 0 0 0 "" 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate # 1297c478bd9Sstevel@tonic-gate # Loop for x reports unless the error is reported or the access fail 1307c478bd9Sstevel@tonic-gate # count goes to zero. 1317c478bd9Sstevel@tonic-gate # 1327c478bd9Sstevel@tonic-gate while (( (x -= 1) >= 0 )) 1337c478bd9Sstevel@tonic-gate do 1347c478bd9Sstevel@tonic-gate (( aborted > 0 )) && break 1357c478bd9Sstevel@tonic-gate read line 1367c478bd9Sstevel@tonic-gate [ -z "$line" ] && break 1377c478bd9Sstevel@tonic-gate set -A stats $(echo "$line" | 1387c478bd9Sstevel@tonic-gate /usr/bin/awk -F: '{for (i = 1; i <= NF; i++) print $i}') 1397c478bd9Sstevel@tonic-gate [ "${stats[6]}" -ne "0" ] && break # Fault was reported 1407c478bd9Sstevel@tonic-gate # 1417c478bd9Sstevel@tonic-gate # If fail count is zero - increment a loop counter 3 times 1427c478bd9Sstevel@tonic-gate # before aborting this errdef. 1437c478bd9Sstevel@tonic-gate # 1447c478bd9Sstevel@tonic-gate [ "${stats[3]}" = "0" ] && (( (s += 1) > 3 )) && break 1457c478bd9Sstevel@tonic-gate done 1467c478bd9Sstevel@tonic-gate th_manage $1 $2 clear_errdefs # Clear errors. 1477c478bd9Sstevel@tonic-gate [[ $? != 0 ]] && exit 1 1487c478bd9Sstevel@tonic-gate echo "${stats[@]}" 1497c478bd9Sstevel@tonic-gate} 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate# 1527c478bd9Sstevel@tonic-gate# Install, activate and monitor some error definitions 1537c478bd9Sstevel@tonic-gate# usage: run_subtest <driver> <instance> < errdefs 1547c478bd9Sstevel@tonic-gate# 1557c478bd9Sstevel@tonic-gaterun_subtest() 1567c478bd9Sstevel@tonic-gate{ 1577c478bd9Sstevel@tonic-gate let edefid=0 1587c478bd9Sstevel@tonic-gate drv=$1 1597c478bd9Sstevel@tonic-gate inst=$2 1607c478bd9Sstevel@tonic-gate if [ $devpath = "NULL" ] 1617c478bd9Sstevel@tonic-gate then 1627c478bd9Sstevel@tonic-gate path=$(th_manage $1 $2 getpath) 1637c478bd9Sstevel@tonic-gate else 1647c478bd9Sstevel@tonic-gate path=$devpath 1657c478bd9Sstevel@tonic-gate fi 1667c478bd9Sstevel@tonic-gate while read line 1677c478bd9Sstevel@tonic-gate do 1687c478bd9Sstevel@tonic-gate set -- $(echo "$line" | \ 1697c478bd9Sstevel@tonic-gate /usr/bin/awk '{for (i = 1; i <= NF; i++) print $i}') 1707c478bd9Sstevel@tonic-gate w=${line##*"-w "} 1717c478bd9Sstevel@tonic-gate let a=${w%%" "*} 1727c478bd9Sstevel@tonic-gate let b=${w##*" "} 1737c478bd9Sstevel@tonic-gate let x='a / b' 1747c478bd9Sstevel@tonic-gate (( a % b > 0 )) && (( x += 1 )) 1757c478bd9Sstevel@tonic-gate prepare_for_errdef $path $drv $inst 1 1767c478bd9Sstevel@tonic-gate set -A status $(th_define $* 2>./elog | \ 1777c478bd9Sstevel@tonic-gate monitor_edef $drv $inst $x) 1787c478bd9Sstevel@tonic-gate if [ "${status[2]}" -gt 0 ]; then 1797c478bd9Sstevel@tonic-gate res="test not triggered" 1807c478bd9Sstevel@tonic-gate elif [ "${status[1]}" -eq 0 ]; then 181*00d0963fSdilpreet res="success (error undetected)" 1827c478bd9Sstevel@tonic-gate elif [ "${status[1]}" -gt 0 ]; then 183*00d0963fSdilpreet if [ "${status[6]}" -eq 16 ]; then 184*00d0963fSdilpreet res="failure (no service impact reported)" 185*00d0963fSdilpreet else 186*00d0963fSdilpreet res="success (error reported)" 187*00d0963fSdilpreet fi 1887c478bd9Sstevel@tonic-gate else 1897c478bd9Sstevel@tonic-gate res= 1907c478bd9Sstevel@tonic-gate fi 1917c478bd9Sstevel@tonic-gate echo "Subtest $edefid: Result: \"$res\"" 1927c478bd9Sstevel@tonic-gate echo $line 1937c478bd9Sstevel@tonic-gate if [ -n "${status[7]}" ]; then 1947c478bd9Sstevel@tonic-gate let i=6 1957c478bd9Sstevel@tonic-gate let l=${#status[@]} 1967c478bd9Sstevel@tonic-gate echo " Fail Msg :\t\c" 1977c478bd9Sstevel@tonic-gate while (( (i += 1) <= l )) 1987c478bd9Sstevel@tonic-gate do 1997c478bd9Sstevel@tonic-gate echo "${status[$i]} \c" 2007c478bd9Sstevel@tonic-gate done 2017c478bd9Sstevel@tonic-gate echo "" 2027c478bd9Sstevel@tonic-gate fi 2037c478bd9Sstevel@tonic-gate echo "\tFail Time :\t${status[0]}\tMsg Time :\t${status[1]}" 2047c478bd9Sstevel@tonic-gate echo "\tAcc count :\t${status[2]}\tFail count:\t${status[3]}" 2057c478bd9Sstevel@tonic-gate echo "\tAccess Chk:\t${status[4]}\tEmsg count:\t${status[5]}" 206*00d0963fSdilpreet if [ "${status[6]}" -eq 0 ]; then 207*00d0963fSdilpreet echo "\tSeverity:\tSERVICE UNAFFECTED" 208*00d0963fSdilpreet elif [ "${status[6]}" -eq -16 ]; then 209*00d0963fSdilpreet echo "\tSeverity:\tSERVICE DEGRADED" 210*00d0963fSdilpreet elif [ "${status[6]}" -eq -32 ]; then 211*00d0963fSdilpreet echo "\tSeverity:\tSERVICE LOST" 212*00d0963fSdilpreet fi 2137c478bd9Sstevel@tonic-gate ((edefid += 1)) 2147c478bd9Sstevel@tonic-gate done 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate fixup_script 0 2177c478bd9Sstevel@tonic-gate prepare_for_errdef $path $drv $inst 0 2187c478bd9Sstevel@tonic-gate} 219