Skip to content

Commit

Permalink
tests: prune cat (ab)uses
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#13259
  • Loading branch information
nabijaczleweli authored and andrewc12 committed Sep 23, 2022
1 parent eada1f8 commit aa13d1c
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 67 deletions.
28 changes: 13 additions & 15 deletions tests/zfs-tests/tests/functional/cli_root/zdb/zdb_objset_id.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/zfs-tests/tests/functional/mmp/mmp_write_distribution.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/zfs-tests/tests/functional/pam/utilities.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -42,6 +42,6 @@ function rmconfig {
}

function references {
log_must [ "$(cat "${runstatedir}/$(id -u ${username})")" == "$1" ]
log_must [ "$(<"${runstatedir}/$(id -u ${username})")" = "$1" ]
}

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions tests/zfs-tests/tests/functional/rsend/rsend.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] && \
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/zfs-tests/tests/functional/rsend/send-c_zstreamdump.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')

#
Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/xattr/cleanup.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
18 changes: 6 additions & 12 deletions tests/zfs-tests/tests/functional/xattr/xattr_common.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}

0 comments on commit aa13d1c

Please sign in to comment.