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. $STF_SUITE/tests/functional/cli_root/zpool_events/zpool_events.kshlib
19
20#
21# DESCRIPTION:
22# 'zpool events poolname' should only display events from the chosen pool.
23#
24# STRATEGY:
25# 1. Create an additional pool
26# 2. Clear all ZFS events
27# 3. Generate some ZFS events on both pools
28# 4. Verify 'zpool events poolname' successfully display events
29#
30
31verify_runnable "both"
32
33function cleanup
34{
35	destroy_pool $NEWPOOL
36	rm -f $DISK
37}
38
39log_assert "'zpool events poolname' should only display events from poolname."
40log_onexit cleanup
41
42NEWPOOL="newpool"
43DISK="$TEST_BASE_DIR/$NEWPOOL.dat"
44
45# 1. Create an additional pool
46log_must truncate -s $MINVDEVSIZE $DISK
47log_must zpool create $NEWPOOL $DISK
48
49# 2. Clear all ZFS events
50log_must zpool events -c
51
52# 3. Generate some ZFS events on both pools
53for i in {1..$EVENTS_NUM}; do
54	log_must zpool clear $TESTPOOL
55	log_must zpool clear $NEWPOOL
56done
57# wait a bit to allow the kernel module to process new events
58zpool_events_settle
59
60# 4. Verify 'zpool events poolname' successfully display events
61zpool events -v $TESTPOOL |
62   awk -v POOL=$TESTPOOL '/pool = / && $3 != "\""POOL"\"" {exit 1}' ||
63	log_fail "Unexpected events for pools other than $TESTPOOL"
64
65zpool events -v $NEWPOOL |
66   awk -v POOL=$NEWPOOL '/pool = / && $3 != "\""POOL"\"" {exit 1}' ||
67	log_fail "Unexpected events for pools other than $NEWPOOL"
68
69log_pass "'zpool events poolname' display events only from the chosen pool."
70