3 # $NetBSD: h_funcs.subr,v 1.5 2006/11/09 16:20:06 jmmv Exp $
5 # Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Julio M. Merino Vidal, developed as part of Google's Summer of Code
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions
15 # 1. Redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer.
17 # 2. Redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution.
21 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
37 # Helper functions for tests written in shell script.
46 # -------------------------------------------------------------------------
50 # Called by tests when a command fails unexpectedly. Terminates
51 # execution and tries to clean up the mount point.
54 if [ -d ${Work_Dir} ]; then
59 [ ${Verbose} -eq 2 ] && err "Test ended unexpectedly"
60 [ ${Verbose} -eq 1 ] && echo " failed."
64 # -------------------------------------------------------------------------
68 # Shows the given error message and terminates the program.
71 echo "${Prog_Name}: $*" 1>&2
75 # -------------------------------------------------------------------------
79 # Mounts tmpfs over ${Work_Dir} and changes the current directory
80 # to the mount point. Optional arguments may be passed to the
84 mkdir ${Work_Dir} || die
86 mount -t tmpfs "$@" tmpfs ${Work_Dir} || die
88 mount -t tmpfs tmpfs ${Work_Dir} || die
93 # -------------------------------------------------------------------------
97 # Prints a message about what a test is going to do.
100 [ ${Verbose} -gt 1 ] && echo " $*..."
103 # -------------------------------------------------------------------------
107 # Unmounts the file system mounted by test_mount.
111 umount ${Work_Dir} || die
112 rmdir ${Work_Dir} || die
115 # -------------------------------------------------------------------------
117 # kqueue_monitor expected_nevents file1 [.. fileN]
119 # Monitors the commands given through stdin (one per line) using
120 # kqueue and stores the events raised in a log that can be later
121 # verified with kqueue_check.
125 test_name "Running kqueue-monitored commands and expecting" \
127 ${Src_Dir}/h_tools kqueue ${*} >kqueue.log || return 1
128 got=$(wc -l kqueue.log | awk '{ print $1 }')
129 test ${got} -eq ${nev}
132 # -------------------------------------------------------------------------
134 # kqueue_check file event
136 # Checks if kqueue raised the given event when monitoring the
140 grep "^${1} - ${2}$" kqueue.log >/dev/null
143 # -------------------------------------------------------------------------
148 [ $(id -un) = root ] || err "Must be run as root"
150 args=$(getopt u:v:w: $*)
151 if [ $? -ne 0 ]; then
152 echo "Usage: ${Prog_Name} [-u unprived_user] [-v level] " \
157 while [ $# -gt 0 ]; do
160 Unprived_User="$2"; shift
175 [ ${Verbose} -eq 1 ] && echo -n "${Prog_Name}:"
176 [ ${Verbose} -eq 2 ] && echo "${Prog_Name}: Running tests"
178 [ ${Verbose} -eq 1 ] && echo " ok."
179 [ ${Verbose} -eq 2 ] && echo "${Prog_Name}: All tests were successful"