common/tools/ats/update_brag_status.pl
changeset 1090 46b3578a07ad
parent 1040 f1f85b34a96f
child 1115 abbcac685ab1
equal deleted inserted replaced
1089:9c363aa36549 1090:46b3578a07ad
    17 use Getopt::Long;
    17 use Getopt::Long;
    18 use XML::Simple;
    18 use XML::Simple;
    19 use Tie::File;
    19 use Tie::File;
    20 
    20 
    21 my $brag_file;
    21 my $brag_file;
    22 my $ats_report;
    22 my $ats3_report;
       
    23 my $ats4_report;
    23 my $test_report;
    24 my $test_report;
    24 my $help;
    25 my $help;
    25 my $line;
    26 my $line;
    26 my $auto_tests_total;
    27 my $auto_tests_total;
    27 my $auto_tests_passed;
    28 my $auto_tests_passed;
    44 sub usage($);
    45 sub usage($);
    45 sub help();
    46 sub help();
    46 sub usage_error();
    47 sub usage_error();
    47 
    48 
    48 my %optmap = (  'brag-file' => \$brag_file,
    49 my %optmap = (  'brag-file' => \$brag_file,
    49 			    'ats-report' => \$ats_report,
    50 			    'ats3-report' => \$ats3_report,
       
    51 				'ats4-report' => \$ats4_report,
    50 			    'test-report' => \$test_report,
    52 			    'test-report' => \$test_report,
    51 				'help' => \$help);
    53 				'help' => \$help);
    52 
    54 
    53 GetOptions(\%optmap,
    55 GetOptions(\%optmap,
    54           'brag-file=s',
    56           'brag-file=s',
    55           'ats-report=s',
    57           'ats3-report=s',
       
    58           'ats4-report=s',
    56           'test-report=s',
    59           'test-report=s',
    57 		  'help!') 
    60 		  'help!') 
    58           or usage_error();
    61           or usage_error();
    59 
    62 
    60 if ($help) {
    63 if ($help) {
    62 }
    65 }
    63 
    66 
    64 # --brag-file is mandatory.
    67 # --brag-file is mandatory.
    65 usage_error(), unless (defined($brag_file));
    68 usage_error(), unless (defined($brag_file));
    66 
    69 
    67 # --ats-report is mandatory.
    70 # --ats3-report/ats4-report is mandatory.
    68 usage_error(), unless (defined($ats_report));
    71 usage_error(), unless ((defined($ats3_report)) || (defined($ats4_report)));
    69 
    72 
    70 open (FILE, "<$ats_report") or die ("Couldn't open $ats_report for reading: $!\n");
    73 if (defined($ats3_report)) { # Get ATS3 Smoketest results.
    71 my $read_flag = -1;
    74 	open (FILE, "<$ats3_report") or die ("Couldn't open $ats3_report for reading: $!\n");
    72 print "Reading $ats_report... ";
    75 	my $read_flag = -1;
    73 while ($line = <FILE>) {
    76 	print "Reading $ats3_report... ";
    74 	chomp $line;
    77 	while ($line = <FILE>) {
    75 	if ($read_flag >= 0) { $read_flag++ }
    78 		chomp $line;
    76 	if ($read_flag == 1) { # Get Total number of tests.
    79 		if ($read_flag >= 0) { $read_flag++ }
    77 		$auto_tests_total = $line;
    80 		if ($read_flag == 1) { # Get Total number of tests.
    78 		# Remove td tags.
    81 			$auto_tests_total = $line;
    79 		$auto_tests_total =~ s/^.*\">//;
    82 			# Remove td tags.
    80 		$auto_tests_total =~ s/<.*//;
    83 			$auto_tests_total =~ s/^.*\">//;
    81 	}
    84 			$auto_tests_total =~ s/<.*//;
    82 	if ($read_flag == 4) { # Get number of Passed tests.
    85 		}
    83 		($auto_tests_passed) = split /\//,$line;
    86 		if ($read_flag == 4) { # Get number of Passed tests.
    84 		$auto_tests_passed =~ s/^.*\">//; # Remove opening td tag.
    87 			($auto_tests_passed) = split /\//,$line;
    85 	}
    88 			$auto_tests_passed =~ s/^.*\">//; # Remove opening td tag.
    86 	if ($read_flag == 5) { # Get number of Failed tests.
    89 		}
    87 		($auto_tests_failed) = split /\//,$line;
    90 		if ($read_flag == 5) { # Get number of Failed tests.
    88 		$auto_tests_failed =~ s/^.*\">//; # Remove opening td tag.
    91 			($auto_tests_failed) = split /\//,$line;
    89 
    92 			$auto_tests_failed =~ s/^.*\">//; # Remove opening td tag.
    90 	}
    93 		}
    91 	if ($read_flag == 7) { # Get number of Not run tests.
    94 		if ($read_flag == 7) { # Get number of Not run tests.
    92 		($auto_tests_notrun) = split /\//,$line;
    95 			($auto_tests_notrun) = split /\//,$line;
    93 		$auto_tests_notrun =~ s/^.*\">//; # Remove opening td tag.
    96 			$auto_tests_notrun =~ s/^.*\">//; # Remove opening td tag.
    94 	}
    97 		}
    95 	if ($line eq "<td class=\"tableData\">Nested tests<\/td>") { # Set flag for reading results.
    98 		if ($line eq "<td class=\"tableData\">Nested tests<\/td>") { # Set flag for reading results.
    96 		$read_flag = 0;
    99 			$read_flag = 0;
    97 	}
   100 		}
    98 	if (($line eq "<\/tr>") && ($read_flag >= 0)) { # Exit loop.
   101 		if (($line eq "<\/tr>") && ($read_flag >= 0)) { # Exit loop.
    99 		last;
   102 			last;
   100 	};
   103 		};
   101 }
   104 	}
   102 close FILE;
   105 	close FILE;
       
   106 }
       
   107 if (defined($ats4_report)) { # Get ATS4 Smoketest results.
       
   108 	$auto_tests_total = 0;
       
   109 	$auto_tests_passed = 0;
       
   110 	$auto_tests_failed = 0;
       
   111 	$auto_tests_notrun = 0;
       
   112 	open (FILE, "<$ats4_report") or die ("Couldn't open $ats4_report for reading: $!\n");
       
   113 	my $read_flag = -1;
       
   114 	print "Reading $ats4_report... ";
       
   115 	while ($line = <FILE>) {
       
   116 		chomp $line;
       
   117 		if ($read_flag >= 0) { $read_flag++ }
       
   118 		if ($read_flag == 3) { # Get status.
       
   119 			$auto_tests_total++;
       
   120 			if ($line =~ "PASSED") { $auto_tests_passed++ }
       
   121 			if ($line =~ "FAILED") { $auto_tests_failed++ }
       
   122 			if (($line =~ "SKIPPED") || ($line =~ "NOT_AVAILABLE")) { $auto_tests_notrun++ }
       
   123 			# Re-set flag.
       
   124 			$read_flag = -1;
       
   125 		}
       
   126 		if ($line eq "<result type=\"TestCaseResult\">") { # Set flag for reading results.
       
   127 			$read_flag = 0;
       
   128 		}
       
   129 	}
       
   130 	close FILE;
       
   131 }
   103 print "complete\n";
   132 print "complete\n";
   104 print "Total number of tests: $auto_tests_total\n";
   133 print "Total number of tests: $auto_tests_total\n";
   105 print "Passed tests: $auto_tests_passed\n";
   134 print "Passed tests: $auto_tests_passed\n";
   106 print "Failed tests: $auto_tests_failed\n";
   135 print "Failed tests: $auto_tests_failed\n";
   107 print "Not run tests: $auto_tests_notrun\n";
   136 print "Not run tests: $auto_tests_notrun\n";
   108 
   137 
   109 # Define detailshref attribute.
   138 # Define detailshref attribute.
   110 $temp_path = $brag_file;
   139 $temp_path = $brag_file;
   111 $temp_path =~ s/\\/\//g; # Replace \ with /
   140 $temp_path =~ s/\\/\//g; # Replace \ with /
   112 $temp_path =~ s/\/summary\/.*//;
   141 $temp_path =~ s/\/summary\/.*//;
   113 $detailshref = $ats_report;
   142 if (defined($ats3_report)) { $detailshref = $ats3_report };
       
   143 if (defined($ats4_report)) { $detailshref = $ats4_report };
   114 $detailshref =~ s/\\/\//g; # Replace \ with /
   144 $detailshref =~ s/\\/\//g; # Replace \ with /
   115 $detailshref =~ s/($temp_path)/../;
   145 $detailshref =~ s/($temp_path)/../;
   116 
   146 
   117 if (defined($test_report)) { # Get manual Smoketest results.
   147 if (defined($test_report)) { # Get manual Smoketest results.
   118 	print "Parsing " . $test_report . "... ";
   148 	print "Parsing " . $test_report . "... ";
   225     my $fh = $error == 0 ? *STDOUT : *STDERR;
   255     my $fh = $error == 0 ? *STDOUT : *STDERR;
   226     print $fh "update_brag_status.pl\n" .
   256     print $fh "update_brag_status.pl\n" .
   227             "Specify the BRAG xml file and ATS report\n" .
   257             "Specify the BRAG xml file and ATS report\n" .
   228             "synopsis:\n" .
   258             "synopsis:\n" .
   229             "  update_brag_status.pl --help\n" .
   259             "  update_brag_status.pl --help\n" .
   230             "  update_brag_status.pl [--brag-file=XML_FILE] [--ats-report=HTML_REPORT] [--test-report=XML_REPORT] \n" .
   260             "  update_brag_status.pl [--brag-file=XML_FILE] [--ats3-report=HTML_REPORT] [--ats4-report=SIMPLELOGGER_REPORT] [--test-report=XML_REPORT] \n" .
   231             "options:\n" .
   261             "options:\n" .
   232             "  --help                        Display this help and exit.\n" .
   262             "  --help                            Display this help and exit.\n" .
   233             "  --brag-file=XML_FILE          XML_FILE is the full path to the file containing BRAG summary.\n" .
   263             "  --brag-file=XML_FILE              XML_FILE is the full path to the file containing BRAG summary.\n" .
   234             "  --ats-report=HTML_REPORT      HTML_REPORT is the full path to the ATS report.\n" .
   264             "  --ats3-report=HTML_REPORT         HTML_REPORT is the full path to the ATS3 report.\n" .
   235             "  --test-report=XML_REPORT      XML_REPORT is the name of the test report for manually executed tests.\n" .
   265             "  --ats4-report=SIMPLELOGGER_REPORT SIMPLELOGGER_REPORT is the full path to the ATS4 report.\n" .
   236 			"                                If not specified only automated tests results will be taken into account.\n";
   266             "  --test-report=XML_REPORT          XML_REPORT is the name of the test report for manually executed tests.\n" .
       
   267 			"                                    If not specified only automated tests results will be taken into account.\n";
   237     exit $error;            
   268     exit $error;            
   238 }
   269 }
   239 
   270 
   240 sub help()
   271 sub help()
   241 {
   272 {