1#
2# This file and its contents are supplied under the terms of the
3# Common Development and Distribution License ("CDDL"), version 1.0.
4# You may only use this file in accordance with the terms of version
5# 1.0 of the CDDL.
6#
7# A full copy of the text of the CDDL should have accompanied this
8# source.  A copy of the CDDL is also available via the Internet at
9# http://www.illumos.org/license/CDDL.
10#
11
12#
13# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
14#
15
16. $STF_SUITE/include/libtest.shlib
17. $STF_SUITE/tests/functional/cli_root/zpool_events/zpool_events.cfg
18
19#
20# Wait to allow the kernel module to process ZFS events until we reach $eventnum
21# or a timeout of $timeout seconds expire, whichever comes first
22#
23function zpool_events_settle # <eventnum> [timeout]
24{
25	typeset eventnum="${1:-$EVENTS_NUM}"
26	typeset timeout="${2:-3}"
27	typeset -i count
28	typeset -i i=0
29
30	while [[ $i -lt $timeout ]]; do
31		count=$(zpool events -H | wc -l)
32		if [[ $count -ge $eventnum ]]; then
33			break
34		fi
35		i=$((i+1))
36		sleep 1
37	done
38	log_note "waited $i seconds"
39}
40