summaryrefslogtreecommitdiffstats
path: root/tests/protocol
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-12-22 11:35:43 +0000
committerRichard W.M. Jones <rjones@redhat.com>2011-12-22 13:04:41 +0000
commit498758faee6be7e989869bf7feba5e1026a1bb65 (patch)
tree2c8c599870039286414c7e20d138c91889ca9b05 /tests/protocol
parent5d93d70b4d36b2337104b3dbca07722fa4d47ff5 (diff)
downloadlibguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.tar.gz
libguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.tar.xz
libguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.zip
tests: Split regressions -> various subdirectories of tests/
Diffstat (limited to 'tests/protocol')
-rw-r--r--tests/protocol/Makefile.am38
-rwxr-xr-xtests/protocol/test-both-ends-cancel.sh32
-rwxr-xr-xtests/protocol/test-cancellation-download-librarycancels.sh53
-rwxr-xr-xtests/protocol/test-cancellation-upload-daemoncancels.sh35
-rwxr-xr-xtests/protocol/test-launch-race.pl67
-rwxr-xr-xtests/protocol/test-qemudie-killsub.sh37
-rwxr-xr-xtests/protocol/test-qemudie-launchfail.sh37
-rwxr-xr-xtests/protocol/test-qemudie-midcommand.sh37
-rwxr-xr-xtests/protocol/test-qemudie-synch.sh38
9 files changed, 374 insertions, 0 deletions
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