1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15#
16
17. $STF_SUITE/include/libtest.shlib
18
19#
20# DESCRIPTION:
21# 'zpool events' should only work with supported options.
22#
23# STRATEGY:
24# 1. Verify every supported option is accepted
25# 2. Verify supported options raise an error with unsupported arguments
26# 3. Verify other unsupported options raise an error
27#
28
29verify_runnable "both"
30
31function log_must_follow # <command>
32{
33	typeset command="$1"
34
35	log_must eval "$command > /dev/null &"
36	pid=$!
37	sleep 3
38	kill $pid
39	if [[ $? -ne 0 ]]; then
40		log_fail "'$command' exited early."
41	else
42		log_note "'$command' works successfully."
43	fi
44}
45
46log_assert "'zpool events' should only work with supported options."
47
48typeset goodopts=("" "-v" "-H" "-f" "-vH" "-vf" "-Hf" "-vHf")
49typeset badopts=("-vV" "-Hh" "-fF" "-cC" "-x" "-o" "-")
50
51# 1. Verify every supported option is accepted
52for opt in ${goodopts[@]}
53do
54	# when in 'follow' mode we can't use log_must()
55	if [[ $opt =~ 'f' ]]; then
56		log_must_follow "zpool events $opt"
57		log_must_follow "zpool events $opt $TESTPOOL"
58	else
59		log_must eval "zpool events $opt > /dev/null"
60		log_must eval "zpool events $opt $TESTPOOL > /dev/null"
61	fi
62done
63
64# 2.1 Verify supported options raise an error with unsupported arguments
65for opt in ${goodopts[@]}
66do
67	log_mustnot zpool events $opt "/tmp/"
68	log_mustnot zpool events $opt "$TESTPOOL/fs"
69	log_mustnot zpool events $opt "$TESTPOOL@snap"
70	log_mustnot zpool events $opt "$TESTPOOL#bm"
71	log_mustnot zpool events $opt "$TESTPOOL" "$TESTPOOL"
72done
73
74# 2.2 Additionally, 'zpool events -c' does not support any other option|argument
75log_must eval "zpool events -c > /dev/null"
76log_mustnot zpool events -c "$TESTPOOL"
77for opt in ${goodopts[@]}
78do
79	log_mustnot zpool events -c $opt
80done
81
82# 3. Verify other unsupported options raise an error
83for opt in ${badopts[@]}
84do
85	log_mustnot zpool events $opt
86	log_mustnot zpool events $opt "$TESTPOOL"
87done
88
89log_pass "'zpool events' only works with supported options."
90