[libvirt] [PATCH] libvirt-tck: prefer kvm if multiple domain types exist

When matching capabilities of a guest, if multiple domain types exist (for example, 'qemu' and 'kvm') the order in which they are returned can change. To avoid unpredictable test results, this patch prefers kvm if that domain type exists. If not, the behavior matches what existed before, and the first domain type is returned. --- lib/Sys/Virt/TCK.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm index b2c16e7..56547c6 100644 --- a/lib/Sys/Virt/TCK.pm +++ b/lib/Sys/Virt/TCK.pm @@ -502,7 +502,17 @@ sub match_kernel { my @domains = $caps->guest_domain_types($i); next unless int(@domains); - return ($domains[0], + # Prefer kvm if multiple domain types are returned + my $domain; + if (int(@domains) gt 1) { + for (my $j = 0 ; $j < int(@domains) ; $j++) { + $domain = "kvm" if ($domains[$j] eq "kvm"); + } + } + # If kvm was not found, default to the first one + $domain = $domains[0] if (!defined($domain)); + + return ($domain, $caps->guest_domain_emulator($i, $domains[0]), $caps->guest_domain_loader($i, $domains[0])); } -- 1.8.4.5

On 07/03/14 01:39, Mike Latimer wrote:
When matching capabilities of a guest, if multiple domain types exist (for example, 'qemu' and 'kvm') the order in which they are returned can change.
To avoid unpredictable test results, this patch prefers kvm if that domain type exists. If not, the behavior matches what existed before, and the first domain type is returned.
--- lib/Sys/Virt/TCK.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm index b2c16e7..56547c6 100644 --- a/lib/Sys/Virt/TCK.pm +++ b/lib/Sys/Virt/TCK.pm @@ -502,7 +502,17 @@ sub match_kernel { my @domains = $caps->guest_domain_types($i); next unless int(@domains);
- return ($domains[0], + # Prefer kvm if multiple domain types are returned + my $domain; + if (int(@domains) gt 1) { + for (my $j = 0 ; $j < int(@domains) ; $j++) {
I would use "grep" instead of iterating over all the elements: $domain = "kvm" if (grep /^kvm$/, @domains);
+ $domain = "kvm" if ($domains[$j] eq "kvm"); + } + } + # If kvm was not found, default to the first one + $domain = $domains[0] if (!defined($domain)); + + return ($domain, $caps->guest_domain_emulator($i, $domains[0]),
Indention problem. Osier

On Friday, March 07, 2014 05:55:34 PM Osier Yang wrote:
- return ($domains[0], + # Prefer kvm if multiple domain types are returned + my $domain; + if (int(@domains) gt 1) { + for (my $j = 0 ; $j < int(@domains) ; $j++) {
I would use "grep" instead of iterating over all the elements:
$domain = "kvm" if (grep /^kvm$/, @domains);
Good point. I'll fix the code.
+ $domain = "kvm" if ($domains[$j] eq "kvm"); + } + } + # If kvm was not found, default to the first one + $domain = $domains[0] if (!defined($domain)); + + return ($domain,
$caps->guest_domain_emulator($i, $domains[0]),
Indention problem.
This was due to a tab -vs- space issue. I'll match the existing syntax as well in the patch I'll resubmit. -Mike
participants (2)
-
Mike Latimer
-
Osier Yang