Ensure that sqlite3ViewGetColumnNames() returns non-zero on any error.
[sqlite.git] / doc / testrunner.md
blobd0248573ee05cdfdcb2a202d78e415078ad32afd
3 # The testrunner.tcl Script
5 <ul type=none>
6   <li> 1. <a href=#overview>Overview</a>
7   <li> 2. <a href=#binary_tests>Binary Tests</a>
8 <ul type=none>
9   <li> 2.1. <a href=#organization_tests>Organization of Tcl Tests</a>
10   <li> 2.2. <a href=#run_tests>Commands to Run Tests</a>
11   <li> 2.3. <a href=#binary_test_failures>Investigating Binary Test Failures</a>
12 </ul>
13   <li> 3. <a href=#source_code_tests>Source Tests</a>
14 <ul type=none>
15   <li> 3.1. <a href=#commands_to_run_tests>Commands to Run SQLite Tests</a>
16   <li> 3.2. <a href=#zipvfs_tests>Running ZipVFS Tests</a>
17   <li> 3.3. <a href=#source_code_test_failures>Investigating Source Code Test Failures</a>
18 </ul>
19   <li> 4. <a href=#testrunner_options>Extra testrunner.tcl Options</a>
20   <li> 5. <a href=#cpu_cores>Controlling CPU Core Utilization</a>
21 </ul>
23 <a name=overview></a>
24 # 1. Overview
26 testrunner.tcl is a Tcl script used to run multiple SQLite tests using 
27 multiple jobs. It supports the following types of tests:
29   *  Tcl test scripts.
31   *  Tests run with `make` commands.  Examples:
32       -  `make mdevtest`
33       -  `make releasetest`
34       -  `make sdevtest`
35       -  `make testrunner`
37 testrunner.tcl pipes the output of all tests and builds run into log file
38 **testrunner.log**, created in the current working directory. Search this
39 file to find details of errors.  Suggested search commands:
41    *  `grep "^!" testrunner.log`
42    *  `grep failed testrunner.log`
44 testrunner.tcl also populates SQLite database **testrunner.db**. This database
45 contains details of all tests run, running and to be run. A useful query
46 might be:
48 ```
49   SELECT * FROM script WHERE state='failed'
50 ```
52 Running the command:
54 ```
55   ./testfixture $(TESTDIR)/testrunner.tcl status
56 ```
58 in the directory containing the testrunner.db database runs various queries
59 to produce a succinct report on the state of a running testrunner.tcl script.
60 Running:
62 ```
63   watch ./testfixture $(TESTDIR)/testrunner.tcl status
64 ```
66 in another terminal is a good way to keep an eye on a long running test.
68 Sometimes testrunner.tcl uses the `testfixture` binary that it is run with
69 to run tests (see "Binary Tests" below). Sometimes it builds testfixture and
70 other binaries in specific configurations to test (see "Source Tests").
72 <a name=binary_tests></a>
73 # 2. Binary Tests
75 The commands described in this section all run various combinations of the Tcl
76 test scripts using the `testfixture` binary used to run the testrunner.tcl
77 script (i.e. they do not invoke the compiler to build new binaries, or the
78 `make` command to run tests that are not Tcl scripts). The procedure to run
79 these tests is therefore:
81   1. Build the "testfixture" (or "testfixture.exe" for windows) binary using
82      whatever method seems convenient.
84   2. Test the binary built in step 1 by running testrunner.tcl with it, 
85      perhaps with various options.
87 The following sub-sections describe the various options that can be
88 passed to testrunner.tcl to test binary testfixture builds.
90 <a name=organization_tests></a>
91 ## 2.1. Organization of Tcl Tests
93 Tcl tests are stored in files that match the pattern *\*.test*. They are
94 found in both the $TOP/test/ directory, and in the various sub-directories
95 of the $TOP/ext/ directory of the source tree. Not all *\*.test* files
96 contain Tcl tests - a handful are Tcl scripts designed to invoke other
97 *\*.test* files.
99 The **veryquick** set of tests is a subset of all Tcl test scripts in the
100 source tree. In includes most tests, but excludes some that are very slow.
101 Almost all fault-injection tests (those that test the response of the library
102 to OOM or IO errors) are excluded. It is defined in source file 
103 *test/permutations.test*.
105 The **full** set of tests includes all Tcl test scripts in the source tree.
106 To run a "full" test is to run all Tcl test scripts that can be found in the
107 source tree.
109 File *permutations.test* defines various test "permutations". A permutation
110 consists of:
112   *  A subset of Tcl test scripts, and 
114   *  Runtime configuration to apply before running each test script 
115      (e.g. enabling auto-vacuum, or disable lookaside).
117 Running **all** tests is to run all tests in the full test set, plus a dozen
118 or so permutations. The specific permutations that are run as part of "all"
119 are defined in file *testrunner_data.tcl*.
121 <a name=run_tests></a>
122 ## 2.2. Commands to Run Tests
124 To run the "veryquick" test set, use either of the following:
127   ./testfixture $TESTDIR/testrunner.tcl
128   ./testfixture $TESTDIR/testrunner.tcl veryquick
131 To run the "full" test suite:
134   ./testfixture $TESTDIR/testrunner.tcl full
137 To run the subset of the "full" test suite for which the test file name matches
138 a specified pattern (e.g. all tests that start with "fts5"), either of:
141   ./testfixture $TESTDIR/testrunner.tcl fts5%
142   ./testfixture $TESTDIR/testrunner.tcl 'fts5*'
145 Strictly speaking, for a test to be run the pattern must match the script
146 filename, not including the directory, using the rules of Tcl's 
147 \[string match\] command. Except that before the matching is done, any "%"
148 characters specified as part of the pattern are transformed to "\*".
151 To run "all" tests (full + permutations):
154   ./testfixture $TESTDIR/testrunner.tcl all
157 <a name=binary_test_failures></a>
158 ## 2.3. Investigating Binary Test Failures
160 If a test fails, testrunner.tcl reports name of the Tcl test script and, if
161 applicable, the name of the permutation, to stdout. This information can also
162 be retrieved from either *testrunner.log* or *testrunner.db*.
164 If there is no permutation, the individual test script may be run with:
167   ./testfixture $PATH_TO_SCRIPT
170 Or, if the failure occured as part of a permutation:
173   ./testfixture $TESTDIR/testrunner.tcl $PERMUTATION $PATH_TO_SCRIPT
176 TODO: An example instead of "$PERMUTATION" and $PATH\_TO\_SCRIPT?
178 <a name=source_code_tests></a>
179 # 3. Source Code Tests
181 The commands described in this section invoke the C compiler to build 
182 binaries from the source tree, then use those binaries to run Tcl and
183 other tests. The advantages of this are that:
185   *  it is possible to test multiple build configurations with a single
186      command, and 
188   *  it ensures that tests are always run using binaries created with the
189      same set of compiler options.
191 The testrunner.tcl commands described in this section may be run using
192 either a *testfixture* (or testfixture.exe) build, or with any other Tcl
193 shell that supports SQLite 3.31.1 or newer via "package require sqlite3".
195 TODO: ./configure + Makefile.msc build systems.
197 <a name=commands_to_run_tests></a>
198 ## 3.1. Commands to Run SQLite Tests
200 The **mdevtest** command is equivalent to running the veryquick tests and
201 the `make fuzztest` target once for each of two --enable-all builds - one 
202 with debugging enabled and one without:
205   tclsh $TESTDIR/testrunner.tcl mdevtest
208 In other words, it is equivalent to running:
211   $TOP/configure --enable-all --enable-debug
212   make fuzztest
213   make testfixture
214   ./testfixture $TOP/test/testrunner.tcl veryquick
216   # Then, after removing files created by the tests above:
217   $TOP/configure --enable-all OPTS="-O0"
218   make fuzztest
219   make testfixture
220   ./testfixture $TOP/test/testrunner.tcl veryquick
223 The **sdevtest** command is identical to the mdevtest command, except that the
224 second of the two builds is a sanitizer build. Specifically, this means that
225 OPTS="-fsanitize=address,undefined" is specified instead of OPTS="-O0":
228   tclsh $TESTDIR/testrunner.tcl sdevtest
231 The **release** command runs lots of tests under lots of builds. It runs
232 different combinations of builds and tests depending on whether it is run
233 on Linux, Windows or OSX. Refer to *testrunner\_data.tcl* for the details
234 of the specific tests run.
237   tclsh $TESTDIR/testrunner.tcl release
240 As with <a href=#source code tests>source code tests</a>, one or more patterns
241 may be appended to any of the above commands (mdevtest, sdevtest or release).
242 In that case only Tcl tests (no fuzz or other tests) that match the specified
243 pattern are run. For example, to run the just the Tcl rtree tests in all 
244 builds and configurations supported by "release":
247   tclsh $TESTDIR/testrunner.tcl release rtree%
250 <a name=zipvfs_tests></a>
251 ## 3.2. Running ZipVFS Tests
253 testrunner.tcl can build a zipvfs-enabled testfixture and use it to run
254 tests from the Zipvfs project with the following command:
257   tclsh $TESTDIR/testrunner.tcl --zipvfs $PATH_TO_ZIPVFS
260 This can be combined with any of "mdevtest", "sdevtest" or "release" to
261 test both SQLite and Zipvfs with a single command:
264   tclsh $TESTDIR/testrunner.tcl --zipvfs $PATH_TO_ZIPVFS mdevtest
267 <a name=source_code_test_failures></a>
268 ## 3.3. Investigating Source Code Test Failures
270 Investigating a test failure that occurs during source code testing is a
271 two step process:
273   1. Recreating the build configuration in which the test failed, and
275   2. Re-running the actual test.
277 To recreate a build configuration, use the testrunner.tcl **script** command
278 to create a build script. A build script is a bash script on Linux or OSX, or
279 a dos \*.bat file on windows. For example:
282   # Create a script that recreates build configuration "Device-One" on 
283   # Linux or OSX:
284   tclsh $TESTDIR/testrunner.tcl script Device-One > make.sh 
286   # Create a script that recreates build configuration "Have-Not" on Windows:
287   tclsh $TESTDIR/testrunner.tcl script Have-Not > make.bat 
290 The generated bash or \*.bat file script accepts a single argument - a makefile
291 target to build. This may be used either to run a `make` command test directly,
292 or else to build a testfixture (or testfixture.exe) binary with which to
293 run a Tcl test script, as <a href=#binary_test_failures>described above</a>.
295 <a name=testrunner_options></a>
296 # 4. Extra testrunner.tcl Options
298 The testrunner.tcl script options in this section may be used with both source
299 code and binary tests.
301 The **--buildonly** option instructs testrunner.tcl just to build the binaries
302 required by a test, not to run any actual tests. For example:
305   # Build binaries required by release test.
306   tclsh $TESTDIR/testrunner.tcl --buildonly release"
309 The **--dryrun** option prevents testrunner.tcl from building any binaries
310 or running any tests. Instead, it just writes the shell commands that it
311 would normally execute into the testrunner.log file. Example:
314   # Log the shell commmands that make up the mdevtest test.
315   tclsh $TESTDIR/testrunner.tcl --dryrun mdevtest"
318 The **--explain** option is similar to --dryrun in that it prevents testrunner.tcl
319 from building any binaries or running any tests.  The difference is that --explain
320 prints on standard output a human-readable summary of all the builds and tests that
321 would have been run.
324   # Show what builds and tests would have been run
325   tclsh $TESTDIR/testrunner.tcl --explain mdevtest
328 <a name=cpu_cores></a>
329 # 5. Controlling CPU Core Utilization
331 When running either binary or source code tests, testrunner.tcl reports the
332 number of jobs it intends to use to stdout. e.g.
335   $ ./testfixture $TESTDIR/testrunner.tcl
336   splitting work across 16 jobs
337   ... more output ...
340 By default, testfixture.tcl attempts to set the number of jobs to the number 
341 of real cores on the machine. This can be overridden using the "--jobs" (or -j)
342 switch:
345   $ ./testfixture $TESTDIR/testrunner.tcl --jobs 8
346   splitting work across 8 jobs
347   ... more output ...
350 The number of jobs may also be changed while an instance of testrunner.tcl is
351 running by exucuting the following command from the directory containing the
352 testrunner.log and testrunner.db files:
355   $ ./testfixture $TESTDIR/testrunner.tcl njob $NEW_NUMBER_OF_JOBS