4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
24 # Use is subject to license terms.
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/events/events.cfg
30 function run_and_verify
35 while getopts "e:p:z:" opt; do
38 events[${#events[*]}+1]=$OPTARG
48 shift $(($OPTIND - 1))
50 pool=${pool:-$TESTPOOL}
51 zedlog=${zedlog:-$ZEDLET_DIR/zed.debug.log}
53 cmd=$(echo $fullcmd | awk '{print $1}')
54 subcmd=$(echo $fullcmd | awk '{print $2}')
56 # If we aren't running zpool or zfs, something is wrong
57 [[ $cmd == "zpool" || $cmd == "zfs" ]] || \
58 log_fail "run_and_verify called with \"$cmd ($fullcmd)\""
60 # Run the command as provided and collect the new events.
61 log_must zpool events -c
62 if [[ -f $zedlog ]]; then
63 cp -f $zedlog $zedlog.old
66 log_must eval "$fullcmd"
68 log_must zpool events > $TMP_EVENTS 2>/dev/null
69 log_must zpool events -v > $TMP_EVENTS_FULL 2>/dev/null
70 if [[ -f $zedlog ]]; then
71 sleep 5 # Brief delay for the ZED to handle the event.
72 diff $zedlog.old $zedlog | grep "^> " | sed 's/^> //g' \
76 # Verify all the expected events appear in the log.
77 for event in ${events[*]}; do
79 # Verify the event is in in the short output.
80 log_must grep -q "$event" $TMP_EVENTS
82 # Verify the event is in the verbose output with pool name.
83 log_must awk -v event="$event" \
84 'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
85 $TMP_EVENTS_FULL >$TMP_EVENT_FULL
86 log_must grep -q "pool = \"$pool\"" $TMP_EVENT_FULL
88 # Verify the event was received by the ZED and logged.
89 log_must awk -v event="$event" \
90 'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
91 $TMP_EVENTS_ZED >$TMP_EVENT_ZED
92 log_must grep -q "^ZEVENT_POOL=$pool" $TMP_EVENT_ZED
96 log_must rm -f $TMP_EVENTS $TMP_EVENTS_FULL $TMP_EVENT_FULL \
97 $TMP_EVENTS_ZED $TMP_EVENT_ZED $zedlog.old