diff options
author | Richard Jones <rjones@redhat.com> | 2010-03-30 14:18:44 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-03-30 14:20:23 +0100 |
commit | fc5fbd460aa0aaf6bb65ca5fa1be59345f4f079f (patch) | |
tree | 7e970a3822ca6c62abc624675462f4c8de2cafaf | |
parent | bbe4888cd4aac8f67c6d34e67d8f622c0c4bfcb4 (diff) | |
download | libguestfs-fc5fbd460aa0aaf6bb65ca5fa1be59345f4f079f.tar.gz libguestfs-fc5fbd460aa0aaf6bb65ca5fa1be59345f4f079f.tar.xz libguestfs-fc5fbd460aa0aaf6bb65ca5fa1be59345f4f079f.zip |
tools: Add basic tests for the virt-* tools.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | tools/Makefile.am | 24 | ||||
-rwxr-xr-x | tools/make-test-img.sh | 88 | ||||
-rwxr-xr-x | tools/test-virt-cat.sh | 14 | ||||
-rwxr-xr-x | tools/test-virt-df.sh | 46 | ||||
-rwxr-xr-x | tools/test-virt-list-filesystems.sh | 17 | ||||
-rwxr-xr-x | tools/test-virt-ls.sh | 19 | ||||
-rwxr-xr-x | tools/test-virt-tar.sh | 21 |
8 files changed, 230 insertions, 0 deletions
@@ -225,6 +225,7 @@ stamp-h1 test-tool/libguestfs-test-tool.1 test-tool/libguestfs-test-tool test-tool/libguestfs-test-tool-helper +tools/test.img tools/virt-*.1 /GNUmakefile /maint.mk diff --git a/tools/Makefile.am b/tools/Makefile.am index d212d380..08f126d5 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -30,9 +30,12 @@ tools = \ win-reg EXTRA_DIST = \ + make-test-img.sh run-locally \ $(tools:%=virt-%) +CLEANFILES = test.img + if HAVE_TOOLS bin_SCRIPTS = $(tools:%=virt-%) @@ -61,4 +64,25 @@ $(top_builddir)/html/virt-%.1.html: virt-% --outfile html/$<.1.html \ tools/$< +# Tests. + +random_val := $(shell awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null) + +TESTS_ENVIRONMENT = \ + MALLOC_PERTURB_=$(random_val) \ + LD_LIBRARY_PATH=$(top_builddir)/src/.libs \ + LIBGUESTFS_PATH=$(top_builddir)/appliance \ + PERL5LIB=$(top_builddir)/perl/blib/lib:$(top_builddir)/perl/blib/arch + +# Build a standard test image to be used by all these tests. +check_DATA = test.img +test.img: make-test-img.sh + $(TESTS_ENVIRONMENT) $(srcdir)/make-test-img.sh + +TESTS = test-virt-cat.sh \ + test-virt-df.sh \ + test-virt-list-filesystems.sh \ + test-virt-ls.sh \ + test-virt-tar.sh + endif diff --git a/tools/make-test-img.sh b/tools/make-test-img.sh new file mode 100755 index 00000000..c6481cdd --- /dev/null +++ b/tools/make-test-img.sh @@ -0,0 +1,88 @@ +#!/bin/bash - +# libguestfs virt-* tools +# Copyright (C) 2010 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. + +# Make a standard test image which is used by all the tools/test-*.sh +# test scripts. This test image is supposed to look like a Fedora +# installation, or at least enough of one to fool virt-inspector's +# heuristics. + +export LANG=C +set -e + +rm -f test.img + +cat > fstab <<EOF +LABEL=BOOT /boot ext2 default 0 0 +LABEL=ROOT / ext2 default 0 0 +EOF + +# Create a disk image. +../fish/guestfish <<'EOF' +sparse test.img- 512M +run + +# Format the disk. +part-init /dev/sda mbr +part-add /dev/sda p 64 524287 +part-add /dev/sda p 524288 -64 + +pvcreate /dev/sda2 +vgcreate VG /dev/sda2 +lvcreate Root VG 32 +lvcreate LV1 VG 32 +lvcreate LV2 VG 32 +lvcreate LV3 VG 64 + +# Phony /boot filesystem. +mkfs ext2 /dev/sda1 +set-e2label /dev/sda1 BOOT + +# Phony root filesystem. +mkfs ext2 /dev/VG/Root +set-e2label /dev/VG/Root ROOT + +# Enough to fool virt-inspector. +mount-options "" /dev/VG/Root / +mkdir /boot +mount-options "" /dev/sda1 /boot +mkdir /bin +mkdir /etc +mkdir /usr +upload fstab /etc/fstab +mkdir /boot/grub +touch /boot/grub/grub.conf + +# Test files. +write-file /etc/test1 "abcdefg" 0 +write-file /etc/test2 "" 0 +write-file /bin/test1 "abcdefg" 0 +write-file /bin/test2 "zxcvbnm" 0 +write-file /bin/test3 "1234567" 0 +write-file /bin/test4 "" 0 +ln-s /bin/test1 /bin/test5 +mkfifo 0777 /bin/test6 +mknod 0777 10 10 /bin/test7 + +# Other filesystems. +mkfs ext2 /dev/VG/LV1 +mkfs ext2 /dev/VG/LV2 +mkfs ext2 /dev/VG/LV3 +EOF + +rm fstab +mv test.img- test.img diff --git a/tools/test-virt-cat.sh b/tools/test-virt-cat.sh new file mode 100755 index 00000000..d87c4b8c --- /dev/null +++ b/tools/test-virt-cat.sh @@ -0,0 +1,14 @@ +#!/bin/bash - + +export LANG=C +set -e + +# Read out the test files from the image using virt-cat. +if [ "$(./virt-cat test.img /etc/test1)" != "abcdefg" ]; then + echo "$0: error: mismatch in file test1" + exit 1 +fi +if [ "$(./virt-cat test.img /etc/test2)" != "" ]; then + echo "$0: error: mismatch in file test2" + exit 1 +fi diff --git a/tools/test-virt-df.sh b/tools/test-virt-df.sh new file mode 100755 index 00000000..8e610632 --- /dev/null +++ b/tools/test-virt-df.sh @@ -0,0 +1,46 @@ +#!/bin/bash - + +export LANG=C +set -e + +# Run virt-df. +output=$(./virt-df test.img -h) + +# The output will be slightly different from one machine to another. +# So just do some tests to make sure it looks reasonable. + +# Check title is the first line. +if [[ ! $output =~ ^Filesystem[[:space:]]+Size[[:space:]]+Used[[:space:]]+Available[[:space:]]+Use% ]]; then + echo "$0: error: no title line" + exit 1 +fi + +# Check 6 lines (title line + 5 * filesystems). +if [ $(echo "$output" | wc -l) -ne 6 ]; then + echo "$0: error: not all filesystems were found" + exit 1 +fi + +# Check /dev/VG/LV[1-3] and /dev/VG/Root were found. +if [[ ! $output =~ test.img:/dev/VG/LV1 ]]; then + echo "$0: error: filesystem /dev/VG/LV1 was not found" + exit 1 +fi +if [[ ! $output =~ test.img:/dev/VG/LV2 ]]; then + echo "$0: error: filesystem /dev/VG/LV2 was not found" + exit 1 +fi +if [[ ! $output =~ test.img:/dev/VG/LV3 ]]; then + echo "$0: error: filesystem /dev/VG/LV3 was not found" + exit 1 +fi +if [[ ! $output =~ test.img:/dev/VG/Root ]]; then + echo "$0: error: filesystem /dev/VG/Root was not found" + exit 1 +fi + +# Check /dev/sda1 was found. Might be called /dev/vda1. +if [[ ! $output =~ test.img:/dev/[hsv]da1 ]]; then + echo "$0: error: filesystem /dev/VG/sda1 was not found" + exit 1 +fi diff --git a/tools/test-virt-list-filesystems.sh b/tools/test-virt-list-filesystems.sh new file mode 100755 index 00000000..5fd4b08a --- /dev/null +++ b/tools/test-virt-list-filesystems.sh @@ -0,0 +1,17 @@ +#!/bin/bash - + +export LANG=C +set -e + +# Run virt-list-filesystems. +# Only columns 1 & 2 are guaranteed, we may add more in future. +if [ "$(./virt-list-filesystems -l test.img | sort | awk '{print $1 $2}')" \ + != \ +"/dev/VG/LV1ext2 +/dev/VG/LV2ext2 +/dev/VG/LV3ext2 +/dev/VG/Rootext2 +/dev/sda1ext2" ]; then + echo "$0: error: unexpected output from virt-list-filesystems" + exit 1 +fi diff --git a/tools/test-virt-ls.sh b/tools/test-virt-ls.sh new file mode 100755 index 00000000..d55b764d --- /dev/null +++ b/tools/test-virt-ls.sh @@ -0,0 +1,19 @@ +#!/bin/bash - + +export LANG=C +set -e + +# Just a random UUID. +uuid=868b1447-0ec5-41bf-a2e5-6a77a4c9b66f + +# Read out the test directory using virt-ls. +if [ "$(./virt-ls test.img /bin)" != "test1 +test2 +test3 +test4 +test5 +test6 +test7" ]; then + echo "$0: error: unexpected output from virt-ls" + exit 1 +fi diff --git a/tools/test-virt-tar.sh b/tools/test-virt-tar.sh new file mode 100755 index 00000000..4ee87cbd --- /dev/null +++ b/tools/test-virt-tar.sh @@ -0,0 +1,21 @@ +#!/bin/bash - + +export LANG=C +set -e + +# Read out the test directory using virt-tar. +./virt-tar -x test.img /bin test.tar + +if [ "$(tar tf test.tar)" != "./ +./test1 +./test2 +./test3 +./test4 +./test5 +./test6 +./test7" ]; then + echo "$0: error: unexpected output in tarball from virt-tar" + exit 1 +fi + +rm test.tar |