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