23 function addProxy($sysConfPath, $proxy=
'lart.usa.hp.com:3128')
25 if(file_exists($sysConfPath .
'/fossology.conf'))
27 $fossConf = file_get_contents($sysConfPath .
'/fossology.conf');
28 if($fossConf === FALSE)
30 echo
"ERROR! could not read\n$sysConfPath/fossology.conf\n";
34 $pat =
';no_proxy = localhost,10.1.2.3';
35 $replacepat = $pat .
"\n" .
'http_proxy = ' . $proxy .
"\n";
37 $testConf = preg_replace(
"/.*?no_proxy = .*/", $replacepat, $fossConf,-1,$count);
41 $stat = file_put_contents(
"$sysConfPath/fossology.conf",$testConf);
44 echo
"ERROR! could not write\n$sysConfPath/fossology.conf\n";
50 echo
"ERROR! can't find fossology.conf at:\n$sysConfPath/fossology.conf\n";
68 function allFilePaths($dir) {
75 foreach(
new recursiveIteratorIterator(
76 new recursiveDirectoryIterator($dir)) as $file) {
77 $fileList[] = $file->getPathName($file);
86 print $e->getMessage();
99 function backToParent($howFar)
103 echo
"FATAL! No input at line " . __LINE__ .
" in " . __FILE__ .
"\n";
109 if(@chdir($howFar) == FALSE)
111 echo
"FATAL! could not cd from:\n$here to:\n$howFar\n" .
112 "at line " . __LINE__ .
" in " . __FILE__ .
"\n";
131 function checkTestData()
135 if(array_key_exists(
'WORKSPACE', $_ENV))
137 $WORKSPACE = $_ENV[
'WORKSPACE'];
139 if(is_null($WORKSPACE))
146 if(@chdir($WORKSPACE .
"/fossology/src") === FALSE)
148 echo
"FATAL! runRUnit could not cd to " . $WORKSPACE .
"/fossology/src\n";
153 $dirs = explode(
'/',$home);
154 $size = count($dirs);
156 if($dirs[$size-1] ==
'workspace' )
158 if(chdir(
'fossology/tests') === FALSE)
160 echo
"FATAL! Cannot cd to fossology/tests from" . getcwd() .
"\n";
166 $redHatPath =
'nomos/testdata';
167 $unpackTestFile =
'../ununpack/agent_tests/test-data/testdata4unpack/argmatch.c.gz';
168 $unpackTests =
'../ununpack/agent_tests';
169 $redHatDataFile =
'RedHat.tar.gz';
170 $unpackDataFile =
'unpack-test-data.tar.bz2';
171 $wgetOptions =
' -a wget.log --tries=3 ';
172 $proxy =
'export http_proxy=lart.usa.hp.com:3128;';
173 $Url =
'http://fossology.org/testing/testFiles/';
205 echo
"downloading unpack data.....\n";
206 if(!file_exists($unpackTestFile))
208 echo
"$unpackTestFile DOES NOT EXIST!, need to download data files...\n";
209 if(chdir($unpackTests) === FALSE)
211 echo
"FATAL! cannot cd to $unpackTests\n";
214 $cmd = $proxy .
"wget" . $wgetOptions . $Url .
'/' . $unpackDataFile;
215 $unpkLast = exec($cmd, $unpkOut, $unpkRtn);
218 echo
"ERROR! Download of $Url$unpackDataFile failed\n";
219 echo
"Errors were:\n";print_r($unpkOut) .
"\n";
223 $cmd =
"tar -xf $unpackDataFile";
224 $tarLast = exec($cmd, $tarOut, $tarRtn);
227 echo
"ERROR! un tar of $unpackDataFile failed\n";
228 echo
"Errors were:\n$tarLast\n";print_r($tarOut) .
"\n";
245 function cleanXMLFiles()
249 foreach($unitList as $unitTest)
251 $other = substr($unitTest, 0, 3);
252 if($other ==
'lib' || $other ==
'cli')
254 if(@chdir($unitTest .
'/tests') === FALSE)
256 echo
"Error! cannot cd to " . $unitTest .
"/tests, skipping test\n";
263 if(@chdir($unitTest .
'/agent_tests/Unit') === FALSE)
265 echo
"Error! cannot cd to " . $unitTest .
"/agent_tests/Unit, skipping test\n";
270 foreach(glob(
"$unitTest*.xml") as $fName)
274 $fileName = lcfirst($fName);
275 $last = exec(
"rm $fileName", $rmOut, $rmRtn);
278 echo
"Notice: could not remove $filename, please remove by hand\n";
281 backToParent(
'../../..');
293 function escapeDots($string)
299 $estring = preg_replace(
'/\./',
'\\.', $string);
301 if ($estring === NULL)
308 function lastDir($dirpath) {
310 $dirpath = rtrim($dirpath,
'/');
311 $directories = explode(
'/',$dirpath);
312 return(end($directories));
328 function filesByDir($dir) {
339 $dirObject =
new recursiveIteratorIterator(
340 new recursiveDirectoryIterator($dir),RecursiveIteratorIterator::SELF_FIRST);
342 foreach($dirObject as $name) {
344 $aSubPath = $dirObject->getSubPath();
349 if($aSubPath != $subPath) {
355 $subPath = $dirObject->getSubPath();
356 $spn = $dirObject->getSubPathName();
357 $subDir = dirname($spn);
358 if($subDir == $aSubPath) {
359 $fileName = $dirObject->getFilename();
360 $fileList[] = $fileName;
363 if (empty($subPath)){
367 if(empty($fileList)){
370 $ByDir[$subPath] = $fileList;
393 catch(Exception $e) {
407 public $makeOutput = array();
409 protected $makeErrors;
410 protected $cunitErrors;
411 protected $phpunitErrors;
413 function __construct($unitTest)
415 $this->unitTest = $unitTest;
416 $this->makeErrors = FALSE;
417 $this->cunitErrors = FALSE;
418 $this->phpunitErrors = FALSE;
441 'name'=> $this->unitTest,
450 $cleanMake = exec(
'make clean 2>&1', $cleanOut, $cleanRtn);
453 echo
"Make clean of $this->unitTest did not succeed, return code:$cleanRtn\n";
459 $s = getenv(
'SYSCONFDIR');
461 $lastMake = exec(
'make test 2>&1', $this->makeOutput, $makeRtn);
468 $found = preg_grep(
'/No rule to make target/', $this->makeOutput);
471 $results[
'notest'] = TRUE;
480 $results[
'make'] = TRUE;
482 if($this->checkCunitTestErrors(implode(
"\n", $this->makeOutput)))
484 $results[
'cunit'] = TRUE;
494 if($this->checkPHPTestErrors(implode(
"\n", $this->makeOutput)))
496 $results[
'phpunit'] = TRUE;
501 $results[
'other'] = $other;
511 $nothing= preg_grep(
"/Nothing to be done for \`test\'/", $this->makeOutput);
514 $noTests= preg_grep(
'/NO.*TESTS/', $this->makeOutput);
516 if($nothing or $noTests)
519 $results[
'notest'] = TRUE;
522 if($this->checkCunitTestErrors(implode(
"\n", $this->makeOutput)))
524 $results[
'cunit'] = TRUE;
552 $pat =
'/make.*?Error\s[0-9]+/';
553 $matched = preg_match($pat, $makeString, $matches);
572 $pat =
'/Number of failures:.*/';
573 $matched = preg_match($pat, $makeString, $matches);
578 $number = explode(
':', $matches[0]);
579 $value =
trim($number[1]);
600 $matched = preg_match($pat, $makeString, $matches);
619 $patterns = array(
'/.*\serror\s.*/',
'/.*\sfault.*/');
620 foreach ($patterns as $pattern)
624 $matched = preg_match($pattern, $makeString, $matches);
631 return(implode(
"\n",$matches));
649 $phpunitMake = FALSE;
651 $test = $runResults[
'name'];
652 unset($runResults[
'name']);
654 if($runResults[
'make'] === TRUE && $runResults[
'cunit'] === TRUE)
659 if($runResults[
'make'] === TRUE && $runResults[
'phpunit'] === TRUE)
665 foreach($runResults as $key => $value)
672 if($cunitMake || $phpunitMake)
676 echo
"Error: there were $key errors for $test\n";
677 echo implode(
"\n", array_slice($this->makeOutput, -7)) .
"\n";
684 echo
"There were $key errors for $test\n";
685 $pattern = $this->unitTest .
"_Tests summary:";
686 $found = array_search($pattern, $this->makeOutput);
689 echo implode(
"\n", array_slice($this->makeOutput, -7)) .
"\n";
697 echo
"Error: there were $key errors for $test\n";
698 echo implode(
"\n", array_slice($this->makeOutput, -7)) .
"\n";
705 echo
"No tests for $test\n";
714 echo
"Other errors for $test:\n";
723 echo
"Nomos diff errors for $test:\n";
724 echo $value .
" diffs.\n";
731 echo
"All tests passed for $test\n";
749 function MakeCover($unitTest)
757 $lastCovr = exec(
'make coverage 2>&1', $covrOut, $covrRtn);
759 $Cover =
new RunTest($unitTest);
762 if($Cover->checkMakeErrors(implode(
"\n", $covrOut)))
764 echo
"Error: 'make coverage' of $unitTest did not succeed, " .
765 "return code:$covrRtn\n";
class for making an agent unit or functional test
printResults($runResults)
print the result array. This will print any informative messages including erorrs that may have occur...
CheckPHPTestErrors($makeString)
check for the word FAILURES in the output, this is what PHPUnit prints when there are any failures in...
CheckOtherErrors($makeString)
Check for other common error strings.
MakeTest()
make tests in a directory and check output for errors and no tests.
CheckMakeErrors($makeString)
check the output of make for errors
CheckCunitTestErrors($makeString)
check the test output for cunit style failures
debugprint($val, $title)
Print debug message.
char * trim(char *ptext)
Trimming whitespace.