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