Add doc/testrunner.md, for documenting the testrunner.tcl script.
[sqlite.git] / doc / testrunner.md
blobd828fd76d8bf98e3651774529e1c228212b0adc2
3 # The testrunner.tcl Script
5 # 1. Overview
7 testrunner.tcl is a Tcl script used to run multiple SQLite tests using 
8 multiple jobs. It supports the following types of tests:
10   *  Tcl test scripts.
12   *  Tests run with [make] commands. Specifically, at time of writing, 
13      [make fuzztest], [make mptest], [make sourcetest] and [make threadtest].
15 testrunner.tcl pipes the output of all tests and builds run into log file
16 **testrunner.log**, created in the cwd directory. Searching this file for
17 "failed" is a good way to find the output of a failed test.
19 testrunner.tcl also populates SQLite database **testrunner.db**. This database
20 contains details of all tests run, running and to be run. A useful query
21 might be:
23 ```
24   SELECT * FROM script WHERE state='failed'
25 ```
27 Running the command:
29 ```
30   ./testfixture $(TESTDIR)/testrunner.tcl status
31 ```
33 in the directory containing the testrunner.db database runs various queries
34 to produce a succinct report on the state of a running testrunner.tcl script.
35 Running:
37 ```
38   watch ./testfixture $(TESTDIR)/testrunner.tcl status
39 ```
41 in another terminal is a good way to keep an eye on a long running test.
43 Sometimes testrunner.tcl uses the [testfixture] binary that it is run with
44 to run tests (see "Binary Tests" below). Sometimes it builds testfixture and
45 other binaries in specific configurations to test (see "Source Tests").
47 # 2. Binary Tests
49 The commands described in this section all run various combinations of the Tcl
50 test scripts using the [testfixture] binary used to run the testrunner.tcl
51 script (i.e. they do not invoke the compiler to build new binaries, or the
52 [make] command to run tests that are not Tcl scripts). The procedure to run
53 these tests is therefore:
55   1. Build the "testfixture" (or "testfixture.exe" for windows) binary using
56      whatever method seems convenient.
58   2. Test the binary built in step 1 by running testrunner.tcl with it, 
59      perhaps with various options.
61 The following sub-sections describe the various options that can be
62 passed to testrunner.tcl to test binary testfixture builds.
64 ## 2.1. Organization of Tcl Tests
66 Tcl tests are stored in files that match the pattern *\*.test*. They are
67 found in both the $TOP/test/ directory, and in the various sub-directories
68 of the $TOP/ext/ directory of the source tree. Not all *\*.test* files
69 contain Tcl tests - a handful are Tcl scripts designed to invoke other
70 *\*.test* files.
72 The **veryquick** set of tests is a subset of all Tcl test scripts in the
73 source tree. In includes most tests, but excludes some that are very slow.
74 Almost all fault-injection tests (those that test the response of the library
75 to OOM or IO errors) are excluded. It is defined in source file 
76 *test/permutations.test*.
78 The **full** set of tests includes all Tcl test scripts in the source tree.
79 To run a "full" test is to run all Tcl test scripts that can be found in the
80 source tree.
82 File *permutations.test* defines various test "permutations". A permutation
83 consists of:
85   *  A subset of Tcl test scripts, and 
87   *  Runtime configuration to apply before running each test script 
88      (e.g. enabling auto-vacuum, or disable lookaside).
90 Running **all** tests is to run all tests in the full test set, plus a dozen
91 or so permutations. The specific permutations that are run as part of "all"
92 are defined in file *testrunner_data.tcl*.
94 ## 2.2. Commands to Run Tests
96 To run the "veryquick" test set, use either of the following:
98 ```
99   ./testfixture $TESTDIR/testrunner.tcl
100   ./testfixture $TESTDIR/testrunner.tcl veryquick
103 To run the "full" test suite:
106   ./testfixture $TESTDIR/testrunner.tcl full
109 To run the subset of the "full" test suite for which the test file name matches
110 a specified pattern (e.g. all tests that start with "fts5"), either of:
113   ./testfixture $TESTDIR/testrunner.tcl fts5%
114   ./testfixture $TESTDIR/testrunner.tcl 'fts5*'
117 To run "all" tests (full + permutations):
120   ./testfixture $TESTDIR/testrunner.tcl all
123 <a name=binary_test_failures></a>
124 ## 2.3. Investigating Binary Test Failures
126 If a test fails, testrunner.tcl reports name of the Tcl test script and, if
127 applicable, the name of the permutation, to stdout. This information can also
128 be retrieved from either *testrunner.log* or *testrunner.db*.
130 If there is no permutation, the individual test script may be run with:
133   ./testfixture $PATH_TO_SCRIPT
136 Or, if the failure occured as part of a permutation:
139   ./testfixture $TESTDIR/testrunner.tcl $PERMUTATION $PATH_TO_SCRIPT
142 TODO: An example instead of "$PERMUTATION" and $PATH\_TO\_SCRIPT?
144 # 3. Source Code Tests
146 The commands described in this section invoke the C compiler to build 
147 binaries from the source tree, then use those binaries to run Tcl and
148 other tests. The advantages of this are that:
150   *  it is possible to test multiple build configurations with a single
151      command, and 
153   *  it ensures that tests are always run using binaries created with the
154      same set of compiler options.
156 The testrunner.tcl commands described in this section may be run using
157 either a *testfixture* (or testfixture.exe) build, or with any other Tcl
158 shell that supports SQLite 3.31.1 or newer via "package require sqlite3".
160 TODO: ./configure + Makefile.msc build systems.
162 ## Commands to Run SQLite Tests
164 The **mdevtest** command is equivalent to running the veryquick tests and
165 the [make fuzztest] target once for each of two --enable-all builds - one 
166 with debugging enabled and one without:
169   tclsh $TESTDIR/testrunner.tcl mdevtest
172 In other words, it is equivalent to running:
175   $TOP/configure --enable-all --enable-debug
176   make fuzztest
177   make testfixture
178   ./testfixture $TOP/test/testrunner.tcl veryquick
180   # Then, after removing files created by the tests above:
181   $TOP/configure --enable-all OPTS="-O0"
182   make fuzztest
183   make testfixture
184   ./testfixture $TOP/test/testrunner.tcl veryquick
187 The **sdevtest** command is identical to the mdevtest command, except that the
188 second of the two builds is a sanitizer build. Specifically, this means that
189 OPTS="-fsanitize=address,undefined" is specified instead of OPTS="-O0":
192   tclsh $TESTDIR/testrunner.tcl sdevtest
195 The **release** command runs lots of tests under lots of builds. It runs
196 different combinations of builds and tests depending on whether it is run
197 on Linux, Windows or OSX. Refer to *testrunner\_data.tcl* for the details
198 of the specific tests run.
201   tclsh $TESTDIR/testrunner.tcl release
204 ## Running ZipVFS Tests
206 testrunner.tcl can build a zipvfs-enabled testfixture and use it to run
207 tests from the Zipvfs project with the following command:
210   tclsh $TESTDIR/testrunner.tcl --zipvfs $PATH_TO_ZIPVFS
213 This can be combined with any of "mdevtest", "sdevtest" or "release" to
214 test both SQLite and Zipvfs with a single command:
217   tclsh $TESTDIR/testrunner.tcl --zipvfs $PATH_TO_ZIPVFS mdevtest
220 ## Investigating Source Code Test Failures
222 Investigating a test failure that occurs during source code testing is a
223 two step process:
225   1. Recreating the build configuration in which the test failed, and
227   2. Re-running the actual test.
229 To recreate a build configuration, use the testrunner.tcl **script** command
230 to create a build script. A build script is a bash script on Linux or OSX, or
231 a dos \*.bat file on windows. For example:
234   # Create a script that recreates build configuration "Device-One" on 
235   # Linux or OSX:
236   tclsh $TESTDIR/testrunner.tcl script Device-One > make.sh 
238   # Create a script that recreates build configuration "Have-Not" on Windows:
239   tclsh $TESTDIR/testrunner.tcl script Have-Not > make.bat 
242 The generated bash or \*.bat file script accepts a single argument - a makefile
243 target to build. This may be used either to run a [make] command test directly,
244 or else to build a testfixture (or testfixture.exe) binary with which to
245 run a Tcl test script, as <a href=#binary_test_failures>described above</a>.
249 # 4. Controlling CPU Core Utilization
251 When running either binary or source code tests, testrunner.tcl reports the
252 number of jobs it intends to use to stdout. e.g.
255   $ ./testfixture $TESTDIR/testrunner.tcl
256   splitting work across 16 jobs
257   ... more output ...
260 By default, testfixture.tcl attempts to set the number of jobs to the number 
261 of real cores on the machine. This can be overridden using the "--jobs" (or -j)
262 switch:
265   $ ./testfixture $TESTDIR/testrunner.tcl --jobs 8
266   splitting work across 8 jobs
267   ... more output ...
270 The number of jobs may also be changed while an instance of testrunner.tcl is
271 running by exucuting the following command from the directory containing the
272 testrunner.log and testrunner.db files:
275   $ ./testfixture $TESTDIR/testrunner.tcl njob $NEW_NUMBER_OF_JOBS