FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testFOSSology.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2010 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
39 require_once ('TestEnvironment.php');
40 require_once ('testClasses/check4jobs.php');
41 require_once ('mailTo.php');
42 
43 $usage = NULL;
44 $usage.= "Usage: $argv[0] [-l path] {[-a] | [-b] | [-h] | [-s] | [-v -l]}\n";
45 $usage.= "-a: Run all FOSSology Test Suites\n" .
46  "-b: Run the basic test suite. This runs the SiteTests and any Tests " .
47  "that don't depend on uploads\n" .
48  "-h: Display Usage\n" .
49  "-l path: test results file path \n" .
50  "-s: Run SiteTests only (this is a lightweight suite)\n" .
51  "-v -l: Run the Verify Tests. These tests require uploads to be uploaded first." .
52  " See the test documentation for details\n" .
53  " You must specify a log file when using -v, best to use the same log file" .
54  " that was used in a previous run for example -a -l foo, then -v -l foo when" .
55  " all the files have been uploaded with -a.";
56 
57 global $logFile;
58 global $logFileName;
59 global $LF;
60 global $mailTo;
61 
62 $SiteTests = '../ui/tests/SiteTests';
63 $BasicTests = '../ui/tests/BasicTests';
64 $UserTests = '../ui/tests/Users';
65 $EmailTests = '../ui/tests/EmailNotification';
66 $CopyRight = 'copyright';
67 $nomos = 'nomos';
68 $pkgAgent = 'pkgagent';
69 $VerifyTests = '../ui/tests/VerifyTests';
70 
71 /*
72  * process parameters and run the appropriate test suite,
73  * redirect outputs to log file
74  */
75 $errors = 0;
76 $date = date('Y-m-d');
77 $time = date('h:i:s-a');
78 $defaultLog = "/FossTestResults-$date-$time";
79 $myname = $argv[0];
80 $Home = getcwd();
81 $pid = getmypid();
82 
83 $options = getopt('abehl:sv');
84 if (empty($options)) {
85  print "$usage\n";
86  exit(0);
87 }
88 if (array_key_exists('h', $options)) {
89  print "$usage\n";
90  exit(0);
91 }
92 if (array_key_exists('l', $options)) {
93  $logFile = $options['l'];
94  $logFileName = basename($logFile);
95 }
96 else {
97  // Default Log file, use full path to it
98  $cwd = getcwd();
99  $logFile = $cwd . $defaultLog;
100  //$logFileName = $defaultLog;
101  $logFileName = basename($logFile);
102 }
109 function _runTestEnvSetup() {
110 
111  global $date;
112  global $myname;
113  global $Home;
114  global $logFile;
115  global $LF;
116 
117  $errors = 0;
118  if (chdir($Home) === FALSE) {
119  LogAndPrint($LF, "_runTestEnvSetup ERROR: can't cd to $Home\n");
120  }
121  LogAndPrint($LF, "\n");
122  $UpLast = exec("./uploadTestData.php >> $logFile 2>&1", $dummy, $SUrtn);
123  LogAndPrint($LF, "\n");
124  $UpLast = exec("./fo-runTests.php -l uploadCopyrightData.php -n 'Upload copyright data'>> $logFile 2>&1", $dummy, $Copyrtn);
125  $AALast = exec("./fo-runTests.php -l AgentAddData.php -n 'Agent Add Uploads'>> $logFile 2>&1", $dummy, $AArtn);
126  LogAndPrint($LF, "\n");
127  // need to check the return on the setup and report accordingly.
128  if ($SUrtn != 0) {
129  LogAndPrint($LF, "ERROR when running uploadTestData.php\n");
130  foreach($dummy as $ErrorLine) {
131  print "$ErrorLine\n";
132  }
133  $errors++;
134  }
135  if ($Copyrtn != 0) {
136  LogAndPrint($LF, "ERROR when running uploadCopyrightData.php\n");
137  foreach($dummy as $ErrorLine) {
138  print "$ErrorLine\n";
139  }
140  $errors++;
141  }
142  if ($AArtn != 0) {
143  LogAndPrint($LF, "ERROR when running AgentAddData.php\n");
144  foreach($dummy as $ErrorLine) {
145  print "$ErrorLine\n";
146  }
147  $errors++;
148  }
149  if ($errors != 0) {
150  print "Warning! There were errors in the test setup, one or more test may fail as a result\n";
151  }
152 } //_runTestEnvSetup
153 
154 function getSvnVer() {
155  return (`svnversion`);
156 }
157 
158 function LogAndPrint($FileHandle, $message) {
159  if (empty($message)) {
160  return (FALSE);
161  }
162  if (empty($FileHandle)) {
163  return (FALSE);
164  }
165  if (-1 == fwrite($FileHandle, $message)) {
166  print $message; // if we don't do this nothing will print
167  flush();
168  return (FALSE);
169  }
170  print $message;
171  flush();
172  return (TRUE);
173 }
174 
175 $Svn = getSvnVer();
176 
177 /************* ALL Tests **********************************************/
178 if (array_key_exists("a", $options)) {
179  $LF = fopen($logFile, 'w') or die("can't open $logFile $phperrormsg\n");
180  print "Using log file:$logFile\n";
181  if (chdir($Home) === FALSE) {
182  LogAndPrint($LF, "All Tests ERROR: can't cd to $Home\n");
183  }
184  LogAndPrint($LF, "Running All Tests on: $date at $time using subversion version: $Svn\n");
185 
186  $Cleanup = "This program does not remove the testing folders in case" .
187  " there was a failure and it needs to be looked at. Run " .
188  "the script/test runTestCleanup.php to clean things up.\n";
189 
190  print wordwrap($Cleanup);
191 
192  /*
193  * Create the test users first or nothing will work should this be somewhere else like
194  * in install?
195  */
196  $cmd = "./fo-runTests.php createUIUsers.php -n 'Create UI Users Test' >> $logFile 2>&1";
197  $UIusers = exec($cmd, $dummy, $UsrRtn);
198  if ($UsrRtn != 0) {
199  LogAndPrint($LF, "ERROR when running createUIUsers.php: return code:$UsrRtn\n");
200  LogAndPrint($LF, "last line returned is:$UIusers\n");
201  foreach($dummy as $ErrorLine) {
202  LogAndPrint($LF,"$ErrorLine\n");
203  }
204  LogAndPrint($LF, "The Email Notification tests mail fail as a result\n");
205  }
206  $ctdLast = exec('./checkTestData.php', $ctdOut, $ctdRtn);
207  if($ctdRtn != 0)
208  {
209  LogAndPrint($LF, "ERROR when running check4TestData, see previous errors\n");
210  }
211 
212  if (chdir($SiteTests) === FALSE) {
213  LogandPrint($LF, "ALL Tests ERROR: can't cd to $SiteTests\n");
214  }
215  //print "testFOSS: path is:$_ENV[PATH]\n";
216 
217  $SiteLast = exec("./runSiteTests.php >> $logFile 2>&1", $dummy, $Srtn);
218  LogAndPrint($LF, "\n");
219  if (chdir('../BasicTests') === FALSE) {
220  LogAndPrint($LF, "ALL Tests ERROR: can't cd to $BasicTests\n");
221  }
222  $BasicLast = exec("./runBasicTests.php >> $logFile 2>&1", $dummy, $Brtn);
223  LogAndPrint($LF, "\n");
224 
225  /*
226  * run user tests, create UI users then run Email Notification tests
227  */
228  if (chdir('../Users') === FALSE) {
229  LogAndPrint($LF, "ALL Tests ERROR: can't cd to $UserTests\n");
230  }
231  $testList = "addUserTest.php dupUserTest.php noEmailUserTest.php userEditAnyTest.php";
232  $uCmnd = "/usr/local/bin/fo-runTests -l $testList -n 'User Tests' >> $logFile 2>&1";
233  $UsersLast = exec($uCmnd, $dummy, $Urtn);
234  LogAndPrint($LF, "\n");
235 
236  if (chdir($Home) === FALSE) {
237  $cUInoHome = "All Tests ERROR: can't cd to $Home\n";
238  LogAndPrint($LF, $cUInoHome);
239  }
240 
241  if (chdir($EmailTests) === FALSE) {
242  LogAndPrint($LF, "ALL Tests ERROR: can't cd to $EmailTests\n");
243  }
244 
245  $EmailLast = exec("fo-runTests -l \"`ls`\" -n 'Email Tests' >> $logFile 2>&1", $dummy, $ENrtn);
246  LogAndPrint($LF, "\n");
247 
248  if (chdir($Home) === FALSE) {
249  $cUInoHome = "All Tests ERROR: can't cd to $Home\n";
250  LogAndPrint($LF, $cUInoHome);
251  }
252 
253  if (chdir($pkgAgent) === FALSE) {
254  LogAndPrint($LF, "ALL Tests ERROR: can't cd to $pkgAgent\n");
255  }
256  $PkgLast = exec("fo-runTests -l \"`ls cli*`\" -n 'Package Agent Tests'" .
257  " >> $logFile 2>&1", $dummy, $Pkgrtn);
258  LogAndPrint($LF, "\n");
259 
260  /*
261  * The verify tests require that uploads be done first.
262  */
263  _runTestEnvSetup();
264 
265  // wait for uploads to finish
266  if (chdir($Home) === FALSE) {
267  $UInoHome = "All Tests ERROR: can't cd to $Home\n";
268  LogAndPrint($LF, $UInoHome);
269  }
270  print "Waiting for jobs to finish...\n";
271  $last = exec('./wait4jobs.php', $tossme, $jobsDone);
272  foreach($tossme as $line){
273  print "$line\n";
274  }
275  print "testFOSSology: jobsDone is:$jobsDone\n";
276  if ($jobsDone != 0) {
277  print "ERROR! jobs are not finished after two hours, not running" .
278  "verify tests, please investigate and run verify tests by hand\n";
279  print "Monitor the job Q and when the setup jobs are done, run:\n";
280  print "$myname -v -l $logFile\n";
281  exit(1);
282  }
283  if ($jobsDone == 0) {
284  if (chdir($Home) === FALSE) {
285  $cUInoHome = "All Tests ERROR: can't cd to $Home\n";
286  LogAndPrint($LF, $cUInoHome);
287  }
288  if (chdir($nomos) === FALSE) {
289  LogAndPrint($LF, "ALL Tests ERROR: can't cd to $nomos\n");
290  }
291  // Nomos functional tests
292  $nomosTests = array('ckZendTest.php', 'verifyRedHatTest.php');
293  foreach($nomosTests as $test)
294  {
295  $last = exec("fo-runTests -l $test -n 'Nomos Tests' >> $logFile 2>&1", $dummy, $rtn);
296  LogAndPrint($LF, "\n");
297  }
298 
299  LogAndPrint($LF, "Starting cli1Test\n" );
300  $last = exec('phpunit ./cli1Test.php', $punitOut, $puRtn);
301  if($puRtn != 0)
302  {
303  LogAndPrint($LF, "cli1Test Failed\n");
304  LogAndPrint($LF, $punitOut);
305  LogAndPrint($LF, "\n");
306  }
307  else
308  {
309  LogAndPrint($LF, "cli1Test Passed\n");
310  LogAndPrint($LF, "$last\n");
311  }
312 
313  if (chdir($Home) === FALSE) {
314  $cUInoHome = "All Tests ERROR: can't cd to $Home\n";
315  LogAndPrint($LF, $cUInoHome);
316  }
317  // Copyright tests
318  if (chdir($CopyRight) === FALSE) {
319  LogAndPrint($LF, "ALL Tests ERROR: can't cd to $CopyRight\n");
320  }
321  $CopyLast = exec("fo-runTests -l \"`ls verify*`\" -n 'CopyRight Tests' >> $logFile 2>&1", $dummy, $CRrtn);
322  LogAndPrint($LF, "\n");
323 
324  // phpunit tests
325  $last = exec('phpunit cliParamsTest.php', $punitOut, $puRtn);
326  if($puRtn != 0)
327  {
328  LogAndPrint($LF, "cli1Test Failed\n");
329  LogAndPrint($LF, $punitOut);
330  LogAndPrint($LF, "\n");
331  }
332  else
333  {
334  LogAndPrint($LF, "cli1Test Passed\n");
335  LogAndPrint($LF, "$last\n");
336  }
337 
338  fclose($LF);
339  verifyUploads($logFile);
340  if (!is_null($rtn = saveResults())) {
341  print "ERROR! could not save the test results, please save by hand\n";
342  print "saveResults returned the following error:\n$rtn\n";
343  exit(1);
344  }
345  $resultsHome = "/home/fosstester/public_html/TestResults/Data/Latest/";
346  $reportHome = "$resultsHome" . "$logFileName";
347 
348  if(array_key_exists('e', $options)) {
349  $last = exec("./textReport.php -f $reportHome |
350  mailx -s \"test results\" $mailTo ",$tossme, $rptGen);
351  }
352  $last = system("./textReport.php -f $reportHome", $rtn);
353  if($last === FALSE) {
354  print "Error! Counld not generate text summary report\n";
355  exit(1);
356  }
357  }
358  exit(0);
359 }
360 /**************** Basic Tests (includes Site) *************************/
361 if (array_key_exists("b", $options)) {
362  $LF = fopen($logFile, 'w') or die("can't open $logFile $phperrormsg\n");
363  print "Using log file:$logFile\n";
364  if (chdir($Home) === FALSE) {
365  $BnoHome = "Basic Tests ERROR: can't cd to $Home\n";
366  LogAndPrint($LF, $BnoHome);
367  }
368  $startB = "Running Basic/SiteTests on: $date at $time\n";
369  LogAndPrint($LF, $startB);
370  if (chdir($SiteTests) === FALSE) {
371  $noBS = "Basic/Site Tests ERROR: can't cd to $SiteTests\n";
372  LogAndPrint($LF, $noBS);
373  }
374  print "\n";
375  $SiteLast = exec("./runSiteTests.php >> $logFile 2>&1", $dummy, $Srtn);
376  if (chdir('../BasicTests') === FALSE) {
377  $noBT = "Basic Tests ERROR: can't cd to $BasicTests\n";
378  LogAndPrint($LF, $noBT);
379  }
380  print "\n";
381  $BasicLast = exec("./runBasicTests.php >> $logFile 2>&1", $dummy, $Srtn);
382  fclose($LF);
383  exit(0);
384 }
385 /***************** SiteTest Only **************************************/
386 if (array_key_exists("s", $options)) {
387  $LF = fopen($logFile, 'w') or die("can't open $logFile $phperrormsg\n");
388  print "Using log file:$logFile\n";
389  $Sstart = "Running SiteTests on: $date at $time\n";
390  LogAndPrint($LF, $Sstart);
391  if (chdir($SiteTests) === FALSE) {
392  $noST = "Site Tests ERROR: can't cd to $SiteTests\n";
393  LogAndPrint($LF, $noST);
394  }
395  $SiteLast = exec("./runSiteTests.php >> $logFile 2>&1", $dummy, $Srtn);
396  fclose($LF);
397  exit(0);
398 }
399 /******************** Verify ******************************************/
400 if (array_key_exists("v", $options)) {
401  if (array_key_exists("l", $options)) {
402  $logFile = $options['l'];
403  /*
404  * check if it starts with a slash, if not assume it's relative and make
405  * a complete path of it. If you don't the results end up in the verifyTests
406  * directory.
407  */
408  $position = strpos($logFile,'/');
409  if($position === FALSE) {
410  $logFile = getcwd() . "/$logFile";
411  }
412  $logFileName = basename($logFile);
413  } else {
414  print "Error, must supply a path to a log file with -v option\n";
415  print $usage;
416  exit(1);
417  }
418  print "calling verifyUploads with:$logFile\n";
419  if (!verifyUploads($logFile)) {
420  print "NOTE: One or more verify upload tests had errors, please investigate\n";
421  echo "by running ui/tests/VerifyTests/runVerifyTests.php\n";
422  exit(1);
423  }
424  if (!is_null($rtn = saveResults())) {
425  print "ERROR! could not save the test results, please save by hand\n";
426  exit(1);
427  }
428  exit(0);
429 }
430 function saveResults() {
431 
432  global $Home;
433  global $logFileName;
434  global $LF;
435  global $logFile;
436 
437  $resultsHome = "/home/fosstester/public_html/TestResults/Data/Latest/";
438  if (chdir($Home) === FALSE) {
439  $nohome = "Save Data ERROR: can't cd to $Home\n";
440  LogAndPrint($LF, $nohome);
441  return ($nohome);
442  }
443  //print "saveResults: logFileName is:$logFileName\n";
444  //print "saveResults: resultsHome is:$resultsHome\n";
445  $reportHome = "$resultsHome" . "$logFileName";
446  if (!rename($logFile, $reportHome)) {
447  $E = "Error, could not move\n$logFile\nto\n$reportHome\n";
448  $E.= "Please move it by hand so the reports will be current\n";
449  return ($E);
450  }
451  return (NULL);
452 }
453 function verifyUploads($logfile) {
454  global $Home;
455  global $VerifyTests;
456  global $date;
457  global $time;
458  if (empty($logfile)) {
459  return (FALSE);
460  }
461  $VLF = fopen($logfile, 'a') or die("Can't open $logfile, $phperrormsg");
462  $Vstart = "\nRunning Verify Tests on: $date at $time\n";
463  LogAndPrint($VLF, $Vstart);
464  if (chdir($Home) === FALSE) {
465  $noVhome = "Verify Tests ERROR: can't cd to $Home\n";
466  LogAndPrint($VLF, $noVhome);
467  }
468  if (chdir($VerifyTests) === FALSE) {
469  $noVT = "Verify Tests ERROR: can't cd to $VerifyTests\n";
470  LogAndPrint($VLF, $noVT);
471  }
472  fclose($VLF);
473  echo "Running runVerifyTests\n";
474  $VerifyLast = exec("./runVerifyTests.php >> $logfile 2>&1", $dummy, $Vrtn);
475  if($Vrtn == 0) {
476  return(TRUE);
477  }
478  else {
479  return(FALSE);
480  }
481 }
if(!preg_match("/\s$projectGroup\s/", $groups) &&(posix_getgid() !=$gInfo[ 'gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:33