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 -c' should successfully clear events.
23#
24# STRATEGY:
25# 1. Clear all ZFS events
26# 2. Generate some new ZFS events
27# 3. Verify 'zpool events -c' successfully clears new events
28#
29
30verify_runnable "both"
31
32log_assert "'zpool events -c' should successfully clear events."
33
34# 1. Clear all ZFS events
35# This is needed because we may already over the max number or events queued
36# (zfs_zevent_len_max) generated by previous tests: generating $EVENTS_NUM new
37# events and then counting them is racy and leads to failures, so start from 0.
38log_must zpool events -c
39
40# 2. Generate some new ZFS events
41for i in `seq 1 $EVENTS_NUM`; do
42	log_must zpool clear $TESTPOOL
43done
44# wait a bit to allow the kernel module to process new events
45zpool_events_settle
46EVENTS_NUM=$(zpool events -H | wc -l)
47EVENTS_NUM=${EVENTS_NUM##* }
48
49# 3. Verify 'zpool events -c' successfully clear new events
50CLEAR_OUTPUT=$(zpool events -c)
51if [[ "$CLEAR_OUTPUT" != "cleared $EVENTS_NUM events" ]]; then
52	log_fail "Failed to clear $EVENTS_NUM events: $CLEAR_OUTPUT"
53fi
54EVENTS_NUM=$(zpool events -H | wc -l)
55if [[ $EVENTS_NUM -ne 0 ]];  then
56	log_fail "Unexpected events number: $EVENTS_NUM != 0"
57fi
58
59log_pass "'zpool events -c' successfully clears events."
60