1#/bin/bash 2# 3# Test thread for File system metadata stress testing script 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public 7# License as published by the Free Software Foundation; version 8# 2. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13# General Public License for more details. 14# 15# You should find a copy of v2 of the GNU General Public License somewhere 16# on your Linux system; if not, write to the Free Software Foundation, 17# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18# 19# Copyright (C) 2009, Intel Corp. 20# Author: Shaohui Zheng <shaohui.zheng@intel.com> 21 22# run program and do not display the output 23function run_quiet() 24{ 25 local cmd=$* 26 $cmd >/dev/null 2>&1 27 return $? 28} 29 30function k_log() 31{ 32 echo [$(date "+%m-%d %H:%M:%S")] $* | tee -a $K_LOG 33} 34 35function k_result() 36{ 37 echo [$(date "+%m-%d %H:%M:%S")] $* | tee -a $K_LOG 38 echo $* | egrep "pass|fail" 39 ret_val=$? 40 if [ -f $K_FLAG ] ;then 41 echo [$(date "+%m-%d %H:%M:%S")] $* >> $K_RESULT 42 fi 43 44 if [ ! -f $K_FLAG ] && [ $ret_val -ne 0 ] ;then 45 echo [$(date "+%m-%d %H:%M:%S")] $* >> $K_RESULT 46 fi 47} 48 49# Compare 2 trees, if it is the same, return 0, or return 1 50# 51# we need to make sure whether the tree has changes after we 52# finish a lot of meta operations on he heavy workloads, this 53# function can compare the hierarchy between 2 trees. 54# 55# the basic idea is diff the output by command find. 56 57function k_tree_diff() 58{ 59 local ta=$1 # tree a 60 local tb=$2 # tree b 61 62 local md5a=$(run_quiet cd $ta; find | md5sum | awk '{ print $1}') 63 local md5b=$(run_quiet cd $tb; find | md5sum | awk '{ print $1}') 64 65 if [ $md5a = $md5b ];then 66 return 0 67 else 68 return 1 69 fi 70} 71 72 73dir=$1 74depth=$2 75width=$3 76result= 77 78k_log "thread $1 starts with pid $$" 79echo $$ | tee -a $K_THREADS_PID 80# generate new tree 81k_log "begin to generate tree $dir" 82$K_TREE_GEN $depth $width 83k_log "end to generate tree $dir" 84 85cwd=$(pwd) 86run_quiet cd $K_VAR 87while [ -e $K_FLAG ] 88do 89 new_dir=$dir-new 90 cp $dir $new_dir -pr 91 run_quiet cd $new_dir 92 k_log "thread $dir: begin to traverse dir $new_dir" 93 $K_TREE_TRAV $2 $3 94 k_log "thread $dir: end to traverse dir $new_dir" 95 run_quiet cd - 96 result=pass 97 k_tree_diff $dir $new_dir || result=fail 98 k_result "thread $dir: $result to compare result between dir $dir and $new_dir" 99 100 rm $new_dir -fr 101done 102run_quiet cd $cwd 103 104# test ends, remove the oringal tree 105rm $dir -fr 106