35 function addProxy($sysConfPath, $proxy=
'lart.usa.hp.com:3128')
37 if(file_exists($sysConfPath .
'/fossology.conf'))
39 $fossConf = file_get_contents($sysConfPath .
'/fossology.conf');
40 if($fossConf === FALSE)
42 echo
"ERROR! could not read\n$sysConfPath/fossology.conf\n";
46 $pat =
';no_proxy = localhost,10.1.2.3';
47 $replacepat = $pat .
"\n" .
'http_proxy = ' . $proxy .
"\n";
49 $testConf = preg_replace(
"/.*?no_proxy = .*/", $replacepat, $fossConf,-1,$count);
53 $stat = file_put_contents(
"$sysConfPath/fossology.conf",$testConf);
56 echo
"ERROR! could not write\n$sysConfPath/fossology.conf\n";
62 echo
"ERROR! can't find fossology.conf at:\n$sysConfPath/fossology.conf\n";
80 function allFilePaths($dir) {
87 foreach(
new recursiveIteratorIterator(
88 new recursiveDirectoryIterator($dir)) as $file) {
89 $fileList[] = $file->getPathName($file);
98 print $e->getMessage();
111 function backToParent($howFar)
115 echo
"FATAL! No input at line " . __LINE__ .
" in " . __FILE__ .
"\n";
121 if(@chdir($howFar) == FALSE)
123 echo
"FATAL! could not cd from:\n$here to:\n$howFar\n" .
124 "at line " . __LINE__ .
" in " . __FILE__ .
"\n";
143 function checkTestData()
147 if(array_key_exists(
'WORKSPACE', $_ENV))
149 $WORKSPACE = $_ENV[
'WORKSPACE'];
151 if(is_null($WORKSPACE))
158 if(@chdir($WORKSPACE .
"/fossology/src") === FALSE)
160 echo
"FATAL! runRUnit could not cd to " . $WORKSPACE .
"/fossology/src\n";
165 $dirs = explode(
'/',$home);
166 $size = count($dirs);
168 if($dirs[$size-1] ==
'workspace' )
170 if(chdir(
'fossology/tests') === FALSE)
172 echo
"FATAL! Cannot cd to fossology/tests from" . getcwd() .
"\n";
178 $redHatPath =
'nomos/testdata';
179 $unpackTestFile =
'../ununpack/agent_tests/test-data/testdata4unpack/argmatch.c.gz';
180 $unpackTests =
'../ununpack/agent_tests';
181 $redHatDataFile =
'RedHat.tar.gz';
182 $unpackDataFile =
'unpack-test-data.tar.bz2';
183 $wgetOptions =
' -a wget.log --tries=3 ';
184 $proxy =
'export http_proxy=lart.usa.hp.com:3128;';
185 $Url =
'http://fossology.org/testing/testFiles/';
217 echo
"downloading unpack data.....\n";
218 if(!file_exists($unpackTestFile))
220 echo
"$unpackTestFile DOES NOT EXIST!, need to download data files...\n";
221 if(chdir($unpackTests) === FALSE)
223 echo
"FATAL! cannot cd to $unpackTests\n";
226 $cmd = $proxy .
"wget" . $wgetOptions . $Url .
'/' . $unpackDataFile;
227 $unpkLast = exec($cmd, $unpkOut, $unpkRtn);
230 echo
"ERROR! Download of $Url$unpackDataFile failed\n";
231 echo
"Errors were:\n";print_r($unpkOut) .
"\n";
235 $cmd =
"tar -xf $unpackDataFile";
236 $tarLast = exec($cmd, $tarOut, $tarRtn);
239 echo
"ERROR! un tar of $unpackDataFile failed\n";
240 echo
"Errors were:\n$tarLast\n";print_r($tarOut) .
"\n";
257 function cleanXMLFiles()
261 foreach($unitList as $unitTest)
263 $other = substr($unitTest, 0, 3);
264 if($other ==
'lib' || $other ==
'cli')
266 if(@chdir($unitTest .
'/tests') === FALSE)
268 echo
"Error! cannot cd to " . $unitTest .
"/tests, skipping test\n";
275 if(@chdir($unitTest .
'/agent_tests/Unit') === FALSE)
277 echo
"Error! cannot cd to " . $unitTest .
"/agent_tests/Unit, skipping test\n";
282 foreach(glob(
"$unitTest*.xml") as $fName)
286 $fileName = lcfirst($fName);
287 $last = exec(
"rm $fileName", $rmOut, $rmRtn);
290 echo
"Notice: could not remove $filename, please remove by hand\n";
293 backToParent(
'../../..');
305 function escapeDots($string)
311 $estring = preg_replace(
'/\./',
'\\.', $string);
313 if ($estring === NULL)
320 function lastDir($dirpath) {
322 $dirpath = rtrim($dirpath,
'/');
323 $directories = explode(
'/',$dirpath);
324 return(end($directories));
340 function filesByDir($dir) {
351 $dirObject =
new recursiveIteratorIterator(
352 new recursiveDirectoryIterator($dir),RecursiveIteratorIterator::SELF_FIRST);
354 foreach($dirObject as $name) {
356 $aSubPath = $dirObject->getSubPath();
361 if($aSubPath != $subPath) {
367 $subPath = $dirObject->getSubPath();
368 $spn = $dirObject->getSubPathName();
369 $subDir = dirname($spn);
370 if($subDir == $aSubPath) {
371 $fileName = $dirObject->getFilename();
372 $fileList[] = $fileName;
375 if (empty($subPath)){
379 if(empty($fileList)){
382 $ByDir[$subPath] = $fileList;
405 catch(Exception $e) {
419 public $makeOutput = array();
421 protected $makeErrors;
422 protected $cunitErrors;
423 protected $phpunitErrors;
425 function __construct($unitTest)
427 $this->unitTest = $unitTest;
428 $this->makeErrors = FALSE;
429 $this->cunitErrors = FALSE;
430 $this->phpunitErrors = FALSE;
455 'name'=> $this->unitTest,
464 $cleanMake = exec(
'make clean 2>&1', $cleanOut, $cleanRtn);
467 echo
"Make clean of $this->unitTest did not succeed, return code:$cleanRtn\n";
473 $s = getenv(
'SYSCONFDIR');
475 $lastMake = exec(
'make test 2>&1', $this->makeOutput, $makeRtn);
482 $found = preg_grep(
'/No rule to make target/', $this->makeOutput);
485 $results[
'notest'] = TRUE;
494 $results[
'make'] = TRUE;
496 if($this->checkCunitTestErrors(implode(
"\n", $this->makeOutput)))
498 $results[
'cunit'] = TRUE;
508 if($this->checkPHPTestErrors(implode(
"\n", $this->makeOutput)))
510 $results[
'phpunit'] = TRUE;
515 $results[
'other'] = $other;
525 $nothing= preg_grep(
"/Nothing to be done for \`test\'/", $this->makeOutput);
528 $noTests= preg_grep(
'/NO.*TESTS/', $this->makeOutput);
530 if($nothing or $noTests)
533 $results[
'notest'] = TRUE;
536 if($this->checkCunitTestErrors(implode(
"\n", $this->makeOutput)))
538 $results[
'cunit'] = TRUE;
566 $pat =
'/make.*?Error\s[0-9]+/';
567 $matched = preg_match($pat, $makeString, $matches);
586 $pat =
'/Number of failures:.*/';
587 $matched = preg_match($pat, $makeString, $matches);
592 $number = explode(
':', $matches[0]);
593 $value =
trim($number[1]);
614 $matched = preg_match($pat, $makeString, $matches);
633 $patterns = array(
'/.*\serror\s.*/',
'/.*\sfault.*/');
634 foreach ($patterns as $pattern)
638 $matched = preg_match($pattern, $makeString, $matches);
645 return(implode(
"\n",$matches));
663 $phpunitMake = FALSE;
665 $test = $runResults[
'name'];
666 unset($runResults[
'name']);
668 if($runResults[
'make'] === TRUE && $runResults[
'cunit'] === TRUE)
673 if($runResults[
'make'] === TRUE && $runResults[
'phpunit'] === TRUE)
679 foreach($runResults as $key => $value)
686 if($cunitMake || $phpunitMake)
690 echo
"Error: there were $key errors for $test\n";
691 echo implode(
"\n", array_slice($this->makeOutput, -7)) .
"\n";
698 echo
"There were $key errors for $test\n";
699 $pattern = $this->unitTest .
"_Tests summary:";
700 $found = array_search($pattern, $this->makeOutput);
703 echo implode(
"\n", array_slice($this->makeOutput, -7)) .
"\n";
711 echo
"Error: there were $key errors for $test\n";
712 echo implode(
"\n", array_slice($this->makeOutput, -7)) .
"\n";
719 echo
"No tests for $test\n";
728 echo
"Other errors for $test:\n";
737 echo
"Nomos diff errors for $test:\n";
738 echo $value .
" diffs.\n";
745 echo
"All tests passed for $test\n";
763 function MakeCover($unitTest)
771 $lastCovr = exec(
'make coverage 2>&1', $covrOut, $covrRtn);
773 $Cover =
new RunTest($unitTest);
776 if($Cover->checkMakeErrors(implode(
"\n", $covrOut)))
778 echo
"Error: 'make coverage' of $unitTest did not succeed, " .
779 "return code:$covrRtn\n";
printResults($runResults)
print the result array. This will print any informative messages including erorrs that may have occur...
debugprint($val, $title)
Print debug message.
class for making an agent unit or functional test
MakeTest()
make tests in a directory and check output for errors and no tests.
CheckPHPTestErrors($makeString)
check for the word FAILURES in the output, this is what PHPUnit prints when there are any failures in...
CheckMakeErrors($makeString)
check the output of make for errors
CheckCunitTestErrors($makeString)
check the test output for cunit style failures
CheckOtherErrors($makeString)
Check for other common error strings.
char * trim(char *ptext)
Trimming whitespace.