1#!/usr/bin/php 2<?php 3/*********************************************************** 4 Copyright (C) 2008 Hewlett-Packard Development Company, L.P. 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 version 2 as published by the Free Software Foundation. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along 16 with this program; if not, write to the Free Software Foundation, Inc., 17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 ***********************************************************/ 19 20/** 21 * textReport 22 * \brief Generate a summary report from a single test run 23 * 24 * Takes the raw results file produced by the tests, parses it and generates 25 * the summary on stdout. 26 * 27 * @param string $resultsFile -f <file> 28 * 29 * @version "$Id: textReport.php 3567 2010-10-15 01:06:58Z rrando $" 30 * 31 * Created on Aug. 25, 1009 32 */ 33 34require_once('reportClass.php'); 35require_once('testSuites.php'); 36 37 38//$res = '/home/markd/Src/fossology/tests/FossTestResults-2009-08-25-10:31:39-pm'; 39 40$options = getopt("hf:"); 41 42$Usage = "$argv[0] [-h] -f <test-results-file>\n"; 43 44if(empty($options)) { 45 print $Usage; 46 exit(1); 47} 48 49if(array_key_exists('h',$options)) { 50 print $Usage; 51 exit(0); 52} 53if(array_key_exists('f',$options)) { 54 $filePath = $options['f']; 55 if(!strlen($filePath)) { 56 print $Usage; 57 exit(1); 58 } 59 if(!file_exists($filePath)) { 60 print "Error! $filePath does not exist or is not readable\n"; 61 exit(1); 62 } 63} 64 65$tr = new TestReport($filePath); 66 67$results = $tr->parseResultsFile($filePath); 68//print "got back the following from parseResultsFile:\n"; 69//print_r($results) . "\n"; 70 71$totalPasses = 0; 72$totalFailures = 0; 73$totalExceptions = 0; 74 75/** 76 * groupByType 77 * 78 * group a failure type by suite. Used to gather up all failures or exceptions 79 * for a given test suite. 80 * 81 * @param string $suiteName the name of the test suite 82 * @param array $list an array of keys => array (the list) 83 * @return array $failType 84 * 85 */ 86function groupByType($suiteName, $list) { 87 88 if(!is_array($list)) { 89 return(FALSE); 90 } 91 if(!strlen($suiteName)) { 92 return(FALSE); 93 } 94 95 foreach($list as $nextList){ 96 foreach($nextList as $index => $resultList){ 97 $failTypeList[] = $resultList; 98 } 99 } 100 return($failType[$suiteName] = $failTypeList); 101} // groupByType 102 103function printByType($typeName, $typeList) { 104 105 if(!is_array($typeList)) { 106 return(FALSE); 107 } 108 if(!strlen($typeName)) { 109 return(FALSE); 110 } 111 112 print "The following Test Suites had $typeName:\n"; 113 foreach($typeList as $suite => $flist){ 114 //print "DB: fsuite and flist are:$fsuite,$flist\n"; 115 print "$suite:\n"; 116 $len = strlen($suite); 117 $len++; // for the ':' 118 printf("%'-{$len}s\n", ''); 119 foreach ($flist as $fline) { 120 print " $fline\n"; 121 } 122 print "\n"; 123 } 124} // printByType 125 126// summarize the results for this run. Note failures and exceptions by suite 127 128$suiteFailures = array(); 129$suiteExceptions = array(); 130$suitesRun = array(); 131 132foreach($results as $suite => $result) { 133 foreach($result as $partResult) { 134 135 // gather the unique suites that were run 136 if (array_key_exists($suite, $testSuites)) 137 { 138 if(!in_array($suite, $suitesRun)) 139 { 140 $suitesRun[] = $suite; 141 } 142 } 143 if (is_array($partResult)) { 144 if(array_key_exists('failures',$partResult)) { 145 $suiteFailures[$suite] = groupByType($suite,$partResult); 146 } 147 148 if(array_key_exists('exceptions',$partResult)) { 149 $suiteExceptions[$suite] = groupByType($suite,$partResult); 150 } 151 } 152 // it's the suite result summary, compute totals 153 else { 154 list($passes, $fail, $except) = preg_split('/:/',$partResult); 155 //print "DB: passes, fail, except are:$passes,$fail,$except\n"; 156 $totalPasses += $passes; 157 $totalFailures += $fail; 158 $totalExceptions+= $except; 159 } 160 } 161} 162// print the summary and any failures and exceptions 163 164print "Test Results for FOSSology UI Test suite\n"; 165print "Tests run on $tr->Date at $tr->Time using SVN Version $tr->Svn\n"; 166print "The tests Suites that were run are:\n"; 167printf("%'-35s\n", ''); 168 169foreach ($suitesRun as $suite) 170{ 171 if (array_key_exists($suite, $testSuites)) 172 { 173 print "$suite: $testSuites[$suite]\n\n"; 174 } 175} 176 177print "Test Results Summary\n"; 178printf("%'-37s\n", ''); 179print "Total Passes: $totalPasses\n"; 180print "Total Failures: $totalFailures\n"; 181print "Total Exceptions: $totalExceptions\n"; 182printf("%'-37s\n", ''); 183//print "The following Test Suites had Failures:\n"; 184printByType('failures', $suiteFailures); 185printf("%'-37s\n", ''); 186//print "The following Test Suites had Exceptions:\n"; 187printByType('Exceptions', $suiteExceptions); 188 189exit(0); 190?> 191