1*dd50e0ccSTony Hutter# 2*dd50e0ccSTony Hutter# Common functions used by the zpool_status and zpool_iostat tests for running 3*dd50e0ccSTony Hutter# scripts with the -c option. 4*dd50e0ccSTony Hutter# 5*dd50e0ccSTony Hutter# Copyright (c) 2017 Lawrence Livermore National Security, LLC. 6*dd50e0ccSTony Hutter# 7*dd50e0ccSTony Hutter 8*dd50e0ccSTony Hutter. $STF_SUITE/include/libtest.shlib 9*dd50e0ccSTony Hutter 10*dd50e0ccSTony Hutterfunction test_zpool_script { 11*dd50e0ccSTony Hutter script="$1" 12*dd50e0ccSTony Hutter testpool="$2" 13*dd50e0ccSTony Hutter cmd="$3" 14*dd50e0ccSTony Hutter wholecmd="$cmd $script $testpool" 15*dd50e0ccSTony Hutter out="$($wholecmd)" 16*dd50e0ccSTony Hutter 17*dd50e0ccSTony Hutter # Default number of columns that get printed without -c 18*dd50e0ccSTony Hutter if echo "$cmd" | grep -q iostat ; then 19*dd50e0ccSTony Hutter # iostat 20*dd50e0ccSTony Hutter dcols=7 21*dd50e0ccSTony Hutter else 22*dd50e0ccSTony Hutter 23*dd50e0ccSTony Hutter # status 24*dd50e0ccSTony Hutter dcols=5 25*dd50e0ccSTony Hutter fi 26*dd50e0ccSTony Hutter 27*dd50e0ccSTony Hutter # Get the new column name that the script created 28*dd50e0ccSTony Hutter col="$(echo "$out" | \ 29*dd50e0ccSTony Hutter awk '/^pool +alloc +free +read +write +/ {print $8} \ 30*dd50e0ccSTony Hutter /NAME +STATE +READ +WRITE +CKSUM/ {print $6}')" 31*dd50e0ccSTony Hutter 32*dd50e0ccSTony Hutter if [ -z "$col" ] ; then 33*dd50e0ccSTony Hutter log_fail "'$wholecmd' created no new columns" 34*dd50e0ccSTony Hutter fi 35*dd50e0ccSTony Hutter 36*dd50e0ccSTony Hutter # Count the number of columns for each vdev. Each script should produce 37*dd50e0ccSTony Hutter # at least one new column value. Even if scripts return blank, zpool 38*dd50e0ccSTony Hutter # will convert the blank to a '-' to make things awk-able. Normal 39*dd50e0ccSTony Hutter # zpool iostat -v output is 7 columns, so if the script ran correctly 40*dd50e0ccSTony Hutter # we should see more than that. 41*dd50e0ccSTony Hutter if ! newcols=$(echo "$out" | \ 42*dd50e0ccSTony Hutter awk '/\/dev/{print NF-'$dcols'; if (NF <= '$dcols') {exit 1}}' | \ 43*dd50e0ccSTony Hutter head -n 1) ; \ 44*dd50e0ccSTony Hutter then 45*dd50e0ccSTony Hutter log_fail "'$wholecmd' didn't create a new column value" 46*dd50e0ccSTony Hutter else 47*dd50e0ccSTony Hutter log_note "'$wholecmd' passed ($newcols new columns)" 48*dd50e0ccSTony Hutter fi 49*dd50e0ccSTony Hutter} 50