zoe Tue, 28 Jul 2009 20:48:15 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=286467
Log:
code to use an external memory checker (valgrind)
framework to add others
Changed paths:
U php/phpruntests/trunk/src/configuration/rtCommandLineOptions.php
A php/phpruntests/trunk/src/configuration/rtExternalTool.php
U php/phpruntests/trunk/src/configuration/rtRuntestsConfiguration.php
A php/phpruntests/trunk/src/configuration/tools/
A php/phpruntests/trunk/src/configuration/tools/rtValgrind.php
U php/phpruntests/trunk/src/rtClassMap.php
U php/phpruntests/trunk/src/testcase/rtTestConfiguration.php
U
php/phpruntests/trunk/src/testcase/sections/executablesections/rtFileSection.php
A php/phpruntests/trunk/tests/configuration/rtExternalToolTest.php
Modified: php/phpruntests/trunk/src/configuration/rtCommandLineOptions.php
===================================================================
--- php/phpruntests/trunk/src/configuration/rtCommandLineOptions.php 2009-07-28 20:35:06 UTC (rev 286466)
+++ php/phpruntests/trunk/src/configuration/rtCommandLineOptions.php 2009-07-28 20:48:15 UTC (rev 286467)
@@ -74,6 +74,7 @@
'temp-source',
'temp-target',
'set-timeout',
+ 'mopts',
);
/**
Added: php/phpruntests/trunk/src/configuration/rtExternalTool.php
===================================================================
--- php/phpruntests/trunk/src/configuration/rtExternalTool.php (rev 0)
+++ php/phpruntests/trunk/src/configuration/rtExternalTool.php 2009-07-28 20:48:15 UTC (rev 286467)
@@ -0,0 +1,45 @@
+<?php
+/**
+ * rtExternalTool
+ *
+ * Class to handle using an external tool (default is valgrind)
+ *
+ * @category Testing
+ * @package RUNTESTS
+ * @author Zoe Slattery <[email protected]>
+ * @author Stefan Priebsch <[email protected]>
+ * @copyright 2009 The PHP Group
+ * @license http://www.php.net/license/3_01.txt PHP License 3.01
+ * @link http://qa.php.net/
+ *
+ */
+
+class rtExternalTool
+{
+ protected $command;
+ protected $options;
+ protected $version;
+
+ public static function getInstance($configuration)
+ {
+ if($configuration->hasCommandLineOption('m')) {
+ return new rtValgrind();
+ } else {
+ $name = 'rt' . $configuration->getCommandLineOption('mtool');
+ return new $name();
+ }
+ }
+
+ public function init(rtRuntestsConfiguration $configuration) {
+ $this->setVersion();
+ $this->setCommand($configuration);
+ $this->setOptions($configuration);
+ }
+
+ public function getCommand() {
+ return $this->command;
+ }
+
+
+}
+?>
\ No newline at end of file
Modified: php/phpruntests/trunk/src/configuration/rtRuntestsConfiguration.php
===================================================================
--- php/phpruntests/trunk/src/configuration/rtRuntestsConfiguration.php 2009-07-28 20:35:06 UTC (rev 286466)
+++ php/phpruntests/trunk/src/configuration/rtRuntestsConfiguration.php 2009-07-28 20:48:15 UTC (rev 286467)
@@ -22,6 +22,8 @@
private $settings;
private $environmentVariables;
private $commandLine;
+
+ private $externalTool = null;
private $settingNames = array (
@@ -67,6 +69,15 @@
//extend test command line using TEST_PHP_ARGS
$options = new rtAddToCommandLine();
$options->parseAdditionalOptions($this->commandLine, $this->environmentVariables);
+
+ //if there is an external tool - configure it
+
+ if($this->commandLine->hasOption('m') || $this->commandLine->hasOption('mtool')) {
+ $this->externalTool = rtExternalTool::getInstance($this);
+ $this->externalTool->checkAvailable($this);
+ $this->externalTool->init($this);
+
+ }
//set configuration
foreach ($this->settingNames as $name => $className) {
@@ -144,5 +155,17 @@
public function getUserEnvironment() {
$this->environmentVariables->getUserSuppliedVariables();
}
+
+ public function hasExternalTool() {
+ if($this->externalTool != null) {
+ return true;
+ }
+ return false;
+ }
+
+ public function getExternalToolCommand() {
+ return $this->externalTool->getCommand();
+ }
+
}
?>
Added: php/phpruntests/trunk/src/configuration/tools/rtValgrind.php
===================================================================
--- php/phpruntests/trunk/src/configuration/tools/rtValgrind.php (rev 0)
+++ php/phpruntests/trunk/src/configuration/tools/rtValgrind.php 2009-07-28 20:48:15 UTC (rev 286467)
@@ -0,0 +1,52 @@
+<?php
+/**
+ * rtvalgrind
+ *
+ * Class to handle using an external tool (default is valgrind)
+ *
+ * @category Testing
+ * @package RUNTESTS
+ * @author Zoe Slattery <[email protected]>
+ * @author Stefan Priebsch <[email protected]>
+ * @copyright 2009 The PHP Group
+ * @license http://www.php.net/license/3_01.txt PHP License 3.01
+ * @link http://qa.php.net/
+ *
+ */
+
+
+class rtValgrind extends rtExternalTool
+{
+ public function checkAvailable($configuration)
+ {
+ $p = new rtIsValgrindAvailable();
+ if(!$p->check($configuration)) {
+ throw new rtException($p->getMessage());
+ }
+ }
+
+
+ public function setVersion() {
+ $phpRunner = new rtPhpRunner('valgrind --version');
+ $valgrindheader = $phpRunner->runPHP();
+ $this->version = preg_replace("/valgrind-([0-9])\.([0-9])\.([0-9]+)([.-]\w+)?(\s+)/", '$1$2$3', $valgrindheader, 1, $replace_count);
+ }
+
+ public function setCommand() {
+ $this->command = "valgrind -q --tool=memcheck --trace-children=yes";
+ }
+
+ public function setOptions($configuration) {
+ $options = "";
+ if($configuration->hasCommandLineOption('mopts')) {
+ $options = preg_replace('/\"/', '', $configuration->getCommandLineOption('mopts'));
+ }
+
+ if($this->version >= 330) {
+ $this->command .= " " . $options . " --log-file=";
+ } else {
+ $this->command .= " " . $options . " --log-file-exactly=";
+ }
+ }
+}
+?>
\ No newline at end of file
Modified: php/phpruntests/trunk/src/rtClassMap.php
===================================================================
--- php/phpruntests/trunk/src/rtClassMap.php 2009-07-28 20:35:06 UTC (rev 286466)
+++ php/phpruntests/trunk/src/rtClassMap.php 2009-07-28 20:48:15 UTC (rev 286467)
@@ -23,6 +23,7 @@
'rtAddToCommandLine' => 'configuration/rtAddToCommandLine.php',
'rtCommandLineOptions' => 'configuration/rtCommandLineOptions.php',
'rtEnvironmentVariables' => 'configuration/rtEnvironmentVariables.php',
+ 'rtExternalTool' => 'configuration/rtExternalTool.php',
'rtIniAsCommandLineArgs' => 'configuration/rtIniAsCommandLineArgs.php',
'rtPreCondition' => 'configuration/rtPreCondition.php',
'rtPreConditionList' => 'configuration/rtPreConditionList.php',
@@ -36,6 +37,7 @@
'rtTestDirectorySetting' => 'configuration/settings/rtTestDirectorySetting.php',
'rtTestFileSetting' => 'configuration/settings/rtTestFileSetting.php',
'rtWorkingDirectorySetting' => 'configuration/settings/rtWorkingDirectorySetting.php',
+ 'rtValgrind' => 'configuration/tools/rtValgrind.php',
'rtUnixConfiguration' => 'configuration/unix/rtUnixConfiguration.php',
'rtUnixEnvironmentVariables' => 'configuration/unix/rtUnixEnvironmentVariables.php',
'rtUnixPreConditionList' => 'configuration/unix/rtUnixPreConditionList.php',
Modified: php/phpruntests/trunk/src/testcase/rtTestConfiguration.php
===================================================================
--- php/phpruntests/trunk/src/testcase/rtTestConfiguration.php 2009-07-28 20:35:06 UTC (rev 286466)
+++ php/phpruntests/trunk/src/testcase/rtTestConfiguration.php 2009-07-28 20:48:15 UTC (rev 286467)
@@ -109,7 +109,7 @@
}
private function setPhpExecutable($runConfiguration, $sectionHeadings)
- {
+ {
if ($this->cgiTest) {
if($runConfiguration->getSetting('PhpCgiExecutable') != null) {
$this->phpExecutable = $runConfiguration->getSetting('PhpCgiExecutable'). " -C";
Modified: php/phpruntests/trunk/src/testcase/sections/executablesections/rtFileSection.php
===================================================================
--- php/phpruntests/trunk/src/testcase/sections/executablesections/rtFileSection.php 2009-07-28 20:35:06 UTC (rev 286466)
+++ php/phpruntests/trunk/src/testcase/sections/executablesections/rtFileSection.php 2009-07-28 20:48:15 UTC (rev 286467)
@@ -16,10 +16,12 @@
{
private $twoBlankLines = '\r?\n\r?\n';
private $headers;
+ private $memFileName;
public function setExecutableFileName($testName)
{
- $this->fileName = $testName.".php";
+ $this->fileName = $testName . ".php";
+ $this->memFileName = $testName . ".mem";
}
protected function init() {
@@ -27,8 +29,16 @@
public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration)
{
+
$testStatus = $testCase->getStatus();
$this->writeExecutableFile();
+
+ $commandPrefix = "";
+ if($runConfiguration->hasExternalTool()) {
+ $commandPrefix = $runConfiguration->getExternalToolCommand();
+ //This assumes that the external tool write its output to a *.mem file
+ $commandPrefix .= $this->memFileName;
+ }
$phpExecutable = $testCase->testConfiguration->getPhpExecutable();
@@ -40,13 +50,13 @@
}
- $phpCommand = $phpExecutable;
+ $phpCommand = $commandPrefix . " " . $phpExecutable;
$phpCommand .= ' '. $testCase->testConfiguration->getPhpCommandLineArguments();
$phpCommand .= ' -f '.$this->fileName;
$phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments();
$phpCommand .= ' 2>&1 '.$testCase->testConfiguration->getInputFileString();
-
+
$PhpRunner = new rtPhpRunner($phpCommand,
$testCase->testConfiguration->getEnvironmentVariables(),
$runConfiguration->getSetting('WorkingDirectory'),
Added: php/phpruntests/trunk/tests/configuration/rtExternalToolTest.php
===================================================================
--- php/phpruntests/trunk/tests/configuration/rtExternalToolTest.php (rev 0)
+++ php/phpruntests/trunk/tests/configuration/rtExternalToolTest.php 2009-07-28 20:48:15 UTC (rev 286467)
@@ -0,0 +1,38 @@
+<?php
+require_once 'PHPUnit/Framework.php';
+require_once dirname(__FILE__) . '../../../src/rtAutoload.php';
+
+class rtExternalToolTest extends PHPUnit_Framework_TestCase
+{
+
+
+ public function testCreate()
+ {
+
+ $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-m', 'test.phpt'));
+ $this->externalTool = rtExternalTool::getInstance($config);
+ $this->externalTool->checkAvailable($config);
+ $this->externalTool->init($config);
+
+ $string = substr($this->externalTool->getCommand(), 0, 48);
+
+ $this->assertEquals('valgrind -q --tool=memcheck --trace-children=yes', $string);
+
+ }
+
+ public function testCreate2()
+ {
+
+ $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-m', '--mopts', '"blah blah"', 'test.phpt'));
+ $this->externalTool = rtExternalTool::getInstance($config);
+ $this->externalTool->checkAvailable($config);
+ $this->externalTool->init($config);
+
+ $string = substr($this->externalTool->getCommand(), 0, 58);
+ $this->assertEquals('valgrind -q --tool=memcheck --trace-children=yes blah blah', $string);
+
+ }
+
+}
+?>
+
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php