From af327273622391d515958a292689c7d3df79abfc Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 19 Dec 2014 18:41:21 +0200 Subject: Android: Check XML output and optionally stop on fail. The failures will be printed in red color. Use -f param to stop on fail. Change-Id: Ife58f9264a9ac859d739842c6d1359acde807ce7 Reviewed-by: Eskil Abrahamsen Blomfeldt --- tests/auto/android/runtests_androiddeployqt.pl | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/auto/android') diff --git a/tests/auto/android/runtests_androiddeployqt.pl b/tests/auto/android/runtests_androiddeployqt.pl index fe67257b4b..8e9376da35 100755 --- a/tests/auto/android/runtests_androiddeployqt.pl +++ b/tests/auto/android/runtests_androiddeployqt.pl @@ -40,6 +40,8 @@ use File::Temp 'tempdir'; use File::Path 'remove_tree'; use Getopt::Long; use Pod::Usage; +use XML::Simple; +use Term::ANSIColor; ### default options my @stack = cwd; @@ -53,6 +55,7 @@ my $testsubset = ""; my $man = 0; my $help = 0; my $make_clean = 0; +my $stop_on_fail = 0; my $time_out=400; my $android_toolchain_version = "4.8"; my $host_arch = "linux-x86"; @@ -89,6 +92,7 @@ GetOptions('h|help' => \$help , 'strip=s' => \$strip_tool , 'readelf=s' => \$readelf_tool , 'testcase=s' => \$testcase + , 'f|fail' => sub { $stop_on_fail = 1 } , 'silent' => sub { $silent = 1 } , 'ci' => sub { $ci_use = 1 } , 'uninstall' => sub { $uninstall = 1 } @@ -311,6 +315,37 @@ if ($output =~ m/.*\[ro.build.version.sdk\]: \[(\d+)\]/) $sdk_api=9 if ($sdk_api>9); } +sub checkXMLOutput +{ + print color 'bold red'; + my $fileName = shift; + my $XMLOutput = eval { XMLin($fileName, ForceArray => 1) }; + if (!defined($XMLOutput)) { + print "Can't parse the $fileName file, probably the test crased.\n"; + print color 'reset'; + die "Stopping\n" if $stop_on_fail; + return; + } + my $testName = $XMLOutput->{name}; + my $fail = 0; + while (my($node_key, $node_valule) = each (%{$XMLOutput})) { + next if $node_key ne "TestFunction"; + while (my($function_key, $function_valule) = each (%{$node_valule})) { + while (my($test_key, $test_valule) = each (%{$function_valule})) { + next if $test_key ne "Incident"; + for my $incident (@{$test_valule}) { + if ($incident->{type} ne "pass") { + print "test $testName::$function_key failed $incident->{file}:$incident->{line}\n"; + $fail = 1; + } + } + } + } + } + print color 'reset'; + die "Stopping\n" if $stop_on_fail and $fail; +} + sub startTest { my $testName = shift; @@ -352,6 +387,7 @@ sub startTest sleep(3); system("$adb_tool $device_serial pull /data/data/$packageName/output.xml $output_dir/$output_file.xml") if ($get_xml); + system("$adb_tool $device_serial pull /data/data/$packageName/output.txt $output_dir/$output_file.txt") if ($get_txt); if ($get_txt){ print "Tesresults for $packageName:\n"; @@ -359,6 +395,8 @@ sub startTest print_output("$output_dir/$output_file.txt", $packageName, $insignificance); } system("$adb_tool $device_serial uninstall $packageName") if ($uninstall); + + checkXMLOutput("$output_dir/$output_file.xml") if ($get_xml); return 1; } @@ -439,6 +477,9 @@ runtests.pl [options] =head1 OPTIONS =over 8 +=item B<-f --fail> + +Stop the script when test fails. Default 0 =item B<-s --serial = serial> -- cgit v1.2.3