📄 test-framework.sh
字号:
RC=0 do_facet mds sysctl -w lustre.fail_loc=0x119 do_facet client "$@" || RC=$? do_facet mds sysctl -w lustre.fail_loc=0 return $RC}pause_bulk() {#define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214 RC=0 do_facet ost1 sysctl -w lustre.fail_loc=0x214 do_facet client "$1" || RC=$? do_facet client "sync" do_facet ost1 sysctl -w lustre.fail_loc=0 return $RC}drop_ldlm_cancel() {#define OBD_FAIL_LDLM_CANCEL 0x304 RC=0 do_facet client sysctl -w lustre.fail_loc=0x304 do_facet client "$@" || RC=$? do_facet client sysctl -w lustre.fail_loc=0 return $RC}drop_bl_callback() {#define OBD_FAIL_LDLM_BL_CALLBACK 0x305 RC=0 do_facet client sysctl -w lustre.fail_loc=0x305 do_facet client "$@" || RC=$? do_facet client sysctl -w lustre.fail_loc=0 return $RC}drop_ldlm_reply() {#define OBD_FAIL_LDLM_REPLY 0x30c RC=0 do_facet mds sysctl -w lustre.fail_loc=0x30c do_facet client "$@" || RC=$? do_facet mds sysctl -w lustre.fail_loc=0 return $RC}clear_failloc() { facet=$1 pause=$2 sleep $pause echo "clearing fail_loc on $facet" do_facet $facet "sysctl -e -w lustre.fail_loc=0"}cancel_lru_locks() { $LCTL mark "cancel_lru_locks $1 start" for d in `find $LPROC/ldlm/namespaces | egrep -i $1`; do [ -f $d/lru_size ] && echo clear > $d/lru_size [ -f $d/lock_unused_count ] && grep [1-9] $d/lock_unused_count /dev/null done $LCTL mark "cancel_lru_locks $1 stop"}default_lru_size(){ NR_CPU=$(grep -c "processor" /proc/cpuinfo) DEFAULT_LRU_SIZE=$((100 * NR_CPU)) echo "$DEFAULT_LRU_SIZE"}lru_resize_enable(){ NS=$1 test "x$NS" = "x" && NS="mdc" for F in $LPROC/ldlm/namespaces/*$NS*/lru_size; do D=$(dirname $F) log "Enable lru resize for $(basename $D)" echo "0" > $F done}lru_resize_disable(){ NS=$1 test "x$NS" = "x" && NS="mdc" for F in $LPROC/ldlm/namespaces/*$NS*/lru_size; do D=$(dirname $F) log "Disable lru resize for $(basename $D)" DEFAULT_LRU_SIZE=$(default_lru_size) echo "$DEFAULT_LRU_SIZE" > $F done}pgcache_empty() { for a in /proc/fs/lustre/llite/*/dump_page_cache; do if [ `wc -l $a | awk '{print $1}'` -gt 1 ]; then echo there is still data in page cache $a ? cat $a; return 1; fi done return 0}debugsave() { DEBUGSAVE="$(sysctl -n lnet.debug)"}debugrestore() { [ -n "$DEBUGSAVE" ] && sysctl -w lnet.debug="${DEBUGSAVE}" DEBUGSAVE=""}################################### Test interface ##################################error_noexit() { local TYPE=${TYPE:-"FAIL"} local ERRLOG sysctl -e -w lustre.fail_loc=0 || true log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ " ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s) echo "Dumping lctl log to $ERRLOG" # We need to dump the logs on all nodes local NODES=$(nodes_list) for NODE in $NODES; do do_node $NODE $LCTL dk $ERRLOG done debugrestore [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG}error() { error_noexit "$@" $FAIL_ON_ERROR && exit 1 || true}error_exit() { error_noexit "$@" exit 1}# use only if we are ignoring failures for this test, bugno required.# (like ALWAYS_EXCEPT, but run the test and ignore the results.)# e.g. error_ignore 5494 "your message"error_ignore() { TYPE="IGNORE (bz$1)" shift error_noexit "$@"}skip () { log " SKIP: ${TESTSUITE} ${TESTNAME} $@" [ "$TESTSUITELOG" ] && echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG}build_test_filter() { [ "$ONLY" ] && log "only running test `echo $ONLY`" for O in $ONLY; do eval ONLY_${O}=true done [ "$EXCEPT$ALWAYS_EXCEPT" ] && \ log "skipping tests: `echo $EXCEPT $ALWAYS_EXCEPT`" [ "$EXCEPT_SLOW" ] && \ log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`" for E in $EXCEPT $ALWAYS_EXCEPT; do eval EXCEPT_${E}=true done for E in $EXCEPT_SLOW; do eval EXCEPT_SLOW_${E}=true done for G in $GRANT_CHECK_LIST; do eval GCHECK_ONLY_${G}=true done}_basetest() { echo $*}basetest() { IFS=abcdefghijklmnopqrstuvwxyz _basetest $1}run_test() { export base=`basetest $1` if [ ! -z "$ONLY" ]; then testname=ONLY_$1 if [ ${!testname}x != x ]; then run_one $1 "$2" return $? fi testname=ONLY_$base if [ ${!testname}x != x ]; then run_one $1 "$2" return $? fi echo -n "." return 0 fi testname=EXCEPT_$1 if [ ${!testname}x != x ]; then TESTNAME=test_$1 skip "skipping excluded test $1" return 0 fi testname=EXCEPT_$base if [ ${!testname}x != x ]; then TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)" return 0 fi testname=EXCEPT_SLOW_$1 if [ ${!testname}x != x ]; then TESTNAME=test_$1 skip "skipping SLOW test $1" return 0 fi testname=EXCEPT_SLOW_$base if [ ${!testname}x != x ]; then TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)" return 0 fi run_one $1 "$2" return $?}EQUALS="======================================================================"equals_msg() { msg="$@" local suffixlen=$((${#EQUALS} - ${#msg})) [ $suffixlen -lt 5 ] && suffixlen=5 log `echo $(printf '===== %s %.*s\n' "$msg" $suffixlen $EQUALS)`}log() { echo "$*" lsmod | grep lnet > /dev/null || load_modules local MSG="$*" # Get rif of ' MSG=${MSG//\'/\\\'} MSG=${MSG//\(/\\\(} MSG=${MSG//\)/\\\)} MSG=${MSG//\;/\\\;} MSG=${MSG//\|/\\\|} MSG=${MSG//\>/\\\>} MSG=${MSG//\</\\\<} local NODES=$(nodes_list) for NODE in $NODES; do do_node $NODE $LCTL mark "$MSG" 2> /dev/null || true done}trace() { log "STARTING: $*" strace -o $TMP/$1.strace -ttt $* RC=$? log "FINISHED: $*: rc $RC" return 1}pass() { echo PASS $@}check_mds() { FFREE=`cat /proc/fs/lustre/mds/*/filesfree` FTOTAL=`cat /proc/fs/lustre/mds/*/filestotal` [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true}reset_fail_loc () { local myNODES=$(nodes_list) local NODE for NODE in $myNODES; do do_node $NODE sysctl -e -w lustre.fail_loc=0 || true done}run_one() { testnum=$1 message=$2 tfile=f${testnum} export tdir=d0.${TESTSUITE}/d${base} local SAVE_UMASK=`umask` umask 0022 mkdir -p $DIR/$tdir BEFORE=`date +%s` log "== test $testnum: $message ============ `date +%H:%M:%S` ($BEFORE)" #check_mds export TESTNAME=test_$testnum test_${testnum} || error "test_$testnum failed with $?" #check_mds reset_fail_loc check_grant ${testnum} || error "check_grant $testnum failed with $?" [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \ error "LBUG/LASSERT detected" ps auxww | grep -v grep | grep -q multiop && error "multiop still running" pass "($((`date +%s` - $BEFORE))s)" rmdir ${DIR}/$tdir >/dev/null 2>&1 || true unset TESTNAME unset tdir umask $SAVE_UMASK cd $SAVE_PWD $CLEANUP}canonical_path() { (cd `dirname $1`; echo $PWD/`basename $1`)}sync_clients() { [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync cd $SAVE_PWD}check_grant() { export base=`basetest $1` [ "$CHECK_GRANT" == "no" ] && return 0 testname=GCHECK_ONLY_${base} [ ${!testname}x == x ] && return 0 echo -n "checking grant......" cd $SAVE_PWD # write some data to sync client lost_grant rm -f $DIR1/${tfile}_check_grant_* 2>&1 for i in `seq $OSTCOUNT`; do $LFS setstripe $DIR1/${tfile}_check_grant_$i -i $(($i -1)) -c 1 dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \ count=1 > /dev/null 2>&1 done # sync all the data and make sure no pending data on server sync_clients #get client grant and server grant client_grant=0 for d in ${LPROC}/osc/*/cur_grant_bytes; do client_grant=$((client_grant + `cat $d`)) done server_grant=0 for d in ${LPROC}/obdfilter/*/tot_granted; do server_grant=$((server_grant + `cat $d`)) done # cleanup the check_grant file for i in `seq $OSTCOUNT`; do rm $DIR1/${tfile}_check_grant_$i done #check whether client grant == server grant if [ $client_grant != $server_grant ]; then echo "failed: client:${client_grant} server: ${server_grant}" return 1 else echo "pass" fi}######################### helper functionsosc_to_ost(){ osc=$1 ost=`echo $1 | awk -F_ '{print $3}'` if [ -z $ost ]; then ost=`echo $1 | sed 's/-osc.*//'` fi echo $ost}remote_mds (){ [ -z "$(lctl dl | grep mdt)" ]}remote_mds_nodsh(){ remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]}remote_ost (){ [ -z "$(lctl dl | grep ost)" ]}remote_ost_nodsh(){ remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]}osts_nodes () { local OSTNODES=$(facet_host ost1) local NODES_sort for num in `seq $OSTCOUNT`; do local myOST=$(facet_host ost$num) OSTNODES="$OSTNODES $myOST" done NODES_sort=$(for i in $OSTNODES; do echo $i; done | sort -u) echo $NODES_sort}nodes_list () { # FIXME. We need a list of clients local myNODES=$HOSTNAME local myNODES_sort if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then myNODES="$myNODES $(osts_nodes) $mds_HOST" fi myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u) echo $myNODES_sort}is_patchless (){ lctl get_param version | grep -q patchless}check_runas_id_ret() { local myRC=0 local myRUNAS_ID=$1 shift local myRUNAS=$@ if [ -z "$myRUNAS" ]; then error_exit "myRUNAS command must be specified for check_runas_id" fi mkdir $DIR/d0_runas_test chmod 0755 $DIR chown $myRUNAS_ID:$myRUNAS_ID $DIR/d0_runas_test $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=1 rm -rf $DIR/d0_runas_test return $myRC}check_runas_id() { local myRUNAS_ID=$1 shift local myRUNAS=$@ check_runas_id_ret $myRUNAS_ID $myRUNAS || \ error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_ID. Please set RUNAS_ID to some UID which exists on MDS and client or add user $myRUNAS_ID:$myRUNAS_ID on these nodes."}# Run multiop in the background, but wait for it to print# "PAUSING" to its stdout before returning from this function.multiop_bg_pause() { MULTIOP_PROG=${MULTIOP_PROG:-multiop} FILE=$1 ARGS=$2 TMPPIPE=/tmp/multiop_open_wait_pipe.$$ mkfifo $TMPPIPE echo "$MULTIOP_PROG $FILE v$ARGS" $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE & echo "TMPPIPE=${TMPPIPE}" read -t 60 multiop_output < $TMPPIPE if [ $? -ne 0 ]; then rm -f $TMPPIPE return 1 fi rm -f $TMPPIPE if [ "$multiop_output" != "PAUSING" ]; then echo "Incorrect multiop output: $multiop_output" kill -9 $PID return 1 fi return 0}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -