]> granicus.if.org Git - zfs/commitdiff
ZTS: change `$(cat)` to `$(<)` for speedup
authorGeorge Melikov <mail@gmelikov.ru>
Wed, 31 Oct 2018 17:00:06 +0000 (20:00 +0300)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 31 Oct 2018 17:00:06 +0000 (12:00 -0500)
It's better to use ksh/bash built in methods,
rather than spawn new processes every time.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: George Melikov <mail@gmelikov.ru>
Closes #8071

15 files changed:
tests/zfs-tests/callbacks/zfs_mmp.ksh
tests/zfs-tests/include/libtest.shlib
tests/zfs-tests/tests/functional/channel_program/channel_common.kshlib
tests/zfs-tests/tests/functional/pool_checkpoint/pool_checkpoint.kshlib
tests/zfs-tests/tests/functional/privilege/cleanup.ksh
tests/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh
tests/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh
tests/zfs-tests/tests/functional/procfs/pool_state.ksh
tests/zfs-tests/tests/functional/procfs/procfs_list_stale_read.ksh
tests/zfs-tests/tests/functional/removal/removal_multiple_indirection.ksh
tests/zfs-tests/tests/functional/removal/removal_sanity.ksh
tests/zfs-tests/tests/functional/removal/removal_with_dedup.ksh
tests/zfs-tests/tests/functional/removal/removal_with_ganging.ksh
tests/zfs-tests/tests/functional/removal/remove_mirror_sanity.ksh
tests/zfs-tests/tests/perf/perf.shlib

index df2cd132d31a3845b19c0fc6bf5cffde4a5c6a4d..402e0b03f6182010da9d9943ff6b9ade781a5751 100755 (executable)
@@ -18,7 +18,7 @@
 
 # $1: number of lines to output (default: 40)
 typeset lines=${1:-40}
-typeset history=$(cat /sys/module/zfs/parameters/zfs_multihost_history)
+typeset history=$(</sys/module/zfs/parameters/zfs_multihost_history)
 
 if [ $history -eq 0 ]; then
        exit
index 51088fccbfffa71dd0abb4d322e9549b529ed18b..e66b2cbaf625a6af086b0275cbd18cc411e7fd2c 100644 (file)
@@ -3332,7 +3332,7 @@ function zed_stop
 
        log_note "Stopping ZED"
        if [[ -f ${ZEDLET_DIR}/zed.pid ]]; then
-               zedpid=$(cat ${ZEDLET_DIR}/zed.pid)
+               zedpid=$(<${ZEDLET_DIR}/zed.pid)
                kill $zedpid
                while ps -p $zedpid > /dev/null; do
                        sleep 1
index c1ecc52969a5f1317cced7607e5000b86a615dbd..722a477556fe2442a2a16732eeee36e4c65bdfcc 100644 (file)
@@ -67,10 +67,10 @@ function log_program
 
                outdiff=$(diff "$basename.out" "$tmpout")
                if [[ $? -ne 0 ]]; then
-                       output=$(cat $tmpout)
+                       output=$(<$tmpout)
                        rm $tmpout $tmperr $tmpin
                        log_fail "Output mismatch. Expected:\n" \
-                               "$(cat $basename.out)\nBut got:\n$output\n" \
+                               "$(<$basename.out)\nBut got:\n$output\n" \
                                "Diff:\n$outdiff"
                fi
 
@@ -78,10 +78,10 @@ function log_program
 
                outdiff=$(diff "$basename.err" "$tmperr")
                if [[ $? -ne 0 ]]; then
-                       outputerror=$(cat $tmperr)
+                       outputerror=$(<$tmperr)
                        rm $tmpout $tmperr $tmpin
                        log_fail "Error mismatch. Expected:\n" \
-                               "$(cat $basename.err)\nBut got:\n$outputerror\n" \
+                               "$(<$basename.err)\nBut got:\n$outputerror\n" \
                                "Diff:\n$outdiff"
                fi
 
@@ -89,7 +89,7 @@ function log_program
 
                grep -q "$expecterror" $tmperr
                if [[ $? -ne 0 ]]; then
-                       outputerror=$(cat $tmperr)
+                       outputerror=$(<$tmperr)
                        rm $tmpout $tmperr $tmpin
                        log_fail "Error mismatch. Expected to contain:\n" \
                                "$expecterror\nBut got:\n$outputerror\n"
@@ -100,7 +100,7 @@ function log_program
                # If there's no expected output, error reporting is allowed to
                # vary, but ensure that we didn't fail silently.
                #
-               if [[ -z "$(cat $tmperr)" ]]; then
+               if [[ -z "$(<$tmperr)" ]]; then
                        rm $tmpout $tmperr $tmpin
                        log_fail "error with no stderr output"
                fi
index 3638e3dfec982e4b0be04447c3494e0d49c62b61..455a1d12d24e7e068476d7ed0af29da0f9cbdff1 100644 (file)
@@ -220,8 +220,8 @@ function test_verify_pre_checkpoint_state
 {
        log_must zfs list $FS0
        log_must zfs list $FS1
-       log_must [ "$(cat $FS0FILE)" = "$FILECONTENTS0" ]
-       log_must [ "$(cat $FS1FILE)" = "$FILECONTENTS1" ]
+       log_must [ "$(<$FS0FILE)" = "$FILECONTENTS0" ]
+       log_must [ "$(<$FS1FILE)" = "$FILECONTENTS1" ]
 
        #
        # If we've opened the checkpointed state of the
@@ -236,15 +236,15 @@ function test_verify_pre_checkpoint_state
        # Ensure post-checkpoint state is not present
        #
        log_mustnot zfs list $FS2
-       log_mustnot [ "$(cat $FS0FILE)" = "$NEWFILECONTENTS0" ]
+       log_mustnot [ "$(<$FS0FILE)" = "$NEWFILECONTENTS0" ]
 }
 
 function nested_verify_pre_checkpoint_state
 {
        log_must zfs list $NESTEDFS0
        log_must zfs list $NESTEDFS1
-       log_must [ "$(cat $NESTEDFS0FILE)" = "$FILECONTENTS0" ]
-       log_must [ "$(cat $NESTEDFS1FILE)" = "$FILECONTENTS1" ]
+       log_must [ "$(<$NESTEDFS0FILE)" = "$FILECONTENTS0" ]
+       log_must [ "$(<$NESTEDFS1FILE)" = "$FILECONTENTS1" ]
 
        #
        # If we've opened the checkpointed state of the
@@ -259,7 +259,7 @@ function nested_verify_pre_checkpoint_state
        # Ensure post-checkpoint state is not present
        #
        log_mustnot zfs list $NESTEDFS2
-       log_mustnot [ "$(cat $NESTEDFS0FILE)" = "$NEWFILECONTENTS0" ]
+       log_mustnot [ "$(<$NESTEDFS0FILE)" = "$NEWFILECONTENTS0" ]
 }
 
 function test_change_state_after_checkpoint
@@ -284,8 +284,8 @@ function test_verify_post_checkpoint_state
 {
        log_must zfs list $FS0
        log_must zfs list $FS2
-       log_must [ "$(cat $FS0FILE)" = "$NEWFILECONTENTS0" ]
-       log_must [ "$(cat $FS2FILE)" = "$NEWFILECONTENTS2" ]
+       log_must [ "$(<$FS0FILE)" = "$NEWFILECONTENTS0" ]
+       log_must [ "$(<$FS2FILE)" = "$NEWFILECONTENTS2" ]
 
        log_must zdb $TESTPOOL
 
@@ -294,7 +294,7 @@ function test_verify_post_checkpoint_state
        # is not present
        #
        log_mustnot zfs list $FS1
-       log_mustnot [ "$(cat $FS0FILE)" = "$FILECONTENTS0" ]
+       log_mustnot [ "$(<$FS0FILE)" = "$FILECONTENTS0" ]
 }
 
 function fragment_before_checkpoint
index 0ef27460454c7ccfa5268685469334c988012474..45a6a0f762c7d5da44772b710688910eff33ba1f 100755 (executable)
@@ -37,10 +37,10 @@ fi
 
 verify_runnable "global"
 
-ZFS_USER=$(cat $TEST_BASE_DIR/zfs-privs-test-user.txt)
+ZFS_USER=$(<$TEST_BASE_DIR/zfs-privs-test-user.txt)
 [[ -z $ZFS_USER ]] && log_fail "no ZFS_USER found"
 
-USES_NIS=$(cat $TEST_BASE_DIR/zfs-privs-test-nis.txt)
+USES_NIS=$(<$TEST_BASE_DIR/zfs-privs-test-nis.txt)
 
 if [ "${USES_NIS}" == "true" ]
 then
index 672bb8848633115016216b7478481ac63d2c0f53..ae869380d061ffeaba495baf503556095ca52082 100755 (executable)
@@ -63,7 +63,7 @@ fi
 
 log_assert "The RBAC profile \"ZFS Storage Management\" works"
 
-ZFS_USER=$(cat $TEST_BASE_DIR/zfs-privs-test-user.txt)
+ZFS_USER=$(<$TEST_BASE_DIR/zfs-privs-test-user.txt)
 
 # the user shouldn't be able to do anything initially
 log_mustnot user_run $ZFS_USER "zpool create $TESTPOOL $DISKS"
index da8e33ce7e804b45e58d7b81b6f2ee3e42014add..22cfaf55d739f0940774b0960c5463dab15bfdfa 100755 (executable)
@@ -66,7 +66,7 @@ fi
 
 log_assert "The RBAC profile \"ZFS File System Management\" works"
 
-ZFS_USER=$(cat $TEST_BASE_DIR/zfs-privs-test-user.txt)
+ZFS_USER=$(<$TEST_BASE_DIR/zfs-privs-test-user.txt)
 
 # Set a $DATASET where we can create child files systems
 if is_global_zone; then
index 3c29266e5d9d58c0fc2a4be3ca998a81a4c159ca..a3afe0c429deef02003c6f4d4062969b2b69c0c4 100755 (executable)
@@ -86,7 +86,7 @@ function check_all
 
        state1=$(zpool status $pool | awk '/state: /{print $2}');
        state2=$(zpool list -H -o health $pool)
-       state3=$(cat /proc/spl/kstat/zfs/$pool/state)
+       state3=$(</proc/spl/kstat/zfs/$pool/state)
        log_note "Checking $expected = $state1 = $state2 = $state3"
        if [[ "$expected" == "$state1" &&  "$expected" == "$state2" && \
            "$expected" == "$state3" ]] ; then
index c363e7f8b175c10af0fa58ed11ce1fc72504df65..95a5e5c1ebc641948b89aa98a37cdb5f14266125 100755 (executable)
@@ -86,7 +86,7 @@ typeset default_max_entries
 
 log_onexit cleanup
 
-default_max_entries=$(cat $MAX_ENTRIES_PARAM) || log_fail
+default_max_entries=$(<$MAX_ENTRIES_PARAM) || log_fail
 echo 50 >$MAX_ENTRIES_PARAM || log_fail
 
 # Clear all of the existing entries.
index 1f71ec0e45b244a50ee992f3c19b51784f8fd058..97b67a46262cd78ab1f5def2266d8bde1229274b 100755 (executable)
@@ -67,8 +67,8 @@ log_onexit cleanup
 log_must set_tunable32 zfs_remove_max_segment 32768
 
 log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=128k count=1
-FILE_CONTENTS=`cat $TESTDIR/$TESTFILE0`
-log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+FILE_CONTENTS=$(<$TESTDIR/$TESTFILE0)
+log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 
 for i in {1..10}; do
        log_must zpool remove $TESTPOOL $TMPDIR/dsk1
@@ -78,7 +78,7 @@ for i in {1..10}; do
 
        log_must zinject -a
        log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null
-       log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+       log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 
        log_must zpool remove $TESTPOOL $TMPDIR/dsk2
        log_must wait_for_removal $TESTPOOL
@@ -87,7 +87,7 @@ for i in {1..10}; do
 
        log_must zinject -a
        log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null
-       log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+       log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 done
 
 log_pass "File contents transferred completely from one disk to another."
index f7f69c7d262f3415be63c237a7f76718b6ec1868..e927e3c0e25b86f819fb2a71ff30c4e0168a8224 100755 (executable)
@@ -27,13 +27,13 @@ log_onexit default_cleanup_noexit
 FILE_CONTENTS="Leeloo Dallas mul-ti-pass."
 
 echo $FILE_CONTENTS  >$TESTDIR/$TESTFILE0
-log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 
 log_must zpool remove $TESTPOOL $REMOVEDISK
 log_must wait_for_removal $TESTPOOL
 log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK
 
 log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null
-log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 
 log_pass "Removed device not in use after removal."
index 4b6c94a80193b80dea269183ac7f80d2b37cd374..ac79b7c17268ea2b208d3c5708910e0ca4e88461 100755 (executable)
@@ -31,9 +31,9 @@ FILE_CONTENTS="Leeloo Dallas mul-ti-pass."
 echo $FILE_CONTENTS  >$TESTDIR/$TESTFILE0
 echo $FILE_CONTENTS  >$TESTDIR/$TESTFILE1
 echo $FILE_CONTENTS  >$TESTDIR/$TESTFILE2
-log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
-log_must [ "x$(cat $TESTDIR/$TESTFILE1)" = "x$FILE_CONTENTS" ]
-log_must [ "x$(cat $TESTDIR/$TESTFILE2)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE1)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE2)" = "x$FILE_CONTENTS" ]
 
 log_must zpool remove $TESTPOOL $REMOVEDISK
 log_must wait_for_removal $TESTPOOL
@@ -42,8 +42,8 @@ log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK
 log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null
 log_must dd if=/$TESTDIR/$TESTFILE1 of=/dev/null
 log_must dd if=/$TESTDIR/$TESTFILE2 of=/dev/null
-log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
-log_must [ "x$(cat $TESTDIR/$TESTFILE1)" = "x$FILE_CONTENTS" ]
-log_must [ "x$(cat $TESTDIR/$TESTFILE2)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE1)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE2)" = "x$FILE_CONTENTS" ]
 
 log_pass "Removed device not in use after removal."
index 0cb22e3e1ac24d75b3cc1ef9a31506d931bb9a19..35c90e6a56b27863fc19887fbd8946ed1a30fcbe 100755 (executable)
@@ -34,7 +34,7 @@ log_onexit cleanup
 FILE_CONTENTS="Leeloo Dallas mul-ti-pass."
 
 echo $FILE_CONTENTS  >$TESTDIR/$TESTFILE0
-log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 log_must file_write -o create -f $TESTDIR/$TESTFILE1 -b $((2**20)) -c $((2**7))
 
 log_must zpool remove $TESTPOOL $REMOVEDISK
@@ -42,6 +42,6 @@ log_must wait_for_removal $TESTPOOL
 log_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK
 
 log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null
-log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 
 log_pass "Removed device not in use after removal."
index fa3fb5de78529c68059a1e240d66705dd85e2308..4473771521ba0d77ed4199527dbcbf0ed782a698 100755 (executable)
@@ -39,7 +39,7 @@ elif [[ -f $WORDS_FILE2 ]]; then
     log_must cp $WORDS_FILE2 $TESTDIR
 else
     echo $FILE_CONTENTS  >$TESTDIR/$TESTFILE0
-    log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+    log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 fi
 
 log_must zpool remove $TESTPOOL mirror-1
@@ -52,7 +52,7 @@ elif [[ -f $WORDS_FILE2 ]]; then
     log_must diff $WORDS_FILE2 $TESTDIR/words
 else
     log_must dd if=/$TESTDIR/$TESTFILE0 of=/dev/null
-    log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
+    log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
 fi
 
 log_pass "Removed top-level mirror device not in use after removal."
index c851ee32df7d03d05ed6022d837aa52f0426bce9..3802c6aec70f576a18363b64c8e806c4ac7e1262 100644 (file)
@@ -416,7 +416,7 @@ function get_system_config
                        then
                                printf ",\n" >>$config
                        fi
-                       printf  "    \"$tunable\": \"$(cat $zfs_tunables/$tunable)\"" \
+                       printf  "    \"$tunable\": \"$(<$zfs_tunables/$tunable)\"" \
                            >>$config
                done
                printf "\n  }\n" >>$config