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