diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-12-22 12:15:06 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-12-22 15:48:11 +0000 |
commit | cd077b8229731e292798f34dd56892cbfa6f1e0e (patch) | |
tree | d7c2fb6e9d8c34b8f73152c297f243eee74dc450 /tests | |
parent | c649817586e5b4df53b251d1290422f5ef046045 (diff) | |
download | libguestfs-cd077b8229731e292798f34dd56892cbfa6f1e0e.tar.gz libguestfs-cd077b8229731e292798f34dd56892cbfa6f1e0e.tar.xz libguestfs-cd077b8229731e292798f34dd56892cbfa6f1e0e.zip |
tests: Split images -> tests/data + tests/guests
Diffstat (limited to 'tests')
39 files changed, 910 insertions, 19 deletions
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am new file mode 100644 index 00000000..43f40a19 --- /dev/null +++ b/tests/data/Makefile.am @@ -0,0 +1,152 @@ +# libguestfs test images +# 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 $(top_srcdir)/subdir-rules.mk + +# Old RHEL 5 autoconf doesn't have builddir. +builddir ?= $(top_builddir)/tests/data + +EXTRA_DIST = \ + helloworld.tar \ + helloworld.tar.gz \ + helloworld.tar.xz \ + mbr-ext2-empty.img.gz \ + empty known-1 known-2 known-3 known-4 known-5 \ + bin-i586-dynamic \ + bin-sparc-dynamic \ + bin-win32.exe \ + bin-win64.exe \ + bin-x86_64-dynamic \ + lib-i586.so \ + lib-sparc.so \ + lib-win32.dll \ + lib-win64.dll \ + lib-x86_64.so \ + test-grep.txt + +noinst_DATA = test.iso + +CLEANFILES = \ + test.iso test.sqsh \ + 100kallzeroes 100kallnewlines 100kallspaces 100krandom 10klines \ + initrd + +images_files_src = \ + $(srcdir)/helloworld.tar \ + $(srcdir)/helloworld.tar.gz \ + $(srcdir)/helloworld.tar.xz \ + $(srcdir)/empty \ + $(srcdir)/known-1 \ + $(srcdir)/known-2 \ + $(srcdir)/known-3 \ + $(srcdir)/known-4 \ + $(srcdir)/known-5 \ + $(srcdir)/bin-i586-dynamic \ + $(srcdir)/bin-sparc-dynamic \ + $(srcdir)/bin-win32.exe \ + $(srcdir)/bin-win64.exe \ + $(srcdir)/bin-x86_64-dynamic \ + $(srcdir)/lib-i586.so \ + $(srcdir)/lib-sparc.so \ + $(srcdir)/lib-win32.dll \ + $(srcdir)/lib-win64.dll \ + $(srcdir)/lib-x86_64.so \ + $(srcdir)/test-grep.txt + +images_files_build = \ + $(builddir)/100kallzeroes \ + $(builddir)/100kallnewlines \ + $(builddir)/100kallspaces \ + $(builddir)/100krandom \ + $(builddir)/10klines \ + $(builddir)/abssymlink \ + $(builddir)/hello.b64 \ + $(builddir)/initrd \ + $(builddir)/initrd-x86_64.img \ + $(builddir)/initrd-x86_64.img.gz \ + $(builddir)/test-grep.txt.gz + +images_files = $(images_files_src) $(images_files_build) + +test.iso: $(images_files) + rm -f $@ $@-t + mkdir -p directory + $(GENISOIMAGE) -J -r -graft-points \ + -o $@-t \ + $(images_files) /directory=directory + rmdir directory + mv $@-t $@ + +$(builddir)/100kallzeroes: + rm -f $@ $@-t + dd if=/dev/zero of=$@-t bs=1024 count=100 + mv $@-t $@ + +$(builddir)/100kallnewlines: $(builddir)/100kallzeroes + rm -f $@ $@-t + tr '\0' '\n' < $< > $@-t + mv $@-t $@ + +$(builddir)/100kallspaces: $(builddir)/100kallzeroes + rm -f $@ $@-t + tr '\0' ' ' < $< > $@-t + mv $@-t $@ + +$(builddir)/100krandom: + rm -f $@ $@-t + dd if=/dev/urandom of=$@-t bs=1024 count=100 + mv $@-t $@ + +$(builddir)/10klines: + rm -f $@ $@-t + i=0; \ + while [ $$i -lt 10000 ]; do \ + echo "$${i}abcdefghijklmnopqrstuvwxyz"; \ + i=$$(($$i+1)); \ + done > $@-t + mv $@-t $@ + +$(builddir)/abssymlink: + ln -sf /10klines $@ + +$(builddir)/hello.b64: + echo "hello" | base64 > $@ + +$(builddir)/initrd: empty known-1 known-2 known-3 known-4 known-5 + rm -f $@ $@-t + for f in $^; do echo $$f; done | cpio -o -H newc | gzip --best > $@-t + mv $@-t $@ + +# Create a dummy initrd with a single file called 'bin/nash' which +# is used to test the Sys::Guestfs::Lib::file_architecture function. +$(builddir)/initrd-x86_64.img: bin-x86_64-dynamic + rm -rf bin $@ $@-t + mkdir bin + cp $< bin/nash + echo bin/nash | cpio -o -H newc > $@-t + mv $@-t $@ + rm -rf bin $@-t + +$(builddir)/initrd-x86_64.img.gz: initrd-x86_64.img + rm -f $@ $@-t + gzip --best -c $< > $@-t + mv $@-t $@ + +$(builddir)/test-grep.txt.gz: test-grep.txt + rm -f $@ $@-t + gzip --best -c $< > $@-t + mv $@-t $@ diff --git a/tests/data/README-binfiles b/tests/data/README-binfiles new file mode 100644 index 00000000..f99fc847 --- /dev/null +++ b/tests/data/README-binfiles @@ -0,0 +1,13 @@ +The bin-* and lib-* files are used for testing the +Sys::Guestfs::Lib::file_architecture API. + +The bin-* files are generated from empty source files (ie. +"main(){}") on the respective architectures. + +The lib-* files are generated from a (really) empty source file called +lib.c which is linked into a library using gcc -shared on the +respective architectures. + +If you are concerned that these binary files "lack source" then you +can just remove them, but you may need to patch out tests in the perl/ +directory. diff --git a/tests/data/bin-i586-dynamic b/tests/data/bin-i586-dynamic Binary files differnew file mode 100755 index 00000000..4f770633 --- /dev/null +++ b/tests/data/bin-i586-dynamic diff --git a/tests/data/bin-sparc-dynamic b/tests/data/bin-sparc-dynamic Binary files differnew file mode 100755 index 00000000..138839af --- /dev/null +++ b/tests/data/bin-sparc-dynamic diff --git a/tests/data/bin-win32.exe b/tests/data/bin-win32.exe Binary files differnew file mode 100755 index 00000000..db6d5758 --- /dev/null +++ b/tests/data/bin-win32.exe diff --git a/tests/data/bin-win64.exe b/tests/data/bin-win64.exe Binary files differnew file mode 100755 index 00000000..98bddc02 --- /dev/null +++ b/tests/data/bin-win64.exe diff --git a/tests/data/bin-x86_64-dynamic b/tests/data/bin-x86_64-dynamic Binary files differnew file mode 100755 index 00000000..033ac759 --- /dev/null +++ b/tests/data/bin-x86_64-dynamic diff --git a/tests/data/empty b/tests/data/empty new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/data/empty diff --git a/tests/data/helloworld.tar b/tests/data/helloworld.tar Binary files differnew file mode 100644 index 00000000..191a31b2 --- /dev/null +++ b/tests/data/helloworld.tar diff --git a/tests/data/helloworld.tar.gz b/tests/data/helloworld.tar.gz Binary files differnew file mode 100644 index 00000000..9d36cc97 --- /dev/null +++ b/tests/data/helloworld.tar.gz diff --git a/tests/data/helloworld.tar.xz b/tests/data/helloworld.tar.xz Binary files differnew file mode 100644 index 00000000..661f1a20 --- /dev/null +++ b/tests/data/helloworld.tar.xz diff --git a/tests/data/known-1 b/tests/data/known-1 new file mode 100644 index 00000000..8baef1b4 --- /dev/null +++ b/tests/data/known-1 @@ -0,0 +1 @@ +abc diff --git a/tests/data/known-2 b/tests/data/known-2 new file mode 100644 index 00000000..0373d933 --- /dev/null +++ b/tests/data/known-2 @@ -0,0 +1 @@ +abcdef diff --git a/tests/data/known-3 b/tests/data/known-3 new file mode 100644 index 00000000..3ac370d7 --- /dev/null +++ b/tests/data/known-3 @@ -0,0 +1,27 @@ + I WANDERED lonely as a cloud + That floats on high o'er vales and hills, + When all at once I saw a crowd, + A host, of golden daffodils; + Beside the lake, beneath the trees, + Fluttering and dancing in the breeze. + + Continuous as the stars that shine + And twinkle on the milky way, + They stretched in never-ending line + Along the margin of a bay: + Ten thousand saw I at a glance, + Tossing their heads in sprightly dance. + + The waves beside them danced; but they + Out-did the sparkling waves in glee: + A poet could not but be gay, + In such a jocund company: + I gazed--and gazed--but little thought + What wealth the show to me had brought: + + For oft, when on my couch I lie + In vacant or in pensive mood, + They flash upon that inward eye + Which is the bliss of solitude; + And then my heart with pleasure fills, + And dances with the daffodils. diff --git a/tests/data/known-4 b/tests/data/known-4 new file mode 100644 index 00000000..f5bc74f6 --- /dev/null +++ b/tests/data/known-4 @@ -0,0 +1,3 @@ +abc +def +ghi
\ No newline at end of file diff --git a/tests/data/known-5 b/tests/data/known-5 new file mode 100644 index 00000000..3122d943 --- /dev/null +++ b/tests/data/known-5 @@ -0,0 +1,2 @@ +abcdefghi +jklmnopqr
\ No newline at end of file diff --git a/tests/data/lib-i586.so b/tests/data/lib-i586.so Binary files differnew file mode 100755 index 00000000..e82023a1 --- /dev/null +++ b/tests/data/lib-i586.so diff --git a/tests/data/lib-sparc.so b/tests/data/lib-sparc.so Binary files differnew file mode 100755 index 00000000..7feec75e --- /dev/null +++ b/tests/data/lib-sparc.so diff --git a/tests/data/lib-win32.dll b/tests/data/lib-win32.dll Binary files differnew file mode 100755 index 00000000..e1a2d2e6 --- /dev/null +++ b/tests/data/lib-win32.dll diff --git a/tests/data/lib-win64.dll b/tests/data/lib-win64.dll Binary files differnew file mode 100755 index 00000000..ca94485c --- /dev/null +++ b/tests/data/lib-win64.dll diff --git a/tests/data/lib-x86_64.so b/tests/data/lib-x86_64.so Binary files differnew file mode 100755 index 00000000..8cee4d20 --- /dev/null +++ b/tests/data/lib-x86_64.so diff --git a/tests/data/mbr-ext2-empty.img.gz b/tests/data/mbr-ext2-empty.img.gz Binary files differnew file mode 100644 index 00000000..5438c1dd --- /dev/null +++ b/tests/data/mbr-ext2-empty.img.gz diff --git a/tests/data/test-grep.txt b/tests/data/test-grep.txt new file mode 100644 index 00000000..1d24b9a0 --- /dev/null +++ b/tests/data/test-grep.txt @@ -0,0 +1,7 @@ +abc +def +ghi +ghi + +abc123 +ABC diff --git a/tests/extra/Makefile.am b/tests/extra/Makefile.am index 7d1cc22e..582fa555 100644 --- a/tests/extra/Makefile.am +++ b/tests/extra/Makefile.am @@ -104,22 +104,22 @@ test-tools-null: # Invocations of tools on internal images shouldn't leak memory. test-tools-internal: - $(RUN_VG) ../../cat/virt-cat -a ../images/fedora.img /etc/fstab >/dev/null - $(RUN_VG) ../../cat/virt-filesystems -a ../images/fedora.img >/dev/null - $(RUN_VG) ../../cat/virt-filesystems -a ../images/fedora.img --all --long -h --uuid >/dev/null - $(RUN_VG) ../../cat/virt-ls -a ../images/fedora.img / >/dev/null - $(RUN_VG) ../../cat/virt-ls -a ../images/fedora.img -l / >/dev/null - $(RUN_VG) ../../cat/virt-ls -a ../images/fedora.img -R / >/dev/null - $(RUN_VG) ../../cat/virt-ls -a ../images/fedora.img -lR / >/dev/null - $(RUN_VG) ../../df/virt-df -a ../images/fedora.img >/dev/null - $(RUN_VG) ../../df/virt-df -a ../images/fedora.img -h >/dev/null - $(RUN_VG) ../../fish/guestfish -a ../images/fedora.img run - $(RUN_VG) ../../fish/guestfish -a ../images/fedora.img -i exit - $(RUN_VG) ../../inspector/virt-inspector -a ../images/debian.img >/dev/null - $(RUN_VG) ../../inspector/virt-inspector -a ../images/fedora.img >/dev/null - $(RUN_VG) ../../inspector/virt-inspector -a ../images/fedora-md1.img -a ../images/fedora-md2.img >/dev/null - $(RUN_VG) ../../inspector/virt-inspector -a ../images/ubuntu.img >/dev/null - $(RUN_VG) ../../inspector/virt-inspector -a ../images/windows.img >/dev/null + $(RUN_VG) ../../cat/virt-cat -a ../guests/fedora.img /etc/fstab >/dev/null + $(RUN_VG) ../../cat/virt-filesystems -a ../guests/fedora.img >/dev/null + $(RUN_VG) ../../cat/virt-filesystems -a ../guests/fedora.img --all --long -h --uuid >/dev/null + $(RUN_VG) ../../cat/virt-ls -a ../guests/fedora.img / >/dev/null + $(RUN_VG) ../../cat/virt-ls -a ../guests/fedora.img -l / >/dev/null + $(RUN_VG) ../../cat/virt-ls -a ../guests/fedora.img -R / >/dev/null + $(RUN_VG) ../../cat/virt-ls -a ../guests/fedora.img -lR / >/dev/null + $(RUN_VG) ../../df/virt-df -a ../guests/fedora.img >/dev/null + $(RUN_VG) ../../df/virt-df -a ../guests/fedora.img -h >/dev/null + $(RUN_VG) ../../fish/guestfish -a ../guests/fedora.img run + $(RUN_VG) ../../fish/guestfish -a ../guests/fedora.img -i exit + $(RUN_VG) ../../inspector/virt-inspector -a ../guests/debian.img >/dev/null + $(RUN_VG) ../../inspector/virt-inspector -a ../guests/fedora.img >/dev/null + $(RUN_VG) ../../inspector/virt-inspector -a ../guests/fedora-md1.img -a ../guests/fedora-md2.img >/dev/null + $(RUN_VG) ../../inspector/virt-inspector -a ../guests/ubuntu.img >/dev/null + $(RUN_VG) ../../inspector/virt-inspector -a ../guests/windows.img >/dev/null # Invocations of tools on real images shouldn't leak memory. test-df-real: diff --git a/tests/guests/Makefile.am b/tests/guests/Makefile.am new file mode 100644 index 00000000..ee28034a --- /dev/null +++ b/tests/guests/Makefile.am @@ -0,0 +1,106 @@ +# libguestfs test images +# 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 $(top_srcdir)/subdir-rules.mk + +# Old RHEL 5 autoconf doesn't have builddir. +builddir ?= $(top_builddir)/tests/guests + +EXTRA_DIST = \ + guest-aux/make-debian-img.sh \ + guest-aux/debian-packages \ + guest-aux/make-fedora-img.pl \ + guest-aux/fedora-name.db.txt \ + guest-aux/fedora-name.db \ + guest-aux/fedora-packages.db.txt \ + guest-aux/fedora-packages.db \ + guest-aux/make-ubuntu-img.sh \ + guest-aux/make-windows-img.sh \ + guest-aux/windows-software \ + guest-aux/windows-software.reg \ + guest-aux/windows-system \ + guest-aux/windows-system.reg \ + guest-aux/minimal-hive + +# This is 'check_DATA' because we don't need it until 'make check' +# time and we need the tools we have built in order to make it. +check_DATA = debian.img fedora.img fedora-md1.img fedora-md2.img ubuntu.img windows.img + +CLEANFILES = $(check_DATA) + +# Make a (dummy) Fedora image. +fedora.img: guest-aux/make-fedora-img.pl \ + guest-aux/fedora-name.db \ + guest-aux/fedora-packages.db + TMPDIR=$(top_builddir) \ + SRCDIR=$(srcdir) \ + LAYOUT=partitions \ + ../../run $< + +# Make a (dummy) Fedora image using md devices +fedora-md1.img fedora-md2.img: guest-aux/make-fedora-img.pl \ + guest-aux/fedora-name.db \ + guest-aux/fedora-packages.db + TMPDIR=$(top_builddir) \ + SRCDIR=$(srcdir) \ + LAYOUT=partitions-md \ + ../../run $< + +guest-aux/fedora-name.db: guest-aux/fedora-name.db.txt + rm -f $@ $@-t + mkdir -p guest-aux + $(DB_LOAD) $@-t < $< + mv $@-t $@ + +guest-aux/fedora-packages.db: guest-aux/fedora-packages.db.txt + rm -f $@ $@-t + mkdir -p guest-aux + $(DB_LOAD) $@-t < $< + mv $@-t $@ + +# Make a (dummy) Debian image. +debian.img: guest-aux/make-debian-img.sh + TMPDIR=$(top_builddir) \ + SRCDIR=$(srcdir) \ + bash $< + +# Make a (dummy) Ubuntu image. +ubuntu.img: guest-aux/make-ubuntu-img.sh + TMPDIR=$(top_builddir) \ + SRCDIR=$(srcdir) \ + bash $< + +# Make a (dummy) Windows image. +windows.img: guest-aux/make-windows-img.sh \ + guest-aux/windows-software guest-aux/windows-system + TMPDIR=$(top_builddir) \ + SRCDIR=$(srcdir) \ + bash $< + +# Since users might not have the tools needed to create this, we +# also distribute these files. +guest-aux/windows-software: guest-aux/windows-software.reg + rm -f $@ $@-t + cp guest-aux/minimal-hive $@-t + hivexregedit --merge $@-t --prefix 'HKEY_LOCAL_MACHINE\SOFTWARE' $< + mv $@-t $@ + +guest-aux/windows-system: guest-aux/windows-system.reg + rm -f $@ $@-t + cp guest-aux/minimal-hive $@-t + hivexregedit --merge $@-t --prefix 'HKEY_LOCAL_MACHINE\SYSTEM' $< + mv $@-t $@ diff --git a/tests/guests/guest-aux/debian-packages b/tests/guests/guest-aux/debian-packages new file mode 100644 index 00000000..38afc975 --- /dev/null +++ b/tests/guests/guest-aux/debian-packages @@ -0,0 +1,48 @@ +Package: test1 +Status: installed ok +Priority: optional +Section: libs +Installed-Size: 123 +Architecture: amd64 +Source: test +Version: 1.2.3-1 +Config-Version: 1.2.3-1 +Depends: libc6 (>= 2.3) +Description: this is a test package + This is a test package. + . + Don't confuse it with a real package. +Homepage: http://libguestfs.org/ + +Package: test2 +Status: installed ok +Priority: optional +Section: libs +Installed-Size: 123 +Architecture: amd64 +Source: test +Version: 1.2.3-1 +Config-Version: 1.2.3-1 +Depends: libc6 (>= 2.3) +Description: this is a test package + This is a test package. + . + Don't confuse it with a real package. +Homepage: http://libguestfs.org/ + +Package: test3 +Status: installed ok +Priority: optional +Section: libs +Installed-Size: 123 +Architecture: amd64 +Source: test +Version: 1.2.3-1 +Config-Version: 1.2.3-1 +Depends: libc6 (>= 2.3) +Description: this is a test package + This is a test package. + . + Don't confuse it with a real package. +Homepage: http://libguestfs.org/ + diff --git a/tests/guests/guest-aux/fedora-name.db.txt b/tests/guests/guest-aux/fedora-name.db.txt new file mode 100644 index 00000000..105b0fec --- /dev/null +++ b/tests/guests/guest-aux/fedora-name.db.txt @@ -0,0 +1,13 @@ +VERSION=3 +format=print +type=hash +h_nelem=3 +db_pagesize=4096 +HEADER=END + test1 + !\0b\00\00\00\00\00\00 + test2 + 7\0b\00\00\00\00\00\00 + test3 + \dd\0c\00\00\00\00\00\00 +DATA=END diff --git a/tests/guests/guest-aux/fedora-packages.db.txt b/tests/guests/guest-aux/fedora-packages.db.txt new file mode 100644 index 00000000..3939d6bd --- /dev/null +++ b/tests/guests/guest-aux/fedora-packages.db.txt @@ -0,0 +1,13 @@ +VERSION=3 +format=print +type=hash +h_nelem=3 +db_pagesize=4096 +HEADER=END + !\0b\00\00 + \00test1\001.0\001.fc14\00 + 7\0b\00\00 + \00test2\002.0\002.fc14\00 + \dd\0c\00\00 + \00test3\003.0\003.fc14\00 +DATA=END diff --git a/tests/guests/guest-aux/make-debian-img.sh b/tests/guests/guest-aux/make-debian-img.sh new file mode 100755 index 00000000..b936f817 --- /dev/null +++ b/tests/guests/guest-aux/make-debian-img.sh @@ -0,0 +1,92 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2010 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Make a Debian image which is enough to fool the inspection heuristics. + +export LANG=C +set -e + +# fstab file. +cat > fstab.tmp <<EOF +LABEL=BOOT /boot ext2 default 0 0 +/dev/debian/root / ext2 default 0 0 +/dev/debian/usr /usr ext2 default 1 2 +/dev/debian/var /var ext2 default 1 2 +/dev/debian/home /home ext2 default 1 2 +EOF + +# Create a disk image. +../../run ../../fish/guestfish <<EOF +sparse debian.img.tmp 512M +run + +# Format the disk. +part-init /dev/sda mbr +part-add /dev/sda p 64 524287 +part-add /dev/sda p 524288 -64 + +pvcreate /dev/sda2 +vgcreate debian /dev/sda2 +lvcreate root debian 64 +lvcreate usr debian 32 +lvcreate var debian 32 +lvcreate home debian 32 + +# Phony /boot filesystem. +mkfs-opts ext2 /dev/sda1 blocksize:4096 +set-e2label /dev/sda1 BOOT +set-e2uuid /dev/sda1 01234567-0123-0123-0123-012345678901 + +# Phony root and other filesystems. +mkfs-opts ext2 /dev/debian/root blocksize:4096 +set-e2uuid /dev/debian/root 01234567-0123-0123-0123-012345678902 +mkfs-opts ext2 /dev/debian/usr blocksize:4096 +set-e2uuid /dev/debian/usr 01234567-0123-0123-0123-012345678903 +mkfs-opts ext2 /dev/debian/var blocksize:4096 +set-e2uuid /dev/debian/var 01234567-0123-0123-0123-012345678904 +mkfs-opts ext2 /dev/debian/home blocksize:4096 +set-e2uuid /dev/debian/home 01234567-0123-0123-0123-012345678905 + +# Enough to fool inspection API. +mount-options "" /dev/debian/root / +mkdir /boot +mount-options "" /dev/sda1 /boot +mkdir /usr +mount-options "" /dev/debian/usr /usr +mkdir /var +mount-options "" /dev/debian/var /var +mkdir /home +mount-options "" /dev/debian/home /home +mkdir /bin +mkdir /etc +mkdir-p /var/lib/dpkg + +upload fstab.tmp /etc/fstab +write /etc/debian_version "5.0.1" +write /etc/hostname "debian.invalid" + +upload ${SRCDIR}/guest-aux/debian-packages /var/lib/dpkg/status + +upload ${SRCDIR}/../data/bin-x86_64-dynamic /bin/ls + +mkdir /boot/grub +touch /boot/grub/grub.conf +EOF + +rm fstab.tmp +mv debian.img.tmp debian.img diff --git a/tests/guests/guest-aux/make-fedora-img.pl b/tests/guests/guest-aux/make-fedora-img.pl new file mode 100755 index 00000000..eb0cf770 --- /dev/null +++ b/tests/guests/guest-aux/make-fedora-img.pl @@ -0,0 +1,195 @@ +#!/usr/bin/perl +# 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. + +# Make a standard test image which is used by all the tools test +# scripts. This test image is supposed to look like a Fedora +# installation, or at least enough of one to fool the inspection API +# heuristics. + +use strict; +use warnings; + +use Sys::Guestfs; +use File::Temp; + +my @images; +my $g = Sys::Guestfs->new(); + +my $bootdev; +my $rootdev; + +foreach ('LAYOUT', 'SRCDIR') { + defined($ENV{$_}) or die "Missing environment variable: $_"; +} + +if ($ENV{LAYOUT} eq 'partitions') { + push (@images, 'fedora.img.tmp'); + + open(my $fstab, '>', 'fstab.tmp') or die; + print $fstab <<EOF; +LABEL=BOOT /boot ext2 default 0 0 +LABEL=ROOT / ext2 default 0 0 +EOF + close($fstab) or die; + + $bootdev = '/dev/sda1'; + $rootdev = '/dev/sda2'; + + open(my $img, '>', 'fedora.img.tmp') or die; + truncate($img, 512*1024*1024) or die; + close($img) or die; + + $g->add_drive('fedora.img.tmp'); + $g->launch(); + + $g->part_init('/dev/sda', 'mbr'); + $g->part_add('/dev/sda', 'p', 64, 524287); + $g->part_add('/dev/sda', 'p', 524288, -64); +} + +elsif ($ENV{LAYOUT} eq 'partitions-md') { + push(@images, 'fedora-md1.img.tmp', 'fedora-md2.img.tmp'); + + open(my $fstab, '>', 'fstab.tmp') or die; + print $fstab <<EOF; +/dev/md0 /boot ext2 default 0 0 +LABEL=ROOT / ext2 default 0 0 +EOF + close($fstab) or die; + + $bootdev = '/dev/md/boot'; + $rootdev = '/dev/md/root'; + + foreach my $img (@images) { + open(my $fh, '>', $img) or die; + truncate($fh, 512*1024*1024) or die; + close($fh) or die; + + $g->add_drive($img); + } + + $g->launch(); + + # Format the disks. + foreach ('a', 'b') { + $g->part_init("/dev/sd$_", 'mbr'); + $g->part_add("/dev/sd$_", 'p', 64, 524287); + $g->part_add("/dev/sd$_", 'p', 524288, -64); + } + + $g->md_create('boot', ['/dev/sda1', '/dev/sdb1']); + $g->md_create('root', ['/dev/sda2', '/dev/sdb2']); + + open(my $mdadm, '>', 'mdadm.tmp') or die; + print $mdadm <<EOF; +MAILADDR root +AUTO +imsm +1.x -all +EOF + + my $i = 0; + foreach ('boot', 'root') { + my %detail = $g->md_detail("/dev/md/$_"); + print $mdadm "ARRAY /dev/md$i level=raid1 num-devices=2 UUID=", + $detail{uuid}, "\n"; + $i++; + } + + close($mdadm) or die; +} + +else { + print STDERR "$0: Unknown LAYOUT: ",$ENV{LAYOUT},"\n"; + exit 1; +} + +$g->pvcreate($rootdev); +$g->vgcreate('VG', [$rootdev]); +$g->lvcreate('Root', 'VG', 32); +$g->lvcreate('LV1', 'VG', 32); +$g->lvcreate('LV2', 'VG', 32); +$g->lvcreate('LV3', 'VG', 64); + +# Phony /boot filesystem +$g->mkfs_opts('ext2', $bootdev, blocksize => 4096); +$g->set_e2label($bootdev, 'BOOT'); +$g->set_e2uuid($bootdev, '01234567-0123-0123-0123-012345678901'); + +# Phony root filesystem. +$g->mkfs_opts('ext2', '/dev/VG/Root', blocksize => 4096); +$g->set_e2label('/dev/VG/Root', 'ROOT'); +$g->set_e2uuid('/dev/VG/Root', '01234567-0123-0123-0123-012345678902'); + +# Enough to fool inspection API. +$g->mount_options('', '/dev/VG/Root', '/'); +$g->mkdir('/boot'); +$g->mount_options('', $bootdev, '/boot'); +$g->mkdir('/bin'); +$g->mkdir('/etc'); +$g->mkdir('/etc/sysconfig'); +$g->mkdir('/usr'); +$g->mkdir_p('/var/lib/rpm'); + +$g->upload('fstab.tmp', '/etc/fstab'); +$g->write('/etc/redhat-release', 'Fedora release 14 (Phony)'); +$g->write('/etc/fedora-release', 'Fedora release 14 (Phony)'); +$g->write('/etc/sysconfig/network', 'HOSTNAME=fedora.invalid'); + +if (-f 'mdadm.tmp') { + $g->upload('mdadm.tmp', '/etc/mdadm.conf'); + unlink('mdadm.tmp') or die; +} + +$g->upload('guest-aux/fedora-name.db', '/var/lib/rpm/Name'); +$g->upload('guest-aux/fedora-packages.db', '/var/lib/rpm/Packages'); + +$g->upload($ENV{SRCDIR}.'/../data/bin-x86_64-dynamic', '/bin/ls'); + +$g->mkdir('/boot/grub'); +$g->touch('/boot/grub/grub.conf'); + +# Test files. +$g->write('/etc/test1', 'abcdefg'); +$g->write('/etc/test2', ''); +$g->write('/etc/test3', +'a +b +c +d +e +f +'); +$g->write('/bin/test1', 'abcdefg'); +$g->write('/bin/test2', 'zxcvbnm'); +$g->write('/bin/test3', '1234567'); +$g->write('/bin/test4', ''); +$g->ln_s('/bin/test1', '/bin/test5'); +$g->mkfifo(0777, '/bin/test6'); +$g->mknod(0777, 10, 10, '/bin/test7'); + +# Other filesystems. +# Note that these should be empty, for testing virt-df. +$g->mkfs_opts('ext2', '/dev/VG/LV1', blocksize => 4096); +$g->mkfs_opts('ext2', '/dev/VG/LV2', blocksize => 1024); +$g->mkfs_opts('ext2', '/dev/VG/LV3', blocksize => 2048); + +# Cleanup +unlink('fstab.tmp') or die; +foreach my $img (@images) { + $img =~ /^(.*)\.tmp$/ or die; + rename($img, $1) or die; +} diff --git a/tests/guests/guest-aux/make-ubuntu-img.sh b/tests/guests/guest-aux/make-ubuntu-img.sh new file mode 100755 index 00000000..e55c7908 --- /dev/null +++ b/tests/guests/guest-aux/make-ubuntu-img.sh @@ -0,0 +1,81 @@ +#!/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. + +# Make an Ubuntu image which is enough to fool the inspection heuristics. + +export LANG=C +set -e + +# fstab file. +cat > fstab.tmp <<EOF +LABEL=BOOT /boot ext2 default 0 0 +/dev/sda2 / ext2 default 1 2 +EOF + +# lsb-release file. +cat > release.tmp <<'EOF' +DISTRIB_ID=Ubuntu +DISTRIB_RELEASE=10.10 +DISTRIB_CODENAME=maverick +DISTRIB_DESCRIPTION="Ubuntu 10.10 (Phony Pharaoh)" +EOF + +# Create a disk image. +../../run ../../fish/guestfish <<EOF +sparse ubuntu.img.tmp 512M +run + +# Format the disk. +part-init /dev/sda mbr +part-add /dev/sda p 64 524287 +part-add /dev/sda p 524288 -64 + +# Phony /boot filesystem. +mkfs-opts ext2 /dev/sda1 blocksize:4096 +set-e2label /dev/sda1 BOOT +set-e2uuid /dev/sda1 01234567-0123-0123-0123-012345678901 + +# Phony root filesystem (Ubuntu doesn't use LVM by default). +mkfs-opts ext2 /dev/sda2 blocksize:4096 +set-e2uuid /dev/sda2 01234567-0123-0123-0123-012345678902 + +# Enough to fool inspection API. +mount-options "" /dev/sda2 / +mkdir /boot +mount-options "" /dev/sda1 /boot +mkdir /bin +mkdir /etc +mkdir /home +mkdir /usr +mkdir-p /var/lib/dpkg + +upload fstab.tmp /etc/fstab +write /etc/debian_version "5.0.1" +upload release.tmp /etc/lsb-release +write /etc/hostname "ubuntu.invalid" + +upload ${SRCDIR}/guest-aux/debian-packages /var/lib/dpkg/status + +upload ${SRCDIR}/../data/bin-x86_64-dynamic /bin/ls + +mkdir /boot/grub +touch /boot/grub/grub.conf +EOF + +rm fstab.tmp release.tmp +mv ubuntu.img.tmp ubuntu.img diff --git a/tests/guests/guest-aux/make-windows-img.sh b/tests/guests/guest-aux/make-windows-img.sh new file mode 100755 index 00000000..74546302 --- /dev/null +++ b/tests/guests/guest-aux/make-windows-img.sh @@ -0,0 +1,71 @@ +#!/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. + +# Make a Windows image which is enough to fool the inspection heuristics. + +export LANG=C +set -e + +# If the currently compiled libguestfs doesn't support +# ntfs-3g/ntfsprogs then we cannot create a Windows phony image. +# Nothing actually uses windows.img in the standard build so we can +# just 'touch' it and emit a warning. +if ! ../../run ../../fish/guestfish -a /dev/null run : available "ntfs3g ntfsprogs"; then + echo "***" + echo "Warning: cannot create windows.img because there is no NTFS" + echo "support in this build of libguestfs. Just touching the output" + echo "file instead." + echo "***" + touch windows.img + exit 0 +fi + +# Create a disk image. +../../run ../../fish/guestfish <<EOF +sparse windows.img.tmp 512M +run + +# Format the disk. +part-init /dev/sda mbr +part-add /dev/sda p 64 524287 +part-add /dev/sda p 524288 -64 + +# Disk ID. +pwrite-device /dev/sda "1234" 0x01b8 + +# Phony boot loader filesystem. +mkfs ntfs /dev/sda1 + +# Phony root filesystem. +mkfs ntfs /dev/sda2 + +# Enough to fool inspection API. +mount-options "" /dev/sda2 / +mkdir-p /Windows/System32/Config + +upload ${SRCDIR}/guest-aux/windows-software /Windows/System32/Config/SOFTWARE +upload ${SRCDIR}/guest-aux/windows-system /Windows/System32/Config/SYSTEM + +upload ${SRCDIR}/../data/bin-win32.exe /Windows/System32/cmd.exe + +mkdir "/Program Files" +touch /autoexec.bat + +EOF + +mv windows.img.tmp windows.img diff --git a/tests/guests/guest-aux/minimal-hive b/tests/guests/guest-aux/minimal-hive Binary files differnew file mode 100755 index 00000000..3f4ee58c --- /dev/null +++ b/tests/guests/guest-aux/minimal-hive diff --git a/tests/guests/guest-aux/windows-software b/tests/guests/guest-aux/windows-software Binary files differnew file mode 100755 index 00000000..d936ea88 --- /dev/null +++ b/tests/guests/guest-aux/windows-software diff --git a/tests/guests/guest-aux/windows-software.reg b/tests/guests/guest-aux/windows-software.reg new file mode 100644 index 00000000..2c0f41ce --- /dev/null +++ b/tests/guests/guest-aux/windows-software.reg @@ -0,0 +1,49 @@ +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft] + +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT] + +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion] +"ProductName"=str(1):"Microsoft Windows 7 Phony Edition" +"CurrentVersion"=str(1):"6.1" +"InstallationType"=str(1):"Client" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows] + +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion] + +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall] + +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\test1] +"DisplayName"=str(1):"Test1 is not real software" +"URLInfoAbout"=str(1):"http://libguestfs.org/" +"DisplayVersion"=str(1):"1.2.3" +"VersionMajor"=dword:00000001 +"VersionMinor"=dword:00000002 + +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\test2] +"DisplayName"=str(1):"Test2 is not real software" +"URLInfoAbout"=str(1):"http://libguestfs.org/" +"DisplayVersion"=str(1):"1.2.4" +"Comments"=str(1):"Longer description about phony test2 software" + +[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\test3] +"DisplayName"=str(1):"Test3 is not real software" +"DisplayVersion"=str(1):"1.2.5" +"Publisher"=str(1):"Red Hat Inc." +"InstallLocation"=str(1):"C:\\Program Files\\Red Hat\\test3" + +[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node] + +[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft] + +[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft\Windows] + +[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft\Windows\CurrentVersion] + +[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft\Windows\CurrentVersion\Uninstall] + +[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft\Windows\CurrentVersion\Uninstall\test4] +"DisplayName"=str(1):"Test4 is not real software" +"DisplayVersion"=str(1):"1.2.6" +"Publisher"=str(1):"Red Hat Inc." +"Comments"=str(1):"WOW6432node is where 32 bit emulated apps are installed on 64 bit Windows" diff --git a/tests/guests/guest-aux/windows-system b/tests/guests/guest-aux/windows-system Binary files differnew file mode 100755 index 00000000..3a232142 --- /dev/null +++ b/tests/guests/guest-aux/windows-system diff --git a/tests/guests/guest-aux/windows-system.reg b/tests/guests/guest-aux/windows-system.reg new file mode 100644 index 00000000..5478d2de --- /dev/null +++ b/tests/guests/guest-aux/windows-system.reg @@ -0,0 +1,17 @@ +[HKEY_LOCAL_MACHINE\SYSTEM\Select] +"Current"=dword:00000001 +"Default"=dword:00000001 +"Failed"=dword:00000000 +"LastKnownGood"=dword:00000002 + +[HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices] +"\\DosDevices\\C:"=hex(3):31,32,33,34,00,00,00,10,00,00,00,00 + +[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001] + +[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services] + +[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip] + +[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters] +"Hostname"=str(1):"windows.invalid" diff --git a/tests/md/test-inspect-fstab-md.sh b/tests/md/test-inspect-fstab-md.sh index 2a6cb6a9..1804d33e 100755 --- a/tests/md/test-inspect-fstab-md.sh +++ b/tests/md/test-inspect-fstab-md.sh @@ -35,8 +35,8 @@ 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 +cp ../guests/fedora-md1.img test1.img +cp ../guests/fedora-md2.img test2.img $guestfish -i test[12].img <<'EOF' | sort > test.output exists /boot/grub/grub.conf diff --git a/tests/md/test-inspect-fstab.sh b/tests/md/test-inspect-fstab.sh index 72a11fad..576ce031 100755 --- a/tests/md/test-inspect-fstab.sh +++ b/tests/md/test-inspect-fstab.sh @@ -28,7 +28,7 @@ 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 +cp ../guests/fedora.img test1.img cat <<'EOF' > test.fstab /dev/VG/Root / ext2 default 0 0 |