Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding and testing code to read skipif.inc files to enable whole dire…

…ctory skips
  • Loading branch information...
commit 68730ea02f1d723b6bfa75055365add8fad7ebc0 1 parent 5b5cec2
zoe slattery authored
View
2  build/build.xml
@@ -32,7 +32,7 @@
</target>
<target name="lint" description="Lint check all PHP files.">
- <phplint haltonfailure="true">
+ <phplint haltonfailure="true" level="debug">
<fileset dir="src">
<include name="*.php"/>
<include name="**/*.php"/>
View
8 phpt-tests/group_of_tests/sample_test.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Try a sample test
+--FILE--
+<?php
+ echo "Hello world\n";
+?>
+--EXPECT--
+Hello world
View
3  phpt-tests/group_of_tests/skipif.inc
@@ -0,0 +1,3 @@
+<?php
+ echo "skip me please \n";
+?>
View
2  src/run-tests.php
@@ -20,8 +20,6 @@ function rtExceptionHandler(Exception $e) {
set_exception_handler('rtExceptionHandler');
-
-
/*
* check the version of the running php-executable and
* ensure that is 5.3 or higher
View
12 src/testcase/rtTestOutputWriter.php
@@ -98,7 +98,7 @@ public function write($filename=null)
* @param integer $processCount
* @return string
*/
- public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount)
+ public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount, $skippedGroups)
{
// if the overview was already created retun it
if (!is_null($this->overview)) {
@@ -134,6 +134,12 @@ public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount
$str = '';
$str .= "\n\n----------------------------------------\n";
+ $str .= "Number of skipped groups:";
+ $blanks = 30 - strlen("Number of skipped groups:") - strlen(count($skippedGroups));
+ $str = $this->writeBlanks($str, $blanks);
+ $str .= count($skippedGroups);
+ $str .= "\n----------------------------------------\n";
+
$str .= "Tests:";
$blanks = 30 - strlen("Tests:") - strlen($count);
$str = $this->writeBlanks($str, $blanks);
@@ -194,9 +200,9 @@ public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount
}
- public function printOverview($parallelGroups=NULL, $serialGroups = NULL, $processCount=NULL) {
+ public function printOverview($parallelGroups=NULL, $serialGroups = NULL, $processCount=NULL, $skippedGroups=null) {
- print $this->getOverview($parallelGroups, $serialGroups, $processCount);
+ print $this->getOverview($parallelGroups, $serialGroups, $processCount, $skippedGroups);
flush();
}
View
27 src/testgroup/rtGroupConfiguration.php
@@ -21,6 +21,8 @@ class rtGroupConfiguration
protected $isRedirect=false;
protected $serialGroup=false;
protected $redirectFromID = null;
+ protected $skipFile = "";
+ protected $hasSkipCode = false;
public function __construct($directory)
@@ -29,8 +31,7 @@ public function __construct($directory)
}
public function parseRedirect(rtPHPTest $redirectedTest) {
- //Going to assume that we have already parsed the SKIPIF (if it exists)
- //var_dump($redirectedTest->getSection('REDIRECTTEST')->getContents());
+
$name = $redirectedTest->getName();
$code = implode($redirectedTest->getSection('REDIRECTTEST')->getContents(), "\n");
@@ -75,7 +76,7 @@ public function parseRedirect(rtPHPTest $redirectedTest) {
//Find the key in the full name of the test contains the redirect
$position = strpos($name, $key);
- //Take the root strng from before the key
+ //Take the root string from before the key
$root=substr($name, 0, $position);
$title = $redirectedTest->getSection('TEST')->getContents();
@@ -94,14 +95,22 @@ public function parseRedirect(rtPHPTest $redirectedTest) {
}
- public function parse() {
- //Here insert code to read a config file from the test directory that determines whether the set of tests shoudl be run
+ public function parseConfiguration() {
+ //Here insert code to read a config file from the test directory that determines whether the set of tests should be run
//in parallel or not?
$this->serialGroup = false;
+
+
+ //Code to read the directory skipif, run it and skip the directory
+ if(file_exists($this->testDirectory. "/skipif.inc")) {
+ $this->hasSkipCode = true;
+ $this->skipFile = $this->testDirectory."/skipif.inc";
+ }
return;
}
+
public function getEnvironmentVariables() {
return $this->environmentVariables;
}
@@ -116,6 +125,12 @@ public function isSerial() {
}
public function getRedirectFromID() {
return $this->redirectFromID;
- }
+ }
+ public function hasSkipCode() {
+ return $this->hasSkipCode;
+ }
+ public function getSkipFile() {
+ return $this->skipFile;
+ }
}
View
8 src/testgroup/rtGroupResults.php
@@ -22,6 +22,7 @@ class rtGroupResults
protected $runOrder;
protected $runByProcessor = 0;
protected $absTime;
+ protected $isSkipGroup = false;
public function __construct($gn) {
$this->groupName = $gn;
@@ -68,6 +69,10 @@ public function setCount($c) {
public function setProc($p) {
$this->runByProcessor = $p;
}
+ public function setSkip($s) {
+ $this->isSkipGroup = $s;
+ }
+
public function getTime() {
return $this->timeToRun;
}
@@ -82,6 +87,9 @@ public function getProcessorId() {
public function getAbsTime() {
return $this->absTime;
}
+ public function isSkipGroup() {
+ return $this->isSkipGroup;
+ }
}
View
198 src/testgroup/rtPhpTestGroup.php
@@ -19,112 +19,136 @@ class rtPhpTestGroup extends rtTask implements rtTaskInterface
protected $runConfiguration;
protected $groupConfiguration;
protected $groupResults;
-
+
+
public function __construct(rtRuntestsConfiguration $runConfiguration, $directory, $groupConfiguration)
{
- $this->runConfiguration = $runConfiguration;
+ $this->runConfiguration = $runConfiguration;
$this->testDirectory = $directory;
- $this->groupConfiguration = $groupConfiguration;
+ $this->groupConfiguration = $groupConfiguration;
$this->groupResults = new rtGroupResults($directory);
$this->init();
}
-
+
public function __destruct() {
- unset ($this->testCases);
- unset ($this->groupResults);
-
+ unset ($this->testCases);
+ unset ($this->groupResults);
+
}
-
+
public function init()
- {
- if($this->groupConfiguration->isRedirect()) {
- //merge in environmental variables (this is for REDEIRRECT).
- foreach($this->groupConfiguration->getEnvironmentVariables() as $key=>$value) {
- $this->runConfiguration->setEnvironmentVariable($key, $value);
- }
- }
-
-
- $this->testFiles = rtUtil::getTestList($this->testDirectory);
-
- $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
-
- if (!file_exists($testFileName)) {
- echo rtText::get('invalidTestFileName', array($testFileName));
- exit();
+ {
+ if($this->groupConfiguration->isRedirect()) {
+ //merge in environmental variables (this is for REDEIRRECT).
+ foreach($this->groupConfiguration->getEnvironmentVariables() as $key=>$value) {
+ $this->runConfiguration->setEnvironmentVariable($key, $value);
}
-
- // Create a new test file object;
- $testFile = new rtPhpTestFile();
- $testFile->doRead($testFileName);
- $testFile->normaliseLineEndings();
-
- //The test name is the full path to the test file name without the .phpt
-
- $testStatus = new rtTestStatus($testFile->getTestName());
- if ($testFile->arePreconditionsMet() ) {
- // Create a new test case
- $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus, $redirectFromID);
- } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){
- //Redirect handler, save the test case for processing after the main groups have finished.
- //Check to make sure that it shouldn't be skipped, if skipped don't save it
- $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus);
- if($redirectedTest->hasSection('SKIPIF')) {
- $redirectedTest->runSkipif($this->runConfiguration);
- if($redirectedTest->getStatus()->getValue('skip')) {
- $testStatus->setTrue('skip');
- $testStatus->setMessage('skip', $testFile->getExitMessage(). ' and the skip condition has failed');
- $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus);
- } else {
- $testStatus->setTrue('redirected');
- $testStatus->setMessage('redirected', $testFile->getExitMessage());
- $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus);
- $this->groupResults->setRedirectedTestCase($redirectedTest);
- }
-
- }
+ }
+
+ if($this->groupConfiguration->hasSkipCode()) {
- }else {
- $testStatus->setTrue('bork');
- $testStatus->setMessage('bork', $testFile->getExitMessage());
- $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus);
-
+ //If there is some 'skip' code run it to see if the tests should be skipped and then do nothing else
+
+ $phpCommand = $this->runConfiguration->getSetting('PhpExecutable');
+ $arguments = preg_replace('/error_reporting=32767/', 'error_reporting=0', $this->runConfiguration->getSetting('PhpCommandLineArguments'));
+
+ $phpCommand .= ' -f '.$this->groupConfiguration->getSkipFile();
+
+ $runner = new rtPhpRunner($phpCommand);
+ $result = $runner->runphp();
+
+
+ if (preg_match('/^\s*skip\s*(.+)\s*/i', $result, $matches)) {
+ $this->groupResults->setSkip(true);
+
}
+ }
+
+
+ if($this->isSkipGroup() !== true) {
+
+ $this->testFiles = rtUtil::getTestList($this->testDirectory);
+
+ $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
+
+ if (!file_exists($testFileName)) {
+ echo rtText::get('invalidTestFileName', array($testFileName));
+ exit();
+ }
+
+ // Create a new test file object;
+ $testFile = new rtPhpTestFile();
+ $testFile->doRead($testFileName);
+ $testFile->normaliseLineEndings();
+
+ //The test name is the full path to the test file name without the .phpt
+
+ $testStatus = new rtTestStatus($testFile->getTestName());
+ if ($testFile->arePreconditionsMet() ) {
+ // Create a new test case
+ $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus, $redirectFromID);
+ } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){
+ //Redirect handler, save the test case for processing after the main groups have finished.
+ //Check to make sure that it shouldn't be skipped, if skipped don't save it
+ $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus);
+ if($redirectedTest->hasSection('SKIPIF')) {
+ $redirectedTest->runSkipif($this->runConfiguration);
+ if($redirectedTest->getStatus()->getValue('skip')) {
+ $testStatus->setTrue('skip');
+ $testStatus->setMessage('skip', $testFile->getExitMessage(). ' and the skip condition has failed');
+ $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus);
+ } else {
+ $testStatus->setTrue('redirected');
+ $testStatus->setMessage('redirected', $testFile->getExitMessage());
+ $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus);
+ $this->groupResults->setRedirectedTestCase($redirectedTest);
+ }
+
+ }
+
+ } else {
+ $testStatus->setTrue('bork');
+ $testStatus->setMessage('bork', $testFile->getExitMessage());
+ $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus);
+
+ }
+
//echo "\n" .memory_get_usage() . ", setup complete". $testFileName . "\n";
+ }
}
}
public function run()
{
- $s=microtime(true);
-
+ $s=microtime(true);
+
if (count($this->testCases) == 0) {
return;
}
-
+
for($i=0; $i<count($this->testCases); $i++) {
-
- $testCase = $this->testCases[$i];
+
+ $testCase = $this->testCases[$i];
$testCase->executeTest($this->runConfiguration);
-
-
+
+
$testResult = new rtTestResults($testCase);
$testResult->processResults($testCase, $this->runConfiguration);
- $this->groupResults->setTestStatus($testCase->getName(), $testResult->getStatus());
-
-
+ $this->groupResults->setTestStatus($testCase->getName(), $testResult->getStatus());
+
+
}
-
+
$e=microtime(true);
-
+
$this->groupResults->setTime($e-$s);
$this->groupResults->setAbsTime($e);
}
@@ -134,19 +158,23 @@ public function writeGroup($outType, $cid=null)
$testOutputWriter = rtTestOutputWriter::getInstance($this->groupResults->getTestStatusList(), $outType);
$testOutputWriter->write($this->testDirectory, $cid);
}
-
-
+
+
public function getTestCases() {
- return $this->testCases;
+ return $this->testCases;
}
-
+
public function getGroupName() {
- return $this->testDirectory;
+ return $this->testDirectory;
}
-
- public function getGroupResults() {
- return $this->groupResults;
+
+ public function getGroupResults() {
+ return $this->groupResults;
}
-
+
+ public function isSkipGroup() {
+ return $this->groupResults->isSkipGroup();
+ }
+
}
?>
View
785 src/testrun/rtPhpTestRun.php
@@ -15,397 +15,410 @@
*/
class rtPhpTestRun
{
- protected $commandLineArguments;
- protected $runConfiguration;
- protected $redirectedTestCases = array();
- protected $resultList = array(); //An array of arrays of Group Results
- protected $serialTasks = array();
- protected $parallelTasks = array();
- protected $reportStatus = 0;
- protected $numberOfSerialGroups = 0;
- protected $numberOfParallelGroups = 0;
- protected $processorCount;
- protected $runStartTime;
-
- public function __construct($argv)
- {
- $this->commandLineArguments = $argv;
- }
-
- public function run()
- {
+ protected $commandLineArguments;
+ protected $runConfiguration;
+ protected $redirectedTestCases = array();
+ protected $resultList = array(); //An array of arrays of Group Results
+ protected $serialTasks = array();
+ protected $parallelTasks = array();
+ protected $reportStatus = 0;
+ protected $numberOfSerialGroups = 0;
+ protected $numberOfParallelGroups = 0;
+ protected $processorCount;
+ protected $runStartTime;
+ protected $skippedGroups = array();
+
+ public function __construct($argv)
+ {
+ $this->commandLineArguments = $argv;
+ }
+
+ public function run()
+ {
$this->runStartTime = microtime(true);
- //Set SSH variables
-
- // check the operation-system (win/unix)
- $os = (substr(PHP_OS, 0, 3) == "WIN") ? 'Windows' : 'Unix';
-
- //Configure the test environment
- $this->runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments, $os);
- $this->runConfiguration->getUserEnvironment();
- $this->runConfiguration->configure();
-
-
-
- //Check help message
- if($this->runConfiguration->hasCommandLineOption('help') || $this->runConfiguration->hasCommandLineOption('h')) {
- echo rtText::get('help');
- exit;
- }
-
- //Check the preconditions
- $preConditionList = rtPreConditionList::getInstance($os);
- $preConditionList->adaptList();
-
- // $preConditionList->check($this->commandLine, $this->environmentVariables);
- $preConditionList->check($this->runConfiguration);
-
- //Write PHP executable name to the array of env variables. Some
- //test cases expect to be able to use it.
- $php = $this->runConfiguration->getSetting('PhpExecutable');
- $this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php);
-
- //Set reporting option
- $this->setReportStatus();
-
- $this->processorCount = $this->requestedProcessorCount();
-
+ //Set SSH variables
+
+ // check the operation-system (win/unix)
+ $os = (substr(PHP_OS, 0, 3) == "WIN") ? 'Windows' : 'Unix';
+
+ //Configure the test environment
+ $this->runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments, $os);
+ $this->runConfiguration->getUserEnvironment();
+ $this->runConfiguration->configure();
+
+
+
+ //Check help message
+ if($this->runConfiguration->hasCommandLineOption('help') || $this->runConfiguration->hasCommandLineOption('h')) {
+ echo rtText::get('help');
+ exit;
+ }
+
+ //Check the preconditions
+ $preConditionList = rtPreConditionList::getInstance($os);
+ $preConditionList->adaptList();
+
+ // $preConditionList->check($this->commandLine, $this->environmentVariables);
+ $preConditionList->check($this->runConfiguration);
+
+ //Write PHP executable name to the array of env variables. Some
+ //test cases expect to be able to use it.
+ $php = $this->runConfiguration->getSetting('PhpExecutable');
+ $this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php);
+
+ //Set reporting option
+ $this->setReportStatus();
+
+ $this->processorCount = $this->requestedProcessorCount();
+
/*
- * Main decision point. Either we start this with a directory (or set of directories, in which case tests are
+ * Main decision point. Either we start this with a directory (or set of directories, in which case tests are
* run as a group (and in parallel if required) or......
- */
- if ($this->runConfiguration->getSetting('TestDirectories') != null) {
-
- $this->doGroupRuns();
-
- } else {
-
- /*
- *... the input is a test file, or list of files and are just run as single tests
- * and not in parallel
- */
- if ($this->runConfiguration->getSetting('TestFiles') == null) {
- echo rtText::get('invalidTestFileName');
- exit();
- }else{
- $this->run_tests($this->runConfiguration->getSetting('TestFiles'));
- }
- }
-
- if(count($this->redirectedTestCases) > 0) {
- $this->doRedirectedRuns();
- }
-
- if(($this->numberOfSerialGroups != 0) || ($this->numberOfParallelGroups != 0)) {
- $this->createRunOutput();
- }
-
- }
-
- public function doGroupRuns() {
-
- $subDirectories = $this->buildSubDirectoryList($this->runConfiguration->getSetting('TestDirectories'));
- $groupConfigurations = $this->buildGroupConfigurations($subDirectories);
-
- //If there is only one subdirectory, run seqential
-
- if(count($subDirectories) === 1) {
- $this->run_serial_groups($subDirectories, $groupConfigurations);
- $this->numberOfSerialGroups = 1;
-
- } else {
-
- //check to see if this is set to be a parallel run, if not, run the subdirectory groups in sequence.
- if($this->processorCount <= 1) {
- $this->run_serial_groups($subDirectories, $groupConfigurations);
- $this->numberOfSerialGroups = count($subDirectories);
- } else {
- //At least part of this run can be in parallel, check group configurations to make sure that none are set to be serial.
- //This builds parallel and serial task lists.
- foreach($groupConfigurations as $key=>$gc) {
- if($gc->isSerial()) {
- $serialGroups[] = $key;
- } else {
- $parallelGroups[] = $key;
- }
- }
-
- if(isset($serialGroups)) {$this->numberOfSerialGroups = count($serialGroups);}
-
- $this->numberOfParallelGroups = count($parallelGroups);
-
- $this->run_parallel_groups($parallelGroups, $groupConfigurations, $this->processorCount);
- if($this->numberOfSerialGroups > 0) {
- $this->run_serial_groups($serialGroups, $groupConfigurations);
- }
- }
- }
-
- }
-
- public function doRedirectedRuns() {
- foreach($this->redirectedTestCases as $testCase){
-
- $groupConfig = new rtGroupConfiguration(null);
- $groupConfig->parseRedirect($testCase);
-
- $group = $groupConfig->getTestDirectory();
-
- $this->run_serial_groups(array($group), array($group=>$groupConfig));
-
- $this->numberOfSerialGroups++;
-
- }
- }
-
- public function run_parallel_groups($testDirectories, $groupConfigurations, $processCount) {
-
- // create the task-list
- $taskList = array();
- foreach($testDirectories as $testGroup) {
- $taskList[] = new rtTaskTestGroup($this->runConfiguration, $testGroup, $groupConfigurations[$testGroup]);
- }
-
- // run the task-scheduler
- $scheduler = rtTaskScheduler::getInstance();
- $scheduler->setTaskList($taskList);
- $scheduler->setProcessCount($processCount);
- $scheduler->setReportStatus($this->reportStatus);
- $scheduler->run();
-
- foreach($scheduler->getResultList() as $groupResult) {
-
- $this->resultList[] = $groupResult->getTestStatusList();
-
- // Debug - get which group was run by which processor and how long each took
- //
-
- if($this->runConfiguration->hasCommandLineOption('debug')) {
- $time = round($groupResult->getTime(), 2);
-
- $absTime = $groupResult->getAbsTime() - $this->runStartTime;
-
- $absTime = round($absTime, 2);
-
- echo "\nPARDBG," . $absTime. "," . $time . "," . $groupResult->getProcessorId() . "," . $groupResult->getRunOrder() . "," . $groupResult->getGroupName();
-
- }
-
- $redirects = $groupResult->getRedirectedTestCases();
- foreach($redirects as $testCase) {
- $this->redirectedTestCases[] = $testCase;
- }
- }
-
-
-
- }
-
- public function run_serial_groups($testDirectories, $groupConfigurations) {
-
- $count = 0;
-
-
- //xdebug_start_trace('/tmp/memorycheck');
-
- 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->getGroupResults()->getTestStatusList(), $this->reportStatus);
- $this->resultList[] = $testGroup->getGroupResults()->getTestStatusList();
-
- if($this->runConfiguration->hasCommandLineOption('debug')) {
-
- $time = round($testGroup->getGroupResults()->getTime(), 2);
-
- $absTime = ($testGroup->getGroupResults()->getAbsTime()) - $this->runStartTime;
- $absTime = round($absTime, 2);
-
-
- echo "\nSERDBG," . $absTime . "," . $time . "," . $testGroup->getGroupResults()->getProcessorId() . "," . $count . "," . $testGroup->getGroupResults()->getGroupName();
-
- }
-
- // Memory usage debugging
- //$midm2 = memory_get_usage();
-
- $redirects = $testGroup->getGroupResults()->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";
- $count++;
- }
-
- //xdebug_stop_trace();
- }
-
- public function run_tests($testNames) {
-
- //This section deals with running single test cases, or lists of test cases.
-
- foreach ($testNames as $testName) {
+ */
+ if ($this->runConfiguration->getSetting('TestDirectories') != null) {
+
+ $this->doGroupRuns();
+
+ } else {
+
+ /*
+ *... the input is a test file, or list of files and are just run as single tests
+ * and not in parallel
+ */
+ if ($this->runConfiguration->getSetting('TestFiles') == null) {
+ echo rtText::get('invalidTestFileName');
+ exit();
+ }else{
+ $this->run_tests($this->runConfiguration->getSetting('TestFiles'));
+ }
+ }
+
+ if(count($this->redirectedTestCases) > 0) {
+ $this->doRedirectedRuns();
+ }
+
+ if(($this->numberOfSerialGroups != 0) || ($this->numberOfParallelGroups != 0)) {
+ $this->createRunOutput();
+ }
+
+ }
+
+ public function doGroupRuns() {
+
+ $subDirectories = $this->buildSubDirectoryList($this->runConfiguration->getSetting('TestDirectories'));
+
+ //An array of group configuration objects, one for each subdirectory.
+ $groupConfigurations = $this->buildGroupConfigurations($subDirectories);
+
+
+ //If there is only one subdirectory, run seqential
+
+ if(count($subDirectories) === 1) {
+ $this->run_serial_groups($subDirectories, $groupConfigurations);
+ $this->numberOfSerialGroups = 1;
+
+ } else {
+
+ //check to see if this is set to be a parallel run, if not, run the subdirectory groups in sequence.
+ if($this->processorCount <= 1) {
+ $this->run_serial_groups($subDirectories, $groupConfigurations);
+ $this->numberOfSerialGroups = count($subDirectories);
+ } else {
+ //At least part of this run can be in parallel, check group configurations to make sure that none are set to be serial.
+ //This builds parallel and serial task lists.
+ foreach($groupConfigurations as $key=>$gc) {
+ if($gc->isSerial()) {
+ $serialGroups[] = $key;
+ } else {
+ $parallelGroups[] = $key;
+ }
+ }
+
+ if(isset($serialGroups)) {$this->numberOfSerialGroups = count($serialGroups);}
+
+ $this->numberOfParallelGroups = count($parallelGroups);
+
+ $this->run_parallel_groups($parallelGroups, $groupConfigurations, $this->processorCount);
+ if($this->numberOfSerialGroups > 0) {
+ $this->run_serial_groups($serialGroups, $groupConfigurations);
+ }
+ }
+ }
+
+ }
+
+ public function doRedirectedRuns() {
+ foreach($this->redirectedTestCases as $testCase){
+
+ $groupConfig = new rtGroupConfiguration(null);
+ $groupConfig->parseRedirect($testCase);
+
+ $group = $groupConfig->getTestDirectory();
+
+ $this->run_serial_groups(array($group), array($group=>$groupConfig));
+
+ $this->numberOfSerialGroups++;
+
+ }
+ }
+
+ public function run_parallel_groups($testDirectories, $groupConfigurations, $processCount) {
- if (!file_exists($testName)) {
- echo rtText::get('invalidTestFileName', array($testName));
- exit();
- }
-
-
- //Read the test file
- $testFile = new rtPhpTestFile();
- $testFile->doRead($testName);
- $testFile->normaliseLineEndings();
-
- $testStatus = new rtTestStatus($testFile->getTestName());
-
-
- if ($testFile->arePreconditionsMet()) {
- $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus);
-
- //Setup and set the local environment for the test case
- $testCase->executeTest($this->runConfiguration);
-
- $results = new rtTestResults($testCase);
- $results->processResults($testCase, $this->runConfiguration);
- $summaryResults = array($testFile->getTestName() => $results->getStatus());
-
- } elseif (in_array("REDIRECTTEST", $testFile->getSectionHeadings())) {
-
- //Redirect handler
- //Build a list of redirected test cases
-
- $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus);
-
- $testStatus->setTrue('redirected');
- $testStatus->setMessage('redirected', $testFile->getExitMessage());
- $summaryResults = array($testFile->getTestName() => $testStatus);
-
- } else {
- $testStatus->setTrue('bork');
- $testStatus->setMessage('bork', $testFile->getExitMessage());
- $summaryResults = array($testFile->getTestName() => $testStatus);
- }
+ // create the task-list
+ $taskList = array();
+ foreach($testDirectories as $testGroup) {
+ $taskList[] = new rtTaskTestGroup($this->runConfiguration, $testGroup, $groupConfigurations[$testGroup]);
+ }
+
+ // run the task-scheduler
+ $scheduler = rtTaskScheduler::getInstance();
+ $scheduler->setTaskList($taskList);
+ $scheduler->setProcessCount($processCount);
+ $scheduler->setReportStatus($this->reportStatus);
+ $scheduler->run();
+
+ foreach($scheduler->getResultList() as $groupResult) {
+
+ if($groupResult->isSkipGroup()) {
+ $this->skippedGroups[] = $groupResult->getGroupName();
+ } else {
+ $this->resultList[] = $groupResult->getTestStatusList();
+ }
+
+ // Debug - get which group was run by which processor and how long each took
+ //
+
+ if($this->runConfiguration->hasCommandLineOption('debug')) {
+ $time = round($groupResult->getTime(), 2);
+
+ $absTime = $groupResult->getAbsTime() - $this->runStartTime;
+
+ $absTime = round($absTime, 2);
+
+ echo "\nPARDBG," . $absTime. "," . $time . "," . $groupResult->getProcessorId() . "," . $groupResult->getRunOrder() . "," . $groupResult->getGroupName();
+
+ }
+
+ $redirects = $groupResult->getRedirectedTestCases();
+ foreach($redirects as $testCase) {
+ $this->redirectedTestCases[] = $testCase;
+ }
+ }
+
+
+
+ }
+
+ public function run_serial_groups($testDirectories, $groupConfigurations) {
+
+ $count = 0;
+
+ foreach($testDirectories as $subDirectory) {
+
+ // Memory usage debugging
+ //$startm = memory_get_usage();
+
+
+
+ $testGroup = new rtPhpTestGroup($this->runConfiguration, $subDirectory, $groupConfigurations[$subDirectory]);
- rtTestOutputWriter::flushResult($summaryResults, 3);
-
- }
- }
-
- public function buildSubDirectoryList($testDirectories){
-
-
- $subDirectories = array();
- foreach ($testDirectories as $testDirectory) {
- $subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory));
- }
- return $subDirectories;
- }
-
- public function requestedProcessorCount() {
- // check for the cmd-line-option 'z' which defines parellel-execution
- $processCount = 0;
- if ($this->runConfiguration->hasCommandLineOption('z')) {
-
- $processCount = intval($this->runConfiguration->getCommandLineOption('z'));
-
- if (!is_numeric($processCount) || $processCount < 0) {
- $processCount = 2;
- }
- }
- return $processCount;
- }
-
- public function buildGroupConfigurations($subDirectories) {
- $groupConfigurations = array();
- foreach($subDirectories as $subDir) {
- $groupConfig = new rtGroupConfiguration($subDir);
- $groupConfig->parse();
- $groupConfigurations[$subDir] = $groupConfig;
- }
- return $groupConfigurations;
- }
-
- public function buildRedirectsList($results) {
- foreach ($results as $groupResult) {
- foreach($groupResult as $testResult) {
- if($testResult->getStatus() == 'redirected') {
- $this->redirectedTestCases[] = $testResult->getRedirectedTestCase();
- }
- }
- }
- }
-
- public function createRunOutput() {
- $type = null;
- if ($this->runConfiguration->hasCommandLineOption('o')) {
- $type = $this->runConfiguration->getCommandLineOption('o');
- }
-
- $outputWriter = rtTestOutputWriter::getInstance($type);
- $outputWriter->setResultList($this->resultList);
-
- $outputWriter->printOverview($this->numberOfParallelGroups, $this->numberOfSerialGroups, $this->processorCount);
-
- $filename = null;
- if ($this->runConfiguration->hasCommandLineOption('s')) {
- $filename = $this->runConfiguration->getCommandLineOption('s');
- }
-
- if ($type || $filename) {
- $outputWriter->write($filename);
- }
- }
-
- public function setReportStatus() {
- // check for the cmd-line-option 'v' which defines the report-status
- if ($this->runConfiguration->hasCommandLineOption('v')) {
- $this->reportStatus = 1;
- } else if ($this->runConfiguration->hasCommandLineOption('vv')) {
- $this->reportStatus = 2;
- } else if ($this->runConfiguration->hasCommandLineOption('vvv')) {
- $this->reportStatus = 3;
- }
-
- //Set the default for runs from 'make test'
- if ( file_exists(getcwd() . "/sapi/cli/php")) {
- $this->reportStatus = 1;
- }
- }
-
- 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;
- }
-
+
+ if($testGroup->isSkipGroup() == true) {
+ $this->skippedGroups[] = $testGroup->getGroupName();
+ } else {
+
+
+ $testGroup->run();
+
+
+ // Memory usage debugging
+ //$midm = memory_get_usage();
+
+ rtTestOutputWriter::flushResult($testGroup->getGroupResults()->getTestStatusList(), $this->reportStatus);
+ $this->resultList[] = $testGroup->getGroupResults()->getTestStatusList();
+
+ if($this->runConfiguration->hasCommandLineOption('debug')) {
+
+ $time = round($testGroup->getGroupResults()->getTime(), 2);
+
+ $absTime = ($testGroup->getGroupResults()->getAbsTime()) - $this->runStartTime;
+ $absTime = round($absTime, 2);
+
+
+ echo "\nSERDBG," . $absTime . "," . $time . "," . $testGroup->getGroupResults()->getProcessorId() . "," . $count . "," . $testGroup->getGroupResults()->getGroupName();
+
+ }
+
+ // Memory usage debugging
+ //$midm2 = memory_get_usage();
+
+ $redirects = $testGroup->getGroupResults()->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";
+ $count++;
+ }
+ }
+
+ //xdebug_stop_trace();
+ }
+
+ public function run_tests($testNames) {
+
+ //This section deals with running single test cases, or lists of test cases.
+
+ foreach ($testNames as $testName) {
+
+ if (!file_exists($testName)) {
+ echo rtText::get('invalidTestFileName', array($testName));
+ exit();
+ }
+
+
+ //Read the test file
+ $testFile = new rtPhpTestFile();
+ $testFile->doRead($testName);
+ $testFile->normaliseLineEndings();
+
+ $testStatus = new rtTestStatus($testFile->getTestName());
+
+
+ if ($testFile->arePreconditionsMet()) {
+ $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus);
+
+ //Setup and set the local environment for the test case
+ $testCase->executeTest($this->runConfiguration);
+
+ $results = new rtTestResults($testCase);
+ $results->processResults($testCase, $this->runConfiguration);
+ $summaryResults = array($testFile->getTestName() => $results->getStatus());
+
+ } elseif (in_array("REDIRECTTEST", $testFile->getSectionHeadings())) {
+
+ //Redirect handler
+ //Build a list of redirected test cases
+
+ $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus);
+
+ $testStatus->setTrue('redirected');
+ $testStatus->setMessage('redirected', $testFile->getExitMessage());
+ $summaryResults = array($testFile->getTestName() => $testStatus);
+
+ } else {
+ $testStatus->setTrue('bork');
+ $testStatus->setMessage('bork', $testFile->getExitMessage());
+ $summaryResults = array($testFile->getTestName() => $testStatus);
+ }
+
+ rtTestOutputWriter::flushResult($summaryResults, 3);
+
+ }
+ }
+
+ public function buildSubDirectoryList($testDirectories){
+
+
+ $subDirectories = array();
+ foreach ($testDirectories as $testDirectory) {
+ $subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory));
+ }
+ return $subDirectories;
+ }
+
+ public function requestedProcessorCount() {
+ // check for the cmd-line-option 'z' which defines parellel-execution
+ $processCount = 0;
+ if ($this->runConfiguration->hasCommandLineOption('z')) {
+
+ $processCount = intval($this->runConfiguration->getCommandLineOption('z'));
+
+ if (!is_numeric($processCount) || $processCount < 0) {
+ $processCount = 2;
+ }
+ }
+ return $processCount;
+ }
+
+ public function buildGroupConfigurations($subDirectories) {
+ $groupConfigurations = array();
+ foreach($subDirectories as $subDir) {
+ $groupConfig = new rtGroupConfiguration($subDir);
+ $groupConfig->parseConfiguration();
+ $groupConfigurations[$subDir] = $groupConfig;
+ }
+ return $groupConfigurations;
+ }
+
+ public function buildRedirectsList($results) {
+ foreach ($results as $groupResult) {
+ foreach($groupResult as $testResult) {
+ if($testResult->getStatus() == 'redirected') {
+ $this->redirectedTestCases[] = $testResult->getRedirectedTestCase();
+ }
+ }
+ }
+ }
+
+ public function createRunOutput() {
+ $type = null;
+ if ($this->runConfiguration->hasCommandLineOption('o')) {
+ $type = $this->runConfiguration->getCommandLineOption('o');
+ }
+
+ $outputWriter = rtTestOutputWriter::getInstance($type);
+ $outputWriter->setResultList($this->resultList);
+
+ $outputWriter->printOverview($this->numberOfParallelGroups, $this->numberOfSerialGroups, $this->processorCount, $this->skippedGroups);
+
+ $filename = null;
+ if ($this->runConfiguration->hasCommandLineOption('s')) {
+ $filename = $this->runConfiguration->getCommandLineOption('s');
+ }
+
+ if ($type || $filename) {
+ $outputWriter->write($filename);
+ }
+ }
+
+ public function setReportStatus() {
+ // check for the cmd-line-option 'v' which defines the report-status
+ if ($this->runConfiguration->hasCommandLineOption('v')) {
+ $this->reportStatus = 1;
+ } else if ($this->runConfiguration->hasCommandLineOption('vv')) {
+ $this->reportStatus = 2;
+ } else if ($this->runConfiguration->hasCommandLineOption('vvv')) {
+ $this->reportStatus = 3;
+ }
+
+ //Set the default for runs from 'make test'
+ if ( file_exists(getcwd() . "/sapi/cli/php")) {
+ $this->reportStatus = 1;
+ }
+ }
+
+ 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
18 tests/rtGroupConfigurationTest.php
@@ -3,12 +3,26 @@
require_once dirname(__FILE__) . '/rtTestBootstrap.php';
class rtGroupConfigurationTest extends PHPUnit_Framework_TestCase
+
{
+ protected $path_to_group;
+
+ public function setUp() {
+ $this->path_to_group = realpath(dirname(__FILE__) . '/../phpt-tests/group_of_tests');
+ }
+
public function testCreateInstance()
{
- //$directory = realpath(dirname(__FILE__) . '/../phpt-tests');
$config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', RT_PHP_PATH, 'testgroup'));
- $config->configure();
+ $config->configure();
+
+ $groupConfig = new rtGroupConfiguration($this->path_to_group);
+
+ $groupConfig->parseConfiguration();
+
+ $this->assertTrue(file_exists($groupConfig->getSkipFile()));
+ $this->assertTrue($groupConfig->hasSkipCode());
+
}
}
View
14 tests/rtPhpTestGroupTest.php
@@ -53,6 +53,20 @@ public function testFindRedirect()
}
}
+ public function testSkipGroup() {
+ $directory = realpath(dirname(__FILE__) . '/../phpt-tests/group_of_tests');
+ $run_config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', RT_PHP_PATH, $directory));
+
+ $run_config->configure();
+
+ $group_config = new rtGroupConfiguration($directory);
+ $group_config->parseConfiguration();
+
+ $phpTestGroup = new rtPhpTestGroup($run_config, $directory, $group_config);
+ $phpTestGroup->init();
+
+ $this->assertTrue($phpTestGroup->isSkipGroup());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.