From 498758faee6be7e989869bf7feba5e1026a1bb65 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 22 Dec 2011 11:35:43 +0000 Subject: tests: Split regressions -> various subdirectories of tests/ --- .gitignore | 11 +- Makefile.am | 5 +- configure.ac | 6 +- daemon/debug.c | 8 +- fish/Makefile.am | 26 ++++ fish/test-add-domain.sh | 96 ++++++++++++ fish/test-copy.sh | 82 ++++++++++ fish/test-find0.sh | 39 +++++ fish/test-guestfish-a.sh | 45 ++++++ fish/test-guestfish-d.sh | 73 +++++++++ fish/test-guestfish-escapes.sh | 83 +++++++++++ fish/test-guestfish-events.sh | 88 +++++++++++ fish/test-guestfish-tilde.sh | 70 +++++++++ fish/test-read_file.sh | 34 +++++ fish/test-remote.sh | 46 ++++++ fish/test-reopen.sh | 41 +++++ fish/test-stringlist.sh | 60 ++++++++ fish/test-upload-to-dir.sh | 39 +++++ regressions/Makefile.am | 96 ------------ regressions/rhbz501893.c | 56 ------- regressions/rhbz503169c13.sh | 37 ----- regressions/rhbz557655-expected.stderr | 12 -- regressions/rhbz557655-expected.stdout | 8 - regressions/rhbz557655.sh | 86 ----------- regressions/rhbz576879.sh | 33 ---- regressions/rhbz578407.sh | 43 ------ regressions/rhbz580246.sh | 47 ------ regressions/rhbz602997.sh | 71 --------- regressions/rhbz690819.sh | 37 ----- regressions/rhbz727178.sh | 49 ------ regressions/tell-user-to-ignore-errors.sh | 26 ---- regressions/test-add-domain.sh | 96 ------------ regressions/test-bootbootboot.sh | 40 ----- regressions/test-both-ends-cancel.sh | 32 ---- .../test-cancellation-download-librarycancels.sh | 53 ------- .../test-cancellation-upload-daemoncancels.sh | 35 ----- regressions/test-copy.sh | 82 ---------- regressions/test-find0.sh | 39 ----- regressions/test-guestfish-a.sh | 45 ------ regressions/test-guestfish-d.sh | 73 --------- regressions/test-guestfish-escapes.sh | 83 ----------- regressions/test-guestfish-events.sh | 88 ----------- regressions/test-guestfish-tilde.sh | 70 --------- regressions/test-inspect-fstab-md.sh | 74 --------- regressions/test-inspect-fstab.sh | 130 ---------------- regressions/test-launch-race.pl | 67 --------- regressions/test-list-filesystems.sh | 76 ---------- regressions/test-list-md-devices.sh | 59 -------- regressions/test-luks-list.sh | 111 -------------- regressions/test-luks.sh | 93 ------------ regressions/test-lvm-filtering.sh | 92 ------------ regressions/test-lvm-mapping.pl | 99 ------------ regressions/test-mdadm.sh | 166 --------------------- regressions/test-noexec-stack.pl | 79 ---------- regressions/test-qemudie-killsub.sh | 37 ----- regressions/test-qemudie-launchfail.sh | 37 ----- regressions/test-qemudie-midcommand.sh | 37 ----- regressions/test-qemudie-synch.sh | 38 ----- regressions/test-read_file.sh | 34 ----- regressions/test-remote.sh | 46 ------ regressions/test-reopen.sh | 41 ----- regressions/test-stringlist.sh | 60 -------- regressions/test-upload-to-dir.sh | 39 ----- src/guestfs.pod | 9 +- tests/luks/Makefile.am | 33 ++++ tests/luks/test-luks-list.sh | 111 ++++++++++++++ tests/luks/test-luks.sh | 93 ++++++++++++ tests/lvm/Makefile.am | 33 ++++ tests/lvm/test-lvm-filtering.sh | 92 ++++++++++++ tests/lvm/test-lvm-mapping.pl | 99 ++++++++++++ tests/md/Makefile.am | 36 +++++ tests/md/test-inspect-fstab-md.sh | 74 +++++++++ tests/md/test-inspect-fstab.sh | 130 ++++++++++++++++ tests/md/test-list-filesystems.sh | 76 ++++++++++ tests/md/test-list-md-devices.sh | 59 ++++++++ tests/md/test-mdadm.sh | 166 +++++++++++++++++++++ tests/protocol/Makefile.am | 38 +++++ tests/protocol/test-both-ends-cancel.sh | 32 ++++ .../test-cancellation-download-librarycancels.sh | 53 +++++++ .../test-cancellation-upload-daemoncancels.sh | 35 +++++ tests/protocol/test-launch-race.pl | 67 +++++++++ tests/protocol/test-qemudie-killsub.sh | 37 +++++ tests/protocol/test-qemudie-launchfail.sh | 37 +++++ tests/protocol/test-qemudie-midcommand.sh | 37 +++++ tests/protocol/test-qemudie-synch.sh | 38 +++++ tests/qemu/qemu-snapshot-isolation.sh | 2 +- tests/regressions/Makefile.am | 54 +++++++ tests/regressions/rhbz501893.c | 56 +++++++ tests/regressions/rhbz503169c13.sh | 37 +++++ tests/regressions/rhbz557655-expected.stderr | 12 ++ tests/regressions/rhbz557655-expected.stdout | 8 + tests/regressions/rhbz557655.sh | 86 +++++++++++ tests/regressions/rhbz576879.sh | 33 ++++ tests/regressions/rhbz578407.sh | 43 ++++++ tests/regressions/rhbz580246.sh | 47 ++++++ tests/regressions/rhbz602997.sh | 71 +++++++++ tests/regressions/rhbz690819.sh | 37 +++++ tests/regressions/rhbz727178.sh | 49 ++++++ tests/regressions/test-noexec-stack.pl | 79 ++++++++++ 99 files changed, 2834 insertions(+), 2769 deletions(-) create mode 100755 fish/test-add-domain.sh create mode 100755 fish/test-copy.sh create mode 100755 fish/test-find0.sh create mode 100755 fish/test-guestfish-a.sh create mode 100755 fish/test-guestfish-d.sh create mode 100755 fish/test-guestfish-escapes.sh create mode 100755 fish/test-guestfish-events.sh create mode 100755 fish/test-guestfish-tilde.sh create mode 100755 fish/test-read_file.sh create mode 100755 fish/test-remote.sh create mode 100755 fish/test-reopen.sh create mode 100755 fish/test-stringlist.sh create mode 100755 fish/test-upload-to-dir.sh delete mode 100644 regressions/Makefile.am delete mode 100644 regressions/rhbz501893.c delete mode 100755 regressions/rhbz503169c13.sh delete mode 100644 regressions/rhbz557655-expected.stderr delete mode 100644 regressions/rhbz557655-expected.stdout delete mode 100755 regressions/rhbz557655.sh delete mode 100755 regressions/rhbz576879.sh delete mode 100755 regressions/rhbz578407.sh delete mode 100755 regressions/rhbz580246.sh delete mode 100755 regressions/rhbz602997.sh delete mode 100755 regressions/rhbz690819.sh delete mode 100755 regressions/rhbz727178.sh delete mode 100755 regressions/tell-user-to-ignore-errors.sh delete mode 100755 regressions/test-add-domain.sh delete mode 100755 regressions/test-bootbootboot.sh delete mode 100755 regressions/test-both-ends-cancel.sh delete mode 100755 regressions/test-cancellation-download-librarycancels.sh delete mode 100755 regressions/test-cancellation-upload-daemoncancels.sh delete mode 100755 regressions/test-copy.sh delete mode 100755 regressions/test-find0.sh delete mode 100755 regressions/test-guestfish-a.sh delete mode 100755 regressions/test-guestfish-d.sh delete mode 100755 regressions/test-guestfish-escapes.sh delete mode 100755 regressions/test-guestfish-events.sh delete mode 100755 regressions/test-guestfish-tilde.sh delete mode 100755 regressions/test-inspect-fstab-md.sh delete mode 100755 regressions/test-inspect-fstab.sh delete mode 100755 regressions/test-launch-race.pl delete mode 100755 regressions/test-list-filesystems.sh delete mode 100755 regressions/test-list-md-devices.sh delete mode 100755 regressions/test-luks-list.sh delete mode 100755 regressions/test-luks.sh delete mode 100755 regressions/test-lvm-filtering.sh delete mode 100755 regressions/test-lvm-mapping.pl delete mode 100755 regressions/test-mdadm.sh delete mode 100755 regressions/test-noexec-stack.pl delete mode 100755 regressions/test-qemudie-killsub.sh delete mode 100755 regressions/test-qemudie-launchfail.sh delete mode 100755 regressions/test-qemudie-midcommand.sh delete mode 100755 regressions/test-qemudie-synch.sh delete mode 100755 regressions/test-read_file.sh delete mode 100755 regressions/test-remote.sh delete mode 100755 regressions/test-reopen.sh delete mode 100755 regressions/test-stringlist.sh delete mode 100755 regressions/test-upload-to-dir.sh create mode 100644 tests/luks/Makefile.am create mode 100755 tests/luks/test-luks-list.sh create mode 100755 tests/luks/test-luks.sh create mode 100644 tests/lvm/Makefile.am create mode 100755 tests/lvm/test-lvm-filtering.sh create mode 100755 tests/lvm/test-lvm-mapping.pl create mode 100644 tests/md/Makefile.am create mode 100755 tests/md/test-inspect-fstab-md.sh create mode 100755 tests/md/test-inspect-fstab.sh create mode 100755 tests/md/test-list-filesystems.sh create mode 100755 tests/md/test-list-md-devices.sh create mode 100755 tests/md/test-mdadm.sh create mode 100644 tests/protocol/Makefile.am create mode 100755 tests/protocol/test-both-ends-cancel.sh create mode 100755 tests/protocol/test-cancellation-download-librarycancels.sh create mode 100755 tests/protocol/test-cancellation-upload-daemoncancels.sh create mode 100755 tests/protocol/test-launch-race.pl create mode 100755 tests/protocol/test-qemudie-killsub.sh create mode 100755 tests/protocol/test-qemudie-launchfail.sh create mode 100755 tests/protocol/test-qemudie-midcommand.sh create mode 100755 tests/protocol/test-qemudie-synch.sh create mode 100644 tests/regressions/Makefile.am create mode 100644 tests/regressions/rhbz501893.c create mode 100755 tests/regressions/rhbz503169c13.sh create mode 100644 tests/regressions/rhbz557655-expected.stderr create mode 100644 tests/regressions/rhbz557655-expected.stdout create mode 100755 tests/regressions/rhbz557655.sh create mode 100755 tests/regressions/rhbz576879.sh create mode 100755 tests/regressions/rhbz578407.sh create mode 100755 tests/regressions/rhbz580246.sh create mode 100755 tests/regressions/rhbz602997.sh create mode 100755 tests/regressions/rhbz690819.sh create mode 100755 tests/regressions/rhbz727178.sh create mode 100755 tests/regressions/test-noexec-stack.pl diff --git a/.gitignore b/.gitignore index c322a279..9271d74f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ *~ *.a +test1.img +test2.img +test.err +test.out ABOUT-NLS aclocal.m4 align/stamp-virt-alignment-scan.pod @@ -294,11 +298,6 @@ python/examples/stamp-guestfs-python.pod python/guestfs.py python/guestfs-py.c python/guestfs.pyc -regressions/rhbz501893 -regressions/test1.img -regressions/test2.img -regressions/test.err -regressions/test.out rescue/stamp-virt-rescue.pod rescue/virt-rescue rescue/virt-rescue.1 @@ -340,7 +339,6 @@ src/libguestfs.syms src/stamp-guestfs.pod *.swp stamp-h1 -test1.img test-tool/libguestfs-test-tool test-tool/libguestfs-test-tool.1 test-tool/libguestfs-test-tool-helper @@ -359,6 +357,7 @@ tests/c-api/test*.img tests/c-api/tests tests/c-api/tests.c tests/c-api/test*.tmp +tests/regressions/rhbz501893 tools/test.img tools/virt-*.1 tools/virt-*.pl diff --git a/Makefile.am b/Makefile.am index 5c8ff677..31da8755 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,10 @@ SUBDIRS += appliance endif # Tests and the test-tool. -SUBDIRS += gnulib/tests tests/c-api tests/qemu regressions extratests test-tool +SUBDIRS += gnulib/tests tests/c-api tests/qemu +SUBDIRS += tests/protocol tests/lvm tests/luks tests/md +SUBDIRS += tests/regressions +SUBDIRS += extratests test-tool # Guestfish. SUBDIRS += fish diff --git a/configure.ac b/configure.ac index ac09844e..33d2aea1 100644 --- a/configure.ac +++ b/configure.ac @@ -1041,7 +1041,6 @@ AC_CONFIG_FILES([Makefile po/Makefile.in python/Makefile python/examples/Makefile - regressions/Makefile rescue/Makefile resize/Makefile ruby/Makefile @@ -1051,7 +1050,12 @@ AC_CONFIG_FILES([Makefile src/Makefile test-tool/Makefile tests/c-api/Makefile + tests/luks/Makefile + tests/lvm/Makefile + tests/md/Makefile + tests/protocol/Makefile tests/qemu/Makefile + tests/regressions/Makefile tools/Makefile]) AC_OUTPUT diff --git a/daemon/debug.c b/daemon/debug.c index bb91c9ef..31cef465 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -280,7 +280,9 @@ debug_env (const char *subcmd, int argc, char *const *const argv) return out; } -/* Return binaries in the appliance. See regressions/rhbz727178.sh */ +/* Return binaries in the appliance. + * See tests/regressions/rhbz727178.sh + */ static char * debug_binaries (const char *subcmd, int argc, char *const *const argv) { @@ -306,7 +308,9 @@ debug_binaries (const char *subcmd, int argc, char *const *const argv) return out; } -/* Run 'ldd' on a file from the appliance. See regressions/rhbz727178.sh */ +/* Run 'ldd' on a file from the appliance. + * See tests/regressions/rhbz727178.sh + */ static char * debug_ldd (const char *subcmd, int argc, char *const *const argv) { diff --git a/fish/Makefile.am b/fish/Makefile.am index c940c2b8..2624a7d5 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -45,6 +45,7 @@ BUILT_SOURCES = \ EXTRA_DIST = \ $(BUILT_SOURCES) \ + $(TESTS) \ rc_protocol.x \ guestfish.pod \ guestfish-bash-completion.sh \ @@ -226,3 +227,28 @@ toolsconf_DATA = libguestfs-tools.conf bashcompletiondir = $(sysconfdir)/bash_completion.d bashcompletion_DATA = guestfish-bash-completion.sh + +# 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 \ + TMPDIR=$(top_builddir) + +TESTS = \ + test-add-domain.sh \ + test-copy.sh \ + test-find0.sh \ + test-guestfish-a.sh \ + test-guestfish-d.sh \ + test-guestfish-escapes.sh \ + test-guestfish-events.sh \ + test-guestfish-tilde.sh \ + test-read_file.sh \ + test-remote.sh \ + test-reopen.sh \ + test-stringlist.sh \ + test-upload-to-dir.sh diff --git a/fish/test-add-domain.sh b/fish/test-add-domain.sh new file mode 100755 index 00000000..6154a758 --- /dev/null +++ b/fish/test-add-domain.sh @@ -0,0 +1,96 @@ +#!/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 add-domain command. + +set -e + +rm -f test1.img test2.img test3.img test4.img test.xml test.out + +cwd="$(pwd)" + +truncate -s 1M test1.img test2.img test3.img test4.img + +# Libvirt test XML, see libvirt.git/examples/xml/test/testnode.xml +cat > test.xml < + + guest + + hvm + + + 524288 + + + + + + + + + + + + + + + + + + + + + + + + +EOF + +../fish/guestfish >test.out <test.out <test.out <test.out 2>&1 + +! grep -sq 'add_drive.*format' test.out + +../fish/guestfish -x --format=qcow2 -a /dev/null test.out 2>&1 + +grep -sq 'add_drive.*format:qcow2' test.out + +../fish/guestfish -x --ro --format=qcow2 -a /dev/null test.out 2>&1 + +grep -sq 'add_drive.*readonly:true.*format:qcow2' test.out + +../fish/guestfish -x --format -a /dev/null test.out 2>&1 + +! grep -sq 'add_drive.*format' test.out + +../fish/guestfish -x -a /dev/null --format=qcow2 test.out 2>&1 + +! grep -sq 'add_drive.*format' test.out + +rm -f test.out diff --git a/fish/test-guestfish-d.sh b/fish/test-guestfish-d.sh new file mode 100755 index 00000000..41f16094 --- /dev/null +++ b/fish/test-guestfish-d.sh @@ -0,0 +1,73 @@ +#!/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 guestfish -d option. + +set -e + +rm -f test1.img test2.img test3.img test4.img test.xml test.out + +cwd="$(pwd)" + +truncate -s 1M test1.img test2.img test3.img test4.img + +# Libvirt test XML, see libvirt.git/examples/xml/test/testnode.xml +cat > test.xml < + + guest + + hvm + + + 524288 + + + + + + + + + + + + + + + + + + + + + + + + +EOF + +../fish/guestfish -c "test://$cwd/test.xml" --ro -d guest \ + debug-drives test.out +grep -sq "test1.img.*snapshot=on" test.out +! grep -sq "test1.img.*format" test.out +grep -sq "test2.img.*snapshot=on.*format=raw" test.out +grep -sq "test3.img.*snapshot=on.*format=qcow2" test.out +grep -sq "test4.img.*snapshot=on.*format=raw" test.out + +rm -f test1.img test2.img test3.img test4.img test.xml test.out diff --git a/fish/test-guestfish-escapes.sh b/fish/test-guestfish-escapes.sh new file mode 100755 index 00000000..73f41d5f --- /dev/null +++ b/fish/test-guestfish-escapes.sh @@ -0,0 +1,83 @@ +#!/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 string escapes. + +set -e + +rm -f test.output test.error test.error.old + +../fish/guestfish <<'EOF' 2>test.error | od > test.output +echo "" +echo " " +echo " " +echo "\n" +echo "\r" +echo "\n\n" +echo "\x01" +echo "\001" +echo "\100" + +# These are invalid: +-echo "\x00" +-echo "\000" +-echo "\x" +-echo "\x0" +-echo "\7" +-echo "\77" +-echo "\777" +-echo "\" +-echo "\\\" +-echo " +-echo """ +EOF + +# Since trace and debug output also goes to stderr, we must +# remove it before testing. +mv test.error test.error.old +grep -v '^libguestfs: ' < test.error.old > test.error + +if [ "$(cat test.error)" != "\ +guestfish: invalid escape sequence in string (starting at offset 0) +guestfish: invalid escape sequence in string (starting at offset 0) +guestfish: invalid escape sequence in string (starting at offset 0) +guestfish: invalid escape sequence in string (starting at offset 0) +guestfish: invalid escape sequence in string (starting at offset 0) +guestfish: invalid escape sequence in string (starting at offset 0) +guestfish: invalid escape sequence in string (starting at offset 0) +guestfish: unterminated double quote +guestfish: unterminated double quote +guestfish: unterminated double quote +guestfish: command arguments not separated by whitespace" ]; then + echo "unexpected stderr from guestfish:" + cat test.error + echo "[end of stderr]" + exit 1 +fi + +if [ "$(cat test.output)" != "\ +0000000 020012 020012 005040 005012 005015 005012 000412 000412 +0000020 040012 000012 +0000023" ]; then + echo "unexpected stdout from guestfish:" + cat test.output + echo "[end of stdout]" + exit 1 +fi + +rm -f test.output test.error test.error.old diff --git a/fish/test-guestfish-events.sh b/fish/test-guestfish-events.sh new file mode 100755 index 00000000..ad6fefe4 --- /dev/null +++ b/fish/test-guestfish-events.sh @@ -0,0 +1,88 @@ +#!/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 events. + +set -e + +rm -f test.out + +../fish/guestfish -a /dev/null <<'EOF' > test.out +trace true + +event ev1 * "echo $EVENT $@" +event ev1 * "echo $EVENT $@" +event ev2 * "echo $EVENT $@" + +list-events +delete-event ev1 +list-events +reopen +list-events + +event ev1 close,subprocess_quit "echo $EVENT $@" +event ev2 close,subprocess_quit "echo $EVENT $@" +event ev3 launch "echo $EVENT $@" + +list-events +-delete-event ev4 +list-events +delete-event ev1 +list-events +delete-event ev3 +list-events + +EOF + +if [ "$(cat test.out)" != '"ev1" (0): *: echo $EVENT $@ +"ev1" (1): *: echo $EVENT $@ +"ev2" (2): *: echo $EVENT $@ +"ev2" (2): *: echo $EVENT $@ +enter get_verbose +trace get_verbose +trace get_verbose = 0 +enter get_trace +trace get_trace +trace get_trace = 1 +enter get_autosync +trace get_autosync +trace get_autosync = 1 +enter get_path +trace get_path +trace get_path = "../appliance" +enter get_pgroup +trace get_pgroup +trace get_pgroup = 0 +trace close +close +"ev1" (0): close,subprocess_quit: echo $EVENT $@ +"ev2" (1): close,subprocess_quit: echo $EVENT $@ +"ev3" (2): launch_done: echo $EVENT $@ +"ev1" (0): close,subprocess_quit: echo $EVENT $@ +"ev2" (1): close,subprocess_quit: echo $EVENT $@ +"ev3" (2): launch_done: echo $EVENT $@ +"ev2" (1): close,subprocess_quit: echo $EVENT $@ +"ev3" (2): launch_done: echo $EVENT $@ +"ev2" (1): close,subprocess_quit: echo $EVENT $@ +close' ]; then + echo "$0: unexpected output from guestfish events" + cat test.out + exit 1 +fi + +rm test.out diff --git a/fish/test-guestfish-tilde.sh b/fish/test-guestfish-tilde.sh new file mode 100755 index 00000000..aed44311 --- /dev/null +++ b/fish/test-guestfish-tilde.sh @@ -0,0 +1,70 @@ +#!/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 tilde expansion. +# RHBZ#617440 guestfish: fails to tilde expand '~' when the $HOME env is unset +# RHBZ#511372 guestfish doesn't understand '~' in filenames +# and multiple other fixes to tilde handling. + +set -e + +# Don't rely on $HOME being set when this script is called. +HOME=$(pwd) +export HOME + +if [ `echo 'echo ~' | ../fish/guestfish` != "$HOME" ]; then + echo "$0: failed: did not expand ~ correctly" + exit 1 +fi + +if [ `echo 'echo ~/foo' | ../fish/guestfish` != "$HOME/foo" ]; then + echo "$0: failed: did not expand ~/foo correctly" + exit 1 +fi + +# We can be reasonably sure that the root user will always exist and +# should have a home directory. +root="$(echo ~root)" + +if [ `echo 'echo ~root' | ../fish/guestfish` != "$root" ]; then + echo "$0: failed: did not expand ~root correctly" + exit 1 +fi + +if [ `echo 'echo ~root/foo' | ../fish/guestfish` != "$root/foo" ]; then + echo "$0: failed: did not expand ~root/foo correctly" + exit 1 +fi + +# RHBZ#617440 +unset HOME +home="$(echo ~)" + +if [ `echo 'echo ~' | ../fish/guestfish` != "$home" ]; then + echo "$0: failed: did not expand ~ correctly when \$HOME unset" + exit 1 +fi + +if [ `echo 'echo ~/foo' | ../fish/guestfish` != "$home/foo" ]; then + echo "$0: failed: did not expand ~/foo correctly when \$HOME unset" + exit 1 +fi + +# Setting $HOME to pwd above causes guestfish to create a history +# file. Remove it. +rm -f .guestfish \ No newline at end of file diff --git a/fish/test-read_file.sh b/fish/test-read_file.sh new file mode 100755 index 00000000..cd016e30 --- /dev/null +++ b/fish/test-read_file.sh @@ -0,0 +1,34 @@ +#!/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 read_file call. + +set -e + +rm -f test.out + +../fish/guestfish <<'EOF' > test.out +add-ro ../images/test.iso +run +mount-ro /dev/sda / +read-file /helloworld.tar +EOF + +cmp ../images/helloworld.tar test.out + +rm -f test.out \ No newline at end of file diff --git a/fish/test-remote.sh b/fish/test-remote.sh new file mode 100755 index 00000000..ff5b85ad --- /dev/null +++ b/fish/test-remote.sh @@ -0,0 +1,46 @@ +#!/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 remote control of guestfish. + +set -e + +rm -f test.img + +eval `../fish/guestfish --listen` + +../fish/guestfish --remote alloc test.img 10M +../fish/guestfish --remote run +../fish/guestfish --remote part-disk /dev/sda mbr +../fish/guestfish --remote mkfs ext2 /dev/sda1 +../fish/guestfish --remote mount-options "" /dev/sda1 / + +# Failure of the above commands will cause the guestfish listener to exit. +# Incorrect return from echo_daemon will not, so need to ensure the listener +# exits in any case, while still reporting an error. +error=0 +echo=$(../fish/guestfish --remote echo_daemon "This is a test") +if [ "$echo" != "This is a test" ]; then + error=1; +fi + +../fish/guestfish --remote exit + +rm -f test.img + +exit $error diff --git a/fish/test-reopen.sh b/fish/test-reopen.sh new file mode 100755 index 00000000..321f2a02 --- /dev/null +++ b/fish/test-reopen.sh @@ -0,0 +1,41 @@ +#!/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 reopening the handle in the same process. This used to fail +# but was corrected in 03e1f74ee08dc71bc09cc7655bf4732685f80b43. + +set -e + +rm -f test.img + +../fish/guestfish <<'EOF' +reopen +reopen +reopen + +alloc test.img 5M +run +reopen + +alloc test.img 5M +run +reopen + +EOF + +rm -f test.img diff --git a/fish/test-stringlist.sh b/fish/test-stringlist.sh new file mode 100755 index 00000000..1aa953bc --- /dev/null +++ b/fish/test-stringlist.sh @@ -0,0 +1,60 @@ +#!/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 remote control of guestfish. + +set -e + +rm -f test.img + +eval `../fish/guestfish --listen` + +error=0 + +function check_echo { + test=$1 + expected=$2 + + local echo + + echo=$(../fish/guestfish --remote echo_daemon "$test") + if [ "$echo" != "$expected" ]; then + echo "Expected \"$expected\", got \"$echo\"" + error=1 + fi +} + +../fish/guestfish --remote alloc test.img 10M +../fish/guestfish --remote run + +check_echo "' '" " " +check_echo "\'" "'" +check_echo "'\''" "'" +check_echo "'\' '" "' " +check_echo "'\'foo\''" "'foo'" +check_echo "foo' 'bar" "foo bar" +check_echo "foo' 'bar" "foo bar" +check_echo "'foo' 'bar'" "foo bar" +check_echo "'foo' " "foo" +check_echo " 'foo'" "foo" + +../fish/guestfish --remote exit + +rm -f test.img + +exit $error diff --git a/fish/test-upload-to-dir.sh b/fish/test-upload-to-dir.sh new file mode 100755 index 00000000..41ce5e5a --- /dev/null +++ b/fish/test-upload-to-dir.sh @@ -0,0 +1,39 @@ +#!/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. + +# If you used the guestfish command 'upload' and accidentally set the +# target to a directory instead of the full filename, then previously +# libguestfs would hang. It should return an error instead. + +set -e + +rm -f test1.img test.out + +if ../fish/guestfish -N fs -m /dev/sda1 upload ../images/test.iso / 2>test.out +then + echo "$0: expecting guestfish to return an error" + exit 1 +fi + +if ! grep -q "upload: /: Is a directory" test.out; then + echo "$0: unexpected error message from guestfish" + cat test.out + exit 1 +fi + +rm -f test1.img test.out diff --git a/regressions/Makefile.am b/regressions/Makefile.am deleted file mode 100644 index 00c25f1e..00000000 --- a/regressions/Makefile.am +++ /dev/null @@ -1,96 +0,0 @@ -# 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. - -# Regression tests and other important tests which are not -# specific to the C API. We can write these more easily in -# higher level languages than C. - -include $(top_srcdir)/subdir-rules.mk - -TESTS = \ - tell-user-to-ignore-errors.sh \ - rhbz501893 \ - rhbz503169c13.sh \ - rhbz557655.sh \ - rhbz576879.sh \ - rhbz578407.sh \ - rhbz580246.sh \ - rhbz602997.sh \ - rhbz690819.sh \ - test-add-domain.sh \ - test-both-ends-cancel.sh \ - test-cancellation-download-librarycancels.sh \ - test-cancellation-upload-daemoncancels.sh \ - test-copy.sh \ - test-find0.sh \ - test-guestfish-a.sh \ - test-guestfish-d.sh \ - test-guestfish-escapes.sh \ - test-guestfish-events.sh \ - test-guestfish-tilde.sh \ - test-inspect-fstab.sh \ - test-inspect-fstab-md.sh \ - test-launch-race.pl \ - test-list-filesystems.sh \ - test-list-md-devices.sh \ - test-luks.sh \ - test-luks-list.sh \ - test-lvm-filtering.sh \ - test-lvm-mapping.pl \ - test-mdadm.sh \ - test-noexec-stack.pl \ - test-qemudie-killsub.sh \ - test-qemudie-midcommand.sh \ - test-qemudie-synch.sh \ - test-read_file.sh \ - test-remote.sh \ - test-reopen.sh \ - test-stringlist.sh \ - test-upload-to-dir.sh - -SKIPPED_TESTS = \ - test-bootbootboot.sh - -FAILING_TESTS = \ - test-qemudie-launchfail.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) \ - 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 = \ - $(FAILING_TESTS) \ - $(SKIPPED_TESTS) \ - $(TESTS) \ - rhbz557655-expected.stdout \ - rhbz557655-expected.stderr diff --git a/regressions/rhbz501893.c b/regressions/rhbz501893.c deleted file mode 100644 index 86e85e58..00000000 --- a/regressions/rhbz501893.c +++ /dev/null @@ -1,56 +0,0 @@ -/* 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 - -#include -#include -#include - -#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/regressions/rhbz503169c13.sh b/regressions/rhbz503169c13.sh deleted file mode 100755 index f1cfa5e8..00000000 --- a/regressions/rhbz503169c13.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/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 <> test.out 2>> test.err <> test.out 2>> test.err < 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/regressions/rhbz576879.sh b/regressions/rhbz576879.sh deleted file mode 100755 index 6b7219cf..00000000 --- a/regressions/rhbz576879.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/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 </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/regressions/rhbz580246.sh b/regressions/rhbz580246.sh deleted file mode 100755 index 0e5dbc6e..00000000 --- a/regressions/rhbz580246.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/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/regressions/rhbz602997.sh b/regressions/rhbz602997.sh deleted file mode 100755 index 61b9df60..00000000 --- a/regressions/rhbz602997.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/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 < test.output < 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/regressions/tell-user-to-ignore-errors.sh b/regressions/tell-user-to-ignore-errors.sh deleted file mode 100755 index 65642888..00000000 --- a/regressions/tell-user-to-ignore-errors.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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. - -echo -echo '*****' -echo -echo 'Some of these tests print error messages. You can ignore' -echo 'these error messages as long as the tests print "PASS".' -echo -echo '*****' -echo diff --git a/regressions/test-add-domain.sh b/regressions/test-add-domain.sh deleted file mode 100755 index 6154a758..00000000 --- a/regressions/test-add-domain.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/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 add-domain command. - -set -e - -rm -f test1.img test2.img test3.img test4.img test.xml test.out - -cwd="$(pwd)" - -truncate -s 1M test1.img test2.img test3.img test4.img - -# Libvirt test XML, see libvirt.git/examples/xml/test/testnode.xml -cat > test.xml < - - guest - - hvm - - - 524288 - - - - - - - - - - - - - - - - - - - - - - - - -EOF - -../fish/guestfish >test.out <test.out <test.out <test.out 2>&1 - -! grep -sq 'add_drive.*format' test.out - -../fish/guestfish -x --format=qcow2 -a /dev/null test.out 2>&1 - -grep -sq 'add_drive.*format:qcow2' test.out - -../fish/guestfish -x --ro --format=qcow2 -a /dev/null test.out 2>&1 - -grep -sq 'add_drive.*readonly:true.*format:qcow2' test.out - -../fish/guestfish -x --format -a /dev/null test.out 2>&1 - -! grep -sq 'add_drive.*format' test.out - -../fish/guestfish -x -a /dev/null --format=qcow2 test.out 2>&1 - -! grep -sq 'add_drive.*format' test.out - -rm -f test.out diff --git a/regressions/test-guestfish-d.sh b/regressions/test-guestfish-d.sh deleted file mode 100755 index 41f16094..00000000 --- a/regressions/test-guestfish-d.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/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 guestfish -d option. - -set -e - -rm -f test1.img test2.img test3.img test4.img test.xml test.out - -cwd="$(pwd)" - -truncate -s 1M test1.img test2.img test3.img test4.img - -# Libvirt test XML, see libvirt.git/examples/xml/test/testnode.xml -cat > test.xml < - - guest - - hvm - - - 524288 - - - - - - - - - - - - - - - - - - - - - - - - -EOF - -../fish/guestfish -c "test://$cwd/test.xml" --ro -d guest \ - debug-drives test.out -grep -sq "test1.img.*snapshot=on" test.out -! grep -sq "test1.img.*format" test.out -grep -sq "test2.img.*snapshot=on.*format=raw" test.out -grep -sq "test3.img.*snapshot=on.*format=qcow2" test.out -grep -sq "test4.img.*snapshot=on.*format=raw" test.out - -rm -f test1.img test2.img test3.img test4.img test.xml test.out diff --git a/regressions/test-guestfish-escapes.sh b/regressions/test-guestfish-escapes.sh deleted file mode 100755 index 73f41d5f..00000000 --- a/regressions/test-guestfish-escapes.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/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 string escapes. - -set -e - -rm -f test.output test.error test.error.old - -../fish/guestfish <<'EOF' 2>test.error | od > test.output -echo "" -echo " " -echo " " -echo "\n" -echo "\r" -echo "\n\n" -echo "\x01" -echo "\001" -echo "\100" - -# These are invalid: --echo "\x00" --echo "\000" --echo "\x" --echo "\x0" --echo "\7" --echo "\77" --echo "\777" --echo "\" --echo "\\\" --echo " --echo """ -EOF - -# Since trace and debug output also goes to stderr, we must -# remove it before testing. -mv test.error test.error.old -grep -v '^libguestfs: ' < test.error.old > test.error - -if [ "$(cat test.error)" != "\ -guestfish: invalid escape sequence in string (starting at offset 0) -guestfish: invalid escape sequence in string (starting at offset 0) -guestfish: invalid escape sequence in string (starting at offset 0) -guestfish: invalid escape sequence in string (starting at offset 0) -guestfish: invalid escape sequence in string (starting at offset 0) -guestfish: invalid escape sequence in string (starting at offset 0) -guestfish: invalid escape sequence in string (starting at offset 0) -guestfish: unterminated double quote -guestfish: unterminated double quote -guestfish: unterminated double quote -guestfish: command arguments not separated by whitespace" ]; then - echo "unexpected stderr from guestfish:" - cat test.error - echo "[end of stderr]" - exit 1 -fi - -if [ "$(cat test.output)" != "\ -0000000 020012 020012 005040 005012 005015 005012 000412 000412 -0000020 040012 000012 -0000023" ]; then - echo "unexpected stdout from guestfish:" - cat test.output - echo "[end of stdout]" - exit 1 -fi - -rm -f test.output test.error test.error.old diff --git a/regressions/test-guestfish-events.sh b/regressions/test-guestfish-events.sh deleted file mode 100755 index ad6fefe4..00000000 --- a/regressions/test-guestfish-events.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/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 events. - -set -e - -rm -f test.out - -../fish/guestfish -a /dev/null <<'EOF' > test.out -trace true - -event ev1 * "echo $EVENT $@" -event ev1 * "echo $EVENT $@" -event ev2 * "echo $EVENT $@" - -list-events -delete-event ev1 -list-events -reopen -list-events - -event ev1 close,subprocess_quit "echo $EVENT $@" -event ev2 close,subprocess_quit "echo $EVENT $@" -event ev3 launch "echo $EVENT $@" - -list-events --delete-event ev4 -list-events -delete-event ev1 -list-events -delete-event ev3 -list-events - -EOF - -if [ "$(cat test.out)" != '"ev1" (0): *: echo $EVENT $@ -"ev1" (1): *: echo $EVENT $@ -"ev2" (2): *: echo $EVENT $@ -"ev2" (2): *: echo $EVENT $@ -enter get_verbose -trace get_verbose -trace get_verbose = 0 -enter get_trace -trace get_trace -trace get_trace = 1 -enter get_autosync -trace get_autosync -trace get_autosync = 1 -enter get_path -trace get_path -trace get_path = "../appliance" -enter get_pgroup -trace get_pgroup -trace get_pgroup = 0 -trace close -close -"ev1" (0): close,subprocess_quit: echo $EVENT $@ -"ev2" (1): close,subprocess_quit: echo $EVENT $@ -"ev3" (2): launch_done: echo $EVENT $@ -"ev1" (0): close,subprocess_quit: echo $EVENT $@ -"ev2" (1): close,subprocess_quit: echo $EVENT $@ -"ev3" (2): launch_done: echo $EVENT $@ -"ev2" (1): close,subprocess_quit: echo $EVENT $@ -"ev3" (2): launch_done: echo $EVENT $@ -"ev2" (1): close,subprocess_quit: echo $EVENT $@ -close' ]; then - echo "$0: unexpected output from guestfish events" - cat test.out - exit 1 -fi - -rm test.out diff --git a/regressions/test-guestfish-tilde.sh b/regressions/test-guestfish-tilde.sh deleted file mode 100755 index aed44311..00000000 --- a/regressions/test-guestfish-tilde.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/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 tilde expansion. -# RHBZ#617440 guestfish: fails to tilde expand '~' when the $HOME env is unset -# RHBZ#511372 guestfish doesn't understand '~' in filenames -# and multiple other fixes to tilde handling. - -set -e - -# Don't rely on $HOME being set when this script is called. -HOME=$(pwd) -export HOME - -if [ `echo 'echo ~' | ../fish/guestfish` != "$HOME" ]; then - echo "$0: failed: did not expand ~ correctly" - exit 1 -fi - -if [ `echo 'echo ~/foo' | ../fish/guestfish` != "$HOME/foo" ]; then - echo "$0: failed: did not expand ~/foo correctly" - exit 1 -fi - -# We can be reasonably sure that the root user will always exist and -# should have a home directory. -root="$(echo ~root)" - -if [ `echo 'echo ~root' | ../fish/guestfish` != "$root" ]; then - echo "$0: failed: did not expand ~root correctly" - exit 1 -fi - -if [ `echo 'echo ~root/foo' | ../fish/guestfish` != "$root/foo" ]; then - echo "$0: failed: did not expand ~root/foo correctly" - exit 1 -fi - -# RHBZ#617440 -unset HOME -home="$(echo ~)" - -if [ `echo 'echo ~' | ../fish/guestfish` != "$home" ]; then - echo "$0: failed: did not expand ~ correctly when \$HOME unset" - exit 1 -fi - -if [ `echo 'echo ~/foo' | ../fish/guestfish` != "$home/foo" ]; then - echo "$0: failed: did not expand ~/foo correctly when \$HOME unset" - exit 1 -fi - -# Setting $HOME to pwd above causes guestfish to create a history -# file. Remove it. -rm -f .guestfish \ No newline at end of file diff --git a/regressions/test-inspect-fstab-md.sh b/regressions/test-inspect-fstab-md.sh deleted file mode 100755 index da163fc0..00000000 --- a/regressions/test-inspect-fstab-md.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/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/regressions/test-inspect-fstab.sh b/regressions/test-inspect-fstab.sh deleted file mode 100755 index 332cde0c..00000000 --- a/regressions/test-inspect-fstab.sh +++ /dev/null @@ -1,130 +0,0 @@ -#!/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/regressions/test-launch-race.pl b/regressions/test-launch-race.pl deleted file mode 100755 index 5a660cee..00000000 --- a/regressions/test-launch-race.pl +++ /dev/null @@ -1,67 +0,0 @@ -#!/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/regressions/test-list-filesystems.sh b/regressions/test-list-filesystems.sh deleted file mode 100755 index 353cdd0b..00000000 --- a/regressions/test-list-filesystems.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/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 < 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/regressions/test-luks.sh b/regressions/test-luks.sh deleted file mode 100755 index fcf9d709..00000000 --- a/regressions/test-luks.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/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 <$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/regressions/test-mdadm.sh b/regressions/test-mdadm.sh deleted file mode 100755 index 7314ca56..00000000 --- a/regressions/test-mdadm.sh +++ /dev/null @@ -1,166 +0,0 @@ -#!/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 < 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/regressions/test-noexec-stack.pl b/regressions/test-noexec-stack.pl deleted file mode 100755 index 6de0b570..00000000 --- a/regressions/test-noexec-stack.pl +++ /dev/null @@ -1,79 +0,0 @@ -#!/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"); -} diff --git a/regressions/test-qemudie-killsub.sh b/regressions/test-qemudie-killsub.sh deleted file mode 100755 index 8ee7ae82..00000000 --- a/regressions/test-qemudie-killsub.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/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/regressions/test-qemudie-launchfail.sh b/regressions/test-qemudie-launchfail.sh deleted file mode 100755 index e3fcb827..00000000 --- a/regressions/test-qemudie-launchfail.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/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/regressions/test-qemudie-midcommand.sh b/regressions/test-qemudie-midcommand.sh deleted file mode 100755 index cdf3f038..00000000 --- a/regressions/test-qemudie-midcommand.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/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/regressions/test-qemudie-synch.sh b/regressions/test-qemudie-synch.sh deleted file mode 100755 index 697c83bd..00000000 --- a/regressions/test-qemudie-synch.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/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/regressions/test-read_file.sh b/regressions/test-read_file.sh deleted file mode 100755 index cd016e30..00000000 --- a/regressions/test-read_file.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/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 read_file call. - -set -e - -rm -f test.out - -../fish/guestfish <<'EOF' > test.out -add-ro ../images/test.iso -run -mount-ro /dev/sda / -read-file /helloworld.tar -EOF - -cmp ../images/helloworld.tar test.out - -rm -f test.out \ No newline at end of file diff --git a/regressions/test-remote.sh b/regressions/test-remote.sh deleted file mode 100755 index ff5b85ad..00000000 --- a/regressions/test-remote.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/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 remote control of guestfish. - -set -e - -rm -f test.img - -eval `../fish/guestfish --listen` - -../fish/guestfish --remote alloc test.img 10M -../fish/guestfish --remote run -../fish/guestfish --remote part-disk /dev/sda mbr -../fish/guestfish --remote mkfs ext2 /dev/sda1 -../fish/guestfish --remote mount-options "" /dev/sda1 / - -# Failure of the above commands will cause the guestfish listener to exit. -# Incorrect return from echo_daemon will not, so need to ensure the listener -# exits in any case, while still reporting an error. -error=0 -echo=$(../fish/guestfish --remote echo_daemon "This is a test") -if [ "$echo" != "This is a test" ]; then - error=1; -fi - -../fish/guestfish --remote exit - -rm -f test.img - -exit $error diff --git a/regressions/test-reopen.sh b/regressions/test-reopen.sh deleted file mode 100755 index 321f2a02..00000000 --- a/regressions/test-reopen.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/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 reopening the handle in the same process. This used to fail -# but was corrected in 03e1f74ee08dc71bc09cc7655bf4732685f80b43. - -set -e - -rm -f test.img - -../fish/guestfish <<'EOF' -reopen -reopen -reopen - -alloc test.img 5M -run -reopen - -alloc test.img 5M -run -reopen - -EOF - -rm -f test.img diff --git a/regressions/test-stringlist.sh b/regressions/test-stringlist.sh deleted file mode 100755 index 1aa953bc..00000000 --- a/regressions/test-stringlist.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/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 remote control of guestfish. - -set -e - -rm -f test.img - -eval `../fish/guestfish --listen` - -error=0 - -function check_echo { - test=$1 - expected=$2 - - local echo - - echo=$(../fish/guestfish --remote echo_daemon "$test") - if [ "$echo" != "$expected" ]; then - echo "Expected \"$expected\", got \"$echo\"" - error=1 - fi -} - -../fish/guestfish --remote alloc test.img 10M -../fish/guestfish --remote run - -check_echo "' '" " " -check_echo "\'" "'" -check_echo "'\''" "'" -check_echo "'\' '" "' " -check_echo "'\'foo\''" "'foo'" -check_echo "foo' 'bar" "foo bar" -check_echo "foo' 'bar" "foo bar" -check_echo "'foo' 'bar'" "foo bar" -check_echo "'foo' " "foo" -check_echo " 'foo'" "foo" - -../fish/guestfish --remote exit - -rm -f test.img - -exit $error diff --git a/regressions/test-upload-to-dir.sh b/regressions/test-upload-to-dir.sh deleted file mode 100755 index 41ce5e5a..00000000 --- a/regressions/test-upload-to-dir.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/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. - -# If you used the guestfish command 'upload' and accidentally set the -# target to a directory instead of the full filename, then previously -# libguestfs would hang. It should return an error instead. - -set -e - -rm -f test1.img test.out - -if ../fish/guestfish -N fs -m /dev/sda1 upload ../images/test.iso / 2>test.out -then - echo "$0: expecting guestfish to return an error" - exit 1 -fi - -if ! grep -q "upload: /: Is a directory" test.out; then - echo "$0: unexpected error message from guestfish" - cat test.out - exit 1 -fi - -rm -f test1.img test.out diff --git a/src/guestfs.pod b/src/guestfs.pod index 45f63297..85760659 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -2737,8 +2737,9 @@ the OCaml description. You can supply zero or as many tests as you want per API call. The tests can either be added as part of the API description (C), or in some rarer cases you may -want to drop a script into C. Note that adding a script -to C is slower, so if possible use the first method. +want to drop a script into C. Note that adding +a script to C is slower, so if possible use the +first method. The following describes the test environment used when you add an API test in C. @@ -2996,10 +2997,6 @@ The build infrastructure and PO files for translations of manpages and POD files. Eventually this will be combined with the C directory, but that is rather complicated. -=item C - -Regression tests. - =item C L command and documentation. 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 <$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 < 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 < 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 + +#include +#include +#include + +#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 <> test.out 2>> test.err <> test.out 2>> test.err < 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 </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 < test.output < 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"); +} -- cgit