Skip to content

Commit

Permalink
Some changes to reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
zoe slattery committed Oct 11, 2012
1 parent b3d8d59 commit b668d1f
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 117 deletions.
1 change: 0 additions & 1 deletion src/run-tests.php
Expand Up @@ -33,7 +33,6 @@ function rtExceptionHandler(Exception $e) {
require_once dirname(__FILE__) . '/rtAutoload.php'; require_once dirname(__FILE__) . '/rtAutoload.php';


$s = microtime(true); $s = microtime(true);
var_dump($argv);


$phpTestRun = new rtPhpTestRun($argv); $phpTestRun = new rtPhpTestRun($argv);
$phpTestRun->run(); $phpTestRun->run();
Expand Down
4 changes: 4 additions & 0 deletions src/taskScheduler/rtTaskTestGroup.php
Expand Up @@ -36,6 +36,10 @@ public function run()
$testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory, $this->groupConfig); $testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory, $this->groupConfig);
$testGroup->run(); $testGroup->run();
$this->result = $testGroup->getResults(); $this->result = $testGroup->getResults();

$testGroup->__destruct();
unset($testGroup);

return true; return true;
} }


Expand Down
10 changes: 5 additions & 5 deletions src/testcase/output/rtTestOutputWriterCSV.php
Expand Up @@ -27,14 +27,14 @@ public function createOutput()
{ {
foreach ($this->resultList as $testGroupResults) { foreach ($this->resultList as $testGroupResults) {


foreach ($testGroupResults as $testResult) { foreach ($testGroupResults as $testName=>$status) {


$outputString = $testResult->getName(); $outputString = $testName;
$testStatus = $testResult->getStatus();


foreach($testStatus->getTestStateNames() as $name) {
foreach($status->getTestStateNames() as $name) {


if($testStatus->getValue($name)) { if($status->getValue($name)) {
$outputString .= " , ". strtoupper($name); $outputString .= " , ". strtoupper($name);
} }
} }
Expand Down
8 changes: 4 additions & 4 deletions src/testcase/output/rtTestOutputWriterHTML.php
Expand Up @@ -73,19 +73,19 @@ public function createOutput()
$tbody = $this->dom->createElement('tbody'); $tbody = $this->dom->createElement('tbody');
$table->appendChild($tbody); $table->appendChild($tbody);


foreach ($testGroupResults as $testResult) { foreach ($testGroupResults as $testName => $testStatus) {


$tr = $this->dom->createElement('tr'); $tr = $this->dom->createElement('tr');
$tbody->appendChild($tr); $tbody->appendChild($tr);


// name // name
$td = $this->dom->createElement('td', $testResult->getName()); $td = $this->dom->createElement('td', $testName);
$td->setAttribute('class', 'mainCol'); $td->setAttribute('class', 'mainCol');
$tr->appendChild($td); $tr->appendChild($td);


// status // status
$status = $testResult->getStatus();
$s = $status->__toString(); $s = $testStatus->__toString();


$td = $this->dom->createElement('td', strtoupper($s)); $td = $this->dom->createElement('td', strtoupper($s));
$td->setAttribute('class', $s); $td->setAttribute('class', $s);
Expand Down
8 changes: 4 additions & 4 deletions src/testcase/output/rtTestOutputWriterList.php
Expand Up @@ -26,10 +26,10 @@ public function createOutput()
{ {
foreach ($this->resultList as $testGroupResults) { foreach ($this->resultList as $testGroupResults) {


foreach ($testGroupResults as $testResult) { foreach ($testGroupResults as $testName => $testStatus) {


$outputString = ""; $outputString = "";
$testStatus = $testResult->getStatus();


foreach($testStatus->getTestStateNames() as $name) { foreach($testStatus->getTestStateNames() as $name) {


Expand All @@ -39,8 +39,8 @@ public function createOutput()
} }
} }


$outputString .= " " . $testResult->getTitle();
$outputString .= " [" . $testResult->getName() . ".phpt]"; $outputString .= " [" . $testName . ".phpt]";
$this->output .= $outputString."\n"; $this->output .= $outputString."\n";
} }
} }
Expand Down
37 changes: 7 additions & 30 deletions src/testcase/output/rtTestOutputWriterXML.php
Expand Up @@ -49,41 +49,34 @@ public function createOutput()


$state = array(); $state = array();


foreach ($testGroupResults as $testResult) { foreach ($testGroupResults as $testName => $testStatus) {


// create test-node // create test-node
$testNode = $this->dom->createElement('testcase'); $testNode = $this->dom->createElement('testcase');
$groupNode->appendChild($testNode); $groupNode->appendChild($testNode);


// name // name
$n = explode($wdir, $testResult->getName()); $n = explode($wdir, $testName);
$n = explode('/', $n[1]); $n = explode('/', $n[1]);
$n = array_pop($n); $n = array_pop($n);
$testNode->setAttribute('name', $n); $testNode->setAttribute('name', $n);


// status // status
$status = $testResult->getStatus();
$s = $status->__toString(); $s = $testStatus->__toString();
$testNode->setAttribute('status', strtoupper($s)); $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 // message
$msg = $status->getMessage($s); $msg = $testStatus->getMessage($s);


if (!is_null($msg)) { if (!is_null($msg)) {
$msgNode = $this->dom->createElement('message', utf8_encode(htmlentities($msg))); $msgNode = $this->dom->createElement('message', utf8_encode(htmlentities($msg)));
$testNode->appendChild($msgNode); $testNode->appendChild($msgNode);
} }


// files // files
$files = $testResult->getSavedFileNames(); $files = $testStatus->getSavedFileNames();


if (sizeof($files) > 0) { if (sizeof($files) > 0) {


Expand All @@ -107,22 +100,6 @@ public function createOutput()


$global_count += sizeof($testGroupResults); $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'; $this->dom->encoding = 'UTF-8';
Expand Down
6 changes: 3 additions & 3 deletions src/testcase/rtPhpTest.php
Expand Up @@ -20,7 +20,7 @@ class rtPhpTest
protected $contents; protected $contents;
protected $testStatus; protected $testStatus;
protected $output; protected $output;
protected $sections; protected $sections = array();
protected $fileSection; protected $fileSection;
protected $expectSection; protected $expectSection;
protected $sectionHeadings; protected $sectionHeadings;
Expand Down Expand Up @@ -137,8 +137,8 @@ public function executeTest(rtRuntestsConfiguration $runConfiguration)
} }
/** /**
* *
* Just runs teh SKIPIF section - required for redirect test implementation * Just runs the SKIPIF section - required for redirect test implementation
* @param $runConfiguration * @param $runConfiguration... hmm, should have a testconfiguration?
*/ */


public function runSkipif(rtRuntestsConfiguration $runConfiguration) { public function runSkipif(rtRuntestsConfiguration $runConfiguration) {
Expand Down
43 changes: 21 additions & 22 deletions src/testcase/rtTestOutputWriter.php
Expand Up @@ -118,8 +118,8 @@ public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount
$count = 0; $count = 0;


foreach ($this->resultList as $groupResult) { foreach ($this->resultList as $groupResult) {
foreach($groupResult as $testResult) { foreach($groupResult as $name=>$testStatus) {
$s = $testResult->getStatus()->__toString(); $s = $testStatus->__toString();


if (!isset($state[$s])) { if (!isset($state[$s])) {
$state[$s] = 0; $state[$s] = 0;
Expand Down Expand Up @@ -211,6 +211,7 @@ public function printOverview($groups=NULL, $processCount=NULL) {
*/ */
public static function flushResult(array $results, $state=0, $cid=NULL) public static function flushResult(array $results, $state=0, $cid=NULL)
{ {

switch ($state) { switch ($state) {


case -1: // no ouput case -1: // no ouput
Expand All @@ -227,27 +228,26 @@ public static function flushResult(array $results, $state=0, $cid=NULL)


case 1: // every test-case incl. status case 1: // every test-case incl. status
print "\n"; print "\n";
foreach ($results as $result) { foreach ($results as $name=>$status) {
print strtoupper($result->getStatus())."\t".$result->getName()."\n"; print strtoupper($status->__toString())."\t".$name."\n";
} }
break; break;


case 2: // details about not-passed tests case 2: // details about not-passed tests


foreach ($results as $result) { foreach ($results as $name=>$s) {



$s = $result->getStatus(); $status = $s->__toString();
$name = $s->__toString();


if ($name !== 'pass') { if ($status !== 'pass') {
print "\n"; print "\n";
} }


print strtoupper($name)."\t".$result->getName()."\n"; print strtoupper($s)."\t".$name."\n";


if ($name !== 'pass') { if ($s !== 'pass') {
print "DESC:\t".$result->getTitle()."\n";

$msg = $s->getMessage($name); $msg = $s->getMessage($name);
if (!is_null($msg)) { if (!is_null($msg)) {
print "MSG:\t".$msg."\n"; print "MSG:\t".$msg."\n";
Expand All @@ -260,17 +260,16 @@ public static function flushResult(array $results, $state=0, $cid=NULL)
break; break;


case 3: // all available details 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 "\n";
print strtoupper($name)."\t".$result->getName()."\n";
print "DESC:\t".$result->getTitle()."\n"; print strtoupper($status)."\t".$name."\n";
$msg = $s->getMessage($name); $msg = $s->getMessage($status);


if (!is_null($msg)) { if (!is_null($msg)) {
print "MSG:\t".$msg."\n"; print "MSG:\t".$msg."\n";
Expand All @@ -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"; print "MEM:\t".round(memory_get_usage()/1024, 2)." kB\n";


$files = $result->getSavedFileNames(); $files = $s->getSavedFileNames();


if (sizeof($files) > 0) { if (sizeof($files) > 0) {


Expand Down
36 changes: 14 additions & 22 deletions src/testcase/rtTestResults.php
Expand Up @@ -21,7 +21,6 @@ class rtTestResults
{ {
protected $testStatus; protected $testStatus;
protected $testName = ''; protected $testName = '';
protected $savedFileNames = array();
protected $title = ''; protected $title = '';
protected $time = 0; protected $time = 0;
protected $redirectedTest; protected $redirectedTest;
Expand All @@ -35,11 +34,8 @@ public function init(rtPhpTest $testCase = null, rtTestStatus $testStatus = null
{ {
if ($testCase != null) { if ($testCase != null) {
$this->title = $testCase->getSection('TEST')->getHeader(); $this->title = $testCase->getSection('TEST')->getHeader();
$this->testStatus = $testCase->getStatus(); $this->testStatus = $testCase->getStatus(); //is an object
$this->testName = $testCase->getName(); $this->testName = $testCase->getName();
if($testStatus == 'redirected') {
$this->redirectedTest = $testCase;
}
} else { } else {
$this->testStatus = $testStatus; $this->testStatus = $testStatus;
$this->testName = $testStatus->getTestName(); $this->testName = $testStatus->getTestName();
Expand All @@ -63,7 +59,7 @@ public function processResults(rtPhpTest $testCase, rtRuntestsConfiguration $run


if(file_exists($this->testName . '.mem')) { if(file_exists($this->testName . '.mem')) {
if(filesize($this->testName . '.mem') > 0) { if(filesize($this->testName . '.mem') > 0) {
$this->savedFileNames['mem'] = $this->testName. ".mem"; $this->testStatus->setSavedFileName('mem', $this->testName. ".mem");
} else { } else {
@unlink($this->testName . '.mem'); @unlink($this->testName . '.mem');
} }
Expand All @@ -85,19 +81,19 @@ protected function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfi
if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-php')) { if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-php')) {
$testCase->getFileSection()->deleteFile(); $testCase->getFileSection()->deleteFile();
} else { } else {
$this->savedFileNames['php'] = $this->testName. ".php"; $this->testStatus->setSavedFileName('php', $this->testName. ".php");
} }


if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-out')) { if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-out')) {
$outputFileName = $this->testName.".out"; $outputFileName = $this->testName.".out";
file_put_contents($outputFileName, $testCase->getOutput()); file_put_contents($outputFileName, $testCase->getOutput());
$this->savedFileNames['out'] = $outputFileName; $this->testStatus->setSavedFileName('out', $outputFileName);
} }


if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-exp')) { if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-exp')) {
$expectedFileName = $this->testName.".exp"; $expectedFileName = $this->testName.".exp";
file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents()));
$this->savedFileNames['exp'] = $expectedFileName; $this->testStatus->setSavedFileName('exp', $expectedFileName);
} }


if ($testCase->hasSection('XFAIL')) { if ($testCase->hasSection('XFAIL')) {
Expand All @@ -109,7 +105,7 @@ protected function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfi
if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-clean')) { if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-clean')) {
$testCase->getSection('CLEAN')->deleteFile(); $testCase->getSection('CLEAN')->deleteFile();
} else { } else {
$this->savedFileNames['clean'] = $this->testName. ".clean.php"; $this->testStatus->setSavedFileName('claen', $this->testName. ".clean.php");
} }
} }


Expand All @@ -118,7 +114,7 @@ protected function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfi
} }


if($testCase->getStatus()->getValue('leak') == true) { if($testCase->getStatus()->getValue('leak') == true) {
$this->savedFileNames['mem'] = $testCase->getSection('FILE')->getMemFileName(); $this->testStatus->setSavedFileName('mem', $testCase->getSection('FILE')->getMemFileName());
} }


} }
Expand All @@ -136,9 +132,9 @@ protected function onFail(rtPhpTest $testCase)
file_put_contents($outputFileName, $testCase->getOutput()); file_put_contents($outputFileName, $testCase->getOutput());
file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents()));


$this->savedFileNames['out'] = $outputFileName; $this->testStatus->setSavedFileName('out', $outputFileName);
$this->savedFileNames['exp'] = $expectedFileName; $this->testStatus->setSavedFileName('exp', $expectedFileName);
$this->savedFileNames['diff'] = $differenceFileName; $this->testStatus->setSavedFileName('diff', $differenceFileName);


if ($testCase->hasSection('XFAIL')) { if ($testCase->hasSection('XFAIL')) {
$this->testStatus->setTrue('xfail'); $this->testStatus->setTrue('xfail');
Expand All @@ -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 //Note: if there are clean and skipif files they will not be deleted if the test fails
if ($testCase->hasSection('CLEAN')) { if ($testCase->hasSection('CLEAN')) {
$this->savedFileNames['clean'] = $this->testName. '.clean.php'; $this->testStatus->setSavedFileName('clean', $this->testName. '.clean.php' );
} }


if ($testCase->hasSection('SKIPIF')) { 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) { 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) protected function onSkip(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration)
{ {
if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-skip')) { 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')) { } else if($testCase->hasSection('SKIPIF')) {
$testCase->getSection('SKIPIF')->deleteFile(); $testCase->getSection('SKIPIF')->deleteFile();
} }
Expand All @@ -176,10 +172,6 @@ public function getStatus()
return $this->testStatus; return $this->testStatus;
} }


public function getSavedFileNames()
{
return $this->savedFileNames;
}


public function getName() public function getName()
{ {
Expand Down

0 comments on commit b668d1f

Please sign in to comment.