# # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2017 by Lawrence Livermore National Security, LLC. # Use is subject to license terms. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/events/events.cfg # # Wait for up to 'timeout' seconds for the 'file' to settle, i.e. # not be updated for a period of 'delay' seconds. # function file_wait # file delay timeout { file=$1 delay=${2:-3} timeout=${3:-120} SECONDS=0 while [ $(( $(date +%s) - $(stat -c %Y $file) )) -lt $delay ]; do if [[ $SECONDS -gt $timeout ]]; then return 1 fi sleep 1 done return 0; } function run_and_verify { typeset delay event pool zedlog set -A events while getopts "d:e:p:z:" opt; do case $opt in d) delay=$OPTARG ;; e) events[${#events[*]}+1]=$OPTARG ;; p) pool=$OPTARG ;; z) zedlog=$OPTARG ;; esac done shift $(($OPTIND - 1)) pool=${pool:-$TESTPOOL} delay=${delay:-3} zedlog=${zedlog:-$ZED_DEBUG_LOG} fullcmd="$1" cmd=$(echo $fullcmd | awk '{print $1}') # If we aren't running zpool or zfs, something is wrong [[ $cmd == "zpool" || $cmd == "zfs" ]] || \ log_fail "run_and_verify called with \"$cmd ($fullcmd)\"" log_note "Checking events for command: '$fullcmd'" # Remove any previous events from the logs. log_must zpool events -c log_must truncate -s 0 $zedlog # Run the command as provided. log_must eval "$fullcmd" # Collect the new events and verify there are some. log_must zpool sync -f log_must file_wait $zedlog $delay log_must cp $zedlog $TMP_EVENTS_ZED log_must eval "zpool events >$TMP_EVENTS 2>/dev/null" log_must eval "zpool events -v > $TMP_EVENTS_FULL 2>/dev/null" log_must test -s $TMP_EVENTS log_must test -s $TMP_EVENTS_FULL log_must test -s $TMP_EVENTS_ZED log_note "Events generated:" cat $TMP_EVENTS # Verify all the expected events appear in the log. for event in ${events[*]}; do # Verify the event is in in the short output. log_must grep -q "$event" $TMP_EVENTS # Verify the event is in the verbose output with pool name. awk -v event="$event" \ 'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \ $TMP_EVENTS_FULL >$TMP_EVENT_FULL log_must grep -q "pool = \"$pool\"" $TMP_EVENT_FULL # Verify the event was received by the ZED and logged. awk -v event="$event" \ 'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \ $TMP_EVENTS_ZED >$TMP_EVENT_ZED log_must grep -q "^ZEVENT_POOL=$pool" $TMP_EVENT_ZED done rm -f $TMP_EVENTS $TMP_EVENTS_FULL $TMP_EVENT_FULL \ $TMP_EVENTS_ZED $TMP_EVENT_ZED }