50 require_once (
'TestEnvironment.php');
51 require_once (
'testClasses/check4jobs.php');
52 require_once (
'mailTo.php');
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.";
73 $SiteTests =
'../ui/tests/SiteTests';
74 $BasicTests =
'../ui/tests/BasicTests';
75 $UserTests =
'../ui/tests/Users';
76 $EmailTests =
'../ui/tests/EmailNotification';
77 $CopyRight =
'copyright';
79 $pkgAgent =
'pkgagent';
80 $VerifyTests =
'../ui/tests/VerifyTests';
87 $date = date(
'Y-m-d');
88 $time = date(
'h:i:s-a');
89 $defaultLog =
"/FossTestResults-$date-$time";
94 $options = getopt(
'abehl:sv');
95 if (empty($options)) {
99 if (array_key_exists(
'h', $options)) {
103 if (array_key_exists(
'l', $options)) {
104 $logFile = $options[
'l'];
105 $logFileName = basename($logFile);
110 $logFile = $cwd . $defaultLog;
112 $logFileName = basename($logFile);
120 function _runTestEnvSetup() {
129 if (chdir($Home) === FALSE) {
130 LogAndPrint($LF,
"_runTestEnvSetup ERROR: can't cd to $Home\n");
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");
140 LogAndPrint($LF,
"ERROR when running uploadTestData.php\n");
141 foreach($dummy as $ErrorLine) {
142 print
"$ErrorLine\n";
147 LogAndPrint($LF,
"ERROR when running uploadCopyrightData.php\n");
148 foreach($dummy as $ErrorLine) {
149 print
"$ErrorLine\n";
154 LogAndPrint($LF,
"ERROR when running AgentAddData.php\n");
155 foreach($dummy as $ErrorLine) {
156 print
"$ErrorLine\n";
161 print
"Warning! There were errors in the test setup, one or more test may fail as a result\n";
165 function getSvnVer() {
166 return (`svnversion`);
169 function LogAndPrint($FileHandle, $message) {
170 if (empty($message)) {
173 if (empty($FileHandle)) {
176 if (-1 == fwrite($FileHandle, $message)) {
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");
195 LogAndPrint($LF,
"Running All Tests on: $date at $time using subversion version: $Svn\n");
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";
201 print wordwrap($Cleanup);
207 $cmd =
"./fo-runTests.php createUIUsers.php -n 'Create UI Users Test' >> $logFile 2>&1";
208 $UIusers = exec($cmd, $dummy, $UsrRtn);
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");
215 LogAndPrint($LF,
"The Email Notification tests mail fail as a result\n");
217 $ctdLast = exec(
'./checkTestData.php', $ctdOut, $ctdRtn);
220 LogAndPrint($LF,
"ERROR when running check4TestData, see previous errors\n");
223 if (chdir($SiteTests) === FALSE) {
224 LogandPrint($LF,
"ALL Tests ERROR: can't cd to $SiteTests\n");
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");
233 $BasicLast = exec(
"./runBasicTests.php >> $logFile 2>&1", $dummy, $Brtn);
234 LogAndPrint($LF,
"\n");
239 if (chdir(
'../Users') === FALSE) {
240 LogAndPrint($LF,
"ALL Tests ERROR: can't cd to $UserTests\n");
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");
247 if (chdir($Home) === FALSE) {
248 $cUInoHome =
"All Tests ERROR: can't cd to $Home\n";
249 LogAndPrint($LF, $cUInoHome);
252 if (chdir($EmailTests) === FALSE) {
253 LogAndPrint($LF,
"ALL Tests ERROR: can't cd to $EmailTests\n");
256 $EmailLast = exec(
"fo-runTests -l \"`ls`\" -n 'Email Tests' >> $logFile 2>&1", $dummy, $ENrtn);
257 LogAndPrint($LF,
"\n");
259 if (chdir($Home) === FALSE) {
260 $cUInoHome =
"All Tests ERROR: can't cd to $Home\n";
261 LogAndPrint($LF, $cUInoHome);
264 if (chdir($pkgAgent) === FALSE) {
265 LogAndPrint($LF,
"ALL Tests ERROR: can't cd to $pkgAgent\n");
267 $PkgLast = exec(
"fo-runTests -l \"`ls cli*`\" -n 'Package Agent Tests'" .
268 " >> $logFile 2>&1", $dummy, $Pkgrtn);
269 LogAndPrint($LF,
"\n");
277 if (chdir($Home) === FALSE) {
278 $UInoHome =
"All Tests ERROR: can't cd to $Home\n";
279 LogAndPrint($LF, $UInoHome);
281 print
"Waiting for jobs to finish...\n";
282 $last = exec(
'./wait4jobs.php', $tossme, $jobsDone);
283 foreach($tossme as $line){
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";
294 if ($jobsDone == 0) {
295 if (chdir($Home) === FALSE) {
296 $cUInoHome =
"All Tests ERROR: can't cd to $Home\n";
297 LogAndPrint($LF, $cUInoHome);
299 if (chdir($nomos) === FALSE) {
300 LogAndPrint($LF,
"ALL Tests ERROR: can't cd to $nomos\n");
303 $nomosTests = array(
'ckZendTest.php',
'verifyRedHatTest.php');
304 foreach($nomosTests as $test)
306 $last = exec(
"fo-runTests -l $test -n 'Nomos Tests' >> $logFile 2>&1", $dummy, $rtn);
307 LogAndPrint($LF,
"\n");
310 LogAndPrint($LF,
"Starting cli1Test\n" );
311 $last = exec(
'phpunit ./cli1Test.php', $punitOut, $puRtn);
314 LogAndPrint($LF,
"cli1Test Failed\n");
315 LogAndPrint($LF, $punitOut);
316 LogAndPrint($LF,
"\n");
320 LogAndPrint($LF,
"cli1Test Passed\n");
321 LogAndPrint($LF,
"$last\n");
324 if (chdir($Home) === FALSE) {
325 $cUInoHome =
"All Tests ERROR: can't cd to $Home\n";
326 LogAndPrint($LF, $cUInoHome);
329 if (chdir($CopyRight) === FALSE) {
330 LogAndPrint($LF,
"ALL Tests ERROR: can't cd to $CopyRight\n");
332 $CopyLast = exec(
"fo-runTests -l \"`ls verify*`\" -n 'CopyRight Tests' >> $logFile 2>&1", $dummy, $CRrtn);
333 LogAndPrint($LF,
"\n");
336 $last = exec(
'phpunit cliParamsTest.php', $punitOut, $puRtn);
339 LogAndPrint($LF,
"cli1Test Failed\n");
340 LogAndPrint($LF, $punitOut);
341 LogAndPrint($LF,
"\n");
345 LogAndPrint($LF,
"cli1Test Passed\n");
346 LogAndPrint($LF,
"$last\n");
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";
356 $resultsHome =
"/home/fosstester/public_html/TestResults/Data/Latest/";
357 $reportHome =
"$resultsHome" .
"$logFileName";
359 if(array_key_exists(
'e', $options)) {
360 $last = exec(
"./textReport.php -f $reportHome | 361 mailx -s \"test results\" $mailTo ",$tossme, $rptGen);
363 $last = system(
"./textReport.php -f $reportHome", $rtn);
364 if($last === FALSE) {
365 print
"Error! Counld not generate text summary report\n";
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);
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);
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);
392 $BasicLast = exec(
"./runBasicTests.php >> $logFile 2>&1", $dummy, $Srtn);
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);
406 $SiteLast = exec(
"./runSiteTests.php >> $logFile 2>&1", $dummy, $Srtn);
411 if (array_key_exists(
"v", $options)) {
412 if (array_key_exists(
"l", $options)) {
413 $logFile = $options[
'l'];
419 $position = strpos($logFile,
'/');
420 if($position === FALSE) {
421 $logFile = getcwd() .
"/$logFile";
423 $logFileName = basename($logFile);
425 print
"Error, must supply a path to a log file with -v option\n";
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";
435 if (!is_null($rtn = saveResults())) {
436 print
"ERROR! could not save the test results, please save by hand\n";
441 function saveResults() {
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);
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";
464 function verifyUploads($logfile) {
469 if (empty($logfile)) {
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);
479 if (chdir($VerifyTests) === FALSE) {
480 $noVT =
"Verify Tests ERROR: can't cd to $VerifyTests\n";
481 LogAndPrint($VLF, $noVT);
484 echo
"Running runVerifyTests\n";
485 $VerifyLast = exec(
"./runVerifyTests.php >> $logfile 2>&1", $dummy, $Vrtn);
if(!preg_match("/\s$projectGroup\s/", $groups)&&(posix_getgid()!=$gInfo['gid']))
get monk license list of one specified uploadtree_id