sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 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 | |
| 33 | The testrunner.tcl program is a Tcl script used to run multiple SQLite |
| 34 | tests in parallel, thus reducing testing time on multi-core machines. |
| 35 | The 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 | |
| 41 | The testrunner.tcl script is located in the "test" subdirectory of the |
| 42 | SQLite source tree. So if your shell is current positioned at the top |
| 43 | of 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 test/testrunner.tcl</tt>". |
| 47 | |
| 48 | In 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 |
| 50 | of the SQLite source tree, and so all invocations of the testrunner.tcl |
| 51 | script will be of the form "<tt>test/testrunner.tcl</tt>". If you |
| 52 | are in a different directory, then make appropriate adjustments to |
| 53 | the path. On Windows, add the "<tt>tclsh</tt>" interpreter command |
| 54 | up front. |
| 55 | |
| 56 | <a name="runviamake"></a> |
| 57 | ## 1.2 Run using make |
| 58 | |
| 59 | The standard Makefiles for SQLite include targets that invoke |
| 60 | testrunner.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 | |
| 68 | Since SQLite 3.53.0, there is a "<tt>make.bat</tt>" script in the root |
| 69 | of the source tree that causes the "make" command to work on Windows. |
| 70 | There 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 | |
| 75 | The testrunner.tcl program stores output of all tests and builds run in |
| 76 | log file **testrunner.log**, created in the current working directory. |
| 77 | Search this file to find details of errors. Suggested search commands: |
| 78 | |
| 79 | * `grep "^!" testrunner.log` |
| 80 | * `grep failed testrunner.log` |
| 81 | |
| 82 | The testrunner.tcl program also populates SQLite database **testrunner.db**. |
| 83 | This database contains details of all tests run, running and to be run. |
| 84 | A useful query might be: |
| 85 | |
| 86 | ``` |
| 87 | SELECT * FROM script WHERE state='failed' |
| 88 | ``` |
| 89 | |
| 90 | You can get a summary of errors in a prior run by invoking commands like |
| 91 | those shown below. Note that the testrunner.tcl script can be run directly |
| 92 | on unix systems (including Macs) but you will need to add <tt>tclsh</tt> |
| 93 | to the front on Windows. |
| 94 | |
| 95 | ``` |
| 96 | test/testrunner.tcl errors |
| 97 | test/testrunner.tcl errors -v |
| 98 | ``` |
| 99 | |
| 100 | Running the command: |
| 101 | |
| 102 | ``` |
| 103 | test/testrunner.tcl status |
| 104 | ``` |
| 105 | |
| 106 | in the directory containing the testrunner.db database runs various queries |
| 107 | to produce a succinct report on the state of a running testrunner.tcl script. |
| 108 | A good way to keep and eye on test progress is to run either of the two |
| 109 | following commands: |
| 110 | |
| 111 | ``` |
| 112 | watch test/testrunner.tcl status |
| 113 | test/testrunner.tcl status -d 2 |
| 114 | ``` |
| 115 | |
| 116 | Both of the commands above accomplish about the same thing, but the second |
| 117 | one has the advantage of not requiring "watch" to be installed on your |
| 118 | system. |
| 119 | |
| 120 | Sometimes testrunner.tcl uses the `testfixture` and `sqlite3` binaries that |
| 121 | are in the directory from which testrunner.tcl is run. |
| 122 | (see "Binary Tests" below). Sometimes it builds testfixture and |
| 123 | other binaries in specific configurations to test (see "Source Tests"). |
| 124 | |
| 125 | <a name=help></a> |
| 126 | ## 1.4 Built-in help |
| 127 | |
| 128 | Run this command: |
| 129 | |
| 130 | ``` |
| 131 | test/testrunner.tcl help |
| 132 | ``` |
| 133 | |
| 134 | To get a summary of all of the various command-line options available |
| 135 | with testrunner.tcl |
| 136 | |
| 137 | |
| 138 | <a name=binary_tests></a> |
| 139 | # 2. Binary Tests |
| 140 | |
| 141 | The commands described in this section all run various combinations of the Tcl |
| 142 | test scripts using whatever `testfixture` binary (and maybe also the `sqlite3` |
| 143 | binary, depending on the test) that is found in the directory from which |
| 144 | testrunner.tcl is launched. So typically, one must first run something |
| 145 | like "`make testfixture sqlite3`" before launching binary tests. In other |
| 146 | words, testrunner.tcl does not automatically build the binaries under test |
| 147 | for binary tests. The testrunner.tcl expects the binaries to be available |
| 148 | already. |
| 149 | |
| 150 | The following sub-sections describe the various options that can be |
| 151 | passed to testrunner.tcl to test binary testfixture builds. |
| 152 | |
| 153 | <a name=organization_tests></a> |
| 154 | ## 2.1. Organization of Tcl Tests |
| 155 | |
| 156 | Tcl tests are stored in files that match the pattern *\*.test*. They are |
| 157 | found in both the $TOP/test/ directory, and in the various sub-directories |
| 158 | of the $TOP/ext/ directory of the source tree. Not all *\*.test* files |
| 159 | contain Tcl tests - a handful are Tcl scripts designed to invoke other |
| 160 | *\*.test* files. |
| 161 | |
| 162 | The **veryquick** set of tests is a subset of all Tcl test scripts in the |
| 163 | source tree. In includes most tests, but excludes some that are very slow. |
| 164 | Almost all fault-injection tests (those that test the response of the library |
| 165 | to OOM or IO errors) are excluded. It is defined in source file |
| 166 | *test/permutations.test*. |
| 167 | |
| 168 | The **full** set of tests includes all Tcl test scripts in the source tree. |
| 169 | To run a "full" test is to run all Tcl test scripts that can be found in the |
| 170 | source tree. |
| 171 | |
| 172 | File *permutations.test* defines various test "permutations". A permutation |
| 173 | consists 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 | |
| 180 | Running **all** tests is to run all tests in the full test set, plus a dozen |
| 181 | or so permutations. The specific permutations that are run as part of "all" |
| 182 | are defined in file *testrunner_data.tcl*. |
| 183 | |
| 184 | <a name=run_tests></a> |
| 185 | ## 2.2. Commands to Run Tests |
| 186 | |
| 187 | To run the "veryquick" test set, use either of the following: |
| 188 | |
| 189 | ``` |
| 190 | test/testrunner.tcl |
| 191 | test/testrunner.tcl veryquick |
| 192 | ``` |
| 193 | |
| 194 | To run the "full" test suite: |
| 195 | |
| 196 | ``` |
| 197 | test/testrunner.tcl full |
| 198 | ``` |
| 199 | |
| 200 | To run the subset of the "full" test suite for which the test file name matches |
| 201 | a 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 | |
| 208 | Strictly speaking, for a test to be run the pattern must match the script |
| 209 | filename, not including the directory, using the rules of Tcl's |
| 210 | \[string match\] command. Except that before the matching is done, any "%" |
| 211 | characters specified as part of the pattern are transformed to "\*". |
| 212 | |
| 213 | |
| 214 | To 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 | |
| 223 | If a test fails, testrunner.tcl reports name of the Tcl test script and, if |
| 224 | applicable, the name of the permutation, to stdout. This information can also |
| 225 | be retrieved from either *testrunner.log* or *testrunner.db*. |
| 226 | |
| 227 | If there is no permutation, the individual test script may be run with: |
| 228 | |
| 229 | ``` |
| 230 | ./testfixture $PATH_TO_SCRIPT |
| 231 | ``` |
| 232 | |
| 233 | Or, if the failure occured as part of a permutation: |
| 234 | |
| 235 | ``` |
| 236 | test/testrunner.tcl $PERMUTATION $PATH_TO_SCRIPT |
| 237 | ``` |
| 238 | |
| 239 | One can also rerun all tests that failed or did not complete |
| 240 | in 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 | |
| 249 | The commands described in this section invoke the C compiler to build |
| 250 | binaries from the source tree, then use those binaries to run Tcl and |
| 251 | other 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 | |
| 259 | The testrunner.tcl commands described in this section do not require that |
| 260 | the testfixture and/or sqlite3 binaries be built ahead of time. Those |
| 261 | binaries will be constructed automatically. |
| 262 | |
| 263 | <a name=commands_to_run_tests></a> |
| 264 | ## 3.1. Commands to Run SQLite Tests |
| 265 | |
| 266 | The **mdevtest** command is equivalent to running the veryquick tests and |
| 267 | the `make fuzztest` target once for each of two --enable-all builds - one |
| 268 | with debugging enabled and one without: |
| 269 | |
| 270 | ``` |
| 271 | test/testrunner.tcl mdevtest |
| 272 | ``` |
| 273 | |
| 274 | In 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 | |
| 289 | The **sdevtest** command is identical to the mdevtest command, except that the |
| 290 | second of the two builds is a sanitizer build. Specifically, this means that |
| 291 | OPTS="-fsanitize=address,undefined" is specified instead of OPTS="-O0": |
| 292 | |
| 293 | ``` |
| 294 | test/testrunner.tcl sdevtest |
| 295 | ``` |
| 296 | |
| 297 | The **release** command runs lots of tests under lots of builds. It runs |
| 298 | different combinations of builds and tests depending on whether it is run |
| 299 | on Linux, Windows or OSX. Refer to *testrunner\_data.tcl* for the details |
| 300 | of the specific tests run. |
| 301 | |
| 302 | ``` |
| 303 | test/testrunner.tcl release |
| 304 | ``` |
| 305 | |
| 306 | As with <a href=#source code tests>source code tests</a>, one or more patterns |
| 307 | may be appended to any of the above commands (mdevtest, sdevtest or release). |
| 308 | Pattern 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 | |
| 317 | testrunner.tcl can build a zipvfs-enabled testfixture and use it to run |
| 318 | tests from the Zipvfs project with the following command: |
| 319 | |
| 320 | ``` |
| 321 | test/testrunner.tcl --zipvfs $PATH_TO_ZIPVFS |
| 322 | ``` |
| 323 | |
| 324 | This can be combined with any of "mdevtest", "sdevtest" or "release" to |
| 325 | test 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 | |
| 334 | Investigating a test failure that occurs during source code testing is a |
| 335 | two step process: |
| 336 | |
| 337 | 1. Recreating the build configuration in which the test failed, and |
| 338 | |
| 339 | 2. Re-running the actual test. |
| 340 | |
| 341 | To recreate a build configuration, use the testrunner.tcl **script** command |
| 342 | to create a build script. A build script is a bash script on Linux or OSX, or |
| 343 | a 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 | |
| 354 | The generated bash or \*.bat file script accepts a single argument - a makefile |
| 355 | target to build. This may be used either to run a `make` command test directly, |
| 356 | or else to build a testfixture (or testfixture.exe) binary with which to |
| 357 | run 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 | |
| 362 | Testrunner.tcl will also run fuzzcheck against an external (out of tree) |
| 363 | database, for example fuzzcheck databases generated by dbsqlfuzz. To do |
| 364 | this, simply add the "`--fuzzdb` *FILENAME*" command-line option or set |
| 365 | the FUZZDB environment variable to the name of the external |
| 366 | database. For large external databases, testrunner.tcl will automatically use |
| 367 | the "`--slice`" command-line option of fuzzcheck to divide the work up into |
| 368 | multiple jobs, to increase parallelism. |
| 369 | |
| 370 | Thus, for example, to run a full releasetest including an external |
| 371 | dbsqlfuzz 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 | |
| 379 | The patternlist option to testrunner.tcl will match against fuzzcheck |
| 380 | databases. So if you want to run *only* tests involving the external |
| 381 | database, 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 | |
| 390 | The testrunner.tcl script options in this section may be used with both source |
| 391 | code and binary tests. |
| 392 | |
| 393 | The **--buildonly** option instructs testrunner.tcl just to build the binaries |
| 394 | required 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 | |
| 401 | The **--dryrun** option prevents testrunner.tcl from building any binaries |
| 402 | or running any tests. Instead, it just writes the shell commands that it |
| 403 | would 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 | |
| 410 | The **--explain** option is similar to --dryrun in that it prevents |
| 411 | testrunner.tcl from building any binaries or running any tests. The |
| 412 | difference is that --explain prints on standard output a human-readable |
| 413 | summary 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 | |
| 420 | The **--status** option uses VT100 escape sequences to display the test |
| 421 | status full-screen. This is similar to running |
| 422 | "`watch test/testrunner status`" in a separate window, just more convenient. |
| 423 | Unfortunately, this option does not work correctly on Windows, due to the |
| 424 | sketchy implementation of VT100 escapes on the Windows console. |
| 425 | |
| 426 | <a name=cpu_cores></a> |
| 427 | # 5. Controlling CPU Core Utilization |
| 428 | |
| 429 | When running either binary or source code tests, testrunner.tcl reports the |
| 430 | number 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 | |
| 438 | By default, testfixture.tcl attempts to set the number of jobs to the number |
| 439 | of real cores on the machine. This can be overridden using the "--jobs" (or -j) |
| 440 | switch: |
| 441 | |
| 442 | ``` |
| 443 | $ test/testrunner.tcl --jobs 8 |
| 444 | splitting work across 8 jobs |
| 445 | ... more output ... |
| 446 | ``` |
| 447 | |
| 448 | The number of jobs may also be changed while an instance of testrunner.tcl is |
| 449 | running by exucuting the following command from the directory containing the |
| 450 | testrunner.log and testrunner.db files: |
| 451 | |
| 452 | ``` |
| 453 | $ test/testrunner.tcl njob $NEW_NUMBER_OF_JOBS |
| 454 | ``` |