diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-06-13 16:24:29 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-06-13 23:17:13 +0100 |
commit | 4c828dc568eef7425db7f4a65cb1482329aad72d (patch) | |
tree | f121db100f72595d40298452da55addf1dd8bd1c | |
parent | 8735e92a1dae603f2584684ea802b0f5dc332543 (diff) | |
download | libguestfs-4c828dc568eef7425db7f4a65cb1482329aad72d.tar.gz libguestfs-4c828dc568eef7425db7f4a65cb1482329aad72d.tar.xz libguestfs-4c828dc568eef7425db7f4a65cb1482329aad72d.zip |
tests: Add a test which adds the maximum number of disks and uses them.
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | tests/disks/Makefile.am | 30 | ||||
-rwxr-xr-x | tests/disks/test-max-disks.pl | 162 |
4 files changed, 194 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 58e26924..7f2f6518 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,7 @@ SUBDIRS += tests/qemu SUBDIRS += tests/guests SUBDIRS += tests/c-api SUBDIRS += tests/protocol +SUBDIRS += tests/disks SUBDIRS += tests/lvm SUBDIRS += tests/luks SUBDIRS += tests/md diff --git a/configure.ac b/configure.ac index e17c623e..80323f82 100644 --- a/configure.ac +++ b/configure.ac @@ -1326,6 +1326,7 @@ AC_CONFIG_FILES([Makefile tests/c-api/Makefile tests/charsets/Makefile tests/data/Makefile + tests/disks/Makefile tests/extra/Makefile tests/guests/Makefile tests/luks/Makefile diff --git a/tests/disks/Makefile.am b/tests/disks/Makefile.am new file mode 100644 index 00000000..da68fd50 --- /dev/null +++ b/tests/disks/Makefile.am @@ -0,0 +1,30 @@ +# libguestfs +# Copyright (C) 2012 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +include $(top_srcdir)/subdir-rules.mk + +TESTS = \ + test-max-disks.pl + +random_val := $(shell awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null) + +TESTS_ENVIRONMENT = \ + MALLOC_PERTURB_=$(random_val) \ + $(top_builddir)/run + +EXTRA_DIST = \ + $(TESTS) diff --git a/tests/disks/test-max-disks.pl b/tests/disks/test-max-disks.pl new file mode 100755 index 00000000..3ced9713 --- /dev/null +++ b/tests/disks/test-max-disks.pl @@ -0,0 +1,162 @@ +#!/usr/bin/perl +# Copyright (C) 2012 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 adding maximum number of disks to the guest. + +use strict; +use warnings; + +use Sys::Guestfs; + +my $errors = 0; + +my $g = Sys::Guestfs->new (); + +my $max_disks = $g->max_disks (); +printf "max_disks is %d\n", $max_disks; + +# Create large number of disks. +my ($name, $i, $j); +for ($i = 0; $i < $max_disks; ++$i) { + $name = sprintf "test%d.img", $i; + #print "adding $name => /dev/sd", drive_name($i), "\n"; + + unlink $name; + open FILE, ">$name" or die "$name: $!"; + truncate FILE, 1024*1024 or die "$name: truncate: $!"; + close FILE or die "$name: $!"; + + $g->add_drive_opts ($name, format => "raw"); +} + +$g->launch (); + +# Check the disks were added. +my @devices = $g->list_devices (); +if (@devices != $max_disks) { + print STDERR "$0: incorrect number of devices returned by \$g->list_devices:\n"; + print STDERR "$0: \@devices = ", join (" ", @devices), "\n"; + $errors++; +} + +for ($i = 0; $i < $max_disks; ++$i) { + my $expected = drive_name ($i); + unless ($devices[$i] =~ m{/dev/.d$expected$}) { + print STDERR "$0: incorrect device name at index $i: ", + "expected /dev/sd$expected, but got $devices[$i]\n"; + $errors++; + } +} + +# Check device_index. +for ($i = 0; $i < $max_disks; ++$i) { + if ($i != $g->device_index ($devices[$i])) { + print STDERR "$0: incorrect device index for $devices[$i]\n"; + $errors++; + } +} + +# Put some data on each disk to check they are mountable, writable etc. +for ($i = 0; $i < $max_disks; ++$i) { + my $dev = $devices[$i]; + $g->mkmountpoint ("/mp$i"); + + # To save time in the test, add 15 partitions to the first disk + # and last disks only, and 1 partition to every other disk. Note + # that 15 partitions is the max allowed by virtio-blk. + my $part; + if ($i == 0 || $i == $max_disks-1) { + $g->part_init ($dev, "gpt"); + for ($j = 1; $j <= 14; ++$j) { + $g->part_add ($dev, "p", 64*$j, 64*$j+63); + } + $g->part_add ($dev, "p", 64*15, -64); + $part = $dev . "15"; + } + else { + $g->part_disk ($dev, "mbr"); + $part = $dev . "1"; + } + $g->mkfs ("ext2", "$part"); + $g->mount ("$part", "/mp$i"); + $g->write ("/mp$i/disk$i", "This is disk #$i.\n"); +} + +for ($i = 0; $i < $max_disks; ++$i) { + if ($g->cat ("/mp$i/disk$i") ne "This is disk #$i.\n") { + print STDERR "$0: unexpected content in file /mp$i/disk$i\n"; + $errors++; + } +} + +# Enumerate and check partition names. +my @partitions = $g->list_partitions (); +if (@partitions != $max_disks + 14*2) { + print STDERR "$0: incorrect number of partitions returned by \$g->list_partitions:\n"; + print STDERR "$0: \@partitions = ", join (" ", @partitions), "\n"; + $errors++; +} + +for ($i = 0, $j = 0; $i < $max_disks; ++$i) { + my $expected = drive_name ($i); + if ($i == 0 || $i == $max_disks-1) { + unless ($partitions[$j++] =~ m{/dev/.d${expected}1$} && + $partitions[$j++] =~ m{/dev/.d${expected}2$} && + $partitions[$j++] =~ m{/dev/.d${expected}3$} && + $partitions[$j++] =~ m{/dev/.d${expected}4$} && + $partitions[$j++] =~ m{/dev/.d${expected}5$} && + $partitions[$j++] =~ m{/dev/.d${expected}6$} && + $partitions[$j++] =~ m{/dev/.d${expected}7$} && + $partitions[$j++] =~ m{/dev/.d${expected}8$} && + $partitions[$j++] =~ m{/dev/.d${expected}9$} && + $partitions[$j++] =~ m{/dev/.d${expected}10$} && + $partitions[$j++] =~ m{/dev/.d${expected}11$} && + $partitions[$j++] =~ m{/dev/.d${expected}12$} && + $partitions[$j++] =~ m{/dev/.d${expected}13$} && + $partitions[$j++] =~ m{/dev/.d${expected}14$} && + $partitions[$j++] =~ m{/dev/.d${expected}15$}) { + print STDERR "$0: incorrect partition name at index $i\n"; + $errors++; + } + } else { + unless ($partitions[$j++] =~ m{/dev/.d${expected}1$}) { + print STDERR "$0: incorrect partition name at index $i\n"; + $errors++; + } + } +} + +$g->umount_all (); +$g->close (); + +for ($i = 0; $i < $max_disks; ++$i) { + $name = sprintf "test%d.img", $i; + unlink $name; +} + +exit ($errors == 0 ? 0 : 1); + +sub drive_name +{ + my $index = shift; + my $prefix = ""; + if ($index >= 26) { + $prefix = drive_name ($index/26 - 1); + } + $index %= 26; + return $prefix . chr (97 + $index); +} |