FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
FossologyFunctionalTests.php
1 #!/usr/bin/php
2 <?php
3 /***********************************************************
4  Copyright (C) 2011 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  ***********************************************************/
30 // @todo add in phpunit tests
31 
32 // ?? where do new user access tests go?
33 
34 
35 /* simpletest includes */
36 require_once '/usr/local/simpletest/unit_tester.php';
37 require_once '/usr/local/simpletest/collector.php';
38 require_once '/usr/local/simpletest/web_tester.php';
39 require_once '/usr/local/simpletest/reporter.php';
40 require_once '/usr/local/simpletest/extensions/junit_xml_reporter.php';
41 
42 require_once('common-Report.php');
43 
44 global $testSuite;
45 global $home;
46 
47 // The tests are run inside of jenkins the workspace level, so you have to cd
48 // into the sources.
49 // @todo, fix this to work in both jenkins and non-jenkins runs.
50 
51 if(chdir('fossology/tests') === FALSE)
52 {
53  echo "FATAL! cannot cd to fossology/tests\n";
54  exit(1);
55 }
56 $home = getcwd();
57 
58 $WORKSPACE = NULL;
59 
60 if(array_key_exists('WORKSPACE', $_ENV))
61 {
62  $WORKSPACE = $_ENV['WORKSPACE'];
63 }
64 
65 // this file is used for all reports
66 $xslFile = $WORKSPACE . '/fossology/tests/Reports/hudson/junit-noframes.xsl';
67 
68 // check that test config file exists and that test data exists
69 $ckConfig = exec('./checkConfig.php', $configOut, $configRtn);
70 if($configRtn != 0)
71 {
72  echo "FATAL! Cannot create test configuation file TestEnvironment.php in " .
73  "....fossology/tests\n";
74  exit(1);
75 }
76 $ckTdata = exec('./checkTestData.php', $tdOut, $tdRtn);
77 if($tdRtn != 0)
78 {
79  echo "FATAL! Errors when downloading and installing test data\n";
80  echo "Errors were:\n";print_r($tdOut) . "\n";
81  exit(1);
82 }
83 
84 // run the functional tests
85 $cmdLine = "$WORKSPACE" . '/fossology/tests/runFunctionalTests.php > '.
86  "$WORKSPACE" . '/fossology/tests/Functional-Test-Results.xml';
87 $lastFunc = exec($cmdLine, $output, $rtn);
88 
89 // Generate an html report from the junit report produced by the test run
90 
91 //echo "Generating html report\n";
92 $inFile = $WORKSPACE . '/fossology/tests/Functional-Test-Results.xml';
93 $outFile = $WORKSPACE . '/fossology/tests/Reports/FunctionalTestResults.html';
94 
95 $report = genHtml($inFile, $outFile, $xslFile);
96 if(!empty($report))
97 {
98  echo "Error: Could not generate an Upload Test HTML report." .
99  "FunctionalTestResults.html.\n";
100 }
101 // check for failures in the report
102 else
103 {
104  try {
105  $upFail = check4failures($inFile);
106  if(!is_null($upFail))
107  {
108  echo "There were errors in $inFile\n";
109  //print_r($upFail) . "\n";
110  exit(1);
111  }
112  }
113  catch (Exception $e)
114  {
115  echo "Failure: Could not check file $inFile for failures\n";
116  exit(1);
117  }
118 }
119 
120 if(chdir($home) === FALSE)
121 {
122  echo "FATAL! cannot cd to $home\n";
123  exit(1);
124 }
125 // Run the uploads (which are a set of tests in themselves)
126 $cmdLine = "$WORKSPACE" . '/fossology/tests/runUploadsTest.php > ' .
127  "$WORKSPACE" . '/fossology/tests/Uploads-Results.xml';
128 $lastFunc = exec($cmdLine, $output, $rtn);
129 if($rtn != 0)
130 {
131  echo "NOTE: Uploads did not finish in 2 hours, will not run Verify Tests\n";
132  exit(1);
133 }
134 // Generate an upload test html report from the junit report
135 //echo "Generating html report\n";
136 $inFile = $WORKSPACE . '/fossology/tests/Uploads-Results.xml';
137 $outFile = $WORKSPACE . '/fossology/tests/Reports/UploadsTestResults.html';
138 $upFail = array();
139 
140 $report = genHtml($inFile, $outFile, $xslFile);
141 if(!empty($report))
142 {
143  echo "Error: Could not generate an Upload Test HTML report " .
144  "Uploads-Results.xml.\n";
145 }
146 // check for failures in the report
147 else
148 {
149  try {
150  $urFail = check4failures($inFile);
151  if(!is_null($urFail))
152  {
153  echo "There were errors in the $inFile\n";
154  //print_r($urFail) . "\n";
155  exit(1);
156  }
157  }
158  catch (Exception $e)
159  {
160  echo "Failure: Could not check file $inFile for failures\n";
161  exit(1);
162  }
163 }
164 
165 // Run the upload verification tests
166 $xmlFile = "$WORKSPACE" . '/fossology/tests/Uploads-Test-Results.xml';
167 $cmdLine = "$WORKSPACE" . '/fossology/tests/runVerifyUploadsTests.php > ' .
168  "$xmlFile";
169 $lastFunc = exec($cmdLine, $output, $rtn);
170 
171 // remove the blank line at the top of the file
172 // @todo find out how the blank line is being generated and fix.
173 $inFile = $WORKSPACE . '/fossology/tests/Uploads-Test-Results.xml';
174 $outFile = $WORKSPACE . '/fossology/tests/Reports/VerifyTestResults.html';
175 
176 $fileString = file_get_contents($inFile,FALSE ,NULL, 1);
177 $bytes = 0;
178 $bytes = file_put_contents($inFile, $fileString);
179 if($bytes > 0)
180 {
181  // Generate an upload test html report from the junit report
182  //echo "Generating html report\n";
183 
184  $report = genHtml($inFile, $outFile, $xslFile);
185  if(!empty($report))
186  {
187  echo "Error: Could not generate an Upload Test HTML report " .
188  "VerifyTestResults.html.";
189  }
190  // check for failures in the report
191  else
192  {
193  try {
194  $verFail = check4failures($inFile);
195  if(!is_null($verFail))
196  {
197  echo "There were errors in the $inFile\n";
198  //print_r($verFail) . "\n";
199  exit(1);
200  }
201  }
202  catch (Exception $e)
203  {
204  echo "Failure: Could not check file $inFile for failures\n";
205  exit(1);
206  }
207  }
208 }
209 else
210 {
211  echo "ERROR: No data written to file:\n$cacheFile\n";
212 }
213 ?>