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