diff options
Diffstat (limited to 'tests')
35 files changed, 1989 insertions, 1 deletions
diff --git a/tests/luks/Makefile.am b/tests/luks/Makefile.am new file mode 100644 index 00000000..2bc21eda --- /dev/null +++ b/tests/luks/Makefile.am @@ -0,0 +1,33 @@ +# libguestfs +# Copyright (C) 2009-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +include $(top_srcdir)/subdir-rules.mk + +TESTS = \ + test-luks.sh \ + test-luks-list.sh + +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 \ + TMPDIR=$(top_builddir) + +EXTRA_DIST = \ + $(TESTS) diff --git a/tests/luks/test-luks-list.sh b/tests/luks/test-luks-list.sh new file mode 100755 index 00000000..80ff6e7a --- /dev/null +++ b/tests/luks/test-luks-list.sh @@ -0,0 +1,111 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test LUKS devices appear in the output of list-dm-devices. + +set -e + +[ -n "$SKIP_TEST_LUKS_SH" ] && { + echo "test-luks-list.sh skipped (environment variable set)" + exit 0 +} + +rm -f test1.img test.output + +../../fish/guestfish --keys-from-stdin > test.output <<'EOF' +sparse test1.img 1G +run +part-init /dev/sda mbr +part-add /dev/sda p 64 1048575 +part-add /dev/sda p 1048576 -64 + +# Create LUKS device with key "key0" in slot 0. +luks-format /dev/sda1 0 +key0 + +# Create some unrelated LVs. +pvcreate /dev/sda2 +vgcreate VG /dev/sda2 +lvcreate LV1 /dev/VG 100 +lvcreate LV2 /dev/VG 200 +lvcreate LV3 /dev/VG 100 + +# Open the device as 'lukstest'. +luks-open /dev/sda1 lukstest +key0 + +# List devices, '/dev/mapper/lukstest' should appear. +echo test 1 +list-dm-devices + +# Close the device. +luks-close /dev/mapper/lukstest + +# List devices, '/dev/mapper/lukstest' should not appear. +echo test 2 +list-dm-devices + +# Open the device again. +luks-open /dev/sda1 lukstest +key0 + +# Check no LVs appear in list-dm-devices output. +echo test 3 +list-dm-devices + +# Check LUKS device doesn't appear in any of the other lists. +echo test 4 +list-devices | sed 's,^/dev/[hv]d,/dev/sd,' +echo test 5 +list-partitions | sed 's,^/dev/[hv]d,/dev/sd,' +echo test 6 +lvs +echo test 7 +vgs +echo test 8 +pvs | sed 's,^/dev/[hv]d,/dev/sd,' + +EOF + +# Expected vs actual output. +if [ "$(cat test.output)" != "\ +test 1 +/dev/mapper/lukstest +test 2 +test 3 +/dev/mapper/lukstest +test 4 +/dev/sda +test 5 +/dev/sda1 +/dev/sda2 +test 6 +/dev/VG/LV1 +/dev/VG/LV2 +/dev/VG/LV3 +test 7 +VG +test 8 +/dev/sda2" ]; then + echo "test-luks-list.sh: Unexpected output from test:" + cat test.output + echo "[end of output]" + exit 1 +fi + +rm -f test1.img test.output diff --git a/tests/luks/test-luks.sh b/tests/luks/test-luks.sh new file mode 100755 index 00000000..a9edca0c --- /dev/null +++ b/tests/luks/test-luks.sh @@ -0,0 +1,93 @@ +#!/bin/bash - +# libguestfs +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test LUKS device creation, opening, key slots. + +set -e + +[ -n "$SKIP_TEST_LUKS_SH" ] && { + echo "test-luks.sh skipped (environment variable set)" + exit 0 +} + +rm -f test1.img + +../../fish/guestfish --keys-from-stdin <<EOF +sparse test1.img 1G +run +part-disk /dev/sda mbr + +# Create LUKS device with key "key0" in slot 0. +luks-format /dev/sda1 0 +key0 + +# Open the device. +luks-open /dev/sda1 lukstest +key0 + +# Put some LVM structures on the encrypted device. +pvcreate /dev/mapper/lukstest +vgcreate VG /dev/mapper/lukstest +lvcreate LV1 VG 64 +lvcreate LV2 VG 64 +vg-activate-all false + +# Close the device. +luks-close /dev/mapper/lukstest + +# Add keys in other slots. +luks-add-key /dev/sda1 1 +key0 +key1 +luks-add-key /dev/sda1 2 +key1 +key2 +luks-add-key /dev/sda1 3 +key2 +key3 + +# Check we can open the device with one of the new keys. +luks-open /dev/sda1 lukstest +key1 +luks-close /dev/mapper/lukstest +luks-open /dev/sda1 lukstest +key3 +luks-close /dev/mapper/lukstest + +# Remove a key. +luks-kill-slot /dev/sda1 1 +key0 + +# This is expected to fail. +-luks-open /dev/sda1 lukstest +key1 + +# Replace a key slot. +luks-kill-slot /dev/sda1 3 +key2 +luks-add-key /dev/sda1 3 +key2 +newkey3 + +luks-open /dev/sda1 lukstest +newkey3 +luks-close /dev/mapper/lukstest + +EOF + +rm -f test1.img diff --git a/tests/lvm/Makefile.am b/tests/lvm/Makefile.am new file mode 100644 index 00000000..290f6b3d --- /dev/null +++ b/tests/lvm/Makefile.am @@ -0,0 +1,33 @@ +# libguestfs +# Copyright (C) 2009-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +include $(top_srcdir)/subdir-rules.mk + +TESTS = \ + test-lvm-filtering.sh \ + test-lvm-mapping.pl + +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 \ + TMPDIR=$(top_builddir) + +EXTRA_DIST = \ + $(TESTS) diff --git a/tests/lvm/test-lvm-filtering.sh b/tests/lvm/test-lvm-filtering.sh new file mode 100755 index 00000000..d5ae8d50 --- /dev/null +++ b/tests/lvm/test-lvm-filtering.sh @@ -0,0 +1,92 @@ +#!/bin/bash - +# libguestfs +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test LVM device filtering. + +set -e + +rm -f test1.img test2.img + +actual=$(../../fish/guestfish <<'EOF' +sparse test1.img 1G +sparse test2.img 1G + +run + +part-disk /dev/sda mbr +part-disk /dev/sdb mbr + +pvcreate /dev/sda1 +pvcreate /dev/sdb1 + +vgcreate VG1 /dev/sda1 +vgcreate VG2 /dev/sdb1 + +# Should see VG1 and VG2 +vgs + +# Should see just VG1 +lvm-set-filter /dev/sda +vgs +lvm-set-filter /dev/sda1 +vgs + +# Should see just VG2 +lvm-set-filter /dev/sdb +vgs +lvm-set-filter /dev/sdb1 +vgs + +# Should see VG1 and VG2 +lvm-set-filter "/dev/sda /dev/sdb" +vgs +lvm-set-filter "/dev/sda1 /dev/sdb1" +vgs +lvm-set-filter "/dev/sda /dev/sdb1" +vgs +lvm-set-filter "/dev/sda1 /dev/sdb" +vgs +lvm-clear-filter +vgs +EOF +) + +expected="VG1 +VG2 +VG1 +VG1 +VG2 +VG2 +VG1 +VG2 +VG1 +VG2 +VG1 +VG2 +VG1 +VG2 +VG1 +VG2" + +rm -f test1.img test2.img + +if [ "$actual" != "$expected" ]; then + echo "LVM filter test failed. Actual output was:" + echo "$actual" + exit 1 +fi diff --git a/tests/lvm/test-lvm-mapping.pl b/tests/lvm/test-lvm-mapping.pl new file mode 100755 index 00000000..3e6faa5e --- /dev/null +++ b/tests/lvm/test-lvm-mapping.pl @@ -0,0 +1,99 @@ +#!/usr/bin/perl +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test the discovery of relationships between LVM PVs, VGs and LVs. + +use strict; +use warnings; + +use Sys::Guestfs; + +my $testimg = "test.img"; + +unlink $testimg; +open FILE, ">$testimg" or die "$testimg: $!"; +truncate FILE, 256*1024*1024 or die "$testimg: truncate: $!"; +close FILE or die "$testimg: $!"; + +my $g = Sys::Guestfs->new (); + +#$g->set_verbose (1); +#$g->set_trace (1); + +$g->add_drive_opts ($testimg, format => "raw"); +$g->launch (); + +# Create an arrangement of PVs, VGs and LVs. +$g->sfdiskM ("/dev/sda", [",127", "128,"]); + +$g->pvcreate ("/dev/sda1"); +$g->pvcreate ("/dev/sda2"); +$g->vgcreate ("VG", ["/dev/sda1", "/dev/sda2"]); + +$g->lvcreate ("LV1", "VG", 32); +$g->lvcreate ("LV2", "VG", 32); +$g->lvcreate ("LV3", "VG", 32); + +# Now let's get the arrangement. +my @pvs = $g->pvs (); +my @lvs = $g->lvs (); + +my %pvuuids; +foreach my $pv (@pvs) { + my $uuid = $g->pvuuid ($pv); + $pvuuids{$uuid} = $pv; +} +my %lvuuids; +foreach my $lv (@lvs) { + my $uuid = $g->lvuuid ($lv); + $lvuuids{$uuid} = $lv; +} + +# In this case there is only one VG, called "VG", but in a real +# program you'd want to repeat these steps for each VG that you found. +my @pvuuids_in_VG = $g->vgpvuuids ("VG"); +my @lvuuids_in_VG = $g->vglvuuids ("VG"); + +my @pvs_in_VG; +foreach my $uuid (@pvuuids_in_VG) { + push @pvs_in_VG, $pvuuids{$uuid}; +} +@pvs_in_VG = sort @pvs_in_VG; + +my @lvs_in_VG; +foreach my $uuid (@lvuuids_in_VG) { + push @lvs_in_VG, $lvuuids{$uuid}; +} +@lvs_in_VG = sort @lvs_in_VG; + +unless (@pvs_in_VG == 2 && + $pvs_in_VG[0] eq "/dev/vda1" && $pvs_in_VG[1] eq "/dev/vda2") { + die "unexpected set of PVs for volume group VG: [", + join (", ", @pvs_in_VG), "]\n" +} + +unless (@lvs_in_VG == 3 && + $lvs_in_VG[0] eq "/dev/VG/LV1" && + $lvs_in_VG[1] eq "/dev/VG/LV2" && + $lvs_in_VG[2] eq "/dev/VG/LV3") { + die "unexpected set of LVs for volume group VG: [", + join (", ", @lvs_in_VG), "]\n" +} + +undef $g; + +unlink $testimg or die "$testimg: unlink: $!"; diff --git a/tests/md/Makefile.am b/tests/md/Makefile.am new file mode 100644 index 00000000..c778956f --- /dev/null +++ b/tests/md/Makefile.am @@ -0,0 +1,36 @@ +# libguestfs +# Copyright (C) 2009-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +include $(top_srcdir)/subdir-rules.mk + +TESTS = \ + test-inspect-fstab.sh \ + test-inspect-fstab-md.sh \ + test-list-filesystems.sh \ + test-list-md-devices.sh \ + test-mdadm.sh + +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 \ + TMPDIR=$(top_builddir) + +EXTRA_DIST = \ + $(TESTS)
\ No newline at end of file diff --git a/tests/md/test-inspect-fstab-md.sh b/tests/md/test-inspect-fstab-md.sh new file mode 100755 index 00000000..2a6cb6a9 --- /dev/null +++ b/tests/md/test-inspect-fstab-md.sh @@ -0,0 +1,74 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test the handling of MD devices specified in /etc/fstab + +set -e +export LANG=C + +# The first test requires a new Augeas lens for parsing mdadm.conf. +# If this is not present in the appliance or on the host, skip the +# test. +f=$(grep mdadm_conf.aug ../../appliance/supermin.d/hostfiles | head -1) +if [ -z "$f" -o ! -f "$f" ]; then + echo "$0: test skipped because Augeas mdadm.conf lens is not available." + exit 0 +fi + +guestfish=../../fish/guestfish + +rm -f test1.img test.fstab test.output + +# First, test the regular fedora image, which specifies /boot as /dev/md0 +cp ../../images/fedora-md1.img test1.img +cp ../../images/fedora-md2.img test2.img + +$guestfish -i test[12].img <<'EOF' | sort > test.output + exists /boot/grub/grub.conf +EOF + +if [ "$(cat test.output)" != "true" ]; then + echo "$0: /boot not correctly mounted (/dev/md0)" + exit 1 +fi + +# Test inspection when /boot is specfied as /dev/md/boot +cat <<'EOF' > test.fstab +/dev/VG/Root / ext2 default 0 0 +/dev/md/boot /boot ext2 default 0 0 +EOF + +$guestfish -a test1.img -a test2.img <<'EOF' + run + mount-options "" /dev/VG/Root / + upload test.fstab /etc/fstab +EOF + +$guestfish -i test[12].img <<'EOF' | sort > test.output + exists /boot/grub/grub.conf +EOF + +if [ "$(cat test.output)" != "true" ]; then + echo "$0: error: /boot not correctly mounted (/dev/md/boot)" + cat test.output + exit 1 +fi + +rm test.fstab +rm test[12].img +rm test.output diff --git a/tests/md/test-inspect-fstab.sh b/tests/md/test-inspect-fstab.sh new file mode 100755 index 00000000..72a11fad --- /dev/null +++ b/tests/md/test-inspect-fstab.sh @@ -0,0 +1,130 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test various aspects of core inspection of /etc/fstab. +# This also tests: https://bugzilla.redhat.com/668574 + +set -e +export LANG=C + +guestfish=../../fish/guestfish + +rm -f test1.img test.fstab test.output + +# Start with the regular (good) fedora image, modify /etc/fstab +# and then inspect it. +cp ../../images/fedora.img test1.img + +cat <<'EOF' > test.fstab +/dev/VG/Root / ext2 default 0 0 + +# Xen-style partition names. +/dev/xvda1 /boot ext2 default 0 0 + +# Non-existant device. +/dev/sdb3 /var ext2 default 0 0 + +# Non-existant mountpoint. +/dev/VG/LV1 /nosuchfile ext2 default 0 0 +EOF + +$guestfish -a test1.img <<'EOF' + run + mount-options "" /dev/VG/Root / + upload test.fstab /etc/fstab +EOF + +# This will give a warning, but should not fail. +$guestfish -a test1.img -i <<'EOF' | sort > test.output + inspect-get-mountpoints /dev/VG/Root +EOF + +if [ "$(cat test.output)" != "/: /dev/VG/Root +/boot: /dev/vda1 +/nosuchfile: /dev/VG/LV1 +/var: /dev/sdb3" ]; then + echo "$0: error: unexpected output from inspect-get-mountpoints command" + cat test.output + exit 1 +fi + +# Test device name hints + +cat <<'EOF' > test.fstab +/dev/VG/Root / ext2 default 0 0 + +# Device name which requires a hint +/dev/xvdg1 /boot ext2 default 0 0 +EOF + +$guestfish -a test1.img <<'EOF' + run + mount-options "" /dev/VG/Root / + upload test.fstab /etc/fstab +EOF + +$guestfish <<'EOF' > test.output + add-drive-opts test1.img readonly:true name:xvdg + run + inspect-os + inspect-get-mountpoints /dev/VG/Root +EOF + +if [ "$(cat test.output)" != "/dev/VG/Root +/: /dev/VG/Root +/boot: /dev/vda1" ]; then + echo "$0: error: unexpected output from inspect-get-mountpoints command" + cat test.output + exit 1 +fi + +cat <<'EOF' > test.fstab +/dev/VG/Root / ext2 default 0 0 + +# cciss device which requires a hint +/dev/cciss/c1d3p1 /boot ext2 default 0 0 + +# cciss device, whole disk +/dev/cciss/c1d3 /var ext2 default 0 0 +EOF + +$guestfish -a test1.img <<'EOF' + run + mount-options "" /dev/VG/Root / + upload test.fstab /etc/fstab +EOF + +$guestfish <<'EOF' > test.output + add-drive-opts test1.img readonly:true name:cciss/c1d3 + run + inspect-os + inspect-get-mountpoints /dev/VG/Root +EOF + +if [ "$(cat test.output)" != "/dev/VG/Root +/: /dev/VG/Root +/boot: /dev/vda1 +/var: /dev/vda" ]; then + echo "$0: error: unexpected output from inspect-get-mountpoints command" + cat test.output + exit 1 +fi + +rm test.fstab +rm test1.img +rm test.output diff --git a/tests/md/test-list-filesystems.sh b/tests/md/test-list-filesystems.sh new file mode 100755 index 00000000..9aea21a0 --- /dev/null +++ b/tests/md/test-list-filesystems.sh @@ -0,0 +1,76 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test guestfish list-mddevices command + +set -e + +# Create 2 disks partitioned as: +# sda1: 20M ext3 +# sda2: 20M MD (md127) +# +# sdb1: 20M PV (vg0) +# sdb2: 20M MD (md127) +# +# md127 : 20M ext4 +# vg0 : 16M LV (lv0) +# lv0 : 16M vfat +output=$( +../../fish/guestfish <<EOF +# Add 2 empty disks +sparse fs-test1.img 50M +sparse fs-test2.img 50M +run + +part-init /dev/sda mbr +part-add /dev/sda p 64 41023 +part-add /dev/sda p 41024 81983 +part-init /dev/sdb mbr +part-add /dev/sdb p 64 41023 +part-add /dev/sdb p 41024 81983 + +# Create vg0 and lv0 on /dev/sdb1 +pvcreate /dev/sdb1 +vgcreate vg0 /dev/sdb1 +lvcreate lv0 vg0 16 + +# Create an md device from sda2 and sdb2 +md-create test "/dev/sda2 /dev/sdb2" level:raid1 + +# Create filesystems +mkfs ext3 /dev/sda1 +mkfs ext4 /dev/md127 +mkfs vfat /dev/vg0/lv0 + +list-filesystems +EOF +) + +expected="/dev/vda1: ext3 +/dev/md127: ext4 +/dev/vg0/lv0: vfat" + +# Check the output of list-filesystems +if [ "$output" != "$expected" ]; then + echo "$0: error: output of list-filesystems did not match expected output" + printf "%s\n" "$output" + exit 1; +fi + + +rm -f fs-test1.img fs-test2.img diff --git a/tests/md/test-list-md-devices.sh b/tests/md/test-list-md-devices.sh new file mode 100755 index 00000000..99283be5 --- /dev/null +++ b/tests/md/test-list-md-devices.sh @@ -0,0 +1,59 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test guestfish list-md-devices command + +set -e + +output=$( +../../fish/guestfish <<EOF +# Add 2 empty disks +sparse md-test1.img 100M +sparse md-test2.img 100M +run + +# list-md-devices should return nothing +list-md-devices + +# Create a raid1 based on the 2 disks +md-create test "/dev/sda /dev/sdb" level:raid1 +EOF +) + +# Ensure list-md-devices above returned nothing +if [ ! -z "$output" ]; then + echo "$0: error: output of list-md-devices with no MD devices did not match expected output" + echo $output + exit 1; +fi + +# Ensure list-md-devices now returns the newly created md device +output=$( +../../fish/guestfish -a md-test1.img -a md-test2.img <<EOF +run +list-md-devices +EOF +) + +if [ "$output" != "/dev/md127" ]; then + echo "$0: error: output of list-md-devices did not match expected output" + echo "$output" + exit 1 +fi + +rm -f md-test1.img md-test2.img diff --git a/tests/md/test-mdadm.sh b/tests/md/test-mdadm.sh new file mode 100755 index 00000000..e7f5775a --- /dev/null +++ b/tests/md/test-mdadm.sh @@ -0,0 +1,166 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test guestfish md-create and md-detail commands. + +set -e + +rm -f md-test1.img md-test2.img md-test3.img md-test4.img + +../../fish/guestfish <<EOF +# Add four empty disks +sparse md-test1.img 100M +sparse md-test2.img 100M +sparse md-test3.img 100M +sparse md-test4.img 100M +run + +# Create lots of test partitions. +part-init /dev/sda mbr +part-add /dev/sda p 4096 8191 +part-add /dev/sda p 8192 12287 +part-add /dev/sda p 12288 16383 +part-add /dev/sda p 16384 20479 +part-init /dev/sdb mbr +part-add /dev/sdb p 4096 8191 +part-add /dev/sdb p 8192 12287 +part-add /dev/sdb p 12288 16383 +part-add /dev/sdb p 16384 20479 +part-init /dev/sdc mbr +part-add /dev/sdc p 4096 8191 +part-add /dev/sdc p 8192 12287 +part-add /dev/sdc p 12288 16383 +part-add /dev/sdc p 16384 20479 +part-init /dev/sdd mbr +part-add /dev/sdd p 4096 8191 +part-add /dev/sdd p 8192 12287 +part-add /dev/sdd p 12288 16383 +part-add /dev/sdd p 16384 20479 + +# RAID 1. +md-create r1t1 "/dev/sda1 /dev/sdb1" +md-create r1t2 "/dev/sdc1 /dev/sdd1" chunk:65536 + +# RAID 5. +md-create r5t1 "/dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2" \ + missingbitmap:0x10 nrdevices:4 spare:1 level:5 + +md-create r5t2 "/dev/sda3 /dev/sdb3" missingbitmap:0x1 level:5 + +md-create r5t3 "/dev/sdc3 /dev/sdd3" \ + missingbitmap:0x6 nrdevices:2 spare:2 level:5 + +# Make some filesystems and put some content on the +# new RAID devices to see if they work. +mkfs ext2 /dev/md/r1t1 +mkfs ext2 /dev/md/r1t2 +mkfs ext2 /dev/md/r5t1 +mkfs ext2 /dev/md/r5t2 +mkfs ext2 /dev/md/r5t3 + +mkmountpoint /r1t1 +mount /dev/md/r1t1 /r1t1 +mkmountpoint /r1t2 +mount /dev/md/r1t2 /r1t2 +mkmountpoint /r5t1 +mount /dev/md/r5t1 /r5t1 +mkmountpoint /r5t2 +mount /dev/md/r5t2 /r5t2 +mkmountpoint /r5t3 +mount /dev/md/r5t3 /r5t3 + +touch /r1t1/foo +mkdir /r1t2/bar +write /r5t1/foo "hello" +write /r5t2/bar "goodbye" +write /r5t3/baz "testing" + +EOF + +eval `../../fish/guestfish --listen` +../../fish/guestfish --remote add-ro md-test1.img +../../fish/guestfish --remote add-ro md-test2.img +../../fish/guestfish --remote add-ro md-test3.img +../../fish/guestfish --remote add-ro md-test4.img +../../fish/guestfish --remote run + +for md in `../../fish/guestfish --remote list-md-devices`; do + ../../fish/guestfish --remote md-detail "${md}" > md-detail.out + + sed 's/:\s*/=/' md-detail.out > md-detail.out.sh + . md-detail.out.sh + rm -f md-detail.out.sh + + error=0 + case "$name" in + *:r1t1) + [ "$level" == "raid1" ] || error=1 + [ "$devices" == "2" ] || error=1 + ;; + + *:r1t2) + [ "$level" == "raid1" ] || error=1 + [ "$devices" == "2" ] || error=1 + ;; + + *:r5t1) + [ "$level" == "raid5" ] || error=1 + [ "$devices" == "4" ] || error=1 + ;; + + *:r5t2) + [ "$level" == "raid5" ] || error=1 + [ "$devices" == "3" ] || error=1 + ;; + + *:r5t3) + [ "$level" == "raid5" ] || error=1 + [ "$devices" == "2" ] || error=1 + ;; + + *) + error=1 + esac + + [[ "$uuid" =~ ([0-9a-f]{8}:){3}[0-9a-f]{8} ]] || error=1 + [ ! -z "$metadata" ] || error=1 + + if [ "$error" == "1" ]; then + echo "$0: Unexpected output from md-detail for device $md" + cat md-detail.out + ../../fish/guestfish --remote exit + exit 1 + fi +done + +../../fish/guestfish --remote exit + +eval `../../fish/guestfish --listen` +../../fish/guestfish --remote add-ro md-test1.img +../../fish/guestfish --remote add-ro md-test2.img +../../fish/guestfish --remote add-ro md-test3.img +../../fish/guestfish --remote add-ro md-test4.img +../../fish/guestfish --remote run + +for md in `../../fish/guestfish --remote list-md-devices`; do + ../../fish/guestfish --remote md-stop "${md}" +done + +../../fish/guestfish --remote exit + +rm -f md-detail.out md-test1.img md-test2.img md-test3.img md-test4.img diff --git a/tests/protocol/Makefile.am b/tests/protocol/Makefile.am new file mode 100644 index 00000000..0d899dd9 --- /dev/null +++ b/tests/protocol/Makefile.am @@ -0,0 +1,38 @@ +# libguestfs +# Copyright (C) 2009-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +include $(top_srcdir)/subdir-rules.mk + +TESTS = \ + test-both-ends-cancel.sh \ + test-cancellation-download-librarycancels.sh \ + test-cancellation-upload-daemoncancels.sh \ + test-launch-race.pl \ + test-qemudie-killsub.sh \ + test-qemudie-midcommand.sh \ + test-qemudie-synch.sh + +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 \ + TMPDIR=$(top_builddir) + +EXTRA_DIST = \ + $(TESTS) diff --git a/tests/protocol/test-both-ends-cancel.sh b/tests/protocol/test-both-ends-cancel.sh new file mode 100755 index 00000000..accc0191 --- /dev/null +++ b/tests/protocol/test-both-ends-cancel.sh @@ -0,0 +1,32 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2010-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Regression test for: +# https://bugzilla.redhat.com/show_bug.cgi?id=576879#c5 +# where both ends send cancel messages simultaneously. + +set -e + +rm -f test1.img + +../../fish/guestfish -N disk <<EOF +-tar-in /tmp/nosuchfile /blah +ping-daemon +EOF + +rm -f test1.img diff --git a/tests/protocol/test-cancellation-download-librarycancels.sh b/tests/protocol/test-cancellation-download-librarycancels.sh new file mode 100755 index 00000000..a1198c4a --- /dev/null +++ b/tests/protocol/test-cancellation-download-librarycancels.sh @@ -0,0 +1,53 @@ +#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test download where the library cancels. +# +# Download big and small files to /dev/full. This should fail but not +# kill the appliance. We test various randomized file sizes because +# there are many potential race conditions -- for example the daemon +# may or may not send all of its data because the error condition is +# detected. + +set -e + +rm -f test.img + +size=$(awk 'BEGIN{ srand(); print int(16*1024*rand()) }') +echo "$0: test size $size (bytes)" + +../../fish/guestfish <<EOF +# We want the file to be fully allocated. +alloc test.img 10M +run + +part-disk /dev/sda mbr +mkfs ext2 /dev/sda1 +mount-options "" /dev/sda1 / + +fallocate64 /file $size + +# Download the file into /dev/full so it fails. +-download /file /dev/full + +# The daemon should still be reachable after the failure. +ping-daemon + +EOF + +rm -f test.img diff --git a/tests/protocol/test-cancellation-upload-daemoncancels.sh b/tests/protocol/test-cancellation-upload-daemoncancels.sh new file mode 100755 index 00000000..61172e58 --- /dev/null +++ b/tests/protocol/test-cancellation-upload-daemoncancels.sh @@ -0,0 +1,35 @@ +#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test upload where the daemon cancels. +# +# This is pretty easy - we just upload a too-large source file. + +set -e + +rm -f test1.img + +../../fish/guestfish -N fs -m /dev/sda1 <<'EOF' +# Upload image, daemon should cancel because the image is too large +# to upload into itself. +-upload test.img /test + +ping-daemon +EOF + +rm -f test1.img diff --git a/tests/protocol/test-launch-race.pl b/tests/protocol/test-launch-race.pl new file mode 100755 index 00000000..5a660cee --- /dev/null +++ b/tests/protocol/test-launch-race.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test that 2 simultaneous launches in a clean cache directory will both succeed + +use strict; +use warnings; + +use File::Temp qw(tempdir); +use POSIX; + +use Sys::Guestfs; + +# Allow this test to be skipped. +exit 0 if $ENV{SKIP_TEST_LAUNCH_RACE_PL}; + +# Use a temporary TMPDIR to ensure it's clean +my $tmpdir = tempdir (CLEANUP => 1); +$ENV{TMPDIR} = $tmpdir; + +my $testimg = $tmpdir.'/test.img'; +system ("touch $testimg"); + +my $pid = fork(); +die ("fork failed: $!") if ($pid < 0); + +if ($pid == 0) { + my $g = Sys::Guestfs->new (); + $g->add_drive ($testimg); + $g->launch (); + _exit (0); +} + +my $g = Sys::Guestfs->new (); +$g->add_drive ($testimg); +$g->launch (); +$g = undef; + +waitpid ($pid, 0) or die ("waitpid: $!"); +die ("child failed") unless ($? == 0); + +# Check that only 1 temporary cache directory was created. +# +# No cache directory is OK too (as long as the appliance launched w/o +# failure) because it indicates we're not using supermin. +my $dh; +opendir ($dh, $tmpdir) or die ("Failed to open $tmpdir: $!"); +my @cachedirs = grep { /^guestfs\./ } readdir ($dh); +closedir ($dh) or die ("Failed to close $tmpdir: $!"); + +my $ncachedirs = scalar(@cachedirs); +die "Expected 0 or 1 cachedir, found $ncachedirs" + unless $ncachedirs == 0 || $ncachedirs == 1; diff --git a/tests/protocol/test-qemudie-killsub.sh b/tests/protocol/test-qemudie-killsub.sh new file mode 100755 index 00000000..093e73de --- /dev/null +++ b/tests/protocol/test-qemudie-killsub.sh @@ -0,0 +1,37 @@ +#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test if we can handle qemu death from the kill-subprocess command. + +set -e + +rm -f test1.img + +../../fish/guestfish -N disk <<'EOF' +# Kill the subprocess. +kill-subprocess + +# XXX The following sleep should NOT be necessary. +-sleep 1 + +# We should now be able to rerun the subprocess. +run +ping-daemon +EOF + +rm -f test1.img diff --git a/tests/protocol/test-qemudie-launchfail.sh b/tests/protocol/test-qemudie-launchfail.sh new file mode 100755 index 00000000..4dcd671e --- /dev/null +++ b/tests/protocol/test-qemudie-launchfail.sh @@ -0,0 +1,37 @@ +#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test if we can handle qemu failure during launch. + +set -e + +rm -f test.img + +../../fish/guestfish <<'EOF' +alloc test.img 10M + +append "root=/dev/null" +-run + +# We should now be able to rerun the subprocess. +append "" +run +ping-daemon +EOF + +rm -f test.img diff --git a/tests/protocol/test-qemudie-midcommand.sh b/tests/protocol/test-qemudie-midcommand.sh new file mode 100755 index 00000000..73c3b8e6 --- /dev/null +++ b/tests/protocol/test-qemudie-midcommand.sh @@ -0,0 +1,37 @@ +#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test if we can handle qemu death in the middle of a command. + +set -e + +rm -f test.pid test1.img + +../../fish/guestfish -N disk <<'EOF' +# Kill the subprocess after a short wait. +pid | cat > test.pid +! sleep 2 ; kill $(cat test.pid) & + +-sleep 1000 + +# We should now be able to rerun the subprocess. +run +ping-daemon +EOF + +rm -f test.pid test1.img diff --git a/tests/protocol/test-qemudie-synch.sh b/tests/protocol/test-qemudie-synch.sh new file mode 100755 index 00000000..fb4e25f3 --- /dev/null +++ b/tests/protocol/test-qemudie-synch.sh @@ -0,0 +1,38 @@ +#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test if we can handle qemu death synchronously. + +set -e + +rm -f test.pid test1.img + +../../fish/guestfish -N disk <<'EOF' +# Kill subprocess. +pid | cat > test.pid +! kill $(cat test.pid) ; sleep 2 + +# XXX The following sleep should NOT be necessary. +-sleep 1 + +# We should now be able to rerun the subprocess. +run +ping-daemon +EOF + +rm -f test.pid test1.img diff --git a/tests/qemu/qemu-snapshot-isolation.sh b/tests/qemu/qemu-snapshot-isolation.sh index 384706c2..70b68392 100755 --- a/tests/qemu/qemu-snapshot-isolation.sh +++ b/tests/qemu/qemu-snapshot-isolation.sh @@ -33,7 +33,7 @@ test3_md5sum="$(md5sum test3.img | awk '{print $1}')" # The vitally important calls are 'add-drive-ro' and # 'add-drive-opts ... readonly:true'. -../fish/guestfish <<'EOF' +../../fish/guestfish <<'EOF' add-drive-ro test1.img add-drive-opts test2.img format:raw readonly:true add-drive-opts test3.img format:qcow2 readonly:true diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am new file mode 100644 index 00000000..e43d9e9f --- /dev/null +++ b/tests/regressions/Makefile.am @@ -0,0 +1,54 @@ +# libguestfs +# Copyright (C) 2009-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +include $(top_srcdir)/subdir-rules.mk + +TESTS = \ + rhbz501893 \ + rhbz503169c13.sh \ + rhbz557655.sh \ + rhbz576879.sh \ + rhbz578407.sh \ + rhbz580246.sh \ + rhbz602997.sh \ + rhbz690819.sh \ + test-noexec-stack.pl + +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 \ + TMPDIR=$(top_builddir) \ + PERL5LIB=$(top_builddir)/perl/blib/lib:$(top_builddir)/perl/blib/arch \ + NOEXEC_CHECK="$(top_builddir)/src/.libs/libguestfs.so $(top_builddir)/daemon/guestfsd" + +check_PROGRAMS = \ + rhbz501893 + +rhbz501893_SOURCES = rhbz501893.c +rhbz501893_CFLAGS = \ + -I$(top_srcdir)/src -I$(top_builddir)/src \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) +rhbz501893_LDADD = \ + $(top_builddir)/src/libguestfs.la + +EXTRA_DIST = \ + $(TESTS) \ + rhbz557655-expected.stdout \ + rhbz557655-expected.stderr diff --git a/tests/regressions/rhbz501893.c b/tests/regressions/rhbz501893.c new file mode 100644 index 00000000..86e85e58 --- /dev/null +++ b/tests/regressions/rhbz501893.c @@ -0,0 +1,56 @@ +/* Regression test for RHBZ#501893. + * Test that String parameters are checked for != NULL. + * Copyright (C) 2009-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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +#include "guestfs.h" + +int +main (int argc, char *argv[]) +{ + guestfs_h *g = guestfs_create (); + + /* Call some non-daemon functions that have a String parameter, but + * setting that parameter to NULL. Previously this would cause a + * segfault inside libguestfs. After this bug was fixed, this + * turned into an error message. + */ + + assert (guestfs_add_drive (g, NULL) == -1); + assert (guestfs_config (g, NULL, NULL) == -1); + + /* This optional argument must not be NULL. */ + + assert (guestfs_add_drive_opts (g, "/dev/null", + GUESTFS_ADD_DRIVE_OPTS_FORMAT, NULL, + -1) == -1); + + /* These can be safely set to NULL, should be no error. */ + + assert (guestfs_set_path (g, NULL) == 0); + assert (guestfs_set_append (g, NULL) == 0); + assert (guestfs_set_qemu (g, NULL) == 0); + + guestfs_close (g); + exit (EXIT_SUCCESS); +} diff --git a/tests/regressions/rhbz503169c13.sh b/tests/regressions/rhbz503169c13.sh new file mode 100755 index 00000000..1f3c1521 --- /dev/null +++ b/tests/regressions/rhbz503169c13.sh @@ -0,0 +1,37 @@ +#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Regression test for: +# https://bugzilla.redhat.com/show_bug.cgi?id=503169#c13 +# +# The unmount-all command will give this error: +# libguestfs: error: umount: /sysroot/dev: umount: /sysroot/dev: device is busy. +# (In some cases useful info about processes that use +# the device is found by lsof(8) or fuser(1)) + +set -e + +rm -f test1.img + +../../fish/guestfish -N fs -m /dev/sda1 <<EOF +mkdir /dev +-command /ignore-this-error +unmount-all +EOF + +rm test1.img diff --git a/tests/regressions/rhbz557655-expected.stderr b/tests/regressions/rhbz557655-expected.stderr new file mode 100644 index 00000000..4f88ee8d --- /dev/null +++ b/tests/regressions/rhbz557655-expected.stderr @@ -0,0 +1,12 @@ +set-memsize: memsize: integer out of range +set-memsize: memsize: integer out of range +set-memsize: memsize: integer out of range +set-memsize: memsize: integer out of range +set-memsize: memsize: invalid integer parameter (xstrtoll returned 4) +set-memsize: memsize: invalid integer parameter (xstrtoll returned 2) +set-memsize: memsize: invalid integer parameter (xstrtoll returned 2) +*stdin*:12: libguestfs: error: truncate_size: ftruncate: /test: File too large +truncate-size: size: invalid integer parameter (xstrtoll returned 1) +truncate-size: size: invalid integer parameter (xstrtoll returned 4) +truncate-size: size: invalid integer parameter (xstrtoll returned 2) +truncate-size: size: invalid integer parameter (xstrtoll returned 2) diff --git a/tests/regressions/rhbz557655-expected.stdout b/tests/regressions/rhbz557655-expected.stdout new file mode 100644 index 00000000..80bc8bc3 --- /dev/null +++ b/tests/regressions/rhbz557655-expected.stdout @@ -0,0 +1,8 @@ +0 +16 +8 +-1073741824 +1073741823 +1234 +1234 +1234 diff --git a/tests/regressions/rhbz557655.sh b/tests/regressions/rhbz557655.sh new file mode 100755 index 00000000..682ef725 --- /dev/null +++ b/tests/regressions/rhbz557655.sh @@ -0,0 +1,86 @@ +#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Regression test for: +# https://bugzilla.redhat.com/show_bug.cgi?id=557655 +# "guestfish number parsing should not use atoi, should support '0...' for octal and '0x...' for hexadecimal" + +set -e +rm -f test.out test.err +export LANG=C + +../../fish/guestfish >> test.out 2>> test.err <<EOF +# set-memsize is just a convenient non-daemon function that +# takes a single integer argument. +set-memsize 0 +get-memsize +set-memsize 0x10 +get-memsize +set-memsize 010 +get-memsize +set-memsize -1073741824 +get-memsize +set-memsize 1073741823 +get-memsize + +# the following should all provoke error messages: +-set-memsize -9000000000000000 +-set-memsize 9000000000000000 +-set-memsize 0x900000000000 +-set-memsize 07777770000000000000 +-set-memsize ABC +-set-memsize 09 +-set-memsize 123L +EOF + +../../fish/guestfish -N fs -m /dev/sda1 >> test.out 2>> test.err <<EOF +touch /test + +# truncate-size takes an Int64 argument +truncate-size /test 1234 +filesize /test +truncate-size /test 0x4d2 +filesize /test +truncate-size /test 02322 +filesize /test + +# should parse OK, but underlying filesystem will reject it: +-truncate-size /test 0x7fffffffffffffff + +# larger than 64 bits, should be an error: +-truncate-size /test 0x10000000000000000 + +# these should all provoke parse errors: +-truncate-size /test ABC +-truncate-size /test 09 +-truncate-size /test 123L +EOF + +# If we are running with debugging enabled (or even if not), then +# other messages and warnings can end up in the test.err (stderr) log. +# Thus filter out only lines we expect. 'proc 200' is the procedure +# number of truncate_size. +mv test.err test.err~ +grep -E 'set[-_]memsize|truncate[-_]size' test.err~ | + grep -Ev 'libguestfs: trace:' | + grep -Ev 'proc 200' > test.err +rm test.err~ + +diff -u rhbz557655-expected.stdout test.out +diff -u rhbz557655-expected.stderr test.err +rm test.out test.err test1.img diff --git a/tests/regressions/rhbz576879.sh b/tests/regressions/rhbz576879.sh new file mode 100755 index 00000000..852183d3 --- /dev/null +++ b/tests/regressions/rhbz576879.sh @@ -0,0 +1,33 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2010-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Regression test for: +# https://bugzilla.redhat.com/show_bug.cgi?id=576879#c0 +# upload loses synchronization if the disk is not mounted + +set -e + +rm -f test1.img + +../../fish/guestfish -N disk <<EOF +-upload $srcdir/rhbz576879.sh /test.sh +# Shouldn't lose synchronization, so next command should work: +ping-daemon +EOF + +rm -f test1.img
\ No newline at end of file diff --git a/tests/regressions/rhbz578407.sh b/tests/regressions/rhbz578407.sh new file mode 100755 index 00000000..5fe2cc11 --- /dev/null +++ b/tests/regressions/rhbz578407.sh @@ -0,0 +1,43 @@ +#!/bin/bash - +# libguestfs +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Regression test for: +# https://bugzilla.redhat.com/show_bug.cgi?id=578407 +# prefix '-' in sub-command isn't handled by guestfish in remote control mode +# Reported by Qixiang Wan. + +set -e + +guestfish=../../fish/guestfish + +# Start remote guestfish. +eval `$guestfish --listen 2>/dev/null` + +# This should succeed. +$guestfish --remote version > /dev/null + +# This command will fail (because appliance not launched), but +# prefixing with '-' should make remote guestfish ignore the failure. +$guestfish --remote -- -lvs + +# Remote guestfish should still be running. +$guestfish --remote version > /dev/null +$guestfish --remote exit + +# Try some other command line argument tests which are related the fix. +$guestfish -- version : -lvs : version > /dev/null 2>&1 diff --git a/tests/regressions/rhbz580246.sh b/tests/regressions/rhbz580246.sh new file mode 100755 index 00000000..847ced6a --- /dev/null +++ b/tests/regressions/rhbz580246.sh @@ -0,0 +1,47 @@ +#!/bin/bash - +# libguestfs +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test tar_in call when we upload something which is larger than +# available space. +# https://bugzilla.redhat.com/show_bug.cgi?id=580246 + +set -e +export LANG=C + +rm -f test.img test.tar + +dd if=/dev/zero of=test.img bs=1M count=2 +tar cf test.tar test.img + +output=$( +../../fish/guestfish 2>&1 <<'EOF' +add test.img +run +mkfs ext2 /dev/sda +mount /dev/sda / +-tar-in test.tar / +EOF +) + +rm -f test.img test.tar + +# Check for error message in the output. +if [[ ! $output =~ libguestfs:.error:.tar_in ]]; then + echo "Missing error message from tar-in (expecting an error message)" + exit 1 +fi diff --git a/tests/regressions/rhbz602997.sh b/tests/regressions/rhbz602997.sh new file mode 100755 index 00000000..401211d9 --- /dev/null +++ b/tests/regressions/rhbz602997.sh @@ -0,0 +1,71 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# https://bugzilla.redhat.com/show_bug.cgi?id=602997 +# Fix part-get-bootable to work with missing/unordered partitions. + +set -e +export LANG=C + +guestfish=../../fish/guestfish + +rm -f test.img test.output + +$guestfish > test.output <<EOF +sparse test.img 100M +run +part-init /dev/sda mbr +# Create an unordered layout. +# This places part 2 in front of part 1. +part-add /dev/sda p 1001 2000 +part-add /dev/sda p 1 1000 +#part-list /dev/sda +part-set-bootable /dev/sda 1 true +part-get-bootable /dev/sda 1 +part-get-bootable /dev/sda 2 +EOF + +if [ "$(cat test.output)" != "true +false" ]; then + echo "rhbz602997.sh: Unexpected output from test:" + cat test.output + echo "[end of output]" + exit 1 +fi + +$guestfish > test.output <<EOF +sparse test.img 100M +run +part-init /dev/sda mbr +part-add /dev/sda p 1 1000 +part-add /dev/sda p 1001 2000 +part-add /dev/sda p 2001 3000 +part-del /dev/sda 2 +#part-list /dev/sda +part-get-bootable /dev/sda 3 +ping-daemon +EOF + +if [ "$(cat test.output)" != "false" ]; then + echo "rhbz602997.sh: Unexpected output from test:" + cat test.output + echo "[end of output]" + exit 1 +fi + +rm -f test.img test.output diff --git a/tests/regressions/rhbz690819.sh b/tests/regressions/rhbz690819.sh new file mode 100755 index 00000000..a706285c --- /dev/null +++ b/tests/regressions/rhbz690819.sh @@ -0,0 +1,37 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# https://bugzilla.redhat.com/show_bug.cgi?id=690819 +# mkfs fails creating a filesytem on a disk device when using a disk +# with 'ide' interface + +set -e +export LANG=C + +rm -f test.img + +truncate -s 100M test.img + +../../fish/guestfish <<EOF +add-drive-with-if test.img ide +run +mkfs ext3 /dev/sda +mount /dev/sda / +EOF + +rm -f test.img diff --git a/tests/regressions/rhbz727178.sh b/tests/regressions/rhbz727178.sh new file mode 100755 index 00000000..90b5994e --- /dev/null +++ b/tests/regressions/rhbz727178.sh @@ -0,0 +1,49 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# https://bugzilla.redhat.com/show_bug.cgi?id=727178 +# Check that all binaries that we ship in the appliance contain +# corresponding libraries. + +set -e +export LANG=C + +guestfish=../../fish/guestfish +output=rhbz727178.output + +rm -f binaries.tmp $output + +eval `$guestfish -a /dev/null --listen` + +$guestfish --remote -- run +$guestfish --remote -- debug binaries "" | + grep -E '^/(bin|sbin|usr/bin|usr/sbin|usr/libexec)/' > binaries.tmp + +while read ex; do + echo ldd $ex + $guestfish --remote -- -debug ldd $ex +done < binaries.tmp > $output + +if grep -E '\bnot found\b|undefined symbol' $output; then + echo "Error: some libraries are missing from the appliance." + echo "See" $(pwd)/$output + echo "for the complete output." + exit 1 +fi + +rm binaries.tmp $output diff --git a/tests/regressions/test-noexec-stack.pl b/tests/regressions/test-noexec-stack.pl new file mode 100755 index 00000000..6de0b570 --- /dev/null +++ b/tests/regressions/test-noexec-stack.pl @@ -0,0 +1,79 @@ +#!/usr/bin/perl +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; + +die("NOEXEC_CHECK not set") unless(exists($ENV{NOEXEC_CHECK})); + +my @files = split(/ /, $ENV{NOEXEC_CHECK}); + +FILES: foreach my $file (@files) { + my $output; + my @cmd = ('readelf', '-l', $file); + open($output, '-|', @cmd) + or die("$0: failed to run: '".join(' ', @cmd)."': $!\n"); + + my $offset; + my $line = 1; + + # Find the offset of the Flags field + while(<$output>) { + next unless(/^\s*Type\b/); + + my @lines; + push(@lines, $_); + + # Look for a Flg field on this line (32 bit) + $offset = index($_, 'Flg '); + + if(-1 == $offset) { + # 64 bit is split over 2 lines. Look for a Flags field on the next + # line + $_ = <$output>; + $offset = index($_, 'Flags '); + $line = 2; + push(@lines, $_); + } + + die("Unrecognised header: ".join("\n", @lines)) if(-1 == $offset); + last; + } + + # Find the GNU_STACK entry + while(<$output>) { + next unless(/^\s*GNU_STACK\b/); + + # Skip over input lines according to the header + for(my $i = 1; $i < $line; $i++) { + $_ = <$output>; + } + + my $flags = substr($_, $offset, 3); + + $flags =~ /^[ R][ W]([ E])$/ or die("Unrecognised flags: $flags"); + + if('E' eq $1) { + print "***** $file has an executable stack *****\n"; + exit(1); + } + + next FILES; + } + + die("Didn't find GNU_STACK entry"); +} |