Permalink
Browse files

- Importing Zoë's code.

  • Loading branch information...
1 parent 3d6d824 commit af63026425c05e08c3b3588ef37afb1ac1d3a2de Derick Rethans committed Apr 15, 2009
Showing with 9,451 additions and 0 deletions.
  1. +50 −0 build.xml
  2. +23 −0 code-samples/Iterator.php
  3. +92 −0 code-samples/forkrungather.php
  4. +93 −0 code-samples/src/Queue.php
  5. +104 −0 code-samples/tests/ConcurrentQueueTest.php
  6. +27 −0 code-samples/tests/QueueTest.php
  7. +37 −0 cs/all/allCodingStandard.php
  8. +16 −0 cs/compatibility/compatibilityCodingStandard.php
  9. +153 −0 cs/documentation/Sniffs/ClassCommentSniff.php
  10. +610 −0 cs/documentation/Sniffs/FunctionCommentSniff.php
  11. +157 −0 cs/documentation/Sniffs/VariableCommentSniff.php
  12. +46 −0 cs/documentation/documentationCodingStandard.php
  13. +236 −0 cs/formatting/Sniffs/ScopeIndentSniff.php
  14. +66 −0 cs/formatting/formattingCodingStandard.php
  15. +28 −0 cs/guidelines/guidelinesCodingStandard.php
  16. +21 −0 cs/naming/namingCodingStandard.php
  17. BIN documentation/CodingStandards.odt
  18. BIN documentation/Old_Alloptionstable.odt
  19. BIN documentation/Old_run-tests_documentation.odt
  20. BIN documentation/Requirements.odt
  21. BIN documentation/Runtests_class_diags.odp
  22. BIN documentation/Runtests_classes.odt
  23. BIN documentation/Runtests_how_to_run.odt
  24. BIN documentation/Runtests_how_to_test.odt
  25. BIN documentation/Runtests_performance.odt
  26. +1,417 −0 doxygen.conf
  27. +10 −0 phpt-tests/sample_bork.phpt
  28. +7 −0 phpt-tests/sample_clean.php
  29. +17 −0 phpt-tests/sample_clean.phpt
  30. +7 −0 phpt-tests/sample_clean_fail.php
  31. +17 −0 phpt-tests/sample_clean_fail.phpt
  32. +8 −0 phpt-tests/sample_expectf.phpt
  33. +8 −0 phpt-tests/sample_expectregex.phpt
  34. +10 −0 phpt-tests/sample_extra_char.phpt
  35. +10 −0 phpt-tests/sample_skipif.phpt
  36. +8 −0 phpt-tests/sample_test.phpt
  37. +8 −0 phpt-tests/sample_test_fail.phpt
  38. +8 −0 phpt-tests/sample_windows_test.phpt
  39. +10 −0 phpt-tests/sample_xfail.phpt
  40. +10 −0 phpt-tests/sample_xfail2.phpt
  41. +10 −0 phpt-tests/windows_line_endings.php
  42. +51 −0 prototype/compare_results.php
  43. +153 −0 prototype/run-tests-parallel.php
  44. +57 −0 prototype/test_driver_phptestrun.php
  45. BIN prototype/timingdata.ods
  46. +10 −0 sample_directory/sample_bork.phpt
  47. +8 −0 sample_directory/sample_expectf.phpt
  48. +8 −0 sample_directory/sample_expectregex.phpt
  49. +10 −0 sample_directory/sample_skipif.phpt
  50. +8 −0 sample_directory/sample_test.phpt
  51. +8 −0 sample_directory/sample_test_fail.phpt
  52. +77 −0 src/BuildClassMap.php
  53. +7 −0 src/configuration/exceptions/rtEnvironmentException.php
  54. +7 −0 src/configuration/exceptions/rtMissingArgumentException.php
  55. +7 −0 src/configuration/exceptions/rtUnknownIniSettingException.php
  56. +7 −0 src/configuration/exceptions/rtUnknownOptionException.php
  57. +34 −0 src/configuration/preconditions/rtIfParallelHasPcntl.php
  58. +38 −0 src/configuration/preconditions/rtIsExecutableSet.php
  59. +31 −0 src/configuration/preconditions/rtIsPcreLoaded.php
  60. +32 −0 src/configuration/preconditions/rtIsProcOpenAvailable.php
  61. +32 −0 src/configuration/preconditions/rtIsSafeModeDisabled.php
  62. +44 −0 src/configuration/preconditions/rtIsTestFileSpecified.php
  63. +26 −0 src/configuration/rtAddToCommandLine.php
  64. +209 −0 src/configuration/rtCommandLineOptions.php
  65. +72 −0 src/configuration/rtEnvironmentVariables.php
  66. +103 −0 src/configuration/rtIniAsCommandLineArgs.php
  67. +26 −0 src/configuration/rtPreCondition.php
  68. +67 −0 src/configuration/rtPreConditionList.php
  69. +219 −0 src/configuration/rtRuntestsConfiguration.php
  70. +33 −0 src/configuration/rtSetting.php
  71. +29 −0 src/configuration/settings/rtCurrentDirectorySetting.php
  72. +38 −0 src/configuration/settings/rtLogFormatSetting.php
  73. +47 −0 src/configuration/settings/rtPhpCgiExecutableSetting.php
  74. +38 −0 src/configuration/settings/rtPhpCommandLineArgSetting.php
  75. +50 −0 src/configuration/settings/rtPhpExecutableSetting.php
  76. +47 −0 src/configuration/settings/rtTestDirectorySetting.php
  77. +56 −0 src/configuration/settings/rtTestFileSetting.php
  78. +37 −0 src/configuration/settings/rtWorkingDirectorySetting.php
  79. +24 −0 src/configuration/unix/rtUnixConfiguration.php
  80. +20 −0 src/configuration/unix/rtUnixEnvironmentVariables.php
  81. +19 −0 src/configuration/unix/rtUnixPreConditionList.php
  82. +18 −0 src/configuration/unix/rtUnixSettingList.php
  83. +22 −0 src/configuration/windows/rtWinConfiguration.php
  84. +20 −0 src/configuration/windows/rtWinEnvironmentVariables.php
  85. +19 −0 src/configuration/windows/rtWinPreConditionList.php
  86. +20 −0 src/configuration/windows/rtWinSettingList.php
  87. +62 −0 src/rtAutoload.php
  88. +78 −0 src/rtClassMap.php
  89. +29 −0 src/rtDirectoryList.php
  90. +11 −0 src/rtPhptFilterIterator.php
  91. +17 −0 src/rtText.php
  92. +37 −0 src/rtUtil.php
  93. +13 −0 src/run-tests.php
  94. +76 −0 src/testClassMap.php
  95. +5 −0 src/testcase/exceptions/rtCodeRunnerException.php
  96. +50 −0 src/testcase/output/rtTestOutputWriterList.php
  97. +20 −0 src/testcase/output/rtTestOutputWriterXML.php
  98. +33 −0 src/testcase/preconditions/rtHasMandatorySections.php
  99. +30 −0 src/testcase/preconditions/rtHasNoDuplicateSections.php
  100. +46 −0 src/testcase/preconditions/rtIsSectionImplemented.php
  101. +59 −0 src/testcase/preconditions/rtIsValidSectionName.php
  102. +89 −0 src/testcase/rtPhpRunner.php
  103. +164 −0 src/testcase/rtPhpTest.php
  104. +88 −0 src/testcase/rtPhpTestFile.php
  105. +60 −0 src/testcase/rtTestConfiguration.php
  106. +190 −0 src/testcase/rtTestDifference.php
  107. +45 −0 src/testcase/rtTestOutputWriter.php
  108. +11 −0 src/testcase/rtTestPreCondition.php
  109. +172 −0 src/testcase/rtTestResults.php
  110. +21 −0 src/testcase/sections/configurationsections/rtArgsSection.php
  111. +23 −0 src/testcase/sections/configurationsections/rtEnvSection.php
  112. +24 −0 src/testcase/sections/configurationsections/rtIniSection.php
  113. +44 −0 src/testcase/sections/executablesections/rtCleanSection.php
  114. +41 −0 src/testcase/sections/executablesections/rtFileSection.php
  115. +60 −0 src/testcase/sections/executablesections/rtSkipIfSection.php
  116. +11 −0 src/testcase/sections/informationsections/rtCreditsSection.php
  117. +19 −0 src/testcase/sections/informationsections/rtTestHeaderSection.php
  118. +25 −0 src/testcase/sections/informationsections/rtXfailSection.php
  119. +96 −0 src/testcase/sections/outputsections/rtExpectFSection.php
  120. +37 −0 src/testcase/sections/outputsections/rtExpectRegexSection.php
  121. +29 −0 src/testcase/sections/outputsections/rtExpectSection.php
  122. +8 −0 src/testcase/sections/rtConfigurationSection.php
  123. +34 −0 src/testcase/sections/rtExecutableSection.php
  124. +13 −0 src/testcase/sections/rtInformationSection.php
  125. +34 −0 src/testcase/sections/rtOutputSection.php
  126. +58 −0 src/testcase/sections/rtSection.php
  127. +70 −0 src/testgroup/rtPhpTestGroup.php
  128. +99 −0 src/testrun/rtPhpTestRun.php
  129. +1 −0 src/texts/duplicateTestSection.txt
  130. +65 −0 src/texts/help.txt
  131. +2 −0 src/texts/invalidPHPExecutable.txt
  132. +3 −0 src/texts/invalidTestFile.txt
  133. +1 −0 src/texts/invalidTestFileName.txt
  134. +3 −0 src/texts/invalidTestList.txt
  135. +1 −0 src/texts/invalidTestSection.txt
  136. +3 −0 src/texts/missingPHPExecutable.txt
  137. +5 −0 src/texts/missingTestFile.txt
  138. +1 −0 src/texts/missingTestSection.txt
  139. +2 −0 src/texts/nonExistantTestDirectory.txt
  140. +2 −0 src/texts/pcntlNotLoaded.txt
  141. +7 −0 src/texts/pcreNotLoaded.txt
  142. +5 −0 src/texts/procOpenNotAvailable.txt
  143. +6 −0 src/texts/safeModeNotDisabled.txt
  144. +1 −0 src/texts/sectionNotImplemented.txt
  145. +40 −0 tests/configuration/preconditions/rtIfParallelHasPcntlTest.php
  146. +30 −0 tests/configuration/preconditions/rtIsExecutableSetTest.php
  147. +19 −0 tests/configuration/preconditions/rtIsPcreLoadedTest.php
  148. +19 −0 tests/configuration/preconditions/rtIsProcOpenAvailableTest.php
  149. +19 −0 tests/configuration/preconditions/rtIsSafeModeDisabledTest.php
  150. +53 −0 tests/configuration/preconditions/rtIsTestFileSpecifiedTest.php
  151. +21 −0 tests/configuration/rtAddToCommandLineTest.php
  152. +85 −0 tests/configuration/rtCommandLineOptionsTest.php
  153. +50 −0 tests/configuration/rtDirectoryListTest.php
  154. +53 −0 tests/configuration/rtEnvironmentVariablesTest.php
  155. +59 −0 tests/configuration/rtIniAsCommandLineArgsTest.php
  156. +32 −0 tests/configuration/rtPreconditionListTest.php
  157. +26 −0 tests/configuration/rtRuntestsConfigurationTest.php
  158. +15 −0 tests/configuration/settings/rtCurrentDirectorySettingTest.php
  159. +23 −0 tests/configuration/settings/rtLogFormatSettingTest.php
  160. +38 −0 tests/configuration/settings/rtPhpCgiExecutableSettingTest.php
  161. +19 −0 tests/configuration/settings/rtPhpCommandLineArgSettingTest.php
  162. +38 −0 tests/configuration/settings/rtPhpExecutableSettingTest.php
  163. +28 −0 tests/configuration/settings/rtTestDirectorySettingTest.php
  164. +61 −0 tests/configuration/settings/rtTestFileSettingTest.php
  165. +24 −0 tests/configuration/settings/rtWorkingDirectorySettingTest.php
  166. +13 −0 tests/rtTextTest.php
  167. +21 −0 tests/testcase/preconditions/rtHasMandatorySectionsTest.php
  168. +24 −0 tests/testcase/preconditions/rtHasNoDuplicateSectionTest.php
  169. +21 −0 tests/testcase/preconditions/rtIsSectionImplementedTest.php
  170. +22 −0 tests/testcase/preconditions/rtIsValidSectionNameTest.php
  171. +79 −0 tests/testcase/rtCleanExecutionTest.php
  172. +45 −0 tests/testcase/rtPhpRunnerTest.php
  173. +75 −0 tests/testcase/rtPhpTestFileTest.php
  174. +41 −0 tests/testcase/rtPhpTestTest.php
  175. +45 −0 tests/testcase/rtSkipIfExecutionTest.php
  176. +54 −0 tests/testcase/rtTestConfigurationTest.php
  177. +20 −0 tests/testcase/rtTestDifferenceTest.php
  178. +141 −0 tests/testcase/rtTestExecutionTest.php
  179. +62 −0 tests/testcase/rtTestOutputWriterTest.php
  180. +268 −0 tests/testcase/rtTestResultsTest.php
  181. +17 −0 tests/testcase/sections/configurationsections/rtArgsSectionTest.php
  182. +18 −0 tests/testcase/sections/configurationsections/rtEnvSectionTest.php
  183. +18 −0 tests/testcase/sections/configurationsections/rtIniSectionTest.php
  184. +17 −0 tests/testcase/sections/executablesections/rtCleanSectionTest.php
  185. +17 −0 tests/testcase/sections/executablesections/rtFileSectionTest.php
  186. +17 −0 tests/testcase/sections/executablesections/rtSkipIfSectionTest.php
  187. +19 −0 tests/testcase/sections/informationsections/rtCreditsSectionTest.php
  188. +18 −0 tests/testcase/sections/informationsections/rtTestHeaderSectionTest.php
  189. +17 −0 tests/testcase/sections/informationsections/rtXfailSectionTest.php
  190. +83 −0 tests/testcase/sections/outputsections/rtExpectFSectionTest.php
  191. +21 −0 tests/testcase/sections/outputsections/rtExpectRegexSectionTest.php
  192. +35 −0 tests/testcase/sections/outputsections/rtExpectSectionTest.php
  193. +20 −0 tests/testcase/sections/rtSectionTest.php
View
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+
+<project name="runtests" default="test" basedir=".">
+
+ <property name="build.dir" value="_build" />
+
+ <target name="docs" description="Create API documentation.">
+ <delete dir="docs" />
+ <exec command="doxygen doxygen.conf" />
+ </target>
+
+ <target name="lint" description="Run a lint check on all PHP files.">
+ <phplint>
+ <fileset dir="src">
+ <include name="*.php"/>
+ <include name="**/*.php"/>
+ </fileset>
+ </phplint>
+ </target>
+
+ <target name="test" description="Run all unit tests.">
+ <delete dir="coverage" />
+ <exec command="phpunit --coverage-html coverage tests" passthru="true" />
+ </target>
+
+ <target name="sniff" description="Run all PHP_CodeSniffer sniffs.">
+ <exec command="phpcs -n --extensions=php --standard=${project.basedir}/cs/all src" passthru="true" />
+ </target>
+
+ <target name="sniff-compatibility" description="Run PHP_CodeSniffer compatibility sniffs.">
+ <exec command="phpcs -n --extensions=php --standard=${project.basedir}/cs/compatibility src" passthru="true" />
+ </target>
+
+ <target name="sniff-formatting" description="Run PHP_CodeSniffer formatting sniffs.">
+ <exec command="phpcs -n --extensions=php --standard=${project.basedir}/cs/formatting src" passthru="true" />
+ </target>
+
+ <target name="sniff-naming" description="Run PHP_CodeSniffer naming sniffs.">
+ <exec command="phpcs -n --extensions=php --standard=${project.basedir}/cs/naming src" passthru="true" />
+ </target>
+
+ <target name="sniff-documentation" description="Run PHP_CodeSniffer documentation sniffs.">
+ <exec command="phpcs -n --extensions=php --standard=${project.basedir}/cs/documentation src" passthru="true" />
+ </target>
+
+ <target name="sniff-guidelines" description="Run PHP_CodeSniffer guidelines sniffs.">
+ <exec command="phpcs -n --extensions=php --standard=${project.basedir}/cs/guidelines src" passthru="true" />
+ </target>
+
+</project>
View
@@ -0,0 +1,23 @@
+<?php
+
+ public function getTests($aDirectory)
+ {
+ $result = array();
+
+ foreach (new PhptFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($aDirectory))) as $item)
+ {
+ $result[] = $item->getPathname();
+ }
+
+ return $result;
+ }
+
+ class PhptFilterIterator extends FilterIterator
+ {
+ public function accept()
+ {
+ return (substr($this->current(), -strlen('.phpt')) == '.phpt');
+ }
+ }
+
+?>
@@ -0,0 +1,92 @@
+<?php
+
+ // create a subdirectory in temp to store results
+
+ $temp = sys_get_temp_dir();
+ $dir = $temp . '/runtests.' . md5(uniqid());
+
+ if (!file_exists($dir))
+ {
+ mkdir($dir);
+ }
+
+ var_dump('master process ' . getmypid());
+
+ // run five test processes concurrently
+ run_tests(5, $dir);
+
+
+ // collect results from subdirectory in temp
+
+ $result = array();
+
+ foreach (new DirectoryIterator($dir) as $item)
+ {
+ // skip any subdirectories, including . and ..
+ if ($item->isFile())
+ {
+ $result[] = file_get_contents($item->getPathname());
+ }
+ }
+
+ var_dump($result);
+ var_dump('master ' . getmypid() . ' done');
+
+
+ // run $aNumberOfProcesses test processes in parallel
+ // store results to $aResultDir, a subdirectory of temp.
+
+ function run_tests($aNumberOfProcesses, $aResultDir)
+ {
+ $pids = array();
+
+ for ($i = 0; $i < $aNumberOfProcesses; $i++)
+ {
+ $pid = pcntl_fork();
+
+ if ($pid == -1)
+ {
+ throw new Exception('Could not fork process');
+ }
+
+ if ($pid != 0)
+ {
+ // remember the pids of all forked processes
+ $pids[] = $pid;
+ } else {
+ // run the tests, store results in subdirectory in temp
+ run_test($aResultDir);
+ // terminate this child process
+ exit;
+ }
+ }
+
+ // wait for all child processes to terminate
+ // (note: this loop does not care about the order in which child
+ // processes terminate).
+
+ foreach ($pids as $pid)
+ {
+ pcntl_waitpid($pid, $status);
+ }
+ }
+
+
+ // run a single test, storing result to subdirectory in temp
+
+ function run_test($aResultDir)
+ {
+ // create a random result
+ $result = rand(3, 8);
+
+ // output result for comparison with final result
+ var_dump('test process ' . getmypid() . ' result ' . $result);
+
+ // random delay
+ sleep($result);
+
+ // store result for master process to gather later
+ file_put_contents($aResultDir . '/' . getmypid(), $result);
+ }
+
+?>
View
@@ -0,0 +1,93 @@
+<?php
+
+ /**
+ * Queue of runtest file names
+ *
+ * A queue (of runtest file names to run) that is stored in a temporary file.
+ * Can be accessed by multiple processes, guarantees (?) by file locking
+ * that each queue element is only read by exactly one process.
+ *
+ * @author Stefan Priebsch <stefan.priebsch@e-novative.de>
+ */
+ class Queue
+ {
+ protected $queueFile;
+
+ /**
+ * Constructor
+ *
+ * Since multiple queue objects can be used, we only create the
+ * queue file when an array of values is passed to the constructor.
+ *
+ * @param array $aElements array of elements to queue
+ */
+ public function __construct($aElements = null)
+ {
+ $this->queueFile = sys_get_temp_dir() . '/' . 'runtests.queue';
+
+ if (!is_null($aElements))
+ {
+ $this->storeQueue($aElements);
+ }
+ }
+
+ /**
+ * Load the queue
+ *
+ * Since multiple processes access the queue, we must read it from
+ * the filesystem every time we want to access it.
+ * Trailing whitespace of queue elements (i.e. filenames) will be stripped!
+ * For test files, this should not be an issue (Windows silently strips
+ * trailing whitespace in filenames anyway).
+ *
+ * @returns array the queue elements
+ */
+ protected function loadQueue()
+ {
+ $elements = file($this->queueFile);
+ $elements = array_map('rtrim', $elements);
+
+ return $elements;
+ }
+
+ /**
+ * Store the queue
+ *
+ * Stores the queue to a file, one item per line.
+ *
+ * @param array $aElements
+ * @returns void
+ */
+ protected function storeQueue($aElements)
+ {
+ file_put_contents($this->queueFile, implode(PHP_EOL, $aElements));
+ }
+
+ /**
+ * Get next item from queue
+ *
+ * Returns next item in queue. This is an atomic
+ * operation (if all filesystems support locking properly)
+ * to make sure that no two processes can read the
+ * same element from the queue.
+ * Returns NULL if queue is empty.
+ *
+ * @returns string next queue element
+ */
+ public function getNext()
+ {
+ $fp = fopen($this->queueFile, 'r');
+ flock($fp, LOCK_EX);
+
+ $elements = $this->loadQueue();
+ $element = array_pop($elements);
+ $this->storeQueue($elements);
+
+ flock($fp, LOCK_UN);
+ fclose($fp);
+
+ return $element;
+ }
+ }
+
+?>
@@ -0,0 +1,104 @@
+<?php
+
+ require 'PHPUnit/Framework.php';
+ require '../src/Queue.php';
+
+ class ConcurrentQueueTest extends PHPUnit_Framework_TestCase
+ {
+ protected $queue;
+
+ protected function assertQueuesMatch($aExpected, $aResult)
+ {
+ sort($aResult, SORT_NUMERIC);
+ $aResult = array_map('trim', $aResult);
+
+ $this->assertEquals($aExpected, $aResult);
+ }
+
+ protected function initResultFile()
+ {
+ $this->file = sys_get_temp_dir() . '/test.' . md5(uniqid());
+ }
+
+ protected function readResultFile()
+ {
+ $result = file($this->file);
+ unlink($this->file);
+
+ return $result;
+ }
+
+ protected function runConcurrently($aMethodName, $aNumberOfProcesses)
+ {
+ $pids = array();
+
+ for ($i = 0; $i < $aNumberOfProcesses; $i++)
+ {
+ $pid = pcntl_fork();
+
+ if ($pid == -1)
+ {
+ throw new RuntimeException('Could not fork process');
+ }
+
+ if ($pid != 0)
+ {
+ $pids[] = $pid;
+ } else {
+ $this->$aMethodName();
+ exit;
+ }
+ }
+
+ foreach ($pids as $pid)
+ {
+ pcntl_waitpid($pid, $status);
+ }
+ }
+
+ protected function readFromQueue()
+ {
+ while (($item = $this->queue->getNext()) !== null)
+ {
+ file_put_contents($this->file, $item . PHP_EOL, FILE_APPEND);
+ }
+ }
+
+ public function testSmallQueue()
+ {
+ $data = range(0, 10, 1);
+
+ $this->queue = new Queue($data);
+ $this->initResultFile();
+
+ $this->runConcurrently('readFromQueue', 3);
+
+ $this->assertQueuesMatch($data, $this->readResultFile());
+ }
+
+ public function testBigQueue()
+ {
+ $data = range(0, 100, 1);
+
+ $this->queue = new Queue($data);
+ $this->initResultFile();
+
+ $this->runConcurrently('readFromQueue', 10);
+
+ $this->assertQueuesMatch($data, $this->readResultFile());
+ }
+
+ public function testVeryBigQueue()
+ {
+ $data = range(0, 1000, 1);
+
+ $this->queue = new Queue($data);
+ $this->initResultFile();
+
+ $this->runConcurrently('readFromQueue', 25);
+
+ $this->assertQueuesMatch($data, $this->readResultFile());
+ }
+ }
+
+?>
@@ -0,0 +1,27 @@
+<?php
+
+ require 'PHPUnit/Framework.php';
+ require '../src/Queue.php';
+
+ class QueueTest extends PHPUnit_Framework_TestCase
+ {
+ public function testReadFromQueue()
+ {
+ $data = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
+
+ $q = new Queue($data);
+
+ $result = array();
+
+ while (($item = $q->getNext()) !== null)
+ {
+ $result[] = $item;
+ }
+
+ sort($result, SORT_NUMERIC);
+
+ $this->assertEquals($data, $result);
+ }
+ }
+
+?>
Oops, something went wrong.

0 comments on commit af63026

Please sign in to comment.