Skip to content
Browse files

Some changes to reduce memory usage

  • Loading branch information...
1 parent b3d8d59 commit b668d1f0fec05a87f29f2aa9601203228b123916 zoe slattery committed Oct 11, 2012
View
1 src/run-tests.php
@@ -33,7 +33,6 @@ function rtExceptionHandler(Exception $e) {
require_once dirname(__FILE__) . '/rtAutoload.php';
$s = microtime(true);
-var_dump($argv);
$phpTestRun = new rtPhpTestRun($argv);
$phpTestRun->run();
View
4 src/taskScheduler/rtTaskTestGroup.php
@@ -36,6 +36,10 @@ public function run()
$testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory, $this->groupConfig);
$testGroup->run();
$this->result = $testGroup->getResults();
+
+ $testGroup->__destruct();
+ unset($testGroup);
+
return true;
}
View
10 src/testcase/output/rtTestOutputWriterCSV.php
@@ -27,14 +27,14 @@ public function createOutput()
{
foreach ($this->resultList as $testGroupResults) {
- foreach ($testGroupResults as $testResult) {
+ foreach ($testGroupResults as $testName=>$status) {
- $outputString = $testResult->getName();
- $testStatus = $testResult->getStatus();
+ $outputString = $testName;
- foreach($testStatus->getTestStateNames() as $name) {
+
+ foreach($status->getTestStateNames() as $name) {
- if($testStatus->getValue($name)) {
+ if($status->getValue($name)) {
$outputString .= " , ". strtoupper($name);
}
}
View
8 src/testcase/output/rtTestOutputWriterHTML.php
@@ -73,19 +73,19 @@ public function createOutput()
$tbody = $this->dom->createElement('tbody');
$table->appendChild($tbody);
- foreach ($testGroupResults as $testResult) {
+ foreach ($testGroupResults as $testName => $testStatus) {
$tr = $this->dom->createElement('tr');
$tbody->appendChild($tr);
// name
- $td = $this->dom->createElement('td', $testResult->getName());
+ $td = $this->dom->createElement('td', $testName);
$td->setAttribute('class', 'mainCol');
$tr->appendChild($td);
// status
- $status = $testResult->getStatus();
- $s = $status->__toString();
+
+ $s = $testStatus->__toString();
$td = $this->dom->createElement('td', strtoupper($s));
$td->setAttribute('class', $s);
View
8 src/testcase/output/rtTestOutputWriterList.php
@@ -26,10 +26,10 @@ public function createOutput()
{
foreach ($this->resultList as $testGroupResults) {
- foreach ($testGroupResults as $testResult) {
+ foreach ($testGroupResults as $testName => $testStatus) {
$outputString = "";
- $testStatus = $testResult->getStatus();
+
foreach($testStatus->getTestStateNames() as $name) {
@@ -39,8 +39,8 @@ public function createOutput()
}
}
- $outputString .= " " . $testResult->getTitle();
- $outputString .= " [" . $testResult->getName() . ".phpt]";
+
+ $outputString .= " [" . $testName . ".phpt]";
$this->output .= $outputString."\n";
}
}
View
37 src/testcase/output/rtTestOutputWriterXML.php
@@ -49,41 +49,34 @@ public function createOutput()
$state = array();
- foreach ($testGroupResults as $testResult) {
+ foreach ($testGroupResults as $testName => $testStatus) {
// create test-node
$testNode = $this->dom->createElement('testcase');
$groupNode->appendChild($testNode);
// name
- $n = explode($wdir, $testResult->getName());
+ $n = explode($wdir, $testName);
$n = explode('/', $n[1]);
$n = array_pop($n);
$testNode->setAttribute('name', $n);
// status
- $status = $testResult->getStatus();
- $s = $status->__toString();
+
+ $s = $testStatus->__toString();
$testNode->setAttribute('status', strtoupper($s));
-
- // title
- $title = $testResult->getTitle();
-
- if (strlen($title) > 0) {
- $titleNode = $this->dom->createElement('title', utf8_encode(htmlentities($title)));
- $testNode->appendChild($titleNode);
- }
+
// message
- $msg = $status->getMessage($s);
+ $msg = $testStatus->getMessage($s);
if (!is_null($msg)) {
$msgNode = $this->dom->createElement('message', utf8_encode(htmlentities($msg)));
$testNode->appendChild($msgNode);
}
// files
- $files = $testResult->getSavedFileNames();
+ $files = $testStatus->getSavedFileNames();
if (sizeof($files) > 0) {
@@ -107,22 +100,6 @@ public function createOutput()
$global_count += sizeof($testGroupResults);
- // add group-node attributes
-
- $n = explode($wdir, $testGroupResults[0]->getName());
- $n = explode('/', $n[1]);
- array_pop($n);
- $n = implode('/', $n);
-
- $groupNode->setAttribute('name', $n);
- $groupNode->setAttribute('tests', sizeof($testGroupResults));
-
- $time = round($testGroupResults[0]->getTime(), 2);
- $groupNode->setAttribute('time', $time);
-
- foreach ($state as $k => $v) {
- $groupNode->setAttribute($k, $v);
- }
}
$this->dom->encoding = 'UTF-8';
View
6 src/testcase/rtPhpTest.php
@@ -20,7 +20,7 @@ class rtPhpTest
protected $contents;
protected $testStatus;
protected $output;
- protected $sections;
+ protected $sections = array();
protected $fileSection;
protected $expectSection;
protected $sectionHeadings;
@@ -137,8 +137,8 @@ public function executeTest(rtRuntestsConfiguration $runConfiguration)
}
/**
*
- * Just runs teh SKIPIF section - required for redirect test implementation
- * @param $runConfiguration
+ * Just runs the SKIPIF section - required for redirect test implementation
+ * @param $runConfiguration... hmm, should have a testconfiguration?
*/
public function runSkipif(rtRuntestsConfiguration $runConfiguration) {
View
43 src/testcase/rtTestOutputWriter.php
@@ -118,8 +118,8 @@ public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount
$count = 0;
foreach ($this->resultList as $groupResult) {
- foreach($groupResult as $testResult) {
- $s = $testResult->getStatus()->__toString();
+ foreach($groupResult as $name=>$testStatus) {
+ $s = $testStatus->__toString();
if (!isset($state[$s])) {
$state[$s] = 0;
@@ -211,6 +211,7 @@ public function printOverview($groups=NULL, $processCount=NULL) {
*/
public static function flushResult(array $results, $state=0, $cid=NULL)
{
+
switch ($state) {
case -1: // no ouput
@@ -227,27 +228,26 @@ public static function flushResult(array $results, $state=0, $cid=NULL)
case 1: // every test-case incl. status
print "\n";
- foreach ($results as $result) {
- print strtoupper($result->getStatus())."\t".$result->getName()."\n";
+ foreach ($results as $name=>$status) {
+ print strtoupper($status->__toString())."\t".$name."\n";
}
break;
case 2: // details about not-passed tests
- foreach ($results as $result) {
+ foreach ($results as $name=>$s) {
+
- $s = $result->getStatus();
- $name = $s->__toString();
+ $status = $s->__toString();
- if ($name !== 'pass') {
+ if ($status !== 'pass') {
print "\n";
}
- print strtoupper($name)."\t".$result->getName()."\n";
+ print strtoupper($s)."\t".$name."\n";
- if ($name !== 'pass') {
- print "DESC:\t".$result->getTitle()."\n";
-
+ if ($s !== 'pass') {
+
$msg = $s->getMessage($name);
if (!is_null($msg)) {
print "MSG:\t".$msg."\n";
@@ -260,17 +260,16 @@ public static function flushResult(array $results, $state=0, $cid=NULL)
break;
case 3: // all available details
-
- foreach ($results as $result) {
+
+ foreach ($results as $name=>$s) {
+
+ $status = $s->__toString();
- $s = $result->getStatus();
- $name = $s->__toString();
-
print "\n";
- print strtoupper($name)."\t".$result->getName()."\n";
- print "DESC:\t".$result->getTitle()."\n";
-
- $msg = $s->getMessage($name);
+
+ print strtoupper($status)."\t".$name."\n";
+
+ $msg = $s->getMessage($status);
if (!is_null($msg)) {
print "MSG:\t".$msg."\n";
@@ -282,7 +281,7 @@ public static function flushResult(array $results, $state=0, $cid=NULL)
print "MEM:\t".round(memory_get_usage()/1024, 2)." kB\n";
- $files = $result->getSavedFileNames();
+ $files = $s->getSavedFileNames();
if (sizeof($files) > 0) {
View
36 src/testcase/rtTestResults.php
@@ -21,7 +21,6 @@ class rtTestResults
{
protected $testStatus;
protected $testName = '';
- protected $savedFileNames = array();
protected $title = '';
protected $time = 0;
protected $redirectedTest;
@@ -35,11 +34,8 @@ public function init(rtPhpTest $testCase = null, rtTestStatus $testStatus = null
{
if ($testCase != null) {
$this->title = $testCase->getSection('TEST')->getHeader();
- $this->testStatus = $testCase->getStatus();
+ $this->testStatus = $testCase->getStatus(); //is an object
$this->testName = $testCase->getName();
- if($testStatus == 'redirected') {
- $this->redirectedTest = $testCase;
- }
} else {
$this->testStatus = $testStatus;
$this->testName = $testStatus->getTestName();
@@ -63,7 +59,7 @@ public function processResults(rtPhpTest $testCase, rtRuntestsConfiguration $run
if(file_exists($this->testName . '.mem')) {
if(filesize($this->testName . '.mem') > 0) {
- $this->savedFileNames['mem'] = $this->testName. ".mem";
+ $this->testStatus->setSavedFileName('mem', $this->testName. ".mem");
} else {
@unlink($this->testName . '.mem');
}
@@ -85,19 +81,19 @@ protected function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfi
if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-php')) {
$testCase->getFileSection()->deleteFile();
} else {
- $this->savedFileNames['php'] = $this->testName. ".php";
+ $this->testStatus->setSavedFileName('php', $this->testName. ".php");
}
if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-out')) {
$outputFileName = $this->testName.".out";
file_put_contents($outputFileName, $testCase->getOutput());
- $this->savedFileNames['out'] = $outputFileName;
+ $this->testStatus->setSavedFileName('out', $outputFileName);
}
if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-exp')) {
$expectedFileName = $this->testName.".exp";
file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents()));
- $this->savedFileNames['exp'] = $expectedFileName;
+ $this->testStatus->setSavedFileName('exp', $expectedFileName);
}
if ($testCase->hasSection('XFAIL')) {
@@ -109,7 +105,7 @@ protected function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfi
if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-clean')) {
$testCase->getSection('CLEAN')->deleteFile();
} else {
- $this->savedFileNames['clean'] = $this->testName. ".clean.php";
+ $this->testStatus->setSavedFileName('claen', $this->testName. ".clean.php");
}
}
@@ -118,7 +114,7 @@ protected function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfi
}
if($testCase->getStatus()->getValue('leak') == true) {
- $this->savedFileNames['mem'] = $testCase->getSection('FILE')->getMemFileName();
+ $this->testStatus->setSavedFileName('mem', $testCase->getSection('FILE')->getMemFileName());
}
}
@@ -136,9 +132,9 @@ protected function onFail(rtPhpTest $testCase)
file_put_contents($outputFileName, $testCase->getOutput());
file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents()));
- $this->savedFileNames['out'] = $outputFileName;
- $this->savedFileNames['exp'] = $expectedFileName;
- $this->savedFileNames['diff'] = $differenceFileName;
+ $this->testStatus->setSavedFileName('out', $outputFileName);
+ $this->testStatus->setSavedFileName('exp', $expectedFileName);
+ $this->testStatus->setSavedFileName('diff', $differenceFileName);
if ($testCase->hasSection('XFAIL')) {
$this->testStatus->setTrue('xfail');
@@ -148,22 +144,22 @@ protected function onFail(rtPhpTest $testCase)
//Note: if there are clean and skipif files they will not be deleted if the test fails
if ($testCase->hasSection('CLEAN')) {
- $this->savedFileNames['clean'] = $this->testName. '.clean.php';
+ $this->testStatus->setSavedFileName('clean', $this->testName. '.clean.php' );
}
if ($testCase->hasSection('SKIPIF')) {
- $this->savedFileNames['skipif'] = $this->testName. '.skipif.php';
+ $this->testStatus->setSavedFileName('skipif', $this->testName. '.skipif.php' );
}
if($testCase->getStatus()->getValue('leak') == true) {
- $this->savedFileNames['mem'] = $testCase->getSection('FILE')->getMemFileName();
+ $this->testStatus->setSavedFileName('mem', $testCase->getSection('FILE')->getMemFileName());
}
}
protected function onSkip(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration)
{
if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-skip')) {
- $this->savedFileNames['skipif'] = $this->testName. '.skipif.php';
+ $this->testStatus->setSavedFileName('skipif', $this->testName. '.skipif.php' );
} else if($testCase->hasSection('SKIPIF')) {
$testCase->getSection('SKIPIF')->deleteFile();
}
@@ -176,10 +172,6 @@ public function getStatus()
return $this->testStatus;
}
- public function getSavedFileNames()
- {
- return $this->savedFileNames;
- }
public function getName()
{
View
10 src/testcase/rtTestStatus.php
@@ -31,6 +31,7 @@ class rtTestStatus {
'leak',
'redirected',
);
+ protected $savedFileNames = array();
public function __construct($testName)
{
@@ -76,6 +77,15 @@ public function getTestName()
return $this->testName;
}
+ public function getSavedFileNames()
+ {
+ return $this->savedFileNames;
+ }
+ public function setSavedFileName($type, $fileName)
+ {
+ $this->savedFileNames[$type] = $fileName;
+ }
+
public function setExecutedPhpCommand($cmd)
{
$this->executedPhpCommand = $cmd;
View
40 src/testgroup/rtPhpTestGroup.php
@@ -19,6 +19,7 @@ class rtPhpTestGroup extends rtTask implements rtTaskInterface
protected $result = array();
protected $runConfiguration;
protected $groupConfiguration;
+ protected $redirectedTestCases = array();
public function __construct(rtRuntestsConfiguration $runConfiguration, $directory, $groupConfiguration)
{
@@ -27,6 +28,12 @@ public function __construct(rtRuntestsConfiguration $runConfiguration, $director
$this->groupConfiguration = $groupConfiguration;
$this->init();
}
+
+ public function __destruct() {
+ unset ($this->testCases);
+
+ }
+
public function init()
{
@@ -43,6 +50,7 @@ public function init()
$redirectFromID = $this->groupConfiguration->getRedirectFromID();
foreach ($this->testFiles as $testFileName) {
+ //echo "\n" .memory_get_usage() . ", setup start". $testFileName . "\n";
//testFiles is a list of file names relative to the current working directory
@@ -71,18 +79,22 @@ public function init()
if($redirectedTest->getStatus()->getValue('skip')) {
$testStatus->setTrue('skip');
$testStatus->setMessage('skip', $testFile->getExitMessage(). ' and the skip condition has failed');
+ $this->result[$testFile->getTestName()] = $testStatus;
} else {
$testStatus->setTrue('redirected');
$testStatus->setMessage('redirected', $testFile->getExitMessage());
+ $this->result[$testFile->getTestName()] = $testStatus;
+ $this->redirectedTestCases[] = $redirectedTest;
}
- $this->result[] = new rtTestResults($redirectedTest, $testStatus);
+
}
}else {
$testStatus->setTrue('bork');
$testStatus->setMessage('bork', $testFile->getExitMessage());
- $this->result[] = new rtTestResults(null, $testStatus);
+ $this->result[$testFile->getTestName()] = $testStatus;
}
+ //echo "\n" .memory_get_usage() . ", setup complete". $testFileName . "\n";
}
}
@@ -92,15 +104,27 @@ public function run()
if (count($this->testCases) == 0) {
return;
}
-
- foreach ($this->testCases as $testCase) {
+ //$s1 = memory_get_usage();
+
+ //foreach ($this->testCases as $testCase) {
+ for($i=0; $i<count($this->testCases); $i++) {
+
+ $testCase = $this->testCases[$i];
$testCase->executeTest($this->runConfiguration);
+
+
$testResult = new rtTestResults($testCase);
$testResult->processResults($testCase, $this->runConfiguration);
- $this->result[] = $testResult;
+ $this->result[$testCase->getName()] = $testResult->getStatus();
+ //unset($testResult); Makes no diffetence
+ //echo "\n" .memory_get_usage() . ", run end";
}
+
+ //$s2 = memory_get_usage();
+ //unset($this->testCases);
+ //echo "\n" .$s1. ", " .$s2. ", " .memory_get_usage() . ", after freeing test array\n"; //Shows memory creeping up
}
public function writeGroup($outType, $cid=null)
@@ -117,6 +141,10 @@ public function getTestCases() {
public function getResults() {
return $this->result;
}
-
+
+ public function getRedirectedTestCases() {
+ return $this->redirectedTestCases;
+ }
+
}
?>
View
66 src/testrun/rtPhpTestRun.php
@@ -32,6 +32,7 @@ public function __construct($argv)
public function run()
{
+
//Set SSH variables
// check the operation-system (win/unix)
@@ -87,20 +88,15 @@ public function run()
$this->run_tests($this->runConfiguration->getSetting('TestFiles'));
}
}
-
- /*
- * At this stage we have run all groups or tests in the initial input. Now we check if any of those have
- * redirected test cases and if so, run those one group at a time.
- * It might be possible to run these in parallel too?
- */
- $this->buildRedirectsList($this->resultList);
+
if(count($this->redirectedTestCases) > 0) {
$this->doRedirectedRuns();
}
if(($this->numberOfSerialGroups != 0) || ($this->numberOfParallelGroups != 0)) {
$this->createRunOutput();
}
+
}
public function doGroupRuns() {
@@ -117,7 +113,7 @@ public function doGroupRuns() {
} else {
//check to see if this is set to be a parallel run, if not, run the subdirectory groups in sequence.
- if($this->requestedProcessorCount() <= 1) {
+ if($this->requestedProcessorCount() < 1) {
$this->run_serial_groups($subDirectories, $groupConfigurations);
$this->numberOfSerialGroups = count($subDirectories);
} else {
@@ -181,11 +177,42 @@ public function run_parallel_groups($testDirectories, $groupConfigurations, $pro
public function run_serial_groups($testDirectories, $groupConfigurations) {
- foreach($testDirectories as $subDirectory) {
+ $count = 0;
+
+
+ foreach($testDirectories as $subDirectory) {
+
+
+ // Memory usage debugging
+ //$startm = memory_get_usage();
+
+
$testGroup = new rtPhpTestGroup($this->runConfiguration, $subDirectory, $groupConfigurations[$subDirectory]);
$testGroup->run();
+
+ // Memory usage debugging
+ //$midm = memory_get_usage();
+
+
rtTestOutputWriter::flushResult($testGroup->getResults(), $this->reportStatus);
$this->resultList[] = $testGroup->getResults();
+
+ // Memory usage debugging
+ //$midm2 = memory_get_usage();
+
+ $redirects = $testGroup->getRedirectedTestCases();
+ foreach($redirects as $testCase) {
+ $this->redirectedTestCases[] = $testCase;
+ }
+
+ // Memory usage debugging
+ //$midm3 = memory_get_usage();
+
+ $testGroup->__destruct();
+ unset($testGroup);
+
+ // Memory usage debugging
+ //echo "\n" . $startm . ", " . $midm. ", " .$midm2. ", " .$midm3. ", " .memory_get_usage() . ", ". $subDirectory . "\n";
}
}
@@ -201,7 +228,6 @@ public function run_tests($testNames) {
exit();
}
- $allResults = array();
//Read the test file
$testFile = new rtPhpTestFile();
@@ -219,6 +245,7 @@ public function run_tests($testNames) {
$results = new rtTestResults($testCase);
$results->processResults($testCase, $this->runConfiguration);
+ $summaryResults = array($testFile->getTestName() => $results->getStatus());
} elseif (in_array("REDIRECTTEST", $testFile->getSectionHeadings())) {
@@ -229,13 +256,15 @@ public function run_tests($testNames) {
$testStatus->setTrue('redirected');
$testStatus->setMessage('redirected', $testFile->getExitMessage());
- $results = new rtTestResults(null, $testStatus);
+ $summaryResults = array($testFile->getTestName() => $testStatus);
+
} else {
$testStatus->setTrue('bork');
$testStatus->setMessage('bork', $testFile->getExitMessage());
- $results = new rtTestResults(null, $testStatus);
+ $summaryResults = array($testFile->getTestName() => $testStatus);
}
- rtTestOutputWriter::flushResult(array($results), 3);
+
+ rtTestOutputWriter::flushResult($summaryResults, 3);
}
}
@@ -321,5 +350,16 @@ public function setReportStatus() {
}
}
+ public function extractResults($groupResult) {
+ $groupSummary = array();
+ foreach($groupResult as $testResult) {
+ $groupSummary[$testResult->getName()] = $testResult->getStatus();
+ if($testResult->getStatus() == 'redirected') {
+ $this->redirectedTestCases[] = $testResult->getRedirectedTestCase();
+ }
+ }
+ return $groupSummary;
+ }
+
}
?>
View
10 tests/rtPhpTestGroupTest.php
@@ -46,14 +46,10 @@ public function testFindRedirect()
- $inValidTests = $phpTestGroup->getResult();
+ $redirects = $phpTestGroup->getRedirectedTestCases();
- foreach($inValidTests as $testResult) {
- if($testResult->getStatus() == 'redirected') {
- //If the status has been set to redirected it should have a valid REDIRECTTEST section
- $testCase = $testResult->getRedirectedTestCase();
- $this->assertTrue($testCase->hasSection('REDIRECTTEST'));
- }
+ foreach($redirects as $testCase) {
+ $this->assertTrue($testCase->hasSection('REDIRECTTEST'));
}
}

0 comments on commit b668d1f

Please sign in to comment.
Something went wrong with that request. Please try again.