diff --git a/tests/test-runner/bin/test-runner.py.in b/tests/test-runner/bin/test-runner.py.in index 5c868d945a..cb453b266f 100755 --- a/tests/test-runner/bin/test-runner.py.in +++ b/tests/test-runner/bin/test-runner.py.in @@ -291,7 +291,7 @@ User: %s self.result.starttime = monotonic_time() if kmemleak: - cmd = f'echo clear | {SUDO} tee {KMEMLEAK_FILE}' + cmd = f'{SUDO} sh -c "echo clear > {KMEMLEAK_FILE}"' check_output(cmd, shell=True) proc = Popen(privcmd, stdout=PIPE, stderr=PIPE) @@ -305,7 +305,7 @@ User: %s self.result.stdout, self.result.stderr = self.collect_output(proc) if kmemleak: - cmd = f'echo scan | {SUDO} tee {KMEMLEAK_FILE}' + cmd = f'{SUDO} sh -c "echo scan > {KMEMLEAK_FILE}"' check_output(cmd, shell=True) cmd = f'{SUDO} cat {KMEMLEAK_FILE}' self.result.kmemleak = check_output(cmd, shell=True) @@ -880,7 +880,7 @@ class TestRun(object): self.outputdir, LOG_ERR) if options.kmemleak: - cmd = f'echo scan=0 | {SUDO} tee {KMEMLEAK_FILE}' + cmd = f'{SUDO} -c "echo scan=0 > {KMEMLEAK_FILE}"' check_output(cmd, shell=True) iteration = 0 diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index fcde48adc6..0951f719b9 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -8,9 +8,7 @@ # Please keep the contents of each variable sorted for ease of reading # and maintenance. # -export SYSTEM_FILES_COMMON='arp - awk - base64 +export SYSTEM_FILES_COMMON='awk basename bc bunzip2 @@ -52,10 +50,10 @@ export SYSTEM_FILES_COMMON='arp ksh ldd ln - logname ls mkdir mknod + mkfifo mktemp mount mv @@ -67,12 +65,9 @@ export SYSTEM_FILES_COMMON='arp pgrep ping pkill - printenv printf ps - pwd python3 - quotaon readlink rm rmdir @@ -88,32 +83,26 @@ export SYSTEM_FILES_COMMON='arp ssh stat strings - su sudo swapoff swapon sync tail tar - tee timeout touch tr true truncate - umask umount uname uniq - uuidgen vmstat - wait wc' export SYSTEM_FILES_FREEBSD='chflags compress diskinfo - dumpon fsck getextattr gpart @@ -123,7 +112,6 @@ export SYSTEM_FILES_FREEBSD='chflags lsextattr md5 mdconfig - mkfifo newfs pw rmextattr @@ -135,14 +123,11 @@ export SYSTEM_FILES_FREEBSD='chflags uncompress' export SYSTEM_FILES_LINUX='attr - bash blkid blockdev chattr - dmidecode exportfs fallocate - fdisk free getfattr groupadd @@ -159,16 +144,17 @@ export SYSTEM_FILES_LINUX='attr mkswap modprobe mpstat - nproc parted perf - setenforce setfattr sha256sum udevadm useradd userdel - usermod' + usermod + + flock + logger' export ZFS_FILES='zdb zfs diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 88390456a1..5f0f2d56ac 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -2970,59 +2970,6 @@ function get_device_state #pool disk field("", "spares","logs") ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}' } -# -# Given a disk, label it to VTOC regardless what label was on the disk -# $1 disk -# -function labelvtoc -{ - typeset disk=$1 - if [[ -z $disk ]]; then - log_fail "The disk name is unspecified." - fi - typeset label_file=/var/tmp/labelvtoc.$$ - typeset arch=$(uname -p) - - if is_linux || is_freebsd; then - log_note "Currently unsupported by the test framework" - return 1 - fi - - if [[ $arch == "i386" ]]; then - echo "label" > $label_file - echo "0" >> $label_file - echo "" >> $label_file - echo "q" >> $label_file - echo "q" >> $label_file - - fdisk -B $disk >/dev/null 2>&1 - # wait a while for fdisk finishes - sleep 60 - elif [[ $arch == "sparc" ]]; then - echo "label" > $label_file - echo "0" >> $label_file - echo "" >> $label_file - echo "" >> $label_file - echo "" >> $label_file - echo "q" >> $label_file - else - log_fail "unknown arch type" - fi - - format -e -s -d $disk -f $label_file - typeset -i ret_val=$? - rm -f $label_file - # - # wait the format to finish - # - sleep 60 - if ((ret_val != 0)); then - log_fail "unable to label $disk as VTOC." - fi - - return 0 -} - # # get the root filesystem name if it's zfsroot system. # @@ -3077,22 +3024,19 @@ function verify_disk_count function ds_is_volume { typeset type=$(get_prop type $1) - [[ $type = "volume" ]] && return 0 - return 1 + [ $type = "volume" ] } function ds_is_filesystem { typeset type=$(get_prop type $1) - [[ $type = "filesystem" ]] && return 0 - return 1 + [ $type = "filesystem" ] } function ds_is_snapshot { typeset type=$(get_prop type $1) - [[ $type = "snapshot" ]] && return 0 - return 1 + [ $type = "snapshot" ] } # @@ -3108,7 +3052,7 @@ function is_mp { case $(uname) in Linux) - (($(nproc) > 1)) + (($(grep -c '^processor' /proc/cpuinfo) > 1)) ;; FreeBSD) sysctl -n kern.smp.cpus diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_block_size_histogram.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_block_size_histogram.ksh index 75f15f6a88..9a960cecc3 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_block_size_histogram.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_block_size_histogram.ksh @@ -145,7 +145,6 @@ function histo_check_test_pool typeset -i this_rs typeset -i this_ri typeset -i sum_filesizes=0 - typeset dumped typeset stripped let histo_check_pool_size=$(get_pool_prop size ${pool}) @@ -157,11 +156,9 @@ function histo_check_test_pool log_fail "hctp: max_pool_record_size is not numeric ${max_pool_record_size}" fi - dumped="${TEST_BASE_DIR}/${pool}_dump.txt" stripped="${TEST_BASE_DIR}/${pool}_stripped.txt" zdb -Pbbb ${pool} | \ - tee ${dumped} | \ sed -e '1,/^block[ ][ ]*psize[ ][ ]*lsize.*$/d' \ -e '/^size[ ]*Count/d' -e '/^$/,$d' \ > ${stripped} diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_types.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_types.ksh index 51f0295cd3..07b14e7aec 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_types.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_types.ksh @@ -111,11 +111,7 @@ verify_object_class "$MNTPOINT/cdev" "C" # 2. | (Named pipe) log_must zfs snapshot "$TESTSNAP1" -if is_freebsd; then - log_must mkfifo "$MNTPOINT/fifo" -else - log_must mknod "$MNTPOINT/fifo" p -fi +log_must mkfifo "$MNTPOINT/fifo" log_must zfs snapshot "$TESTSNAP2" verify_object_class "$MNTPOINT/fifo" "|" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_024_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_024_pos.ksh index 5b464c3c24..98d2ee543b 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_024_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_024_pos.ksh @@ -74,7 +74,7 @@ child_pools="" function zpool_stress { - typeset pool=$1 + typeset pool="$1-$$" typeset vdev0="$TEST_BASE_DIR/$pool-vdev0.img" typeset vdev1="$TEST_BASE_DIR/$pool-vdev1.img" typeset -i iters=$2 @@ -118,13 +118,11 @@ function zpool_stress # 1. Create 128 process each of which create/destroy a pool 5 times. typeset i=0 while [[ $i -lt 128 ]]; do - typeset uuid=$(uuidgen | cut -c1-13) - - zpool_stress $TESTPOOL-$uuid 5 & + zpool_stress $TESTPOOL-$i 5 & typeset pid=$! child_pids="$child_pids $pid" - child_pools="$child_pools $TESTPOOL-$uuid" + child_pools="$child_pools $TESTPOOL-$i-$pid" ((i = i + 1)) done diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg.ksh index 56a74e4ae4..ce474657b4 100755 --- a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg.ksh @@ -44,22 +44,15 @@ # # -# check to see if we have zfs allow -zfs 2>&1 | grep "allow" > /dev/null -if (($? != 0)) then - log_unsupported "ZFS allow not supported on this machine." -fi - log_assert "zfs allow returns an error when run as a user" log_must zfs allow $TESTPOOL/$TESTFS -log_mustnot zfs allow $(logname) create $TESTPOOL/$TESTFS +log_mustnot zfs allow $(id -un) create $TESTPOOL/$TESTFS # now verify that the above command actually did nothing by # checking for any allow output. ( if no allows are granted, # nothing should be output ) -OUTPUT=$(zfs allow $TESTPOOL/$TESTFS | grep "Local+Descendent" ) -if [ -n "$OUTPUT" ] +if zfs allow $TESTPOOL/$TESTFS | grep -q "Local+Descendent" then log_fail "zfs allow permissions were granted on $TESTPOOL/$TESTFS" fi diff --git a/tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh b/tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh index 3e138cfc9f..208ecfeed3 100755 --- a/tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh @@ -58,7 +58,7 @@ BATCH=1000 log_must mkdir $TESTDIR/src log_must mkdir $TESTDIR/dst -WD=$(pwd) +WD=$PWD cd $TESTDIR/src # create NR_FILES in BATCH at a time to prevent overflowing argument buffer for i in $(seq $(($NR_FILES/$BATCH))); do touch $(seq $((($i-1)*$BATCH+1)) $(($i*$BATCH))); done diff --git a/tests/zfs-tests/tests/functional/mmp/mmp.kshlib b/tests/zfs-tests/tests/functional/mmp/mmp.kshlib index 7ff2636e1f..636d2fa686 100644 --- a/tests/zfs-tests/tests/functional/mmp/mmp.kshlib +++ b/tests/zfs-tests/tests/functional/mmp/mmp.kshlib @@ -69,8 +69,6 @@ function try_pool_import # pool opts message typeset msg=$3 zpool import $opts $pool 2>&1 | grep -i "$msg" - - return $? } function mmp_set_hostid @@ -79,11 +77,7 @@ function mmp_set_hostid zgenhostid $1 - if [ $(hostid) != "$hostid" ]; then - return 1 - fi - - return 0 + [ $(hostid) = "$hostid" ] } function mmp_clear_hostid diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh index ba27d043b7..852bffc7a1 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh @@ -59,8 +59,8 @@ create_xattr $testfile passwd /etc/passwd log_must chmod 000 $testfile if is_illumos; then - log_mustnot su $ZFS_USER -c "runat $testfile cat passwd" - log_mustnot su $ZFS_USER -c "runat $testfile cp /etc/passwd ." + log_mustnot user_run $ZFS_USER runat $testfile cat passwd + log_mustnot user_run $ZFS_USER runat $testfile cp /etc/passwd . else log_mustnot user_run $ZFS_USER " . $STF_SUITE/include/libtest.shlib diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh index 43502bfff2..41c7054f23 100755 --- a/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh +++ b/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh @@ -61,6 +61,6 @@ log_mustnot runat $TESTDIR/myfile.$$ mknod block b 888 888 log_mustnot runat $TESTDIR/myfile.$$ mknod char c -log_mustnot runat $TESTDIR/myfile.$$ mknod fifo p +log_mustnot runat $TESTDIR/myfile.$$ mkfifo fifo log_pass "mkdir, mknod fail" diff --git a/tests/zfs-tests/tests/perf/perf.shlib b/tests/zfs-tests/tests/perf/perf.shlib index 27f56676db..c9b4505e23 100644 --- a/tests/zfs-tests/tests/perf/perf.shlib +++ b/tests/zfs-tests/tests/perf/perf.shlib @@ -254,7 +254,7 @@ function do_collect_scripts # Find a place to deposit performance data collected while under load. function get_perf_output_dir { - typeset dir="$(pwd)/perf_data" + typeset dir="$PWD/perf_data" [[ -d $dir ]] || mkdir -p $dir echo $dir @@ -467,7 +467,7 @@ function get_system_config echo "{" >>$config if is_linux; then - echo " \"ncpus\": \"$(nproc --all)\"," >>$config + echo " \"ncpus\": \"$(lscpu | awk '/^CPU\(s\)/ {print $2; exit}')\"," >>$config echo " \"physmem\": \"$(free -b | \ awk '$1 == "Mem:" { print $2 }')\"," >>$config echo " \"c_max\": \"$(get_max_arc_size)\"," >>$config diff --git a/tests/zfs-tests/tests/perf/scripts/prefetch_io.sh b/tests/zfs-tests/tests/perf/scripts/prefetch_io.sh index 07688ef21b..bc2bb11aef 100755 --- a/tests/zfs-tests/tests/perf/scripts/prefetch_io.sh +++ b/tests/zfs-tests/tests/perf/scripts/prefetch_io.sh @@ -1,5 +1,4 @@ -#!/usr/bin/env bash -# shellcheck disable=SC1004 +#!/bin/sh # # This file and its contents are supplied under the terms of the @@ -21,33 +20,12 @@ # TBD if we can add additional kstats to achieve the desired results # -zfs_kstats="/proc/spl/kstat/zfs" - -function get_prefetch_ios -{ - typeset -l data_misses="$(awk '$1 == "prefetch_data_misses" \ - { print $3; exit }' "$zfs_kstats/arcstats")" - typeset -l metadata_misses="$(awk '$1 == "prefetch_metadata_misses" \ - { print $3; exit }' "$zfs_kstats/arcstats")" - typeset -l total_misses=$(( data_misses + metadata_misses )) - - echo "$total_misses" +getstat() { + awk -v c="$1" '$1 == c {print $3; exit}' /proc/spl/kstat/zfs/arcstats } -function get_prefetched_demand_reads -{ - typeset -l demand_reads="$(awk '$1 == "demand_hit_predictive_prefetch" \ - { print $3; exit }' "$zfs_kstats/arcstats")" - - echo "$demand_reads" -} - -function get_async_upgrade_sync -{ - typeset -l sync_wait="$(awk '$1 == "async_upgrade_sync" \ - { print $3; exit }' "$zfs_kstats/arcstats")" - - echo "$sync_wait" +get_prefetch_ios() { + echo $(( $(getstat prefetch_data_misses) + $(getstat prefetch_metadata_misses) )) } if [ $# -ne 2 ] @@ -58,8 +36,8 @@ fi interval=$2 prefetch_ios=$(get_prefetch_ios) -prefetched_demand_reads=$(get_prefetched_demand_reads) -async_upgrade_sync=$(get_async_upgrade_sync) +prefetched_demand_reads=$(getstat demand_hit_predictive_prefetch) +async_upgrade_sync=$(getstat async_upgrade_sync) while true do @@ -68,12 +46,12 @@ do $(( new_prefetch_ios - prefetch_ios )) prefetch_ios=$new_prefetch_ios - new_prefetched_demand_reads=$(get_prefetched_demand_reads) + new_prefetched_demand_reads=$(getstat demand_hit_predictive_prefetch) printf '%-24s\t%u\n' "prefetched_demand_reads" \ $(( new_prefetched_demand_reads - prefetched_demand_reads )) prefetched_demand_reads=$new_prefetched_demand_reads - new_async_upgrade_sync=$(get_async_upgrade_sync) + new_async_upgrade_sync=$(getstat async_upgrade_sync) printf '%-24s\t%u\n' "async_upgrade_sync" \ $(( new_async_upgrade_sync - async_upgrade_sync )) async_upgrade_sync=$new_async_upgrade_sync