tests: prune cat (ab)uses

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:
наб 2022-03-14 23:47:38 +01:00 committed by Brian Behlendorf
parent f7cc8dddf7
commit b2c5291b7e
16 changed files with 51 additions and 67 deletions

View File

@ -67,34 +67,32 @@ obj=${array[0]}
log_note "file $init_data has object number $obj"
sync_pool $TESTPOOL
output=$(zdb -d $TESTPOOL/$TESTFS)
objset_id=$(echo $output | cut -d, -f2 | cut -d' ' -f2)
IFS=", " read -r _ _ _ _ objset_id _ < <(zdb -d $TESTPOOL/$TESTFS)
objset_hex=$(printf "0x%X" $objset_id)
log_note "objset $TESTPOOL/$TESTFS has objset ID $objset_id ($objset_hex)"
for id in "$objset_id" "$objset_hex"
do
log_note "zdb -dddddd $TESTPOOL/$id $obj"
output=$(zdb -dddddd $TESTPOOL/$id $obj)
echo $output | grep -q "$TESTPOOL/$TESTFS" ||
log_fail "zdb -dddddd $TESTPOOL/$id $obj failed ($TESTPOOL/$TESTFS not in zdb output)"
echo $output | grep -q "file1" ||
log_fail "zdb -dddddd $TESTPOOL/$id $obj failed (file1 not in zdb output)"
output=$(zdb -dddddd $TESTPOOL/$id $obj)
echo $output | grep -q "$TESTPOOL/$TESTFS" ||
log_fail "zdb -dddddd $TESTPOOL/$id $obj failed ($TESTPOOL/$TESTFS not in zdb output)"
echo $output | grep -q "file1" ||
log_fail "zdb -dddddd $TESTPOOL/$id $obj failed (file1 not in zdb output)"
obj=$(printf "0x%X" $obj)
log_note "zdb -NNNNNN $TESTPOOL/$id $obj"
output=$(zdb -NNNNNN $TESTPOOL/$id $obj)
echo $output | grep -q "$TESTPOOL/$TESTFS" ||
log_fail "zdb -NNNNNN $TESTPOOL/$id $obj failed ($TESTPOOL/$TESTFS not in zdb output)"
echo $output | grep -q "file1" ||
log_fail "zdb -NNNNNN $TESTPOOL/$id $obj failed (file1 not in zdb output)"
output=$(zdb -NNNNNN $TESTPOOL/$id $obj)
echo $output | grep -q "$TESTPOOL/$TESTFS" ||
log_fail "zdb -NNNNNN $TESTPOOL/$id $obj failed ($TESTPOOL/$TESTFS not in zdb output)"
echo $output | grep -q "file1" ||
log_fail "zdb -NNNNNN $TESTPOOL/$id $obj failed (file1 not in zdb output)"
done
if is_linux; then
output=$(ls -1 /proc/spl/kstat/zfs/$TESTPOOL |grep objset- |tail -1)
output=$(ls -1 /proc/spl/kstat/zfs/$TESTPOOL | grep objset- | tail -1)
objset_hex=${output#*-}
name_from_proc=$(cat /proc/spl/kstat/zfs/$TESTPOOL/$output |
grep dataset_name | cut -d' ' -f3)
name_from_proc=$(grep dataset_name /proc/spl/kstat/zfs/$TESTPOOL/$output | cut -d' ' -f3)
log_note "checking zdb output for $name_from_proc"
log_must eval "zdb -dddddd $TESTPOOL/$objset_hex | grep -q \"$name_from_proc\""
fi

View File

@ -80,8 +80,8 @@ log_must zfs snapshot $init_snap
log_must eval "zfs send $init_snap > $full_bkup"
log_note "'zfs receive' fails with invalid send streams."
log_mustnot eval "cat </dev/zero | zfs receive $rst_init_snap"
log_mustnot eval "cat </dev/zero | zfs receive -d $rst_root"
log_mustnot eval "cat /dev/zero | zfs receive $rst_init_snap"
log_mustnot eval "cat /dev/zero | zfs receive -d $rst_root"
log_must eval "zfs receive $rst_init_snap < $full_bkup"

View File

@ -70,7 +70,7 @@ for arch in "i386" "sparc"; do
orig_cmds_f=$import_dir/${arch}.orig_history.txt
# remove blank line
orig_cmds_f1=$import_dir/${arch}.orig_history_1.txt
cat $orig_cmds_f | grep -v "^$" > $orig_cmds_f1
grep -v "^$" $orig_cmds_f > $orig_cmds_f1
log_must cp $tst_dir/${arch}.migratedpool.DAT.Z $import_dir
log_must uncompress -f $import_dir/${arch}.migratedpool.DAT.Z

View File

@ -37,7 +37,7 @@ verify_runnable "both"
function cleanup
{
log_must zpool destroy $MMP_POOL
log_must rm $MMP_DIR/file.{0,1,2,3,4,5,6,7}
log_must rm $MMP_DIR/file.{0..7}
log_must rm $MMP_HISTORY_TMP
log_must rmdir $MMP_DIR
log_must mmp_clear_hostid
@ -51,8 +51,8 @@ MMP_HISTORY=/proc/spl/kstat/zfs/$MMP_POOL/multihost
# Step 1
log_must mkdir -p $MMP_DIR
log_must truncate -s 128M $MMP_DIR/file.{0,1,2,3,4,5,6,7}
log_must zpool create -f $MMP_POOL mirror $MMP_DIR/file.{0,1} mirror $MMP_DIR/file.{2,3,4,5,6,7}
log_must truncate -s 128M $MMP_DIR/file.{0..7}
log_must zpool create -f $MMP_POOL mirror $MMP_DIR/file.{0..1} mirror $MMP_DIR/file.{2..7}
# Step 2
log_must mmp_set_hostid $HOSTID1
@ -69,8 +69,8 @@ typeset -i min_writes=999
typeset -i max_writes=0
typeset -i write_count
# copy to get as close to a consistent view as possible
cat $MMP_HISTORY > $MMP_HISTORY_TMP
for x in $(seq 0 7); do
cp $MMP_HISTORY $MMP_HISTORY_TMP
for x in {0..7}; do
write_count=$(grep -c file.${x} $MMP_HISTORY_TMP)
if [ $write_count -lt $min_writes ]; then
min_writes=$write_count

View File

@ -28,7 +28,7 @@ pamservice="pam_zfs_key_test"
pamconfig="/etc/pam.d/${pamservice}"
function keystatus {
log_must [ "$(zfs list -Ho keystatus "$TESTPOOL/pam/${username}")" == "$1" ]
log_must [ "$(zfs list -Ho keystatus "$TESTPOOL/pam/${username}")" = "$1" ]
}
function genconfig {
@ -42,6 +42,6 @@ function rmconfig {
}
function references {
log_must [ "$(cat "${runstatedir}/$(id -u ${username})")" == "$1" ]
log_must [ "$(<"${runstatedir}/$(id -u ${username})")" = "$1" ]
}

View File

@ -85,7 +85,7 @@ done
# Clear out old messages and check that they really are gone
echo 0 >$ZFS_DBGMSG || log_fail "failed to write to $ZFS_DBGMSG"
cat $ZFS_DBGMSG | count_snap_cmds 0
count_snap_cmds 0 < $ZFS_DBGMSG
#
# Even though we don't expect any messages in the file, reading should still
# succeed.

View File

@ -41,8 +41,7 @@
function cleanup
{
[[ -z $msgs1 ]] || log_must rm $msgs1
[[ -z $msgs2 ]] || log_must rm $msgs2
log_must rm -f $msgs1 $msgs2
datasetexists $FS && destroy_dataset $FS -r
}
@ -69,7 +68,7 @@ msgs2=$(mktemp) || log_fail
# Start reading file, pause and read it from another process, and then finish
# reading.
#
{ dd bs=512 count=4; cat $ZFS_DBGMSG >$msgs1; cat; } <$ZFS_DBGMSG >$msgs2
{ dd bs=512 count=4; cp $ZFS_DBGMSG $msgs1; cat; } <$ZFS_DBGMSG >$msgs2
#
# Truncate the result of the read that completed second in case it picked up an

View File

@ -231,7 +231,7 @@ function compare_files
[[ -f $file2 ]] || log_fail "File $file2 does not exist."
log_must eval "get_diff $file1 $file2 >$tmpfile"
typeset range="$(cat $tmpfile)"
typeset range="$(<$tmpfile)"
log_must unmount_redacted $recvfs
[[ "$expected" = "$range" ]] || log_fail "Unexpected range: $range"
}

View File

@ -60,13 +60,10 @@ for recsize in 512 1024 2048 4096 8192 16384; do
log_must eval "zdb -ddddd $sendfs $send_obj >$tmpdir/send.zdb"
log_must eval "zdb -ddddd $recvfs $recv_obj >$tmpdir/recv.zdb"
grep -q "EMBEDDED" $tmpdir/send.zdb || \
log_fail "Obj $send_obj not embedded in $sendfs"
grep -q "EMBEDDED" $tmpdir/recv.zdb || \
log_fail "Obj $recv_obj not embedded in $recvfs"
log_must grep -q "EMBEDDED" $tmpdir/send.zdb
log_must grep -q "EMBEDDED" $tmpdir/recv.zdb
cat $stream | zstream dump -v | log_must grep -q \
"WRITE_EMBEDDED object = $send_obj offset = 0"
log_must eval "zstream dump -v $stream | grep -q \"WRITE_EMBEDDED object = $send_obj offset = 0\""
done
log_must zfs destroy -R $recvfs
@ -91,13 +88,10 @@ for recsize in 1024 4096 16384; do
log_must eval "zdb -ddddd $sendfs $send_obj >$tmpdir/send.zdb"
log_must eval "zdb -ddddd $recvfs $recv_obj >$tmpdir/recv.zdb"
grep -q "EMBEDDED" $tmpdir/send.zdb || \
log_fail "Obj $send_obj not embedded in $sendfs"
grep -q "EMBEDDED" $tmpdir/recv.zdb || \
log_fail "Obj $recv_obj not embedded in $recvfs"
log_must grep -q "EMBEDDED" $tmpdir/send.zdb
log_must grep -q "EMBEDDED" $tmpdir/recv.zdb
cat $stream | zstream dump -v | log_must grep -q \
"WRITE_EMBEDDED object = $send_obj offset = 0"
log_must eval "zstream dump -v $stream | log_must grep -q \"WRITE_EMBEDDED object = $send_obj offset = 0\""
done
log_pass "Embedded blocks and redacted send work correctly together."

View File

@ -53,7 +53,7 @@ log_must mount_redacted -f $recvfs
log_must set_tunable32 ALLOW_REDACTED_DATASET_MOUNT 1
log_must diff $send_mnt/f1 $recv_mnt/f1
log_must eval "get_diff $send_mnt/f2 $recv_mnt/f2 >$tmpdir/get_diff.out"
typeset range=$(cat $tmpdir/get_diff.out)
typeset range=$(<$tmpdir/get_diff.out)
[[ "$RANGE9" = "$range" ]] || log_fail "Unexpected range: $range"
log_must dd if=/dev/urandom of=$send_mnt/f3 bs=1024k count=3
@ -70,7 +70,7 @@ resume_test "zfs send --redact book2 -i $sendfs#book1 $sendfs@snap2" \
log_must diff $send_mnt/f1 $recv_mnt/f1
log_must diff $send_mnt/f2 $recv_mnt/f2
log_must eval "get_diff $send_mnt/f3 $recv_mnt/f3 >$tmpdir/get_diff.out"
range=$(cat $tmpdir/get_diff.out)
range=$(<$tmpdir/get_diff.out)
[[ "$RANGE10" = "$range" ]] || log_fail "Unexpected range: $range"
# Test recv -A works properly and verify saved sends are not allowed

View File

@ -162,7 +162,7 @@ do
# inject read io errors on vdev and verify resilver does not restart
log_must zinject -a -d ${VDEV_FILES[2]} -e io -T read -f 0.25 $TESTPOOL1
log_must eval "cat ${DATAPATHS[1]} > /dev/null"
log_must cp ${DATAPATHS[1]} /dev/null
log_must zinject -c all
# there should still be 2 resilver starts w/o defer, 1 with defer

View File

@ -625,7 +625,7 @@ function resume_test
log_mustnot eval "zfs recv -suv $recvfs </$streamfs/$stream_num"
stream_num=$((stream_num+1))
token=$(zfs get -Hp -o value receive_resume_token $recvfs)
token=$(get_prop receive_resume_token $recvfs)
# Do a dry-run
[ $dryrun -ne 0 ] && \
@ -709,7 +709,7 @@ function stream_has_features
shift
[[ -f $file ]] || log_fail "Couldn't find file: $file"
typeset flags=$(cat $file | zstream dump | \
typeset flags=$(zstream dump $file | \
awk '/features =/ {features = $3} END {print features}')
typeset -A feature
feature[dedup]="1"
@ -759,7 +759,7 @@ function verify_stream_size
[[ -f $stream ]] || log_fail "No such file: $stream"
datasetexists $ds || log_fail "No such dataset: $ds"
typeset stream_size=$(cat $stream | zstream dump | sed -n \
typeset stream_size=$(zstream dump $stream | sed -n \
's/ Total payload size = \(.*\) (0x.*)/\1/p')
typeset inc_size=0
@ -777,8 +777,7 @@ function verify_stream_size
fi
ds_size=$((ds_size - inc_size))
within_percent $stream_size $ds_size $percent || log_fail \
"$stream_size $ds_size differed by too much"
log_must within_percent $stream_size $ds_size $percent
}
# Cleanup function for tests involving resumable send

View File

@ -49,7 +49,7 @@ log_must zfs snapshot $sendfs@full
log_must eval "zfs send -c $sendfs@full >$BACKDIR/full"
log_must stream_has_features $BACKDIR/full lz4 compressed
cat $BACKDIR/full | zstream dump -v > $BACKDIR/dump.out
zstream dump -v $BACKDIR/full > $BACKDIR/dump.out
lsize=$(awk '/^WRITE [^0]/ {lsize += $24} END {printf("%d", lsize)}' \
$BACKDIR/dump.out)
@ -63,8 +63,8 @@ csize_prop=$(get_prop used $sendfs)
within_percent $csize $csize_prop 90 || log_fail \
"$csize and $csize_prop differed by too much"
x=$(get_resume_token "zfs send -c $sendfs@full" $streamfs $recvfs)
resume_token=$(cat /$streamfs/resume_token)
get_resume_token "zfs send -c $sendfs@full" $streamfs $recvfs
resume_token=$(</$streamfs/resume_token)
to_name_fs=$sendfs
log_must eval "zstream token $resume_token | grep $to_name_fs"

View File

@ -134,7 +134,7 @@ function check
[[ -f $stream ]] && log_must rm $stream
log_must eval "zfs send $flags $send_snap >$stream"
$verify eval "zfs recv $recv_ds <$stream"
typeset stream_size=$(cat $stream | zstream dump | sed -n \
typeset stream_size=$(zstream dump $stream | sed -n \
's/ Total write size = \(.*\) (0x.*)/\1/p')
#

View File

@ -30,7 +30,7 @@
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
USES_NIS=$(cat $TEST_BASE_DIR/zfs-xattr-test-nis.txt)
USES_NIS=$(<$TEST_BASE_DIR/zfs-xattr-test-nis.txt)
rm $TEST_BASE_DIR/zfs-xattr-test-nis.txt
if [ "${USES_NIS}" == "true" ]

View File

@ -97,10 +97,10 @@ function delete_xattr { # filename xattr_name
if is_illumos; then
log_must runat $FILE rm $XATTR_NAME
log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1"
else
log_must rm_xattr $XATTR_NAME $FILE
log_mustnot get_xattr $XATTR_NAME $FILE
fi
else
log_must rm_xattr $XATTR_NAME $FILE
log_mustnot get_xattr $XATTR_NAME $FILE
fi
}
# not sure about this : really this should be testing write/append
@ -126,12 +126,6 @@ function verify_write_xattr { # filename xattr_name
function create_expected_output { # expected_output_file contents_of_the_output
typeset FILE=$1
shift
if [[ -f $FILE ]]; then
log_must rm $FILE
fi
for line in $@
do
log_must eval "echo $line >> $FILE"
done
log_must rm -f $FILE
log_must eval "printf '%s\n' $* >> $FILE"
}