diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-12-22 11:35:43 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-12-22 13:04:41 +0000 |
commit | 498758faee6be7e989869bf7feba5e1026a1bb65 (patch) | |
tree | 2c8c599870039286414c7e20d138c91889ca9b05 /fish | |
parent | 5d93d70b4d36b2337104b3dbca07722fa4d47ff5 (diff) | |
download | libguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.tar.gz libguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.tar.xz libguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.zip |
tests: Split regressions -> various subdirectories of tests/
Diffstat (limited to 'fish')
-rw-r--r-- | fish/Makefile.am | 26 | ||||
-rwxr-xr-x | fish/test-add-domain.sh | 96 | ||||
-rwxr-xr-x | fish/test-copy.sh | 82 | ||||
-rwxr-xr-x | fish/test-find0.sh | 39 | ||||
-rwxr-xr-x | fish/test-guestfish-a.sh | 45 | ||||
-rwxr-xr-x | fish/test-guestfish-d.sh | 73 | ||||
-rwxr-xr-x | fish/test-guestfish-escapes.sh | 83 | ||||
-rwxr-xr-x | fish/test-guestfish-events.sh | 88 | ||||
-rwxr-xr-x | fish/test-guestfish-tilde.sh | 70 | ||||
-rwxr-xr-x | fish/test-read_file.sh | 34 | ||||
-rwxr-xr-x | fish/test-remote.sh | 46 | ||||
-rwxr-xr-x | fish/test-reopen.sh | 41 | ||||
-rwxr-xr-x | fish/test-stringlist.sh | 60 | ||||
-rwxr-xr-x | fish/test-upload-to-dir.sh | 39 |
14 files changed, 822 insertions, 0 deletions
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 <<EOF +<node> + <domain type="test"> + <name>guest</name> + <os> + <type>hvm</type> + <boot dev='hd'/> + </os> + <memory>524288</memory> + <devices> + <disk type="file"> + <source file="$cwd/test1.img"/> + <target dev="hda"/> + </disk> + <disk type="file"> + <driver name="qemu" type="raw"/> + <source file="$cwd/test2.img"/> + <target dev="hdb"/> + </disk> + <disk type="file"> + <driver name="qemu" type="qcow2"/> + <source file="$cwd/test3.img"/> + <target dev="hdc"/> + </disk> + <disk type="file"> + <driver name="qemu" type="raw"/> + <source file="$cwd/test4.img"/> + <target dev="hdd"/> + <readonly/> + </disk> + </devices> + </domain> +</node> +EOF + +../fish/guestfish >test.out <<EOF + domain guest libvirturi:test://$cwd/test.xml readonly:true + debug-drives +EOF +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 + +# Test readonlydisk = "ignore". +../fish/guestfish >test.out <<EOF + -domain guest libvirturi:test://$cwd/test.xml readonly:true readonlydisk:ignore + debug-drives +EOF +grep -sq "test1.img" test.out +grep -sq "test2.img" test.out +grep -sq "test3.img" test.out +! grep -sq "test4.img" test.out + +# Test atomicity. +rm test3.img + +../fish/guestfish >test.out <<EOF + -domain guest libvirturi:test://$cwd/test.xml readonly:true + debug-drives +EOF +! grep -sq "test1.img" test.out +! grep -sq "test2.img" test.out +! grep -sq "test3.img" test.out +! grep -sq "test4.img" test.out + +rm -f test1.img test2.img test3.img test4.img test.xml test.out diff --git a/fish/test-copy.sh b/fish/test-copy.sh new file mode 100755 index 00000000..ea6a4cc5 --- /dev/null +++ b/fish/test-copy.sh @@ -0,0 +1,82 @@ +#!/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 copy-in and copy-out commands. + +# This test fails on some versions of mock which lack /dev/fd +# directory. Skip this test in that case. + +test -d /dev/fd || { + echo "$0: Skipping this test because /dev/fd is missing." + exit 0 +} + +set -e + +rm -f test1.img +rm -rf original copy + +mkdir original +cp $srcdir/../images/known* original +cp -P $srcdir/../images/abssymlink* original + +output=$( +../fish/guestfish -N fs -m /dev/sda1 <<EOF +mkdir /data +# This creates a directory /data/images/ +copy-in original /data +is-file /data/original/known-1 +is-file /data/original/known-3 +is-file /data/original/known-5 +is-symlink /data/original/abssymlink +is-file /data/known-1 +is-file /known-1 +EOF +) + +if [ "$output" != \ +"true +true +true +true +false +false" ]; then + echo "$0: error: output of guestfish after copy-in command did not match expected output" + echo "$output" + exit 1 +fi + +mkdir copy + +../fish/guestfish --ro -a test1.img -m /dev/sda1 <<EOF +copy-out /data/original copy +EOF + +if test ! -f copy/original/known-1 || \ + test ! -f copy/original/known-3 || \ + test ! -f copy/original/known-5 || \ + test ! -L copy/original/abssymlink || \ + test -f copy/known-1 || \ + test -f known-1 +then + echo "$0: error: copy-out command failed" + exit 1 +fi + +rm -f test1.img +rm -rf original copy diff --git a/fish/test-find0.sh b/fish/test-find0.sh new file mode 100755 index 00000000..726469c1 --- /dev/null +++ b/fish/test-find0.sh @@ -0,0 +1,39 @@ +#!/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 find0 call. + +set -e + +rm -f test.out + +../fish/guestfish <<'EOF' +add-ro ../images/test.iso +run +mount-ro /dev/sda / +find0 / test.out +EOF + +n=$(tr '\0' '\n' < test.out | grep '^known-[1-5]' | wc -l) +[ "$n" = 5 ] || { + echo find0: Invalid list of files + tr '\0' '\n' < test.out + exit 1 +} + +rm -f test.out diff --git a/fish/test-guestfish-a.sh b/fish/test-guestfish-a.sh new file mode 100755 index 00000000..4fd45f73 --- /dev/null +++ b/fish/test-guestfish-a.sh @@ -0,0 +1,45 @@ +#!/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 -a option. + +set -e + +rm -f test.out + +../fish/guestfish -x -a /dev/null </dev/null >test.out 2>&1 + +! grep -sq 'add_drive.*format' test.out + +../fish/guestfish -x --format=qcow2 -a /dev/null </dev/null >test.out 2>&1 + +grep -sq 'add_drive.*format:qcow2' test.out + +../fish/guestfish -x --ro --format=qcow2 -a /dev/null </dev/null >test.out 2>&1 + +grep -sq 'add_drive.*readonly:true.*format:qcow2' test.out + +../fish/guestfish -x --format -a /dev/null </dev/null >test.out 2>&1 + +! grep -sq 'add_drive.*format' test.out + +../fish/guestfish -x -a /dev/null --format=qcow2 </dev/null >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 <<EOF +<node> + <domain type="test"> + <name>guest</name> + <os> + <type>hvm</type> + <boot dev='hd'/> + </os> + <memory>524288</memory> + <devices> + <disk type="file"> + <source file="$cwd/test1.img"/> + <target dev="hda"/> + </disk> + <disk type="file"> + <driver name="qemu" type="raw"/> + <source file="$cwd/test2.img"/> + <target dev="hdb"/> + </disk> + <disk type="file"> + <driver name="qemu" type="qcow2"/> + <source file="$cwd/test3.img"/> + <target dev="hdc"/> + </disk> + <disk type="file"> + <driver name="qemu" type="raw"/> + <source file="$cwd/test4.img"/> + <target dev="hdd"/> + <readonly/> + </disk> + </devices> + </domain> +</node> +EOF + +../fish/guestfish -c "test://$cwd/test.xml" --ro -d guest \ + debug-drives </dev/null >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 |