README.TESTING 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. [IMPORTANT NOTICE]
  2. ------------------
  3. Failed tests usually indicate a problem with your local system setup
  4. and not within PHP itself (at least for official PHP release versions).
  5. You may decide to automatically submit a test summary to our QA workflow
  6. at the end of a test run.
  7. Please do *not* submit a failed test as a bug or ask for help on why
  8. it failed on your system without providing substantial backup information
  9. on *why* the test failed on your special setup. Thank you :-)
  10. [Testing Basics]
  11. ----------------
  12. The easiest way to test your PHP build is to run "make test" from the
  13. command line after successfully compiling. This will run the complete
  14. tests for all enabled functionalities and extensions using the PHP
  15. CLI binary.
  16. To execute test scripts, you must build PHP with some SAPI, then you
  17. type "make test" to execute all or some test scripts saved under
  18. "tests" directory under source root directory.
  19. Usage:
  20. make test
  21. "make test" basically executes "run-tests.php" script
  22. under the source root (parallel builds will not work). Therefore you
  23. can execute the script as follows:
  24. TEST_PHP_EXECUTABLE=sapi/cli/php \
  25. sapi/cli/php [-c /path/to/php.ini] run-tests.php [ext/foo/tests/GLOB]
  26. [Which "php" executable "make test" look for]
  27. ---------------------------------------------
  28. If you are running the run-tests.php script from the command line (as above)
  29. you must set the TEST_PHP_EXECUTABLE environment variable to explicitly
  30. select the PHP executable that is to be tested, that is, used to run the test scripts.
  31. If you run the tests using make test, the PHP CLI and CGI executables are
  32. automatically set for you. "make test" executes "run-tests.php" script with the CLI binary. Some
  33. test scripts such as session must be executed by CGI SAPI. Therefore,
  34. you must build PHP with CGI SAPI to perform all tests.
  35. NOTE: PHP binary executing "run-tests.php" and php binary used for
  36. executing test scripts may differ. If you use different PHP binary for
  37. executing "run-tests.php" script, you may get errors.
  38. [Which php.ini is used]
  39. -----------------------
  40. "make test" uses the same php.ini file as it would once installed.
  41. The tests have been written to be independent of that php.ini file,
  42. so if you find a test that is affected by a setting, please report
  43. this, so we can address the issue.
  44. [Which test scripts are executed]
  45. ---------------------------------
  46. "run-tests.php" ("make test"), without any arguments executes all
  47. test scripts by extracting all directories named "tests"
  48. from the source root and any subdirectories below. If there are files,
  49. which have a "phpt" extension, "run-tests.php" looks at the sections
  50. in these files, determines whether it should run it, by evaluating
  51. the 'SKIPIF' section. If the test is eligible for execution, the 'FILE'
  52. section is extracted into a ".php" file (with the same name besides
  53. the extension) and gets executed.
  54. When an argument is given or TESTS environment variable is set, the
  55. GLOB is expanded by the shell and any file with extension "*.phpt" is
  56. regarded as a test file.
  57. Tester can easily execute tests selectively with as follows.
  58. Examples:
  59. ./sapi/cli/php run-tests.php ext/mbstring/*
  60. ./sapi/cli/php run-tests.php ext/mbstring/020.phpt
  61. [Test results]
  62. --------------
  63. Test results are printed to standard output. If there is a failed test,
  64. the "run-tests.php" script saves the result, the expected result and the
  65. code executed to the test script directory. For example, if
  66. ext/myext/tests/myext.phpt fails to pass, the following files are created:
  67. ext/myext/tests/myext.php - actual test file executed
  68. ext/myext/tests/myext.log - log of test execution (L)
  69. ext/myext/tests/myext.exp - expected output (E)
  70. ext/myext/tests/myext.out - output from test script (O)
  71. ext/myext/tests/myext.diff - diff of .out and .exp (D)
  72. Failed tests are always bugs. Either the test is bugged or not considering
  73. factors applying to the tester's environment, or there is a bug in PHP.
  74. If this is a known bug, we strive to provide bug numbers, in either the
  75. test name or the file name. You can check the status of such a bug, by
  76. going to: http://bugs.php.net/12345 where 12345 is the bug number.
  77. For clarity and automated processing, bug numbers are prefixed by a hash
  78. sign '#' in test names and/or test cases are named bug12345.phpt.
  79. NOTE: The files generated by tests can be selected by setting the
  80. environment variable TEST_PHP_LOG_FORMAT. For each file you want to be
  81. generated use the character in brackets as shown above (default is LEOD).
  82. The php file will be generated always.
  83. NOTE: You can set environment variable TEST_PHP_DETAILED to enable
  84. detailed test information.
  85. [Automated Testing]
  86. --------------
  87. If you like to keep up to speed, with latest developments and quality
  88. assurance, setting the environment variable NO_INTERACTION to 1, will not
  89. prompt the tester for any user input.
  90. Normally, the exit status of "make test" is zero, regardless of the results
  91. of independent tests. Set the environment variable REPORT_EXIT_STATUS to 1,
  92. and "make test" will set the exit status ("$?") to non-zero, when an
  93. individual test has failed.
  94. Example script to be run by cron(1):
  95. ========== qa-test.sh =============
  96. #!/bin/sh
  97. CO_DIR=$HOME/cvs/php7
  98. MYMAIL=qa-test@domain.com
  99. TMPDIR=/var/tmp
  100. TODAY=`date +"%Y%m%d"`
  101. # Make sure compilation environment is correct
  102. CONFIGURE_OPTS='--disable-all --enable-cli --with-pcre'
  103. export MAKE=gmake
  104. export CC=gcc
  105. # Set test environment
  106. export NO_INTERACTION=1
  107. export REPORT_EXIT_STATUS=1
  108. cd $CO_DIR
  109. cvs update . >>$TMPDIR/phpqatest.$TODAY
  110. ./cvsclean ; ./buildconf ; ./configure $CONFIGURE_OPTS ; $MAKE
  111. $MAKE test >>$TMPDIR/phpqatest.$TODAY 2>&1
  112. if test $? -gt 0
  113. then
  114. cat $TMPDIR/phpqatest.$TODAY | mail -s"PHP-QA Test Failed for $TODAY" $MYMAIL
  115. fi
  116. ========== end of qa-test.sh =============
  117. NOTE: The exit status of run-tests.php will be 1 when
  118. REPORT_EXIT_STATUS is set. The result of "make test" may be higher
  119. than that. At present, gmake 3.79.1 returns 2, so it is
  120. advised to test for non-zero, rather then a specific value.
  121. [Creating new test files]
  122. -------------------------
  123. Writing test file is very easy if you are used to PHP.
  124. See the HOWTO at http://qa.php.net/write-test.php
  125. [How to help us]
  126. ----------------
  127. If you find bug in PHP, you can submit bug report AND test script
  128. for us. You don't have to write complete script, just give us test
  129. script with following format. Please test the script and make sure
  130. you write the correct ACTUAL OUTPUT and EXPECTED OUTPUT before you
  131. submit.
  132. <?php
  133. /*
  134. Bug #12345
  135. substr() bug. Do not return expected string.
  136. ACTUAL OUTPUT
  137. XYXA
  138. EXPECTED OUTPUT
  139. ABCD
  140. */
  141. $str = "XYZABCD";
  142. echo substr($str,3,7);
  143. ?>
  144. [IMPORTANT NOTICE]
  145. ------------------
  146. This is an addendum to README.TESTING with additional information
  147. specific to server-tests.php.
  148. server-tests.php is backward compatible with tests developed for
  149. the original run-tests.php script. server-tests is *not* used by
  150. 'make test'. server-tests was developed to provide support for
  151. testing PHP under it's primary environment, HTTP, and can run the
  152. PHP tests under any of the SAPI modules that are direct executables,
  153. or are accessible via HTTP.
  154. [New features]
  155. ----------------
  156. * Command line interface:
  157. You can run 'php server-tests.php -h' to get all the possible options.
  158. * Configuration file:
  159. the -c argument will allow you to use a configuration file. This is
  160. handy if you are testing multiple environments and need various options
  161. depending on the environment.
  162. see server-tests-config.php for details.
  163. * CGI Emulation:
  164. Will emulate a CGI environment when testing with the cgi sapi executable.
  165. * HTTP testing:
  166. can be configured to run test scripts through an HTTP server running
  167. on localhost. localhost is required since either the web server must
  168. alias a directory to the php source directory, or the test scripts
  169. must be copied to a directory under the web server
  170. (see config options TEST_WEB_BASE_URL, TEST_BASE_PATH, and TEST_WEB_EXT)
  171. * New sections supported for test files (see below)
  172. When running tests over http, tests that require ini settings different that what
  173. the web server runs under will be skipped. Since the test harness defines a number
  174. of ini settings by default, the web server may require special configuration to
  175. make testing work.
  176. [Example Usage]
  177. ----------------
  178. Some (but not all!) examples of usage:
  179. 1. run tests from the php source directory
  180. php server-tests.php -p /path/to/php-cli
  181. 2. run tests using cgi emulation
  182. php server-tests.php -p /path/to/php-cgi
  183. 3. run tests over http, copying test files into document root
  184. php server-tests.php -w -u http://localhost/test -m /path/to/htdocs/test
  185. 4. run tests over http, php sources have been aliased in web server
  186. php server-tests.php -w -u http://localhost/test
  187. 5. run tests using configuration file
  188. php server-tests.php -c /path/to/server-tests-config.php
  189. 6. run tests using configuration file, but overriding some settings:
  190. (config file must be first)
  191. php server-tests.php -c /path/to/server-tests-config.php -w -t 3 -d /path/to/testdir
  192. NOTE: configuration as described in README.TESTING still works.
  193. [New Test Sections]
  194. ----------------
  195. In addition to the traditional test sections
  196. (see http://qa.php.net/write-test.php), several new sections are available
  197. under server-tests.
  198. --POST--
  199. This is not a new section, but not multipart posts are supported for testing
  200. file uploads, or other types of POST data.
  201. --CGI--
  202. This section takes no value. It merely provides a simple marker for tests
  203. that MUST be run as CGI, even if there is no --POST-- or --GET-- sections
  204. in the test file.
  205. --DESCRIPTION--
  206. Not used for anything, just a section for documenting the test
  207. --ENV--
  208. This section get's eval()'d to help build an environment for the
  209. execution of the test. This can be used to change environment
  210. vars that are used for CGI emulation, or simply to set env vars
  211. for cli testing. A full example looks like:
  212. --ENV--
  213. return <<<END
  214. PATH_TRANSLATED=$filename
  215. PATH_INFO=$scriptname
  216. SCRIPT_NAME=$scriptname
  217. END;
  218. Some variables are made easily available for use in this section, they
  219. include:
  220. $filename full native path to file, will become PATH_TRANSLATED
  221. $filepath =dirname($filename)
  222. $scriptname this is what will become SCRIPT_NAME unless you override it
  223. $docroot the equivalent of DOCUMENT_ROOT under Apache
  224. $cwd the directory that the test is being initiated from
  225. $this->conf all server-tests configuration vars
  226. $this->env all environment variables that will get passed to the test
  227. --REQUEST--
  228. This section is also eval'd, and is similar in nature to --ENV--. However,
  229. this section is used to build the url used in an HTTP request. Valid values
  230. to set in this section would include:
  231. SCRIPT_NAME The initial part of the request url
  232. PATH_INFO The pathinfo part of a request url
  233. FRAGMENT The fragment section of a url (after #)
  234. QUERY_STRING The query part of a url (after ?)
  235. --REQUEST--
  236. return <<<END
  237. PATH_INFO=/path/info
  238. END;
  239. --HEADERS--
  240. This section is also eval'd. It is used to provide additional headers sent
  241. in an HTTP request, such as content type for multipart posts, cookies, etc.
  242. --HEADERS--
  243. return <<<END
  244. Content-Type=multipart/form-data; boundary=---------------------------240723202011929
  245. Content-Length=100
  246. END;
  247. --EXPECTHEADERS--
  248. This section can be used to define what headers are required to be
  249. received back from a request, and is checked in addition to the
  250. regular expect sections. For example:
  251. --EXPECTHEADERS--
  252. Status: 404