summaryrefslogtreecommitdiffstats
path: root/pick-guests.pl.in
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-11-12 17:54:31 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-11-13 15:26:29 +0000
commit3636c5fcff69e7a5a5afa126a597883db4c781bb (patch)
tree0d1406c121f1fb684b54f0d33b564246774bb826 /pick-guests.pl.in
parentc4a3ea066be9823d4572b57fd05940345904b826 (diff)
downloadlibguestfs-3636c5fcff69e7a5a5afa126a597883db4c781bb.tar.gz
libguestfs-3636c5fcff69e7a5a5afa126a597883db4c781bb.tar.xz
libguestfs-3636c5fcff69e7a5a5afa126a597883db4c781bb.zip
tests: Replace 'make extra-tests' with individual tests.
'make extra-tests' was a monolithic set of tests that did all sorts of things: valgrind, tests over local guests, tests with upstream qemu, tests with upstream libvirt, tests with the appliance attach method. This made it hard to perform individual tests, eg. just valgrind testing. It was also hard to maintain because the tests were not located in the same directories as the programs and sometimes duplicated tests that were run elsewhere. This commit splits up 'make extra-tests' into 5 separate targets: make check-valgrind # run a subset of tests under valgrind make check-valgrind-local-guests # test under valgrind with local guests make check-with-appliance # test with attach-method == appliance make check-with-upstream-qemu # test with an alternate/upstream qemu make check-with-upstream-libvirt # test with an alternate/upstream libvirt (You can also still run 'make extra-tests' which is now simply a rule that runs the above 5 targets in order). This replaces everything that was in the tests/extra directory, so that has now gone.
Diffstat (limited to 'pick-guests.pl.in')
-rwxr-xr-xpick-guests.pl.in62
1 files changed, 62 insertions, 0 deletions
diff --git a/pick-guests.pl.in b/pick-guests.pl.in
new file mode 100755
index 00000000..1ec2c2aa
--- /dev/null
+++ b/pick-guests.pl.in
@@ -0,0 +1,62 @@
+#!/usr/bin/perl -w
+# @configure_input@
+# Copyright (C) 2009-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.
+
+# Pick guests at random on the local machine which are accessible.
+# This is used by 'make check-valgrind-local-guests'.
+
+use strict;
+
+use Sys::Guestfs;
+use Sys::Virt;
+use List::Util qw(shuffle);
+
+die "$0 nr-guests\n" unless @ARGV == 1;
+my $n = $ARGV[0];
+
+my $vmm = Sys::Virt->new (uri => '@libvirt_ro_uri@');
+my @domains = ($vmm->list_domains, $vmm->list_defined_domains);
+
+# Only guests which are accessible by the current (non-root) user. On
+# the machine where I run these tests, I have added my user account to
+# the 'disk' group, so that most guests are accessible. However
+# because libvirt changes the permissions on guest disks, a guest
+# which has been run on the machine becomes inaccessible, hence the
+# need for this code - RWMJ.
+my @accessible;
+foreach my $dom (@domains) {
+ my $name = $dom->get_name;
+ my $g = Sys::Guestfs->new;
+ eval {
+ $g->add_domain ($name, readonly => 1,
+ libvirturi => '@libvirt_ro_uri@');
+ # $g->launch (); - don't actually need to do this
+ };
+ push @accessible, $name unless $@;
+}
+
+# Randomize the list of guests.
+@accessible = shuffle (@accessible);
+
+$n = @accessible if @accessible < $n;
+
+# Return the first n guests from the list.
+for (my $i = 0; $i < $n; ++$i) {
+ print " " if $i > 0;
+ print $accessible[$i];
+}
+print "\n";