Home | History | Annotate | Line # | Download | only in tmpfs
h_funcs.subr revision 1.1.8.1
      1      1.1  jmmv #!/bin/sh
      2      1.1  jmmv #
      3  1.1.8.1  yamt # $NetBSD: h_funcs.subr,v 1.1.8.1 2008/05/18 12:36:01 yamt Exp $
      4      1.1  jmmv #
      5      1.1  jmmv # Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
      6      1.1  jmmv # All rights reserved.
      7      1.1  jmmv #
      8      1.1  jmmv # Redistribution and use in source and binary forms, with or without
      9      1.1  jmmv # modification, are permitted provided that the following conditions
     10      1.1  jmmv # are met:
     11      1.1  jmmv # 1. Redistributions of source code must retain the above copyright
     12      1.1  jmmv #    notice, this list of conditions and the following disclaimer.
     13      1.1  jmmv # 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  jmmv #    notice, this list of conditions and the following disclaimer in the
     15      1.1  jmmv #    documentation and/or other materials provided with the distribution.
     16      1.1  jmmv #
     17      1.1  jmmv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18      1.1  jmmv # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19      1.1  jmmv # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20      1.1  jmmv # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21      1.1  jmmv # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22      1.1  jmmv # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23      1.1  jmmv # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24      1.1  jmmv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25      1.1  jmmv # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26      1.1  jmmv # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27      1.1  jmmv # POSSIBILITY OF SUCH DAMAGE.
     28      1.1  jmmv #
     29      1.1  jmmv 
     30      1.1  jmmv Mount_Point=
     31      1.1  jmmv 
     32      1.1  jmmv #
     33      1.1  jmmv # test_mount [args]
     34      1.1  jmmv #
     35      1.1  jmmv #	Mounts tmpfs over ${Mount_Point} and changes the current directory
     36      1.1  jmmv #	to the mount point.  Optional arguments may be passed to the
     37      1.1  jmmv #	mount command.
     38      1.1  jmmv #
     39      1.1  jmmv test_mount() {
     40      1.1  jmmv 	require_fs tmpfs
     41      1.1  jmmv 
     42      1.1  jmmv 	Mount_Point=$(pwd)/mntpt
     43      1.1  jmmv 	atf_check "mkdir ${Mount_Point}" 0 null null
     44      1.1  jmmv 	if [ $# -gt 0 ]; then
     45      1.1  jmmv 		atf_check "mount -t tmpfs $* tmpfs ${Mount_Point}" \
     46      1.1  jmmv 		    0 null null
     47      1.1  jmmv 	else
     48      1.1  jmmv 		atf_check "mount -t tmpfs tmpfs ${Mount_Point}" \
     49      1.1  jmmv 		    0 null null
     50      1.1  jmmv 	fi
     51      1.1  jmmv 	cd ${Mount_Point}
     52      1.1  jmmv }
     53      1.1  jmmv 
     54      1.1  jmmv #
     55      1.1  jmmv # test_unmount
     56      1.1  jmmv #
     57      1.1  jmmv #	Unmounts the file system mounted by test_mount.
     58      1.1  jmmv #
     59      1.1  jmmv test_unmount() {
     60      1.1  jmmv 	cd - >/dev/null
     61      1.1  jmmv 	atf_check "umount ${Mount_Point}" 0 null null
     62      1.1  jmmv 	atf_check "rmdir ${Mount_Point}" 0 null null
     63      1.1  jmmv 	Mount_Point=
     64      1.1  jmmv }
     65      1.1  jmmv 
     66      1.1  jmmv #
     67      1.1  jmmv # kqueue_monitor expected_nevents file1 [.. fileN]
     68      1.1  jmmv #
     69      1.1  jmmv #	Monitors the commands given through stdin (one per line) using
     70      1.1  jmmv #	kqueue and stores the events raised in a log that can be later
     71      1.1  jmmv #	verified with kqueue_check.
     72      1.1  jmmv #
     73      1.1  jmmv kqueue_monitor() {
     74      1.1  jmmv 	nev=${1}; shift
     75      1.1  jmmv 	echo "Running kqueue-monitored commands and expecting" \
     76      1.1  jmmv 	    "${nev} events"
     77      1.1  jmmv 	$(atf_get_srcdir)/h_tools kqueue ${*} >kqueue.log || \
     78      1.1  jmmv 	    atf_fail "Could not launch kqueue monitor"
     79      1.1  jmmv 	got=$(wc -l kqueue.log | awk '{ print $1 }')
     80      1.1  jmmv 	test ${got} -eq ${nev} || \
     81      1.1  jmmv 	    atf_fail "Got ${got} events but expected ${nev}"
     82      1.1  jmmv }
     83      1.1  jmmv 
     84      1.1  jmmv #
     85      1.1  jmmv # kqueue_check file event
     86      1.1  jmmv #
     87      1.1  jmmv #	Checks if kqueue raised the given event when monitoring the
     88      1.1  jmmv #	given file.
     89      1.1  jmmv #
     90      1.1  jmmv kqueue_check() {
     91      1.1  jmmv 	echo "Checking if ${1} received ${2}"
     92      1.1  jmmv 	grep "^${1} - ${2}$" kqueue.log >/dev/null || \
     93      1.1  jmmv 	    atf_fail "${1} did not receive ${2}"
     94      1.1  jmmv }
     95