interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / doc / testrunner.md

454 lines · 15100 bytes Raw Blame History Rendered
1
2
3# The testrunner.tcl Script
4
5<ul type=none>
6 <li> 1. <a href=#overview>Overview</a>
7<ul type=none>
8 <li> 1.1. <a href=#runtr>Running testrunner.tcl</a>
9 <li> 1.2. <a href=#runviamake>Run using "make"</a>
10 <li> 1.3. <a href=#outputs>Outputs from testrunner.tcl</a>
11 <li> 1.4. <a href=#help>Built-in help</a>
12</ul>
13 <li> 2. <a href=#binary_tests>Binary Tests</a>
14<ul type=none>
15 <li> 2.1. <a href=#organization_tests>Organization of Tcl Tests</a>
16 <li> 2.2. <a href=#run_tests>Commands to Run Tests</a>
17 <li> 2.3. <a href=#binary_test_failures>Investigating Binary Test Failures</a>
18</ul>
19 <li> 3. <a href=#source_code_tests>Source Tests</a>
20<ul type=none>
21 <li> 3.1. <a href=#commands_to_run_tests>Commands to Run SQLite Tests</a>
22 <li> 3.2. <a href=#zipvfs_tests>Running ZipVFS Tests</a>
23 <li> 3.3. <a href=#source_code_test_failures>Investigating Source Code Test Failures</a>
24 <li> 3.4. <a href=#fuzzdb>External Fuzzcheck Databases</a>
25</ul>
26 <li> 4. <a href=#testrunner_options>Extra testrunner.tcl Options</a>
27 <li> 5. <a href=#cpu_cores>Controlling CPU Core Utilization</a>
28</ul>
29
30<a name=overview></a>
31# 1. Overview
32
33The testrunner.tcl program is a Tcl script used to run multiple SQLite
34tests in parallel, thus reducing testing time on multi-core machines.
35The testrunner.tcl supports running tests that based on `testfixture`,
36`sqlite3`, `fuzzcheck`, and C programs found in test/c.
37
38<a name="runtr"></a>
39## 1.1 Running testrunner.tcl
40
41The testrunner.tcl script is located in the "test" subdirectory of the
42SQLite source tree. So if your shell is current positioned at the top
43of the source tree, you would normally run the script using the command:
44"<tt>test/testrunner.tcl</tt>". On Windows, you have to specify the
45`tclsh` interpreter command first, like this:
46"<tt>tclsh&nbsp;test/testrunner.tcl</tt>".
47
48In this document, we will assume that you are on a unix-like OS
49(not on Windows) and that your current directory is the root
50of the SQLite source tree, and so all invocations of the testrunner.tcl
51script will be of the form "<tt>test/testrunner.tcl</tt>". If you
52are in a different directory, then make appropriate adjustments to
53the path. On Windows, add the "<tt>tclsh</tt>" interpreter command
54up front.
55
56<a name="runviamake"></a>
57## 1.2 Run using make
58
59The standard Makefiles for SQLite include targets that invoke
60testrunner.tcl. So the following commands also run testrunner.tcl:
61
62 * `make test`
63 * `make devtest`
64 * `make releasetest`
65 * `make sdevtest`
66 * `make testrunner`
67
68Since SQLite 3.53.0, there is a "<tt>make.bat</tt>" script in the root
69of the source tree that causes the "make" command to work on Windows.
70There is no need to do something different using "nmake" on Windows.
71
72<a name="outputs"></a>
73## 1.3 Outputs from testrunner.tcl
74
75The testrunner.tcl program stores output of all tests and builds run in
76log file **testrunner.log**, created in the current working directory.
77Search this file to find details of errors. Suggested search commands:
78
79 * `grep "^!" testrunner.log`
80 * `grep failed testrunner.log`
81
82The testrunner.tcl program also populates SQLite database **testrunner.db**.
83This database contains details of all tests run, running and to be run.
84A useful query might be:
85
86```
87 SELECT * FROM script WHERE state='failed'
88```
89
90You can get a summary of errors in a prior run by invoking commands like
91those shown below. Note that the testrunner.tcl script can be run directly
92on unix systems (including Macs) but you will need to add <tt>tclsh</tt>
93to the front on Windows.
94
95```
96 test/testrunner.tcl errors
97 test/testrunner.tcl errors -v
98```
99
100Running the command:
101
102```
103 test/testrunner.tcl status
104```
105
106in the directory containing the testrunner.db database runs various queries
107to produce a succinct report on the state of a running testrunner.tcl script.
108A good way to keep and eye on test progress is to run either of the two
109following commands:
110
111```
112 watch test/testrunner.tcl status
113 test/testrunner.tcl status -d 2
114```
115
116Both of the commands above accomplish about the same thing, but the second
117one has the advantage of not requiring "watch" to be installed on your
118system.
119
120Sometimes testrunner.tcl uses the `testfixture` and `sqlite3` binaries that
121are in the directory from which testrunner.tcl is run.
122(see "Binary Tests" below). Sometimes it builds testfixture and
123other binaries in specific configurations to test (see "Source Tests").
124
125<a name=help></a>
126## 1.4 Built-in help
127
128Run this command:
129
130```
131 test/testrunner.tcl help
132```
133
134To get a summary of all of the various command-line options available
135with testrunner.tcl
136
137
138<a name=binary_tests></a>
139# 2. Binary Tests
140
141The commands described in this section all run various combinations of the Tcl
142test scripts using whatever `testfixture` binary (and maybe also the `sqlite3`
143binary, depending on the test) that is found in the directory from which
144testrunner.tcl is launched. So typically, one must first run something
145like "`make testfixture sqlite3`" before launching binary tests. In other
146words, testrunner.tcl does not automatically build the binaries under test
147for binary tests. The testrunner.tcl expects the binaries to be available
148already.
149
150The following sub-sections describe the various options that can be
151passed to testrunner.tcl to test binary testfixture builds.
152
153<a name=organization_tests></a>
154## 2.1. Organization of Tcl Tests
155
156Tcl tests are stored in files that match the pattern *\*.test*. They are
157found in both the $TOP/test/ directory, and in the various sub-directories
158of the $TOP/ext/ directory of the source tree. Not all *\*.test* files
159contain Tcl tests - a handful are Tcl scripts designed to invoke other
160*\*.test* files.
161
162The **veryquick** set of tests is a subset of all Tcl test scripts in the
163source tree. In includes most tests, but excludes some that are very slow.
164Almost all fault-injection tests (those that test the response of the library
165to OOM or IO errors) are excluded. It is defined in source file
166*test/permutations.test*.
167
168The **full** set of tests includes all Tcl test scripts in the source tree.
169To run a "full" test is to run all Tcl test scripts that can be found in the
170source tree.
171
172File *permutations.test* defines various test "permutations". A permutation
173consists of:
174
175 * A subset of Tcl test scripts, and
176
177 * Runtime configuration to apply before running each test script
178 (e.g. enabling auto-vacuum, or disable lookaside).
179
180Running **all** tests is to run all tests in the full test set, plus a dozen
181or so permutations. The specific permutations that are run as part of "all"
182are defined in file *testrunner_data.tcl*.
183
184<a name=run_tests></a>
185## 2.2. Commands to Run Tests
186
187To run the "veryquick" test set, use either of the following:
188
189```
190 test/testrunner.tcl
191 test/testrunner.tcl veryquick
192```
193
194To run the "full" test suite:
195
196```
197 test/testrunner.tcl full
198```
199
200To run the subset of the "full" test suite for which the test file name matches
201a specified pattern (e.g. all tests that start with "fts5"), either of:
202
203```
204 test/testrunner.tcl fts5%
205 test/testrunner.tcl 'fts5*'
206```
207
208Strictly speaking, for a test to be run the pattern must match the script
209filename, not including the directory, using the rules of Tcl's
210\[string match\] command. Except that before the matching is done, any "%"
211characters specified as part of the pattern are transformed to "\*".
212
213
214To run "all" tests (full + permutations):
215
216```
217 test/testrunner.tcl all
218```
219
220<a name=binary_test_failures></a>
221## 2.3. Investigating Binary Test Failures
222
223If a test fails, testrunner.tcl reports name of the Tcl test script and, if
224applicable, the name of the permutation, to stdout. This information can also
225be retrieved from either *testrunner.log* or *testrunner.db*.
226
227If there is no permutation, the individual test script may be run with:
228
229```
230 ./testfixture $PATH_TO_SCRIPT
231```
232
233Or, if the failure occured as part of a permutation:
234
235```
236 test/testrunner.tcl $PERMUTATION $PATH_TO_SCRIPT
237```
238
239One can also rerun all tests that failed or did not complete
240in the previous invocation by typing:
241
242```
243 test/testrunner.tcl retest
244```
245
246<a name=source_code_tests></a>
247# 3. Source Code Tests
248
249The commands described in this section invoke the C compiler to build
250binaries from the source tree, then use those binaries to run Tcl and
251other tests. The advantages of this are that:
252
253 * it is possible to test multiple build configurations with a single
254 command, and
255
256 * it ensures that tests are always run using binaries created with the
257 same set of compiler options.
258
259The testrunner.tcl commands described in this section do not require that
260the testfixture and/or sqlite3 binaries be built ahead of time. Those
261binaries will be constructed automatically.
262
263<a name=commands_to_run_tests></a>
264## 3.1. Commands to Run SQLite Tests
265
266The **mdevtest** command is equivalent to running the veryquick tests and
267the `make fuzztest` target once for each of two --enable-all builds - one
268with debugging enabled and one without:
269
270```
271 test/testrunner.tcl mdevtest
272```
273
274In other words, it is equivalent to running:
275
276```
277 $TOP/configure --enable-all --enable-debug
278 make fuzztest
279 make testfixture
280 $TOP/test/testrunner.tcl veryquick
281
282 # Then, after removing files created by the tests above:
283 $TOP/configure --enable-all OPTS="-O0"
284 make fuzztest
285 make testfixture
286 $TOP/test/testrunner.tcl veryquick
287```
288
289The **sdevtest** command is identical to the mdevtest command, except that the
290second of the two builds is a sanitizer build. Specifically, this means that
291OPTS="-fsanitize=address,undefined" is specified instead of OPTS="-O0":
292
293```
294 test/testrunner.tcl sdevtest
295```
296
297The **release** command runs lots of tests under lots of builds. It runs
298different combinations of builds and tests depending on whether it is run
299on Linux, Windows or OSX. Refer to *testrunner\_data.tcl* for the details
300of the specific tests run.
301
302```
303 test/testrunner.tcl release
304```
305
306As with <a href=#source code tests>source code tests</a>, one or more patterns
307may be appended to any of the above commands (mdevtest, sdevtest or release).
308Pattern matching is used for both Tcl tests and fuzz tests.
309
310```
311 test/testrunner.tcl release rtree%
312```
313
314<a name=zipvfs_tests></a>
315## 3.2. Running ZipVFS Tests
316
317testrunner.tcl can build a zipvfs-enabled testfixture and use it to run
318tests from the Zipvfs project with the following command:
319
320```
321 test/testrunner.tcl --zipvfs $PATH_TO_ZIPVFS
322```
323
324This can be combined with any of "mdevtest", "sdevtest" or "release" to
325test both SQLite and Zipvfs with a single command:
326
327```
328 test/testrunner.tcl --zipvfs $PATH_TO_ZIPVFS mdevtest
329```
330
331<a name=source_code_test_failures></a>
332## 3.3. Investigating Source Code Test Failures
333
334Investigating a test failure that occurs during source code testing is a
335two step process:
336
337 1. Recreating the build configuration in which the test failed, and
338
339 2. Re-running the actual test.
340
341To recreate a build configuration, use the testrunner.tcl **script** command
342to create a build script. A build script is a bash script on Linux or OSX, or
343a dos \*.bat file on windows. For example:
344
345```
346 # Create a script that recreates build configuration "Device-One" on
347 # Linux or OSX:
348 test/testrunner.tcl script Device-One > make.sh
349
350 # Create a script that recreates build configuration "Have-Not" on Windows:
351 test/testrunner.tcl script Have-Not > make.bat
352```
353
354The generated bash or \*.bat file script accepts a single argument - a makefile
355target to build. This may be used either to run a `make` command test directly,
356or else to build a testfixture (or testfixture.exe) binary with which to
357run a Tcl test script, as <a href=#binary_test_failures>described above</a>.
358
359<a name=fuzzdb></a>
360## 3.4 External Fuzzcheck Databases
361
362Testrunner.tcl will also run fuzzcheck against an external (out of tree)
363database, for example fuzzcheck databases generated by dbsqlfuzz. To do
364this, simply add the "`--fuzzdb` *FILENAME*" command-line option or set
365the FUZZDB environment variable to the name of the external
366database. For large external databases, testrunner.tcl will automatically use
367the "`--slice`" command-line option of fuzzcheck to divide the work up into
368multiple jobs, to increase parallelism.
369
370Thus, for example, to run a full releasetest including an external
371dbsqlfuzz database, run a command like one of these:
372
373```
374 test/testrunner.tcl releasetest --fuzzdb ../fuzz/20250415.db
375 FUZZDB=../fuzz/20250415.db make releasetest
376 nmake /f Makefile.msc FUZZDB=../fuzz/20250415.db releasetest
377```
378
379The patternlist option to testrunner.tcl will match against fuzzcheck
380databases. So if you want to run *only* tests involving the external
381database, you can use a command something like this:
382
383```
384 test/testrunner.tcl releasetest 20250415 --fuzzdb ../fuzz/20250415.db
385```
386
387<a name=testrunner_options></a>
388# 4. Extra testrunner.tcl Options
389
390The testrunner.tcl script options in this section may be used with both source
391code and binary tests.
392
393The **--buildonly** option instructs testrunner.tcl just to build the binaries
394required by a test, not to run any actual tests. For example:
395
396```
397 # Build binaries required by release test.
398 test/testrunner.tcl --buildonly release"
399```
400
401The **--dryrun** option prevents testrunner.tcl from building any binaries
402or running any tests. Instead, it just writes the shell commands that it
403would normally execute into the testrunner.log file. Example:
404
405```
406 # Log the shell commmands that make up the mdevtest test.
407 test/testrunner.tcl --dryrun mdevtest"
408```
409
410The **--explain** option is similar to --dryrun in that it prevents
411testrunner.tcl from building any binaries or running any tests. The
412difference is that --explain prints on standard output a human-readable
413summary of all the builds and tests that would have been run.
414
415```
416 # Show what builds and tests would have been run
417 test/testrunner.tcl --explain mdevtest
418```
419
420The **--status** option uses VT100 escape sequences to display the test
421status full-screen. This is similar to running
422"`watch test/testrunner status`" in a separate window, just more convenient.
423Unfortunately, this option does not work correctly on Windows, due to the
424sketchy implementation of VT100 escapes on the Windows console.
425
426<a name=cpu_cores></a>
427# 5. Controlling CPU Core Utilization
428
429When running either binary or source code tests, testrunner.tcl reports the
430number of jobs it intends to use to stdout. e.g.
431
432```
433 $ test/testrunner.tcl
434 splitting work across 16 jobs
435 ... more output ...
436```
437
438By default, testfixture.tcl attempts to set the number of jobs to the number
439of real cores on the machine. This can be overridden using the "--jobs" (or -j)
440switch:
441
442```
443 $ test/testrunner.tcl --jobs 8
444 splitting work across 8 jobs
445 ... more output ...
446```
447
448The number of jobs may also be changed while an instance of testrunner.tcl is
449running by exucuting the following command from the directory containing the
450testrunner.log and testrunner.db files:
451
452```
453 $ test/testrunner.tcl njob $NEW_NUMBER_OF_JOBS
454```