>From 8612ad24476eee32c811e889a319559c6b04a4d7 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 17 Nov 2009 17:03:31 +0000 Subject: [PATCH 5/5] fuse: Add tests for guestmount. This script contains non-exhaustive tests for the system calls implemented by guestmount. --- fuse/Makefile.am | 8 +++ fuse/test-fuse.sh | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 0 deletions(-) create mode 100755 fuse/test-fuse.sh diff --git a/fuse/Makefile.am b/fuse/Makefile.am index c041058..ebf948a 100644 --- a/fuse/Makefile.am +++ b/fuse/Makefile.am @@ -39,6 +39,8 @@ guestmount_LDADD = \ $(top_builddir)/src/libguestfs.la \ ../gnulib/lib/libgnu.la +# Documentation. + man_MANS = guestmount.1 guestmount.1: guestmount.pod @@ -60,4 +62,10 @@ $(top_builddir)/html/guestmount.1.html: guestmount.pod --outfile html/guestmount.1.html \ fuse/guestmount.pod +# Tests. + +TESTS = test-fuse.sh +TESTS_ENVIRONMENT = \ + top_builddir=.. + endif diff --git a/fuse/test-fuse.sh b/fuse/test-fuse.sh new file mode 100755 index 0000000..57ee310 --- /dev/null +++ b/fuse/test-fuse.sh @@ -0,0 +1,165 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2009 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +unset CDPATH +set -e +#set -v + +if [ -z "$top_builddir" ]; then + echo "$0: environment variable \$top_builddir must be set" + exit 1 +fi + +nr_stages=$(grep "^stage " $0 | wc -l) + +# Allow top_builddir to be a relative path, but also make it absolute, +# and move to that directory for the initial phase of the script. +top_builddir=$(cd "$top_builddir" > /dev/null; pwd) + +# Paths to the other programs and files. NB: Must be absolute paths. +guestfish="$top_builddir/fish/guestfish" +guestmount="$top_builddir/fuse/guestmount" +image="$top_builddir/fuse/test.img" +mp="$top_builddir/fuse/test-mp" + +# Ensure everything is cleaned up on exit. +rm -f "$image" +mkdir -p "$mp" +fusermount -u "$mp" >/dev/null 2>&1 ||: +function cleanup () +{ + status=$? + set +e + [ $status = 0 ] || echo "*** FAILED ***" + echo "Unmounting filesystem and cleaning up." + cd "$top_builddir" + # By the way, if you run this manually from within gnome, then + # randomly /usr/libexec/gvfs-gdu-volume-monitor will decide to do + # whatever it does in the mountpoint directory, preventing you + # from unmounting it! + if [ -x /sbin/fuser ]; then /sbin/fuser "$mp"; fi + fusermount -u "$mp" + rm -f "$image" + rm -rf "$mp" + exit $status +} +trap cleanup INT TERM QUIT EXIT + +s=1 +function stage () +{ + echo "test-fuse: $s/$nr_stages:" "$@" "..." + ((s++)) +} + +stage Create filesystem with some inital content +$guestfish <