]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_events/zpool_events_poolname.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_events / zpool_events_poolname.ksh
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
31 verify_runnable "both"
32
33 function cleanup
34 {
35         destroy_pool $NEWPOOL
36         rm -f $DISK
37 }
38
39 log_assert "'zpool events poolname' should only display events from poolname."
40 log_onexit cleanup
41
42 NEWPOOL="newpool"
43 DISK="$TEST_BASE_DIR/$NEWPOOL.dat"
44
45 # 1. Create an additional pool
46 log_must truncate -s $MINVDEVSIZE $DISK
47 log_must zpool create $NEWPOOL $DISK
48
49 # 2. Clear all ZFS events
50 log_must zpool events -c
51
52 # 3. Generate some ZFS events on both pools
53 for i in `seq 1 $EVENTS_NUM`; do
54         log_must zpool clear $TESTPOOL
55 done
56 for i in `seq 1 $EVENTS_NUM`; do
57         log_must zpool clear $NEWPOOL
58 done
59 # wait a bit to allow the kernel module to process new events
60 zpool_events_settle
61
62 # 4. Verify 'zpool events poolname' successfully display events
63 zpool events -v $TESTPOOL |
64    awk -v POOL=$TESTPOOL '/pool = / {if ($3 != "\""POOL"\"") exit 1}'
65 if [[ $? -ne 0 ]]; then
66         log_fail "Unexpected events for pools other than $TESTPOOL"
67 fi
68 zpool events -v $NEWPOOL |
69    awk -v POOL=$NEWPOOL '/pool = / {if ($3 != "\""POOL"\"") exit 1}'
70 if [[ $? -ne 0 ]]; then
71         log_fail "Unexpected events for pools other than $NEWPOOL"
72 fi
73
74 log_pass "'zpool events poolname' display events only from the chosen pool."