From 4180abcc1fe25ecc1cc82ee114b037f61cdffd15 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 19 Jul 2013 19:36:49 +0100 Subject: [PATCH] tests: Use unique or temporary names for temporary files. Review every test(!) to ensure that it: - Doesn't use a generic name (eg. "test1.img", "test.out") for any temporary file it needs. - Does instead use a unique name or a temporary name (eg. a name like "name-of-the-test.img", or a scratch disk). - Does not use 'rm -f' to clean up its temporary files (so we can detect errors if the wrong temporary file is created or removed). This allows tests to be run in parallel, so they don't stomp on each other's temporary files. --- .gitignore | 4 -- erlang/tests/050-lvcreate.erl | 2 +- erlang/tests/060-readdir.erl | 2 +- fish/test-a.sh | 30 ++++----- fish/test-add-domain.sh | 62 ++++++++++--------- fish/test-copy.sh | 42 ++++++------- fish/test-d.sh | 38 ++++++------ fish/test-edit.sh | 6 +- fish/test-glob.sh | 13 ++-- fish/test-mount-local.sh | 38 ++++++------ fish/test-remote.sh | 6 +- fish/test-reopen.sh | 8 +-- fish/test-stringlist.sh | 6 +- fish/test-upload-to-dir.sh | 10 +-- format/test-virt-format.sh | 10 +-- fuse/test-fuse.sh | 4 +- haskell/Guestfs050LVCreate.hs | 6 +- haskell/Makefile.am | 2 +- python/t/810-rhbz811650.py | 6 +- resize/Makefile.am | 2 +- resize/test-virt-resize.sh | 15 ++--- sparsify/Makefile.am | 2 +- sparsify/test-virt-sparsify.sh | 12 ++-- tests/9p/test-9p.sh | 13 ++-- tests/btrfs/test-btrfs-devices.sh | 12 ++-- tests/c-api/test-add-libvirt-dom.c | 36 ++++++----- tests/guests/Makefile.am | 6 +- tests/hotplug/test-hot-add.pl | 22 +++---- tests/hotplug/test-hot-remove.pl | 28 ++++----- tests/hotplug/test-hotplug-repeated.pl | 14 +++-- tests/luks/test-luks-list.sh | 12 ++-- tests/luks/test-luks.sh | 6 +- tests/lvm/test-lvm-filtering.sh | 8 +-- tests/md/test-inspect-fstab-md.sh | 28 ++++----- tests/md/test-inspect-fstab.sh | 50 +++++++-------- tests/md/test-list-filesystems.sh | 12 ++-- tests/md/test-list-md-devices.sh | 8 +-- tests/md/test-mdadm.sh | 28 ++++----- tests/ntfsclone/test-ntfsclone.sh | 14 ++--- tests/protocol/test-both-ends-cancel.sh | 8 +-- ...st-cancellation-download-librarycancels.sh | 6 +- .../test-cancellation-upload-daemoncancels.sh | 9 ++- tests/protocol/test-qemudie-killsub.sh | 10 ++- tests/protocol/test-qemudie-launchfail.sh | 6 +- tests/protocol/test-qemudie-midcommand.sh | 14 +++-- tests/protocol/test-qemudie-synch.sh | 14 +++-- tests/qemu/qemu-liveness.sh | 12 ++-- tests/qemu/qemu-snapshot-isolation.sh | 28 ++++----- tests/regressions/rhbz503169c13.sh | 6 +- tests/regressions/rhbz557655.sh | 26 ++++---- tests/regressions/rhbz576879.sh | 8 +-- tests/regressions/rhbz580246.sh | 12 ++-- tests/regressions/rhbz602997.sh | 8 +-- tests/regressions/rhbz690819.sh | 8 +-- tests/regressions/rhbz811649.sh | 8 +-- tests/regressions/rhbz895904.sh | 5 +- tests/regressions/rhbz957772.sh | 4 +- tests/regressions/rhbz975797.sh | 16 ++--- tests/rsync/test-rsync.sh | 4 +- tests/selinux/run-test.pl | 10 +-- tests/selinux/test-selinux-direct.sh | 2 - tests/selinux/test-selinux-fuse.sh | 2 - tests/selinux/test-xattrs-direct.sh | 2 - tests/selinux/test-xattrs-fuse.sh | 2 - 64 files changed, 421 insertions(+), 432 deletions(-) diff --git a/.gitignore b/.gitignore index 11b46f95e..b63f3dace 100644 --- a/.gitignore +++ b/.gitignore @@ -106,7 +106,6 @@ Makefile.in /erlang/guestfs.beam /erlang/guestfs.erl /erlang/libguestfs-1.* -/erlang/test.img /examples/copy-over /examples/create-disk /examples/debug-logging @@ -251,7 +250,6 @@ Makefile.in /lua/examples/stamp-guestfs-lua.pod /lua/guestfs.so /lua/lua-guestfs.c -/lua/test.img /m4/ChangeLog /m4/gnulib-cache.m4 /m4/intmax.m4 @@ -405,8 +403,6 @@ Makefile.in /sysprep/sysprep-operations.pod /sysprep/virt-sysprep /sysprep/virt-sysprep.1 -/test1.img -/test2.img /test.err /test.out /tests/c-api/test-add-drive-opts diff --git a/erlang/tests/050-lvcreate.erl b/erlang/tests/050-lvcreate.erl index 8d764c526..17d632981 100755 --- a/erlang/tests/050-lvcreate.erl +++ b/erlang/tests/050-lvcreate.erl @@ -21,7 +21,7 @@ main(_) -> {ok, G} = guestfs:create(), - Disk_image = "test.img", + Disk_image = "test-lvcreate.img", {ok, File} = file:open(Disk_image, [raw, write, binary]), {ok, _} = file:position(File, 512 * 1024 * 1024 - 1), diff --git a/erlang/tests/060-readdir.erl b/erlang/tests/060-readdir.erl index c2f85fc78..4fc0751e5 100755 --- a/erlang/tests/060-readdir.erl +++ b/erlang/tests/060-readdir.erl @@ -21,7 +21,7 @@ main(_) -> {ok, G} = guestfs:create(), - Disk_image = "test.img", + Disk_image = "test-readdir.img", {ok, File} = file:open(Disk_image, [raw, write, binary]), {ok, _} = file:position(File, 10 * 1024 * 1024 - 1), diff --git a/fish/test-a.sh b/fish/test-a.sh index 4a6079071..d0bc15917 100755 --- a/fish/test-a.sh +++ b/fish/test-a.sh @@ -20,30 +20,30 @@ set -e -rm -f test.out -rm -f test1.img +rm -f test-a.out +rm -f test-a.img -./guestfish sparse test1.img 100M +./guestfish sparse test-a.img 100M -./guestfish -x -a test1.img test.out 2>&1 +./guestfish -x -a test-a.img test-a.out 2>&1 -! grep -sq 'add_drive.*format' test.out +! grep -sq 'add_drive.*format' test-a.out -./guestfish -x --format=qcow2 -a test1.img test.out 2>&1 +./guestfish -x --format=qcow2 -a test-a.img test-a.out 2>&1 -grep -sq 'add_drive.*format:qcow2' test.out +grep -sq 'add_drive.*format:qcow2' test-a.out -./guestfish -x --ro --format=qcow2 -a test1.img test.out 2>&1 +./guestfish -x --ro --format=qcow2 -a test-a.img test-a.out 2>&1 -grep -sq 'add_drive.*readonly:true.*format:qcow2' test.out +grep -sq 'add_drive.*readonly:true.*format:qcow2' test-a.out -./guestfish -x --format -a test1.img test.out 2>&1 +./guestfish -x --format -a test-a.img test-a.out 2>&1 -! grep -sq 'add_drive.*format' test.out +! grep -sq 'add_drive.*format' test-a.out -./guestfish -x -a test1.img --format=qcow2 test.out 2>&1 +./guestfish -x -a test-a.img --format=qcow2 test-a.out 2>&1 -! grep -sq 'add_drive.*format' test.out +! grep -sq 'add_drive.*format' test-a.out -rm test.out -rm test1.img +rm test-a.out +rm test-a.img diff --git a/fish/test-add-domain.sh b/fish/test-add-domain.sh index 9548fa1e1..6f8a41746 100755 --- a/fish/test-add-domain.sh +++ b/fish/test-add-domain.sh @@ -20,17 +20,18 @@ set -e -rm -f test1.img test2.img test3.img test4.img test.xml test.out +rm -f test-add-domain-{1,2,3,4}.img +rm -f test-add-domain.xml test-add-domain.out cwd="$(pwd)" -./guestfish sparse test1.img 1M -./guestfish sparse test2.img 1M -./guestfish sparse test3.img 1M -./guestfish sparse test4.img 1M +./guestfish sparse test-add-domain-1.img 1M +./guestfish sparse test-add-domain-2.img 1M +./guestfish sparse test-add-domain-3.img 1M +./guestfish sparse test-add-domain-4.img 1M # Libvirt test XML, see libvirt.git/examples/xml/test/testnode.xml -cat > test.xml < test-add-domain.xml < guest @@ -41,22 +42,22 @@ cat > test.xml <524288 - + - + - + - + @@ -65,35 +66,36 @@ cat > test.xml < EOF -./guestfish >test.out <test-add-domain.out <test.out <test-add-domain.out <test.out <test-add-domain.out < test.xml < test-d.xml < guest @@ -41,22 +42,22 @@ cat > test.xml <524288 - + - + - + - + @@ -65,12 +66,13 @@ cat > test.xml < EOF -./guestfish -c "test://$cwd/test.xml" --ro -d guest \ - debug-drives test.out -grep -sq "test1.img readonly" test.out -! grep -sq "test1.img.*format" test.out -grep -sq "test2.img readonly format=raw" test.out -grep -sq "test3.img readonly format=qcow2" test.out -grep -sq "test4.img readonly format=raw" test.out +./guestfish -c "test://$cwd/test-d.xml" --ro -d guest \ + debug-drives test-d.out +grep -sq "test-d-1.img readonly" test-d.out +! grep -sq "test-d-1.img.*format" test-d.out +grep -sq "test-d-2.img readonly format=raw" test-d.out +grep -sq "test-d-3.img readonly format=qcow2" test-d.out +grep -sq "test-d-4.img readonly format=raw" test-d.out -rm -f test1.img test2.img test3.img test4.img test.xml test.out +rm test-d-{1,2,3,4}.img +rm test-d.xml test-d.out diff --git a/fish/test-edit.sh b/fish/test-edit.sh index b9acf457c..82adad7bb 100755 --- a/fish/test-edit.sh +++ b/fish/test-edit.sh @@ -28,13 +28,13 @@ test -d /dev/fd || { set -e -rm -f test1.img +rm -f test-edit.img # The command will be 'echo ... >>/tmp/tmpfile' export EDITOR="echo second line of text >>" output=$( -./guestfish -N fs -m /dev/sda1 < test.out < test-glob.out < mp/hello - chmod 0600 mp/hello - rm mp/hello + echo 'hello' > test-mount-local-mp/hello + chmod 0600 test-mount-local-mp/hello + rm test-mount-local-mp/hello - echo 'hello' > mp/hello - ln -s mp/hello mp/goodbye - ln mp/hello mp/link - rm mp/goodbye mp/link + echo 'hello' > test-mount-local-mp/hello + ln -s test-mount-local-mp/hello test-mount-local-mp/goodbye + ln test-mount-local-mp/hello test-mount-local-mp/link + rm test-mount-local-mp/goodbye test-mount-local-mp/link - dd if=/dev/zero of=mp/zero bs=10k count=10 + dd if=/dev/zero of=test-mount-local-mp/zero bs=10k count=10 sync - rm mp/zero + rm test-mount-local-mp/zero - echo 'mount-local test successful' > mp/ok + echo 'mount-local test successful' > test-mount-local-mp/ok # Unmount the mountpoint. - ../fuse/guestunmount mp + ../fuse/guestunmount test-mount-local-mp exit 0 fi -rm -f test1.img test.errors -rm -rf mp +rm -f test-mount-local.img test-mount-local.errors +rm -rf test-mount-local-mp -mkdir mp +mkdir test-mount-local-mp -if ! ./guestfish -N fs -m /dev/sda1 2>test.errors <test-mount-local.errors <test.out +if ./guestfish -N test-upload-to-dir.img=fs -m /dev/sda1 upload ../tests/data/test.iso / 2>test-upload-to-dir.out then echo "$0: expecting guestfish to return an error" exit 1 fi -if ! grep -q "upload: /: Is a directory" test.out; then +if ! grep -q "upload: /: Is a directory" test-upload-to-dir.out; then echo "$0: unexpected error message from guestfish" - cat test.out + cat test-upload-to-dir.out exit 1 fi -rm -f test1.img test.out +rm test-upload-to-dir.img test-upload-to-dir.out diff --git a/format/test-virt-format.sh b/format/test-virt-format.sh index 1fd5baace..71cc8026b 100755 --- a/format/test-virt-format.sh +++ b/format/test-virt-format.sh @@ -25,15 +25,15 @@ if [ -n "$SKIP_TEST_VIRT_FORMAT_SH" ]; then exit 77 fi -rm -f test1.img +rm -f test-virt-format.img -$VG ../fish/guestfish -N bootrootlv exit +$VG ../fish/guestfish -N test-virt-format.img=bootrootlv exit -$VG ./virt-format --filesystem=ext3 -a test1.img +$VG ./virt-format --filesystem=ext3 -a test-virt-format.img -if [ "$($VG ../cat/virt-filesystems -a test1.img)" != "/dev/sda1" ]; then +if [ "$($VG ../cat/virt-filesystems -a test-virt-format.img)" != "/dev/sda1" ]; then echo "$0: unexpected output after using virt-format" exit 1 fi -rm -f test1.img +rm test-virt-format.img diff --git a/fuse/test-fuse.sh b/fuse/test-fuse.sh index f17ff22ff..f1e03d025 100755 --- a/fuse/test-fuse.sh +++ b/fuse/test-fuse.sh @@ -50,8 +50,8 @@ top_builddir=$(cd "$top_builddir" > /dev/null; pwd) guestfish="$top_builddir/fish/guestfish" guestmount="$top_builddir/fuse/guestmount" guestunmount="$top_builddir/fuse/guestunmount" -image="$top_builddir/fuse/test.img" -mp="$top_builddir/fuse/test-mp" +image="$top_builddir/fuse/test-fuse.img" +mp="$top_builddir/fuse/test-fuse-mp" if [ ! -x "$guestfish" -o ! -x "$guestmount" -o ! -x "$guestunmount" ] then diff --git a/haskell/Guestfs050LVCreate.hs b/haskell/Guestfs050LVCreate.hs index bec06f018..74bbef847 100644 --- a/haskell/Guestfs050LVCreate.hs +++ b/haskell/Guestfs050LVCreate.hs @@ -26,10 +26,10 @@ main = do g <- G.create {- XXX replace with a call to add_drive_scratch once optional arguments are supported -} - fd <- openFile "test.img" WriteMode + fd <- openFile "test-lv-create.img" WriteMode hSetFileSize fd (500 * 1024 * 1024) hClose fd - G.add_drive_ro g "test.img" + G.add_drive_ro g "test-lv-create.img" G.launch g G.pvcreate g "/dev/sda" @@ -41,4 +41,4 @@ main = do when (lvs /= ["/dev/VG/LV1", "/dev/VG/LV2"]) $ fail "invalid list of LVs returned" - removeLink "test.img" + removeLink "test-lv-create.img" diff --git a/haskell/Makefile.am b/haskell/Makefile.am index ed2224c41..f9574c564 100644 --- a/haskell/Makefile.am +++ b/haskell/Makefile.am @@ -88,7 +88,7 @@ $(built_tests): %: %.hs Guestfs.hs $(GHC) $(GHCFLAGS) --make -main-is $@ -odir .$@ -o $@ $< $(srcdir)/Guestfs.hs -lguestfs -CLEANFILES = $(all_targets) *~ *.hi *.o test.img +CLEANFILES = $(all_targets) *~ *.hi *.o test-lv-create.img clean-local: -rm -rf $(built_tests:%=.%) diff --git a/python/t/810-rhbz811650.py b/python/t/810-rhbz811650.py index ee85c02b6..128f3b5e8 100644 --- a/python/t/810-rhbz811650.py +++ b/python/t/810-rhbz811650.py @@ -18,14 +18,14 @@ import os import guestfs -f = open ("test.img", "w") +f = open ("rhbz811650.img", "w") f.truncate (500 * 1024 * 1024) f.close () g = guestfs.GuestFS (python_return_dict=True) # Deliberate error: the disk format is supposed to be raw. -g.add_drive ("test.img", format="qcow2"); +g.add_drive ("rhbz811650.img", format="qcow2"); # Because error() wasn't being called, guestfs_last_error would return # NULL, causing a segfault in the Python bindings (RHBZ#811650). @@ -34,4 +34,4 @@ try: except: pass -os.unlink ("test.img") +os.unlink ("rhbz811650.img") diff --git a/resize/Makefile.am b/resize/Makefile.am index 9a62f4cc1..06ef7c0b3 100644 --- a/resize/Makefile.am +++ b/resize/Makefile.am @@ -22,7 +22,7 @@ EXTRA_DIST = \ virt-resize.pod \ test-virt-resize.sh -CLEANFILES = *~ *.cmi *.cmo *.cmx *.cmxa *.o virt-resize test.img +CLEANFILES = *~ *.cmi *.cmo *.cmx *.cmxa *.o virt-resize # Alphabetical order. SOURCES = \ diff --git a/resize/test-virt-resize.sh b/resize/test-virt-resize.sh index 0831df4c3..708946cc9 100755 --- a/resize/test-virt-resize.sh +++ b/resize/test-virt-resize.sh @@ -24,20 +24,21 @@ set -e # This exercises a number of interesting codepaths including resizing # LV content, handling GPT, and using qcow2 as a target. -$VG ../fish/guestfish -N bootrootlv:/dev/VG/LV:ext2:ext4:400M:32M:gpt $size_after K" @@ -55,4 +55,4 @@ if [ $size_after -gt 15000 ]; then exit 1 fi -rm -f test1.img test2.img +rm test-virt-sparsify-1.img test-virt-sparsify-2.img diff --git a/tests/9p/test-9p.sh b/tests/9p/test-9p.sh index cd8a062da..62e7fa5f2 100755 --- a/tests/9p/test-9p.sh +++ b/tests/9p/test-9p.sh @@ -32,11 +32,11 @@ if [[ "$backend" != "direct" ]]; then exit 77 fi -rm -f test.img test.out +rm -f test-9p.img test-9p.out ../../fish/guestfish < test.out +ls / | grep 'test-9p.sh\$' > test-9p.out EOF -if [ "$(cat test.out)" != "test-9p.sh" ]; then +if [ "$(cat test-9p.out)" != "test-9p.sh" ]; then echo "$0: unexpected output from listing 9p directory:" - cat test.out + cat test-9p.out + exit 1 fi -rm test.img test.out +rm test-9p.img test-9p.out diff --git a/tests/btrfs/test-btrfs-devices.sh b/tests/btrfs/test-btrfs-devices.sh index 0c0cfd49e..7ef700839 100755 --- a/tests/btrfs/test-btrfs-devices.sh +++ b/tests/btrfs/test-btrfs-devices.sh @@ -38,14 +38,14 @@ if ! $guestfish -a /dev/null run : available btrfs; then exit 77 fi -rm -f test[1234].img +rm -f test-btrfs-devices-{1,2,3,4}.img $guestfish <524288\n" " \n" " \n" - " \n" + " \n" " \n" " \n" " \n" " \n" - " \n" + " \n" " \n" " \n" " \n" " \n" - " \n" + " \n" " \n" " \n" " \n" @@ -80,32 +80,34 @@ main (int argc, char *argv[]) cwd = xgetcwd (); - /* Create the libvirt XML and test images in the current directory. */ - fp = fopen ("test.xml", "w"); + /* Create the libvirt XML and test images in the current + * directory. + */ + fp = fopen ("test-add-libvirt-dom.xml", "w"); if (fp == NULL) { - perror ("test.xml"); + perror ("test-add-libvirt-dom.xml"); exit (EXIT_FAILURE); } make_test_xml (fp, cwd); fclose (fp); - fp = fopen ("test1.img", "w"); + fp = fopen ("test-add-libvirt-dom-1.img", "w"); if (fp == NULL) { - perror ("test1.img"); + perror ("test-add-libvirt-dom-1.img"); exit (EXIT_FAILURE); } fclose (fp); - fp = fopen ("test2.img", "w"); + fp = fopen ("test-add-libvirt-dom-2.img", "w"); if (fp == NULL) { - perror ("test2.img"); + perror ("test-add-libvirt-dom-2.img"); exit (EXIT_FAILURE); } fclose (fp); - fp = fopen ("test3.img", "w"); + fp = fopen ("test-add-libvirt-dom-3.img", "w"); if (fp == NULL) { - perror ("test3.img"); + perror ("test-add-libvirt-dom-3.img"); exit (EXIT_FAILURE); } fclose (fp); @@ -118,7 +120,7 @@ main (int argc, char *argv[]) } /* Create the libvirt connection. */ - snprintf (libvirt_uri, sizeof libvirt_uri, "test://%s/test.xml", cwd); + snprintf (libvirt_uri, sizeof libvirt_uri, "test://%s/test-add-libvirt-dom.xml", cwd); conn = virConnectOpenReadOnly (libvirt_uri); if (!conn) { err = virGetLastError (); @@ -143,10 +145,10 @@ main (int argc, char *argv[]) guestfs_close (g); - unlink ("test.xml"); - unlink ("test1.img"); - unlink ("test2.img"); - unlink ("test3.img"); + unlink ("test-add-libvirt-dom.xml"); + unlink ("test-add-libvirt-dom-1.img"); + unlink ("test-add-libvirt-dom-2.img"); + unlink ("test-add-libvirt-dom-3.img"); exit (EXIT_SUCCESS); } diff --git a/tests/guests/Makefile.am b/tests/guests/Makefile.am index 2bc63d58b..d1af37023 100644 --- a/tests/guests/Makefile.am +++ b/tests/guests/Makefile.am @@ -72,11 +72,11 @@ display = \ # include them in the libvirt fake XML to make sure that virt-df and # virt-alignment-scan don't break when they encounter them. blank-%.img: - rm -f $@ test1.img + rm -f $@ $@-t $(top_builddir)/run \ ../../fish/guestfish \ - -N "$$(echo $@ | sed -e 's/blank-//' -e 's/.img//')" exit - mv test1.img $@ + -N $@-t="$$(echo $@ | sed -e 's/blank-//' -e 's/.img//')" exit + mv $@-t $@ $(call display,$@) # Make a (dummy) Fedora image. diff --git a/tests/hotplug/test-hot-add.pl b/tests/hotplug/test-hot-add.pl index fc11957c8..8016bf47a 100755 --- a/tests/hotplug/test-hot-add.pl +++ b/tests/hotplug/test-hot-add.pl @@ -36,20 +36,20 @@ unless ($backend eq "libvirt" || $backend =~ /^libvirt:/) { $g->launch (); # Create some temporary disks. -open FILE, ">test1.img" or die "test1.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test1.img: truncate: $!"; +open FILE, ">test-hot-add-1.img" or die "test-hot-add-1.img: $!"; +truncate FILE, 512 * 1024 * 1024 or die "test-hot-add-1.img: truncate: $!"; close FILE; -open FILE, ">test2.img" or die "test2.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test2.img: truncate: $!"; +open FILE, ">test-hot-add-2.img" or die "test-hot-add-2.img: $!"; +truncate FILE, 512 * 1024 * 1024 or die "test-hot-add-2.img: truncate: $!"; close FILE; -die unless system ("qemu-img create -f qcow2 test3.img 1G") == 0; +die unless system ("qemu-img create -f qcow2 test-hot-add-3.img 1G") == 0; # Hot-add them. Labels are required. -$g->add_drive ("test1.img", label => "a"); # autodetect format -$g->add_drive ("test2.img", label => "b", format => "raw", readonly => 1); -$g->add_drive ("test3.img", label => "c", format => "qcow2"); +$g->add_drive ("test-hot-add-1.img", label => "a"); # autodetect format +$g->add_drive ("test-hot-add-2.img", label => "b", format => "raw", readonly => 1); +$g->add_drive ("test-hot-add-3.img", label => "c", format => "qcow2"); # Check we can use the disks immediately. $g->part_disk ("/dev/disk/guestfs/a", "mbr"); @@ -59,8 +59,8 @@ $g->mkfs ("ext2", "/dev/disk/guestfs/a1"); $g->shutdown (); $g->close (); -unlink "test1.img"; -unlink "test2.img"; -unlink "test3.img"; +unlink "test-hot-add-1.img"; +unlink "test-hot-add-2.img"; +unlink "test-hot-add-3.img"; exit 0 diff --git a/tests/hotplug/test-hot-remove.pl b/tests/hotplug/test-hot-remove.pl index 145764aa7..316b6b9d8 100755 --- a/tests/hotplug/test-hot-remove.pl +++ b/tests/hotplug/test-hot-remove.pl @@ -33,20 +33,20 @@ unless ($backend eq "libvirt" || $backend =~ /^libvirt:/) { } # Create some temporary disks. -open FILE, ">test1.img" or die "test1.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test1.img: truncate: $!"; +open FILE, ">test-hot-remove-1.img" or die "test-hot-remove-1.img: $!"; +truncate FILE, 512 * 1024 * 1024 or die "test-hot-remove-1.img: truncate: $!"; close FILE; -open FILE, ">test2.img" or die "test2.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test2.img: truncate: $!"; +open FILE, ">test-hot-remove-2.img" or die "test-hot-remove-2.img: $!"; +truncate FILE, 512 * 1024 * 1024 or die "test-hot-remove-2.img: truncate: $!"; close FILE; -die unless system ("qemu-img create -f qcow2 test3.img 1G") == 0; +die unless system ("qemu-img create -f qcow2 test-hot-remove-3.img 1G") == 0; # Hot-add them. Labels are required. -$g->add_drive ("test1.img", label => "a"); # autodetect format -$g->add_drive ("test2.img", label => "b", format => "raw", readonly => 1); -$g->add_drive ("test3.img", label => "c", format => "qcow2"); +$g->add_drive ("test-hot-remove-1.img", label => "a"); # autodetect format +$g->add_drive ("test-hot-remove-2.img", label => "b", format => "raw", readonly => 1); +$g->add_drive ("test-hot-remove-3.img", label => "c", format => "qcow2"); # Remove them (before launch). $g->remove_drive ("a"); @@ -60,9 +60,9 @@ my @devices = $g->list_devices (); die unless 0 == @devices; # Add them again (after launch). -$g->add_drive ("test1.img", label => "a"); # autodetect format -$g->add_drive ("test2.img", label => "b", format => "raw", readonly => 1); -$g->add_drive ("test3.img", label => "c", format => "qcow2"); +$g->add_drive ("test-hot-remove-1.img", label => "a"); # autodetect format +$g->add_drive ("test-hot-remove-2.img", label => "b", format => "raw", readonly => 1); +$g->add_drive ("test-hot-remove-3.img", label => "c", format => "qcow2"); # Check we can use the disks immediately. $g->part_disk ("/dev/disk/guestfs/a", "mbr"); @@ -81,8 +81,8 @@ die unless 0 == @devices; $g->shutdown (); $g->close (); -unlink "test1.img"; -unlink "test2.img"; -unlink "test3.img"; +unlink "test-hot-remove-1.img"; +unlink "test-hot-remove-2.img"; +unlink "test-hot-remove-3.img"; exit 0 diff --git a/tests/hotplug/test-hotplug-repeated.pl b/tests/hotplug/test-hotplug-repeated.pl index 643e98740..635bf41b5 100755 --- a/tests/hotplug/test-hotplug-repeated.pl +++ b/tests/hotplug/test-hotplug-repeated.pl @@ -35,13 +35,17 @@ unless ($backend eq "libvirt" || $backend =~ /^libvirt:/) { $g->launch (); # Create a temporary disk. -open FILE, ">test1.img" or die "test1.img: $!"; -truncate FILE, 512 * 1024 * 1024 or die "test1.img: truncate: $!"; -close FILE; +open FILE, ">test-hotplug-repeated.img" or + die "test-hotplug-repeated.img: $!"; +truncate FILE, 512 * 1024 * 1024 or + die "test-hotplug-repeated.img: truncate: $!"; +close FILE or + die "test-hotplug-repeated.img: close: $!"; my $start_t = time (); while (time () - $start_t <= 60) { - $g->add_drive ("test1.img", label => "a", format => "raw"); + $g->add_drive ("test-hotplug-repeated.img", + label => "a", format => "raw"); $g->remove_drive ("a"); } @@ -52,6 +56,6 @@ die unless 0 == @devices; $g->shutdown (); $g->close (); -unlink "test1.img"; +unlink "test-hotplug-repeated.img"; exit 0 diff --git a/tests/luks/test-luks-list.sh b/tests/luks/test-luks-list.sh index f5984dac8..8bb3f28a4 100755 --- a/tests/luks/test-luks-list.sh +++ b/tests/luks/test-luks-list.sh @@ -25,10 +25,10 @@ set -e exit 77 } -rm -f test1.img test.output +rm -f test-luks-list.img test-luks-list.out -../../fish/guestfish --keys-from-stdin > test.output <<'EOF' -sparse test1.img 1G +../../fish/guestfish --keys-from-stdin > test-luks-list.out <<'EOF' +sparse test-luks-list.img 1G run part-init /dev/sda mbr part-add /dev/sda p 64 1048575 @@ -83,7 +83,7 @@ pvs | sed 's,^/dev/[hv]d,/dev/sd,' EOF # Expected vs actual output. -if [ "$(cat test.output)" != "\ +if [ "$(cat test-luks-list.out)" != "\ test 1 /dev/mapper/lukstest test 2 @@ -103,9 +103,9 @@ VG test 8 /dev/sda2" ]; then echo "test-luks-list.sh: Unexpected output from test:" - cat test.output + cat test-luks-list.out echo "[end of output]" exit 1 fi -rm -f test1.img test.output +rm test-luks-list.img test-luks-list.out diff --git a/tests/luks/test-luks.sh b/tests/luks/test-luks.sh index eee7295dc..ceca81028 100755 --- a/tests/luks/test-luks.sh +++ b/tests/luks/test-luks.sh @@ -25,10 +25,10 @@ set -e exit 77 } -rm -f test1.img +rm -f test-luks.img ../../fish/guestfish --keys-from-stdin < test.output +$guestfish -i inspect-fstab-md-[12].img <<'EOF' | sort > inspect-fstab-md.output exists /boot/grub/grub.conf EOF -if [ "$(cat test.output)" != "true" ]; then +if [ "$(cat inspect-fstab-md.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 +cat <<'EOF' > inspect-fstab-md.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' +$guestfish -a inspect-fstab-md-1.img -a inspect-fstab-md-2.img <<'EOF' run mount /dev/VG/Root / - upload test.fstab /etc/fstab + upload inspect-fstab-md.fstab /etc/fstab EOF -$guestfish -i test[12].img <<'EOF' | sort > test.output +$guestfish -i inspect-fstab-md-[12].img <<'EOF' | sort > inspect-fstab-md.output exists /boot/grub/grub.conf EOF -if [ "$(cat test.output)" != "true" ]; then +if [ "$(cat inspect-fstab-md.output)" != "true" ]; then echo "$0: error: /boot not correctly mounted (/dev/md/boot)" - cat test.output + cat inspect-fstab-md.output exit 1 fi -rm test.fstab -rm test[12].img -rm test.output +rm inspect-fstab-md.fstab +rm inspect-fstab-md-[12].img +rm inspect-fstab-md.output diff --git a/tests/md/test-inspect-fstab.sh b/tests/md/test-inspect-fstab.sh index dff276023..eb92c5e91 100755 --- a/tests/md/test-inspect-fstab.sh +++ b/tests/md/test-inspect-fstab.sh @@ -25,13 +25,13 @@ export LANG=C guestfish=../../fish/guestfish canonical="sed s,/dev/vd,/dev/sd,g" -rm -f test1.qcow2 test.fstab test.output +rm -f inspect-fstab-1.qcow2 inspect-fstab.fstab inspect-fstab.output # Start with the regular (good) fedora image, modify /etc/fstab # and then inspect it. -qemu-img create -F raw -b ../guests/fedora.img -f qcow2 test1.qcow2 +qemu-img create -F raw -b ../guests/fedora.img -f qcow2 inspect-fstab-1.qcow2 -cat <<'EOF' > test.fstab +cat <<'EOF' > inspect-fstab.fstab /dev/VG/Root / ext2 default 0 0 # Xen-style partition names. @@ -49,18 +49,18 @@ cat <<'EOF' > test.fstab /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001-part3 /id3 ext2 default 0 0 EOF -$guestfish -a test1.qcow2 <<'EOF' +$guestfish -a inspect-fstab-1.qcow2 <<'EOF' run mount /dev/VG/Root / - upload test.fstab /etc/fstab + upload inspect-fstab.fstab /etc/fstab EOF # This will give a warning, but should not fail. -$guestfish -a test1.qcow2 -i <<'EOF' | sort | $canonical > test.output +$guestfish -a inspect-fstab-1.qcow2 -i <<'EOF' | sort | $canonical > inspect-fstab.output inspect-get-mountpoints /dev/VG/Root EOF -if [ "$(cat test.output)" != "/: /dev/VG/Root +if [ "$(cat inspect-fstab.output)" != "/: /dev/VG/Root /boot: /dev/sda1 /id1: /dev/sda1 /id3: /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001-part3 @@ -68,41 +68,41 @@ if [ "$(cat test.output)" != "/: /dev/VG/Root /nosuchfile: /dev/VG/LV1 /var: /dev/sdb3" ]; then echo "$0: error #1: unexpected output from inspect-get-mountpoints command" - cat test.output + cat inspect-fstab.output exit 1 fi # Test device name hints -cat <<'EOF' > test.fstab +cat <<'EOF' > inspect-fstab.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.qcow2 <<'EOF' +$guestfish -a inspect-fstab-1.qcow2 <<'EOF' run mount /dev/VG/Root / - upload test.fstab /etc/fstab + upload inspect-fstab.fstab /etc/fstab EOF -$guestfish <<'EOF' | $canonical > test.output - add test1.qcow2 readonly:true name:xvdg +$guestfish <<'EOF' | $canonical > inspect-fstab.output + add inspect-fstab-1.qcow2 readonly:true name:xvdg run inspect-os inspect-get-mountpoints /dev/VG/Root EOF -if [ "$(cat test.output)" != "/dev/VG/Root +if [ "$(cat inspect-fstab.output)" != "/dev/VG/Root /: /dev/VG/Root /boot: /dev/sda1" ]; then echo "$0: error #2: unexpected output from inspect-get-mountpoints command" - cat test.output + cat inspect-fstab.output exit 1 fi -cat <<'EOF' > test.fstab +cat <<'EOF' > inspect-fstab.fstab /dev/VG/Root / ext2 default 0 0 # cciss device which requires a hint @@ -112,28 +112,28 @@ cat <<'EOF' > test.fstab /dev/cciss/c1d3 /var ext2 default 0 0 EOF -$guestfish -a test1.qcow2 <<'EOF' +$guestfish -a inspect-fstab-1.qcow2 <<'EOF' run mount /dev/VG/Root / - upload test.fstab /etc/fstab + upload inspect-fstab.fstab /etc/fstab EOF -$guestfish <<'EOF' | $canonical > test.output - add test1.qcow2 readonly:true name:cciss/c1d3 +$guestfish <<'EOF' | $canonical > inspect-fstab.output + add inspect-fstab-1.qcow2 readonly:true name:cciss/c1d3 run inspect-os inspect-get-mountpoints /dev/VG/Root EOF -if [ "$(cat test.output)" != "/dev/VG/Root +if [ "$(cat inspect-fstab.output)" != "/dev/VG/Root /: /dev/VG/Root /boot: /dev/sda1 /var: /dev/sda" ]; then echo "$0: error #3: unexpected output from inspect-get-mountpoints command" - cat test.output + cat inspect-fstab.output exit 1 fi -rm test.fstab -rm test1.qcow2 -rm test.output +rm inspect-fstab.fstab +rm inspect-fstab-1.qcow2 +rm inspect-fstab.output diff --git a/tests/md/test-list-filesystems.sh b/tests/md/test-list-filesystems.sh index 642e0339f..5ef34b21e 100755 --- a/tests/md/test-list-filesystems.sh +++ b/tests/md/test-list-filesystems.sh @@ -25,7 +25,7 @@ if [ -n "$SKIP_TEST_LIST_FILESYSTEMS_SH" ]; then exit 77 fi -rm -f test.output +rm -f list-fs.output # Create 2 disks partitioned as: # sda1: 20M ext3 @@ -37,10 +37,10 @@ rm -f test.output # md127 : 20M ext4 # vg0 : 16M LV (lv0) # lv0 : 16M vfat -../../fish/guestfish < test.output +../../fish/guestfish < list-fs.output # Add 2 empty disks -sparse fs-test1.img 50M -sparse fs-test2.img 50M +scratch 50M +scratch 50M run part-init /dev/sda mbr @@ -71,11 +71,11 @@ expected="/dev/sda1: ext3 /dev/vg0/lv0: vfat" # Check the output of list-filesystems -if [ "$(cat test.output)" != "$expected" ]; then +if [ "$(cat list-fs.output)" != "$expected" ]; then echo "$0: error: output of list-filesystems did not match expected output" printf "%s\n" "$output" exit 1; fi -rm -f fs-test1.img fs-test2.img test.output +rm list-fs.output diff --git a/tests/md/test-list-md-devices.sh b/tests/md/test-list-md-devices.sh index ad9e5b54a..511f6beee 100755 --- a/tests/md/test-list-md-devices.sh +++ b/tests/md/test-list-md-devices.sh @@ -28,8 +28,8 @@ fi output=$( ../../fish/guestfish < test.pid -! sleep 2 ; kill $(cat test.pid) & +pid | cat > qemudie-midcommand.pid +! sleep 2 ; kill $(cat qemudie-midcommand.pid) & -sleep 1000 # We should now be able to rerun the subprocess. -add test1.img +scratch 100M run ping-daemon EOF -rm -f test.pid test1.img +rm qemudie-midcommand.pid diff --git a/tests/protocol/test-qemudie-synch.sh b/tests/protocol/test-qemudie-synch.sh index eca013d3e..e9431a383 100755 --- a/tests/protocol/test-qemudie-synch.sh +++ b/tests/protocol/test-qemudie-synch.sh @@ -25,20 +25,22 @@ if [ "$(../../fish/guestfish get-backend)" != "direct" ]; then exit 77 fi -rm -f test.pid test1.img +rm -f qemudie-synch.pid -../../fish/guestfish -N disk <<'EOF' +../../fish/guestfish <<'EOF' +scratch 100M +run # Kill subprocess. -pid | cat > test.pid -! kill $(cat test.pid) ; sleep 2 +pid | cat > qemudie-synch.pid +! kill $(cat qemudie-synch.pid) ; sleep 2 # XXX The following sleep should NOT be necessary. -sleep 1 # We should now be able to rerun the subprocess. -add test1.img +scratch 100M run ping-daemon EOF -rm -f test.pid test1.img +rm qemudie-synch.pid diff --git a/tests/qemu/qemu-liveness.sh b/tests/qemu/qemu-liveness.sh index 6ed42ddc1..fe8396a31 100755 --- a/tests/qemu/qemu-liveness.sh +++ b/tests/qemu/qemu-liveness.sh @@ -22,13 +22,13 @@ set -e -rm -f test1.img +rm -f liveness1.img -../../fish/guestfish sparse test1.img 100M -test1_md5sum="$(md5sum test1.img | awk '{print $1}')" +../../fish/guestfish sparse liveness1.img 100M +liveness1_md5sum="$(md5sum liveness1.img | awk '{print $1}')" ../../fish/guestfish <<'EOF' -add test1.img format:raw +add liveness1.img format:raw run part-disk /dev/sda mbr @@ -41,7 +41,7 @@ write /test "This is a test" EOF # Verify that the disk has changed. -if [ "$(md5sum test1.img | awk '{print $1}')" = "$test1_md5sum" ]; then +if [ "$(md5sum liveness1.img | awk '{print $1}')" = "$liveness1_md5sum" ]; then echo "***** ERROR *****" echo "Write operations are not modifying an attached disk." echo @@ -49,4 +49,4 @@ if [ "$(md5sum test1.img | awk '{print $1}')" = "$test1_md5sum" ]; then exit 1 fi -rm test1.img +rm liveness1.img diff --git a/tests/qemu/qemu-snapshot-isolation.sh b/tests/qemu/qemu-snapshot-isolation.sh index 4dc859164..f8fac0645 100755 --- a/tests/qemu/qemu-snapshot-isolation.sh +++ b/tests/qemu/qemu-snapshot-isolation.sh @@ -22,21 +22,21 @@ set -e -rm -f test1.img test2.img test3.img +rm -f isolation1.img isolation2.img isolation3.img -../../fish/guestfish sparse test1.img 100M -test1_md5sum="$(md5sum test1.img | awk '{print $1}')" -../../fish/guestfish sparse test2.img 100M -test2_md5sum="$(md5sum test2.img | awk '{print $1}')" -qemu-img create -f qcow2 test3.img 100M -test3_md5sum="$(md5sum test3.img | awk '{print $1}')" +../../fish/guestfish sparse isolation1.img 100M +isolation1_md5sum="$(md5sum isolation1.img | awk '{print $1}')" +../../fish/guestfish sparse isolation2.img 100M +isolation2_md5sum="$(md5sum isolation2.img | awk '{print $1}')" +qemu-img create -f qcow2 isolation3.img 100M +isolation3_md5sum="$(md5sum isolation3.img | awk '{print $1}')" # The vitally important calls are 'add-drive-ro' and # 'add-drive-opts ... readonly:true'. ../../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 +add-drive-ro isolation1.img +add-drive-opts isolation2.img format:raw readonly:true +add-drive-opts isolation3.img format:qcow2 readonly:true run part-disk /dev/sda mbr @@ -78,14 +78,14 @@ function serious_error exit 1 } -if [ "$(md5sum test1.img | awk '{print $1}')" != "$test1_md5sum" ]; then +if [ "$(md5sum isolation1.img | awk '{print $1}')" != "$isolation1_md5sum" ]; then serious_error fi -if [ "$(md5sum test2.img | awk '{print $1}')" != "$test2_md5sum" ]; then +if [ "$(md5sum isolation2.img | awk '{print $1}')" != "$isolation2_md5sum" ]; then serious_error fi -if [ "$(md5sum test3.img | awk '{print $1}')" != "$test3_md5sum" ]; then +if [ "$(md5sum isolation3.img | awk '{print $1}')" != "$isolation3_md5sum" ]; then serious_error fi -rm test1.img test2.img test3.img +rm isolation1.img isolation2.img isolation3.img diff --git a/tests/regressions/rhbz503169c13.sh b/tests/regressions/rhbz503169c13.sh index 1f3c1521f..44ff2d988 100755 --- a/tests/regressions/rhbz503169c13.sh +++ b/tests/regressions/rhbz503169c13.sh @@ -26,12 +26,10 @@ set -e -rm -f test1.img - -../../fish/guestfish -N fs -m /dev/sda1 <> test.out 2>> test.err <> rhbz557655.out 2>> rhbz557655.err <> test.out 2>> test.err <> rhbz557655.out 2>> rhbz557655.err < test.err -rm test.err~ + grep -Ev 'proc 200' > rhbz557655.err +rm rhbz557655.err~ -diff -u $srcdir/rhbz557655-expected.stdout test.out -diff -u $srcdir/rhbz557655-expected.stderr test.err -rm test.out test.err test1.img +diff -u $srcdir/rhbz557655-expected.stdout rhbz557655.out +diff -u $srcdir/rhbz557655-expected.stderr rhbz557655.err +rm rhbz557655.out rhbz557655.err rhbz557655.img diff --git a/tests/regressions/rhbz576879.sh b/tests/regressions/rhbz576879.sh index 05109af7d..2e803afde 100755 --- a/tests/regressions/rhbz576879.sh +++ b/tests/regressions/rhbz576879.sh @@ -22,12 +22,10 @@ set -e -rm -f test1.img - -../../fish/guestfish -N disk <&1 <<'EOF' -add test.img +add rhbz580246.img run mkfs ext2 /dev/sda mount /dev/sda / --tar-in test.tar / +-tar-in rhbz580246.tar / EOF ) -rm -f test.img test.tar +rm -f rhbz580246.img rhbz580246.tar # Check for error message in the output. if [[ ! $output =~ libguestfs:.error:.tar_in ]]; then diff --git a/tests/regressions/rhbz602997.sh b/tests/regressions/rhbz602997.sh index 401211d93..2231fe79f 100755 --- a/tests/regressions/rhbz602997.sh +++ b/tests/regressions/rhbz602997.sh @@ -24,10 +24,10 @@ export LANG=C guestfish=../../fish/guestfish -rm -f test.img test.output +rm -f test.output $guestfish > test.output < test.output </dev/null 2>&1; then @@ -43,15 +43,15 @@ fi # Use real disk images here since the code for adding /dev/null may # take shortcuts. -truncate -s 1G test1.img -truncate -s 1G test2.img -truncate -s 1G test3.img +truncate -s 1G rhbz975797-1.img +truncate -s 1G rhbz975797-2.img +truncate -s 1G rhbz975797-3.img $timeout ../../fish/guestfish <mount_local ("mp"); + my $mpdir = tempdir (CLEANUP => 1); + $g->mount_local ($mpdir); # Run the test in another process. my $pid = fork (); die "fork: $!" unless defined $pid; if ($pid == 0) { - exec ("$srcdir/run-test.pl", "--test", "mp", $test_type); + exec ("$srcdir/run-test.pl", "--test", $mpdir, $test_type); die "run-test.pl: exec failed: $!\n"; } @@ -145,8 +147,6 @@ if ($test_via eq "direct") { waitpid ($pid, 0); $errors++ if $?; - - rmdir "mp" or die "rmdir: mp: $!"; } # Finish up. diff --git a/tests/selinux/test-selinux-direct.sh b/tests/selinux/test-selinux-direct.sh index ef7ab2182..a0fdb92a8 100755 --- a/tests/selinux/test-selinux-direct.sh +++ b/tests/selinux/test-selinux-direct.sh @@ -16,6 +16,4 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -rm -rf test.img mp - exec $srcdir/run-test.pl selinux direct diff --git a/tests/selinux/test-selinux-fuse.sh b/tests/selinux/test-selinux-fuse.sh index f422b0863..6a6d01012 100755 --- a/tests/selinux/test-selinux-fuse.sh +++ b/tests/selinux/test-selinux-fuse.sh @@ -16,6 +16,4 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -rm -rf test.img mp - exec $srcdir/run-test.pl selinux fuse diff --git a/tests/selinux/test-xattrs-direct.sh b/tests/selinux/test-xattrs-direct.sh index 240d33a76..3585cdb04 100755 --- a/tests/selinux/test-xattrs-direct.sh +++ b/tests/selinux/test-xattrs-direct.sh @@ -16,6 +16,4 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -rm -rf test.img mp - exec $srcdir/run-test.pl xattrs direct diff --git a/tests/selinux/test-xattrs-fuse.sh b/tests/selinux/test-xattrs-fuse.sh index efedf0fd2..9bc5f8285 100755 --- a/tests/selinux/test-xattrs-fuse.sh +++ b/tests/selinux/test-xattrs-fuse.sh @@ -16,6 +16,4 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -rm -rf test.img mp - exec $srcdir/run-test.pl xattrs fuse