tests: review all wc(1) invocations
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13259
This commit is contained in:
parent
23914a3b91
commit
964d41806f
|
@ -2158,8 +2158,7 @@ function check_pool_status # pool token keyword <verbose>
|
|||
typeset keyword=$3
|
||||
typeset verbose=${4:-false}
|
||||
|
||||
scan=$(zpool status -v "$pool" 2>/dev/null | awk -v token="$token:" '
|
||||
($1==token) {print $0}')
|
||||
scan=$(zpool status -v "$pool" 2>/dev/null | awk -v token="$token:" '$1==token')
|
||||
if [[ $verbose == true ]]; then
|
||||
log_note $scan
|
||||
fi
|
||||
|
@ -3075,7 +3074,7 @@ function vdevs_in_pool
|
|||
typeset tmpfile=$(mktemp)
|
||||
zpool status -v "$pool" | grep -A 1000 "config:" >$tmpfile
|
||||
for vdev in "$@"; do
|
||||
grep -wq ${vdev##*/} $tmpfile || && return 1
|
||||
grep -wq ${vdev##*/} $tmpfile || return 1
|
||||
done
|
||||
|
||||
rm -f $tmpfile
|
||||
|
@ -3959,10 +3958,10 @@ function directory_diff # dir_a dir_b
|
|||
# We check ctimes even with zil_replay=1 because the ZIL does store
|
||||
# creation times and we should make sure they match (if the creation times
|
||||
# do not match there is a "c" entry in one of the columns).
|
||||
if ( rsync --version | grep -q "[, ] crtimes" >/dev/null ); then
|
||||
if rsync --version | grep -q "[, ] crtimes"; then
|
||||
args+=("--crtimes")
|
||||
else
|
||||
echo "NOTE: This rsync package does not support --crtimes (-N)."
|
||||
log_note "This rsync package does not support --crtimes (-N)."
|
||||
fi
|
||||
|
||||
# If we are testing a ZIL replay, we need to ignore timestamp changes.
|
||||
|
|
|
@ -86,13 +86,10 @@ log_pos kill $CHILD
|
|||
# Make sure the channel program did not fully complete by enforcing
|
||||
# that not all of the snapshots were created.
|
||||
#
|
||||
snap_count=$(zfs list -t snapshot | grep $TESTPOOL | wc -l)
|
||||
snap_count=$(zfs list -t snapshot | grep -c $TESTPOOL)
|
||||
log_note "$snap_count snapshots created by ZCP"
|
||||
|
||||
if [ "$snap_count" -eq 0 ]; then
|
||||
log_fail "Channel program failed to run."
|
||||
elif [ "$snap_count" -gt 90 ]; then
|
||||
log_fail "Too many snapshots after a cancel ($snap_count)."
|
||||
else
|
||||
log_pass "Canceling a long-running channel program works."
|
||||
fi
|
||||
log_mustnot [ "$snap_count" -eq 0 ]
|
||||
log_mustnot [ "$snap_count" -gt 90 ]
|
||||
|
||||
log_pass "Cancelling a long-running channel program works."
|
||||
|
|
|
@ -69,16 +69,16 @@ obj=${array[0]}
|
|||
log_note "file $init_data has object number $obj"
|
||||
|
||||
output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
|
||||
|grep -m 1 "L1 DVA" |head -n1)
|
||||
|grep -m 1 "L1 DVA" )
|
||||
dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*/\1/p' <<< "$output")
|
||||
log_note "first L1 block $init_data has a DVA of $dva"
|
||||
output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
|
||||
|grep -m 1 "L0 DVA" |head -n1)
|
||||
|grep -m 1 "L0 DVA" )
|
||||
blk_out0=${output##*>}
|
||||
blk_out0=${blk_out0##+([[:space:]])}
|
||||
|
||||
output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
|
||||
|grep -m 1 "1000 L0 DVA" |head -n1)
|
||||
|grep -m 1 "1000 L0 DVA" )
|
||||
blk_out1=${output##*>}
|
||||
blk_out1=${blk_out1##+([[:space:]])}
|
||||
|
||||
|
@ -110,7 +110,7 @@ vdev=$(echo "$dva" | cut -d: -f1)
|
|||
offset=$(echo "$dva" | cut -d: -f2)
|
||||
output=$(export ZDB_NO_ZLE=\"true\";\
|
||||
zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null)
|
||||
block_cnt=$(echo "$output" | grep 'L0' | wc -l)
|
||||
block_cnt=$(echo "$output" | grep -c 'L0')
|
||||
if [ $block_cnt -ne $write_count ]; then
|
||||
log_fail "zdb -R :id (indirect block display) failed"
|
||||
fi
|
||||
|
@ -120,7 +120,7 @@ vdev="$vdev.0"
|
|||
log_note "Reading from DVA $vdev:$offset:$l1_read_size"
|
||||
output=$(export ZDB_NO_ZLE=\"true\";\
|
||||
zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null)
|
||||
block_cnt=$(echo "$output" | grep 'L0' | wc -l)
|
||||
block_cnt=$(echo "$output" | grep -c 'L0')
|
||||
if [ $block_cnt -ne $write_count ]; then
|
||||
log_fail "zdb -R 0.0:offset:length:id (indirect block display) failed"
|
||||
fi
|
||||
|
|
|
@ -167,7 +167,7 @@ while (( i < ${#opts[*]} )); do
|
|||
log_fail "There is no property for" \
|
||||
"dataset $ds in 'get all' output."
|
||||
|
||||
propnum=$(awk -v ds="${ds}$" '$1 ~ ds {print $1}' $propfile | wc -l)
|
||||
propnum=$(awk -v ds="${ds}$" '$1 ~ ds {++cnt} END {print cnt}' $propfile)
|
||||
case $(zfs get -H -o value type $ds) in
|
||||
filesystem )
|
||||
(( propnum < fspropnum )) && \
|
||||
|
|
|
@ -120,7 +120,7 @@ for x in {1..$ITERATIONS}; do
|
|||
for y in {1..$NUM_SNAPS}; do
|
||||
log_must zfs snapshot $TESTPOOL/$MYTEST@$y
|
||||
done;
|
||||
n=$(ls -1 /$TESTPOOL/$MYTEST/.zfs/snapshot | wc -l)
|
||||
n=$(ls /$TESTPOOL/$MYTEST/.zfs/snapshot | wc -l)
|
||||
verify_eq $n $NUM_SNAPS "count"
|
||||
zfs destroy -r $TESTPOOL/$MYTEST;
|
||||
done;
|
||||
|
|
|
@ -115,7 +115,7 @@ function do_test
|
|||
out="$(zpool status -p | grep $VDEV1)"
|
||||
|
||||
if [ "$ERR" == "corrupt" ] ; then
|
||||
events=$(zpool events | grep checksum | wc -l)
|
||||
events=$(zpool events | grep -c checksum)
|
||||
val=$(echo "$out" | awk '{print $5}')
|
||||
str="checksum"
|
||||
elif [ "$ERR" == "io" ] ; then
|
||||
|
|
|
@ -49,14 +49,14 @@ log_must eval "zpool events -H -f > $EVENTS_FILE &"
|
|||
pid=$!
|
||||
|
||||
# 3. Generate some ZFS events
|
||||
for i in `seq 1 $EVENTS_NUM`; do
|
||||
for i in {1..$EVENTS_NUM}; do
|
||||
log_must zpool clear $TESTPOOL
|
||||
done
|
||||
# wait a bit to allow the kernel module to process new events
|
||||
zpool_events_settle
|
||||
|
||||
# 4. Verify 'zpool events -f' successfully recorded these new events
|
||||
EVENTS_LOG=$(cat $EVENTS_FILE | wc -l)
|
||||
EVENTS_LOG=$(wc -l < $EVENTS_FILE)
|
||||
if [[ $EVENTS_LOG -ne $EVENTS_NUM ]]; then
|
||||
log_fail "Unexpected number of events: $EVENTS_LOG != $EVENTS_NUM"
|
||||
fi
|
||||
|
|
|
@ -62,7 +62,7 @@ fi
|
|||
|
||||
zpool iostat $TESTPOOL 1 4 > $tmpfile 2>&1 &
|
||||
sleep 4
|
||||
stat_count=$(grep $TESTPOOL $tmpfile | wc -l)
|
||||
stat_count=$(grep -c $TESTPOOL $tmpfile)
|
||||
|
||||
if [[ $stat_count -ne 4 ]]; then
|
||||
log_fail "zpool iostat [pool_name] [interval] [count] failed"
|
||||
|
|
|
@ -68,10 +68,9 @@ sync_pool $TESTPOOL
|
|||
|
||||
log_must zinject -c all
|
||||
SLOW_IOS=$(zpool status -sp | awk -v d="$DISK" '$0 ~ d {print $6}')
|
||||
DELAY_EVENTS=$(zpool events | grep delay | wc -l)
|
||||
DELAY_EVENTS=$(zpool events | grep -c delay)
|
||||
|
||||
log_must [ $SLOW_IOS -gt 0 ]
|
||||
log_must [ $DELAY_EVENTS -gt 0 ]
|
||||
|
||||
if [ $SLOW_IOS -gt 0 ] && [ $DELAY_EVENTS -gt 0 ] ; then
|
||||
log_pass "Correctly saw $SLOW_IOS slow IOs and $DELAY_EVENTS delay events"
|
||||
else
|
||||
log_fail "Only saw $SLOW_IOS slow IOs and $DELAY_EVENTS delay events"
|
||||
fi
|
||||
|
|
|
@ -57,7 +57,7 @@ function cleanup
|
|||
log_onexit cleanup
|
||||
|
||||
LOGSM_POOL="logsm_import"
|
||||
TESTDISK="$(echo $DISKS | cut -d' ' -f1)"
|
||||
read -r TESTDISK _ <<<"$DISKS"
|
||||
|
||||
log_must zpool create -o cachefile=none -f $LOGSM_POOL $TESTDISK
|
||||
log_must zfs create $LOGSM_POOL/fs
|
||||
|
@ -70,10 +70,7 @@ sync_all_pools
|
|||
log_must set_tunable64 KEEP_LOG_SPACEMAPS_AT_EXPORT 1
|
||||
log_must zpool export $LOGSM_POOL
|
||||
|
||||
LOGSM_COUNT=$(zdb -m -e $LOGSM_POOL | grep "Log Spacemap object" | wc -l)
|
||||
if (( LOGSM_COUNT == 0 )); then
|
||||
log_fail "Pool does not have any log spacemaps after being exported"
|
||||
fi
|
||||
log_must eval "zdb -m -e $LOGSM_POOL | grep -q \"Log Spacemap object\""
|
||||
|
||||
log_must set_tunable64 METASLAB_DEBUG_LOAD 1
|
||||
log_must zpool import $LOGSM_POOL
|
||||
|
|
|
@ -114,9 +114,7 @@ function mv_files
|
|||
#
|
||||
function count_files
|
||||
{
|
||||
typeset -i file_num
|
||||
file_num=$(find $1 -type f -print | wc -l | tr -d ' ')
|
||||
(( file_num != $2 )) && \
|
||||
(( $(find $1 -type f -print | wc -l) != $2 )) && \
|
||||
log_fail "The file number of target directory"\
|
||||
"$2 is not equal to that of the source "\
|
||||
"directory $1"
|
||||
|
|
|
@ -48,8 +48,8 @@ function cleanup
|
|||
function count_snap_cmds
|
||||
{
|
||||
typeset expected_count=$1
|
||||
count=$(grep -E "command: (lt-)?zfs snapshot $FS@testsnapshot" | wc -l)
|
||||
log_must eval "[[ $count -eq $expected_count ]]"
|
||||
count=$(grep -cE "command: (lt-)?zfs snapshot $FS@testsnapshot")
|
||||
log_must [ "$count" -eq "$expected_count" ]
|
||||
}
|
||||
|
||||
typeset -r ZFS_DBGMSG=/proc/spl/kstat/zfs/dbgmsg
|
||||
|
|
|
@ -64,7 +64,7 @@ objset=$(zdb -d $TESTPOOL1/ | sed -ne 's/.*ID \([0-9]*\).*/\1/p')
|
|||
object=$(ls -i /$TESTPOOL1/file | awk '{print $1}')
|
||||
|
||||
# inject event to cause error during resilver
|
||||
log_must zinject -b `printf "%x:%x:0:3fff" $objset $object` $TESTPOOL1
|
||||
log_must zinject -b $(printf "%x:%x:0:3fff" $objset $object) $TESTPOOL1
|
||||
|
||||
# clear events and start resilver
|
||||
log_must zpool events -c
|
||||
|
@ -84,7 +84,7 @@ done
|
|||
log_note "waiting for resilver to finish"
|
||||
for iter in {0..59}
|
||||
do
|
||||
finish=$(zpool events | grep "sysevent.fs.zfs.resilver_finish" | wc -l)
|
||||
finish=$(zpool events | grep -cF "sysevent.fs.zfs.resilver_finish")
|
||||
(( $finish > 0 )) && break
|
||||
sleep 1
|
||||
done
|
||||
|
@ -96,7 +96,7 @@ sync_pool $TESTPOOL1
|
|||
sync_pool $TESTPOOL1
|
||||
|
||||
# check if resilver was restarted
|
||||
start=$(zpool events | grep "sysevent.fs.zfs.resilver_start" | wc -l)
|
||||
start=$(zpool events | grep -cF "sysevent.fs.zfs.resilver_start")
|
||||
(( $start != 1 )) && log_fail "resilver restarted unnecessarily"
|
||||
|
||||
log_pass "Resilver did not restart unnecessarily from scan errors"
|
||||
|
|
|
@ -142,8 +142,7 @@ while (( i < ${#args[*]} )); do
|
|||
if [[ -n ${args[i+3]} ]] ; then
|
||||
log_must zfs set mountpoint=${args[i+3]} ${args[i+2]}
|
||||
|
||||
FILE_COUNT=`ls -Al ${args[i+3]} | grep -v "total" \
|
||||
| grep -v "\.zfs" | wc -l`
|
||||
FILE_COUNT=$(ls -A ${args[i+3]} | grep -cvF ".zfs")
|
||||
if [[ $FILE_COUNT -ne $COUNT ]]; then
|
||||
ls -Al ${args[i+3]}
|
||||
log_fail "AFTER: ${args[i+3]} contains $FILE_COUNT files(s)."
|
||||
|
@ -157,7 +156,7 @@ while (( i < ${#args[*]} )); do
|
|||
(( j = j + 1 ))
|
||||
done
|
||||
|
||||
FILE_COUNT=`ls -Al ${args[i+3]}/after* | grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A ${args[i+3]}/after* | wc -l)
|
||||
if [[ $FILE_COUNT -ne $COUNT ]]; then
|
||||
ls -Al ${args[i+3]}
|
||||
log_fail "${args[i+3]} contains $FILE_COUNT after* files(s)."
|
||||
|
|
|
@ -76,7 +76,7 @@ done
|
|||
|
||||
log_must zfs snapshot $SNAPFS
|
||||
|
||||
FILE_COUNT=`ls -Al $SNAPDIR | grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $SNAPDIR | wc -l)
|
||||
if [[ $FILE_COUNT -ne $COUNT ]]; then
|
||||
ls -Al $SNAPDIR
|
||||
log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
|
||||
|
@ -97,14 +97,13 @@ sync_pool $TESTPOOL
|
|||
#
|
||||
log_must zfs rollback $SNAPFS
|
||||
|
||||
FILE_COUNT=`ls -Al $TESTDIR/after* 2> /dev/null | grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $TESTDIR/after* 2> /dev/null | wc -l)
|
||||
if [[ $FILE_COUNT -ne 0 ]]; then
|
||||
ls -Al $TESTDIR
|
||||
log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
|
||||
fi
|
||||
|
||||
FILE_COUNT=`ls -Al $TESTDIR/before* 2> /dev/null \
|
||||
| grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $TESTDIR/before* 2> /dev/null | wc -l)
|
||||
if [[ $FILE_COUNT -ne $COUNT ]]; then
|
||||
ls -Al $TESTDIR
|
||||
log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
|
||||
|
|
|
@ -79,7 +79,7 @@ done
|
|||
|
||||
log_must zfs snapshot $SNAPFS
|
||||
|
||||
FILE_COUNT=`ls -Al $SNAPDIR | grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $SNAPDIR | wc -l)
|
||||
if [[ $FILE_COUNT -ne $COUNT ]]; then
|
||||
ls -Al $SNAPDIR
|
||||
log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
|
||||
|
@ -112,14 +112,13 @@ done
|
|||
#
|
||||
log_must zfs rollback $SNAPFS.1
|
||||
|
||||
FILE_COUNT=`ls -Al $TESTDIR/aftersecond* 2> /dev/null \
|
||||
| grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $TESTDIR/aftersecond* 2> /dev/null | wc -l)
|
||||
if [[ $FILE_COUNT -ne 0 ]]; then
|
||||
ls -Al $TESTDIR
|
||||
log_fail "$TESTDIR contains $FILE_COUNT aftersecond* files(s)."
|
||||
fi
|
||||
|
||||
FILE_COUNT=`ls -Al $TESTDIR/original* $TESTDIR/afterfirst*| grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $TESTDIR/original* $TESTDIR/afterfirst* | wc -l)
|
||||
if [[ $FILE_COUNT -ne 20 ]]; then
|
||||
ls -Al $TESTDIR
|
||||
log_fail "$TESTDIR contains $FILE_COUNT original* files(s)."
|
||||
|
|
|
@ -86,7 +86,7 @@ log_note "Remove all of the original files"
|
|||
|
||||
i=1
|
||||
while [[ $i -lt $COUNT ]]; do
|
||||
FILECOUNT=`ls $SNAPDIR.$i/file* | wc -l`
|
||||
FILECOUNT=$(ls $SNAPDIR.$i/file* | wc -l)
|
||||
typeset j=1
|
||||
while [ $j -lt $FILECOUNT ]; do
|
||||
log_must file_check $SNAPDIR.$i/file$j $j
|
||||
|
|
|
@ -60,7 +60,7 @@ log_onexit cleanup
|
|||
[ -n $TESTDIR ] && log_must rm -rf $TESTDIR/*
|
||||
|
||||
log_must zfs snapshot $SNAPFS
|
||||
FILE_COUNT=`ls -Al $SNAPDIR | grep -v "total 0" | wc -l`
|
||||
FILE_COUNT=$(ls -A $SNAPDIR | wc -l)
|
||||
if [[ $FILE_COUNT -ne 0 ]]; then
|
||||
ls $SNAPDIR
|
||||
log_fail "BEFORE: $SNAPDIR contains $FILE_COUNT files(s)."
|
||||
|
@ -77,7 +77,7 @@ while [[ $i -lt $COUNT ]]; do
|
|||
(( i = i + 1 ))
|
||||
done
|
||||
|
||||
FILE_COUNT=`ls -Al $SNAPDIR | grep -v "total 0" | wc -l`
|
||||
FILE_COUNT=$(ls -A $SNAPDIR | wc -l)
|
||||
if [[ $FILE_COUNT -ne 0 ]]; then
|
||||
ls $SNAPDIR
|
||||
log_fail "AFTER: $SNAPDIR contains $FILE_COUNT files(s)."
|
||||
|
|
|
@ -90,7 +90,7 @@ log_note "Remove all of the original files"
|
|||
|
||||
i=1
|
||||
while [[ $i -lt $COUNT ]]; do
|
||||
FILECOUNT=`echo $SNAPDIR1.$i/file* | wc -w`
|
||||
FILECOUNT=$(ls $SNAPDIR1.$i/file* 2>/dev/null | wc -l)
|
||||
typeset j=1
|
||||
while [ $j -lt $FILECOUNT ]; do
|
||||
log_must file_check $SNAPDIR1.$i/file$j $j
|
||||
|
|
|
@ -74,7 +74,7 @@ done
|
|||
|
||||
log_must zfs snapshot -r $SNAPPOOL
|
||||
|
||||
FILE_COUNT=`ls -Al $SNAPDIR | grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $SNAPDIR | wc -l)
|
||||
if (( FILE_COUNT != COUNT )); then
|
||||
ls -Al $SNAPDIR
|
||||
log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
|
||||
|
@ -94,14 +94,13 @@ done
|
|||
#
|
||||
log_must zfs rollback $SNAPFS
|
||||
|
||||
FILE_COUNT=`ls -Al $TESTDIR/after* 2> /dev/null | grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $TESTDIR/after* 2> /dev/null | wc -l)
|
||||
if (( FILE_COUNT != 0 )); then
|
||||
ls -Al $TESTDIR
|
||||
log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
|
||||
fi
|
||||
|
||||
FILE_COUNT=`ls -Al $TESTDIR/before* 2> /dev/null \
|
||||
| grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $TESTDIR/before* 2> /dev/null | wc -l)
|
||||
if (( FILE_COUNT != $COUNT )); then
|
||||
ls -Al $TESTDIR
|
||||
log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
|
||||
|
|
|
@ -87,7 +87,7 @@ if ! datasetexists $ctrfs || ! snapexists $snapctrfs; then
|
|||
fi
|
||||
|
||||
for dir in $fsdir $snapdir; do
|
||||
FILE_COUNT=`ls -Al $dir | grep -v "total" | wc -l`
|
||||
FILE_COUNT=$(ls -A $dir | wc -l)
|
||||
(( FILE_COUNT != COUNT )) && log_fail "Got $FILE_COUNT expected $COUNT"
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in New Issue