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