drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 1 | # 2001 September 15 |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 2 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 5 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements some common TCL routines used for regression |
| 12 | # testing the SQLite library |
| 13 | # |
drh | bb77b75 | 2009-04-09 01:23:49 +0000 | [diff] [blame] | 14 | # $Id: tester.tcl,v 1.143 2009/04/09 01:23:49 drh Exp $ |
drh | fbc3eab | 2001-04-06 16:13:42 +0000 | [diff] [blame] | 15 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 16 | #------------------------------------------------------------------------- |
| 17 | # The commands provided by the code in this file to help with creating |
| 18 | # test cases are as follows: |
drh | 8359d8c | 2008-03-29 11:00:54 +0000 | [diff] [blame] | 19 | # |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 20 | # Commands to manipulate the db and the file-system at a high level: |
drh | 8359d8c | 2008-03-29 11:00:54 +0000 | [diff] [blame] | 21 | # |
mistachkin | c548465 | 2012-03-05 22:52:33 +0000 | [diff] [blame] | 22 | # is_relative_file |
mistachkin | 4a41f34 | 2012-03-06 03:00:49 +0000 | [diff] [blame] | 23 | # test_pwd |
mistachkin | f8a7846 | 2012-03-08 20:00:36 +0000 | [diff] [blame] | 24 | # get_pwd |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 25 | # copy_file FROM TO |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 26 | # delete_file FILENAME |
dan | 6f34396 | 2011-07-01 18:26:40 +0000 | [diff] [blame] | 27 | # drop_all_tables ?DB? |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 28 | # forcecopy FROM TO |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 29 | # forcedelete FILENAME |
| 30 | # |
| 31 | # Test the capability of the SQLite version built into the interpreter to |
| 32 | # determine if a specific test can be run: |
| 33 | # |
mistachkin | c60941f | 2012-09-13 01:51:02 +0000 | [diff] [blame] | 34 | # capable EXPR |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 35 | # ifcapable EXPR |
| 36 | # |
| 37 | # Calulate checksums based on database contents: |
| 38 | # |
| 39 | # dbcksum DB DBNAME |
| 40 | # allcksum ?DB? |
| 41 | # cksum ?DB? |
| 42 | # |
| 43 | # Commands to execute/explain SQL statements: |
| 44 | # |
| 45 | # stepsql DB SQL |
| 46 | # execsql2 SQL |
| 47 | # explain_no_trace SQL |
| 48 | # explain SQL ?DB? |
| 49 | # catchsql SQL ?DB? |
| 50 | # execsql SQL ?DB? |
| 51 | # |
| 52 | # Commands to run test cases: |
| 53 | # |
| 54 | # do_ioerr_test TESTNAME ARGS... |
| 55 | # crashsql ARGS... |
| 56 | # integrity_check TESTNAME ?DB? |
drh | 433dccf | 2013-02-09 15:37:11 +0000 | [diff] [blame] | 57 | # verify_ex_errcode TESTNAME EXPECTED ?DB? |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 58 | # do_test TESTNAME SCRIPT EXPECTED |
dan | 153eda0 | 2010-06-21 07:45:47 +0000 | [diff] [blame] | 59 | # do_execsql_test TESTNAME SQL EXPECTED |
| 60 | # do_catchsql_test TESTNAME SQL EXPECTED |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 61 | # |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 62 | # Commands providing a lower level interface to the global test counters: |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 63 | # |
| 64 | # set_test_counter COUNTER ?VALUE? |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 65 | # omit_test TESTNAME REASON ?APPEND? |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 66 | # fail_test TESTNAME |
| 67 | # incr_ntest |
| 68 | # |
| 69 | # Command run at the end of each test file: |
| 70 | # |
| 71 | # finish_test |
| 72 | # |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 73 | # Commands to help create test files that run with the "WAL" and other |
| 74 | # permutations (see file permutations.test): |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 75 | # |
| 76 | # wal_is_wal_mode |
| 77 | # wal_set_journal_mode ?DB? |
| 78 | # wal_check_journal_mode TESTNAME?DB? |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 79 | # permutation |
dan | cb79e51 | 2010-08-06 13:50:07 +0000 | [diff] [blame] | 80 | # presql |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 81 | # |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 82 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 83 | # Set the precision of FP arithmatic used by the interpreter. And |
| 84 | # configure SQLite to take database file locks on the page that begins |
| 85 | # 64KB into the database file instead of the one 1GB in. This means |
| 86 | # the code that handles that special case can be tested without creating |
| 87 | # very large database files. |
| 88 | # |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 89 | set tcl_precision 15 |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 90 | sqlite3_test_control_pending_byte 0x0010000 |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 91 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 92 | |
| 93 | # If the pager codec is available, create a wrapper for the [sqlite3] |
| 94 | # command that appends "-key {xyzzy}" to the command line. i.e. this: |
drh | 3a7fb7c | 2007-08-10 16:41:08 +0000 | [diff] [blame] | 95 | # |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 96 | # sqlite3 db test.db |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 97 | # |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 98 | # becomes |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 99 | # |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 100 | # sqlite3 db test.db -key {xyzzy} |
drh | 9eb9e26 | 2004-02-11 02:18:05 +0000 | [diff] [blame] | 101 | # |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 102 | if {[info command sqlite_orig]==""} { |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 103 | rename sqlite3 sqlite_orig |
| 104 | proc sqlite3 {args} { |
dan | 68928b6 | 2010-06-22 13:46:43 +0000 | [diff] [blame] | 105 | if {[llength $args]>=2 && [string index [lindex $args 0] 0]!="-"} { |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 106 | # This command is opening a new database connection. |
| 107 | # |
| 108 | if {[info exists ::G(perm:sqlite3_args)]} { |
| 109 | set args [concat $args $::G(perm:sqlite3_args)] |
| 110 | } |
dan | 68928b6 | 2010-06-22 13:46:43 +0000 | [diff] [blame] | 111 | if {[sqlite_orig -has-codec] && ![info exists ::do_not_use_codec]} { |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 112 | lappend args -key {xyzzy} |
| 113 | } |
| 114 | |
dan | 3ccd20a | 2010-06-09 19:01:02 +0000 | [diff] [blame] | 115 | set res [uplevel 1 sqlite_orig $args] |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 116 | if {[info exists ::G(perm:presql)]} { |
| 117 | [lindex $args 0] eval $::G(perm:presql) |
| 118 | } |
dan | 1ce1b4a | 2010-12-07 14:32:28 +0000 | [diff] [blame] | 119 | if {[info exists ::G(perm:dbconfig)]} { |
| 120 | set ::dbhandle [lindex $args 0] |
| 121 | uplevel #0 $::G(perm:dbconfig) |
| 122 | } |
dan | 3ccd20a | 2010-06-09 19:01:02 +0000 | [diff] [blame] | 123 | set res |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 124 | } else { |
| 125 | # This command is not opening a new database connection. Pass the |
mistachkin | 48864df | 2013-03-21 21:20:32 +0000 | [diff] [blame] | 126 | # arguments through to the C implementation as the are. |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 127 | # |
| 128 | uplevel 1 sqlite_orig $args |
drh | 9eb9e26 | 2004-02-11 02:18:05 +0000 | [diff] [blame] | 129 | } |
drh | 9eb9e26 | 2004-02-11 02:18:05 +0000 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 133 | proc getFileRetries {} { |
| 134 | if {![info exists ::G(file-retries)]} { |
| 135 | # |
| 136 | # NOTE: Return the default number of retries for [file] operations. A |
| 137 | # value of zero or less here means "disabled". |
| 138 | # |
mistachkin | c60941f | 2012-09-13 01:51:02 +0000 | [diff] [blame] | 139 | return [expr {$::tcl_platform(platform) eq "windows" ? 50 : 0}] |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 140 | } |
| 141 | return $::G(file-retries) |
| 142 | } |
| 143 | |
| 144 | proc getFileRetryDelay {} { |
| 145 | if {![info exists ::G(file-retry-delay)]} { |
| 146 | # |
| 147 | # NOTE: Return the default number of milliseconds to wait when retrying |
| 148 | # failed [file] operations. A value of zero or less means "do not |
| 149 | # wait". |
| 150 | # |
| 151 | return 100; # TODO: Good default? |
| 152 | } |
| 153 | return $::G(file-retry-delay) |
| 154 | } |
| 155 | |
mistachkin | f8a7846 | 2012-03-08 20:00:36 +0000 | [diff] [blame] | 156 | # Return the string representing the name of the current directory. On |
| 157 | # Windows, the result is "normalized" to whatever our parent command shell |
| 158 | # is using to prevent case-mismatch issues. |
| 159 | # |
| 160 | proc get_pwd {} { |
| 161 | if {$::tcl_platform(platform) eq "windows"} { |
mistachkin | 533b8f6 | 2012-03-08 20:28:31 +0000 | [diff] [blame] | 162 | # |
| 163 | # NOTE: Cannot use [file normalize] here because it would alter the |
| 164 | # case of the result to what Tcl considers canonical, which would |
| 165 | # defeat the purpose of this procedure. |
| 166 | # |
| 167 | return [string map [list \\ /] \ |
| 168 | [string trim [exec -- $::env(ComSpec) /c echo %CD%]]] |
mistachkin | f8a7846 | 2012-03-08 20:00:36 +0000 | [diff] [blame] | 169 | } else { |
| 170 | return [pwd] |
| 171 | } |
| 172 | } |
| 173 | |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 174 | # Copy file $from into $to. This is used because some versions of |
| 175 | # TCL for windows (notably the 8.4.1 binary package shipped with the |
| 176 | # current mingw release) have a broken "file copy" command. |
| 177 | # |
| 178 | proc copy_file {from to} { |
| 179 | do_copy_file false $from $to |
| 180 | } |
| 181 | |
| 182 | proc forcecopy {from to} { |
| 183 | do_copy_file true $from $to |
| 184 | } |
| 185 | |
| 186 | proc do_copy_file {force from to} { |
| 187 | set nRetry [getFileRetries] ;# Maximum number of retries. |
| 188 | set nDelay [getFileRetryDelay] ;# Delay in ms before retrying. |
| 189 | |
| 190 | # On windows, sometimes even a [file copy -force] can fail. The cause is |
| 191 | # usually "tag-alongs" - programs like anti-virus software, automatic backup |
| 192 | # tools and various explorer extensions that keep a file open a little longer |
| 193 | # than we expect, causing the delete to fail. |
| 194 | # |
| 195 | # The solution is to wait a short amount of time before retrying the copy. |
| 196 | # |
| 197 | if {$nRetry > 0} { |
| 198 | for {set i 0} {$i<$nRetry} {incr i} { |
| 199 | set rc [catch { |
| 200 | if {$force} { |
| 201 | file copy -force $from $to |
| 202 | } else { |
| 203 | file copy $from $to |
| 204 | } |
| 205 | } msg] |
| 206 | if {$rc==0} break |
| 207 | if {$nDelay > 0} { after $nDelay } |
| 208 | } |
| 209 | if {$rc} { error $msg } |
| 210 | } else { |
| 211 | if {$force} { |
| 212 | file copy -force $from $to |
| 213 | } else { |
| 214 | file copy $from $to |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
mistachkin | c548465 | 2012-03-05 22:52:33 +0000 | [diff] [blame] | 219 | # Check if a file name is relative |
| 220 | # |
| 221 | proc is_relative_file { file } { |
| 222 | return [expr {[file pathtype $file] != "absolute"}] |
| 223 | } |
| 224 | |
mistachkin | 4a41f34 | 2012-03-06 03:00:49 +0000 | [diff] [blame] | 225 | # If the VFS supports using the current directory, returns [pwd]; |
| 226 | # otherwise, it returns only the provided suffix string (which is |
| 227 | # empty by default). |
| 228 | # |
| 229 | proc test_pwd { args } { |
| 230 | if {[llength $args] > 0} { |
| 231 | set suffix1 [lindex $args 0] |
| 232 | if {[llength $args] > 1} { |
| 233 | set suffix2 [lindex $args 1] |
| 234 | } else { |
| 235 | set suffix2 $suffix1 |
| 236 | } |
| 237 | } else { |
| 238 | set suffix1 ""; set suffix2 "" |
| 239 | } |
| 240 | ifcapable curdir { |
mistachkin | 6aa18c9 | 2012-03-08 20:22:42 +0000 | [diff] [blame] | 241 | return "[get_pwd]$suffix1" |
mistachkin | 4a41f34 | 2012-03-06 03:00:49 +0000 | [diff] [blame] | 242 | } else { |
| 243 | return $suffix2 |
| 244 | } |
| 245 | } |
| 246 | |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 247 | # Delete a file or directory |
| 248 | # |
| 249 | proc delete_file {args} { |
| 250 | do_delete_file false {*}$args |
| 251 | } |
| 252 | |
| 253 | proc forcedelete {args} { |
| 254 | do_delete_file true {*}$args |
| 255 | } |
| 256 | |
| 257 | proc do_delete_file {force args} { |
| 258 | set nRetry [getFileRetries] ;# Maximum number of retries. |
| 259 | set nDelay [getFileRetryDelay] ;# Delay in ms before retrying. |
| 260 | |
| 261 | foreach filename $args { |
| 262 | # On windows, sometimes even a [file delete -force] can fail just after |
| 263 | # a file is closed. The cause is usually "tag-alongs" - programs like |
| 264 | # anti-virus software, automatic backup tools and various explorer |
| 265 | # extensions that keep a file open a little longer than we expect, causing |
| 266 | # the delete to fail. |
| 267 | # |
| 268 | # The solution is to wait a short amount of time before retrying the |
| 269 | # delete. |
| 270 | # |
| 271 | if {$nRetry > 0} { |
| 272 | for {set i 0} {$i<$nRetry} {incr i} { |
| 273 | set rc [catch { |
| 274 | if {$force} { |
| 275 | file delete -force $filename |
| 276 | } else { |
| 277 | file delete $filename |
| 278 | } |
| 279 | } msg] |
| 280 | if {$rc==0} break |
| 281 | if {$nDelay > 0} { after $nDelay } |
| 282 | } |
| 283 | if {$rc} { error $msg } |
| 284 | } else { |
| 285 | if {$force} { |
| 286 | file delete -force $filename |
| 287 | } else { |
| 288 | file delete $filename |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
dan | cb35460 | 2010-07-08 09:44:42 +0000 | [diff] [blame] | 294 | proc execpresql {handle args} { |
| 295 | trace remove execution $handle enter [list execpresql $handle] |
| 296 | if {[info exists ::G(perm:presql)]} { |
| 297 | $handle eval $::G(perm:presql) |
| 298 | } |
| 299 | } |
| 300 | |
dan | 68928b6 | 2010-06-22 13:46:43 +0000 | [diff] [blame] | 301 | # This command should be called after loading tester.tcl from within |
| 302 | # all test scripts that are incompatible with encryption codecs. |
| 303 | # |
| 304 | proc do_not_use_codec {} { |
| 305 | set ::do_not_use_codec 1 |
| 306 | reset_db |
| 307 | } |
| 308 | |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 309 | # The following block only runs the first time this file is sourced. It |
| 310 | # does not run in slave interpreters (since the ::cmdlinearg array is |
| 311 | # populated before the test script is run in slave interpreters). |
drh | bec2bf4 | 2000-05-29 23:48:22 +0000 | [diff] [blame] | 312 | # |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 313 | if {[info exists cmdlinearg]==0} { |
| 314 | |
| 315 | # Parse any options specified in the $argv array. This script accepts the |
| 316 | # following options: |
| 317 | # |
| 318 | # --pause |
| 319 | # --soft-heap-limit=NN |
| 320 | # --maxerror=NN |
| 321 | # --malloctrace=N |
| 322 | # --backtrace=N |
| 323 | # --binarylog=N |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 324 | # --soak=N |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 325 | # --file-retries=N |
| 326 | # --file-retry-delay=N |
dan | 6a64d67 | 2011-04-04 15:38:16 +0000 | [diff] [blame] | 327 | # --start=[$permutation:]$testfile |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 328 | # --match=$pattern |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 329 | # |
| 330 | set cmdlinearg(soft-heap-limit) 0 |
| 331 | set cmdlinearg(maxerror) 1000 |
| 332 | set cmdlinearg(malloctrace) 0 |
| 333 | set cmdlinearg(backtrace) 10 |
| 334 | set cmdlinearg(binarylog) 0 |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 335 | set cmdlinearg(soak) 0 |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 336 | set cmdlinearg(file-retries) 0 |
| 337 | set cmdlinearg(file-retry-delay) 0 |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 338 | set cmdlinearg(start) "" |
| 339 | set cmdlinearg(match) "" |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 340 | |
| 341 | set leftover [list] |
| 342 | foreach a $argv { |
| 343 | switch -regexp -- $a { |
| 344 | {^-+pause$} { |
| 345 | # Wait for user input before continuing. This is to give the user an |
| 346 | # opportunity to connect profiling tools to the process. |
| 347 | puts -nonewline "Press RETURN to begin..." |
| 348 | flush stdout |
| 349 | gets stdin |
| 350 | } |
| 351 | {^-+soft-heap-limit=.+$} { |
| 352 | foreach {dummy cmdlinearg(soft-heap-limit)} [split $a =] break |
| 353 | } |
| 354 | {^-+maxerror=.+$} { |
| 355 | foreach {dummy cmdlinearg(maxerror)} [split $a =] break |
| 356 | } |
| 357 | {^-+malloctrace=.+$} { |
| 358 | foreach {dummy cmdlinearg(malloctrace)} [split $a =] break |
| 359 | if {$cmdlinearg(malloctrace)} { |
| 360 | sqlite3_memdebug_log start |
| 361 | } |
| 362 | } |
| 363 | {^-+backtrace=.+$} { |
| 364 | foreach {dummy cmdlinearg(backtrace)} [split $a =] break |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 365 | sqlite3_memdebug_backtrace $value |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 366 | } |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 367 | {^-+binarylog=.+$} { |
| 368 | foreach {dummy cmdlinearg(binarylog)} [split $a =] break |
| 369 | } |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 370 | {^-+soak=.+$} { |
| 371 | foreach {dummy cmdlinearg(soak)} [split $a =] break |
| 372 | set ::G(issoak) $cmdlinearg(soak) |
| 373 | } |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 374 | {^-+file-retries=.+$} { |
| 375 | foreach {dummy cmdlinearg(file-retries)} [split $a =] break |
| 376 | set ::G(file-retries) $cmdlinearg(file-retries) |
| 377 | } |
| 378 | {^-+file-retry-delay=.+$} { |
| 379 | foreach {dummy cmdlinearg(file-retry-delay)} [split $a =] break |
| 380 | set ::G(file-retry-delay) $cmdlinearg(file-retry-delay) |
| 381 | } |
dan | 6a64d67 | 2011-04-04 15:38:16 +0000 | [diff] [blame] | 382 | {^-+start=.+$} { |
| 383 | foreach {dummy cmdlinearg(start)} [split $a =] break |
| 384 | |
| 385 | set ::G(start:file) $cmdlinearg(start) |
| 386 | if {[regexp {(.*):(.*)} $cmdlinearg(start) -> s.perm s.file]} { |
| 387 | set ::G(start:permutation) ${s.perm} |
| 388 | set ::G(start:file) ${s.file} |
| 389 | } |
| 390 | if {$::G(start:file) == ""} {unset ::G(start:file)} |
| 391 | } |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 392 | {^-+match=.+$} { |
| 393 | foreach {dummy cmdlinearg(match)} [split $a =] break |
| 394 | |
| 395 | set ::G(match) $cmdlinearg(match) |
| 396 | if {$::G(match) == ""} {unset ::G(match)} |
| 397 | } |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 398 | default { |
| 399 | lappend leftover $a |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | set argv $leftover |
| 404 | |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 405 | # Install the malloc layer used to inject OOM errors. And the 'automatic' |
| 406 | # extensions. This only needs to be done once for the process. |
| 407 | # |
danielk1977 | f7b9d66 | 2008-06-23 18:49:43 +0000 | [diff] [blame] | 408 | sqlite3_shutdown |
| 409 | install_malloc_faultsim 1 |
| 410 | sqlite3_initialize |
drh | bb77b75 | 2009-04-09 01:23:49 +0000 | [diff] [blame] | 411 | autoinstall_test_functions |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 412 | |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 413 | # If the --binarylog option was specified, create the logging VFS. This |
| 414 | # call installs the new VFS as the default for all SQLite connections. |
| 415 | # |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 416 | if {$cmdlinearg(binarylog)} { |
dan | fbefb89 | 2010-05-12 19:02:35 +0000 | [diff] [blame] | 417 | vfslog new binarylog {} vfslog.bin |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | # Set the backtrace depth, if malloc tracing is enabled. |
| 421 | # |
| 422 | if {$cmdlinearg(malloctrace)} { |
| 423 | sqlite3_memdebug_backtrace $cmdlinearg(backtrace) |
danielk1977 | 185eac9 | 2008-07-12 15:55:54 +0000 | [diff] [blame] | 424 | } |
danielk1977 | f7b9d66 | 2008-06-23 18:49:43 +0000 | [diff] [blame] | 425 | } |
danielk1977 | 03ba3fa | 2009-01-09 10:49:14 +0000 | [diff] [blame] | 426 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 427 | # Update the soft-heap-limit each time this script is run. In that |
| 428 | # way if an individual test file changes the soft-heap-limit, it |
| 429 | # will be reset at the start of the next test file. |
| 430 | # |
| 431 | sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) |
| 432 | |
| 433 | # Create a test database |
| 434 | # |
danielk1977 | 03ba3fa | 2009-01-09 10:49:14 +0000 | [diff] [blame] | 435 | proc reset_db {} { |
| 436 | catch {db close} |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 437 | forcedelete test.db |
| 438 | forcedelete test.db-journal |
| 439 | forcedelete test.db-wal |
danielk1977 | 03ba3fa | 2009-01-09 10:49:14 +0000 | [diff] [blame] | 440 | sqlite3 db ./test.db |
| 441 | set ::DB [sqlite3_connection_pointer db] |
| 442 | if {[info exists ::SETUP_SQL]} { |
| 443 | db eval $::SETUP_SQL |
| 444 | } |
drh | cd61c28 | 2002-03-06 22:01:34 +0000 | [diff] [blame] | 445 | } |
danielk1977 | 03ba3fa | 2009-01-09 10:49:14 +0000 | [diff] [blame] | 446 | reset_db |
drh | bec2bf4 | 2000-05-29 23:48:22 +0000 | [diff] [blame] | 447 | |
| 448 | # Abort early if this script has been run before. |
| 449 | # |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 450 | if {[info exists TC(count)]} return |
drh | bec2bf4 | 2000-05-29 23:48:22 +0000 | [diff] [blame] | 451 | |
drh | ce2198c | 2010-09-10 13:22:59 +0000 | [diff] [blame] | 452 | # Make sure memory statistics are enabled. |
| 453 | # |
| 454 | sqlite3_config_memstatus 1 |
| 455 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 456 | # Initialize the test counters and set up commands to access them. |
| 457 | # Or, if this is a slave interpreter, set up aliases to write the |
| 458 | # counters in the parent interpreter. |
drh | bec2bf4 | 2000-05-29 23:48:22 +0000 | [diff] [blame] | 459 | # |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 460 | if {0==[info exists ::SLAVE]} { |
| 461 | set TC(errors) 0 |
| 462 | set TC(count) 0 |
| 463 | set TC(fail_list) [list] |
| 464 | set TC(omit_list) [list] |
drh | cca17c3 | 2013-04-19 12:32:52 +0000 | [diff] [blame^] | 465 | set TC(warn_list) [list] |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 466 | |
| 467 | proc set_test_counter {counter args} { |
| 468 | if {[llength $args]} { |
| 469 | set ::TC($counter) [lindex $args 0] |
| 470 | } |
| 471 | set ::TC($counter) |
| 472 | } |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 473 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 474 | |
drh | 521cc84 | 2008-04-15 02:36:33 +0000 | [diff] [blame] | 475 | # Record the fact that a sequence of tests were omitted. |
| 476 | # |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 477 | proc omit_test {name reason {append 1}} { |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 478 | set omitList [set_test_counter omit_list] |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 479 | if {$append} { |
| 480 | lappend omitList [list $name $reason] |
| 481 | } |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 482 | set_test_counter omit_list $omitList |
drh | 521cc84 | 2008-04-15 02:36:33 +0000 | [diff] [blame] | 483 | } |
| 484 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 485 | # Record the fact that a test failed. |
| 486 | # |
| 487 | proc fail_test {name} { |
| 488 | set f [set_test_counter fail_list] |
| 489 | lappend f $name |
| 490 | set_test_counter fail_list $f |
| 491 | set_test_counter errors [expr [set_test_counter errors] + 1] |
| 492 | |
| 493 | set nFail [set_test_counter errors] |
| 494 | if {$nFail>=$::cmdlinearg(maxerror)} { |
| 495 | puts "*** Giving up..." |
| 496 | finalize_testing |
| 497 | } |
| 498 | } |
| 499 | |
drh | cca17c3 | 2013-04-19 12:32:52 +0000 | [diff] [blame^] | 500 | # Remember a warning message to be displayed at the conclusion of all testing |
| 501 | # |
| 502 | proc warning {msg {append 1}} { |
| 503 | puts "Warning: $msg" |
| 504 | set warnList [set_test_counter warn_list] |
| 505 | if {$append} { |
| 506 | lappend warnList $msg |
| 507 | } |
| 508 | set_test_counter warn_list $warnList |
| 509 | } |
| 510 | |
| 511 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 512 | # Increment the number of tests run |
| 513 | # |
| 514 | proc incr_ntest {} { |
| 515 | set_test_counter count [expr [set_test_counter count] + 1] |
| 516 | } |
| 517 | |
| 518 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 519 | # Invoke the do_test procedure to run a single test |
| 520 | # |
| 521 | proc do_test {name cmd expected} { |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 522 | global argv cmdlinearg |
| 523 | |
dan | 8c40800 | 2010-11-01 17:38:24 +0000 | [diff] [blame] | 524 | fix_testname name |
| 525 | |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 526 | sqlite3_memdebug_settitle $name |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 527 | |
dan | 92d516a | 2010-07-05 14:54:48 +0000 | [diff] [blame] | 528 | # if {[llength $argv]==0} { |
| 529 | # set go 1 |
| 530 | # } else { |
| 531 | # set go 0 |
| 532 | # foreach pattern $argv { |
| 533 | # if {[string match $pattern $name]} { |
| 534 | # set go 1 |
| 535 | # break |
| 536 | # } |
| 537 | # } |
| 538 | # } |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 539 | |
dan | d506de0 | 2010-07-03 13:59:01 +0000 | [diff] [blame] | 540 | if {[info exists ::G(perm:prefix)]} { |
| 541 | set name "$::G(perm:prefix)$name" |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 542 | } |
| 543 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 544 | incr_ntest |
drh | 5edc312 | 2001-09-13 21:53:09 +0000 | [diff] [blame] | 545 | puts -nonewline $name... |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 546 | flush stdout |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 547 | |
| 548 | if {![info exists ::G(match)] || [string match $::G(match) $name]} { |
| 549 | if {[catch {uplevel #0 "$cmd;\n"} result]} { |
| 550 | puts "\nError: $result" |
| 551 | fail_test $name |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 552 | } else { |
drh | 3f17aef | 2012-04-27 01:08:02 +0000 | [diff] [blame] | 553 | if {[regexp {^~?/.*/$} $expected]} { |
| 554 | if {[string index $expected 0]=="~"} { |
drh | 5343b2d | 2012-09-27 19:53:38 +0000 | [diff] [blame] | 555 | set re [string map {# {[-0-9.]+}} [string range $expected 2 end-1]] |
drh | 3f17aef | 2012-04-27 01:08:02 +0000 | [diff] [blame] | 556 | set ok [expr {![regexp $re $result]}] |
| 557 | } else { |
drh | 5343b2d | 2012-09-27 19:53:38 +0000 | [diff] [blame] | 558 | set re [string map {# {[-0-9.]+}} [string range $expected 1 end-1]] |
drh | 3f17aef | 2012-04-27 01:08:02 +0000 | [diff] [blame] | 559 | set ok [regexp $re $result] |
| 560 | } |
| 561 | } else { |
| 562 | set ok [expr {[string compare $result $expected]==0}] |
| 563 | } |
| 564 | if {!$ok} { |
mistachkin | c60941f | 2012-09-13 01:51:02 +0000 | [diff] [blame] | 565 | # if {![info exists ::testprefix] || $::testprefix eq ""} { |
| 566 | # error "no test prefix" |
| 567 | # } |
drh | 3f17aef | 2012-04-27 01:08:02 +0000 | [diff] [blame] | 568 | puts "\nExpected: \[$expected\]\n Got: \[$result\]" |
| 569 | fail_test $name |
| 570 | } else { |
| 571 | puts " Ok" |
| 572 | } |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 573 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 574 | } else { |
mistachkin | 6c3c1a0 | 2011-11-12 03:17:40 +0000 | [diff] [blame] | 575 | puts " Omitted" |
| 576 | omit_test $name "pattern mismatch" 0 |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 577 | } |
drh | 6558db8 | 2007-04-13 03:23:21 +0000 | [diff] [blame] | 578 | flush stdout |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 579 | } |
dan | a3f5108 | 2010-09-30 18:43:14 +0000 | [diff] [blame] | 580 | |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 581 | proc catchcmd {db {cmd ""}} { |
| 582 | global CLI |
| 583 | set out [open cmds.txt w] |
| 584 | puts $out $cmd |
| 585 | close $out |
| 586 | set line "exec $CLI $db < cmds.txt" |
| 587 | set rc [catch { eval $line } msg] |
| 588 | list $rc $msg |
| 589 | } |
| 590 | |
shaneh | 5550517 | 2011-06-21 19:30:19 +0000 | [diff] [blame] | 591 | proc filepath_normalize {p} { |
| 592 | # test cases should be written to assume "unix"-like file paths |
shaneh | 285a18f | 2011-06-21 19:39:59 +0000 | [diff] [blame] | 593 | if {$::tcl_platform(platform)!="unix"} { |
shaneh | 5550517 | 2011-06-21 19:30:19 +0000 | [diff] [blame] | 594 | # lreverse*2 as a hack to remove any unneeded {} after the string map |
| 595 | lreverse [lreverse [string map {\\ /} [regsub -nocase -all {[a-z]:[/\\]+} $p {/}]]] |
shaneh | c489640 | 2011-06-21 19:38:16 +0000 | [diff] [blame] | 596 | } { |
| 597 | set p |
shaneh | 5550517 | 2011-06-21 19:30:19 +0000 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | proc do_filepath_test {name cmd expected} { |
| 601 | uplevel [list do_test $name [ |
| 602 | subst -nocommands { filepath_normalize [ $cmd ] } |
| 603 | ] [filepath_normalize $expected]] |
| 604 | } |
| 605 | |
dan | 33f5379 | 2011-05-05 19:44:22 +0000 | [diff] [blame] | 606 | proc realnum_normalize {r} { |
shaneh | 4f529e8 | 2011-06-20 17:41:41 +0000 | [diff] [blame] | 607 | # different TCL versions display floating point values differently. |
| 608 | string map {1.#INF inf Inf inf .0e e} [regsub -all {(e[+-])0+} $r {\1}] |
dan | 33f5379 | 2011-05-05 19:44:22 +0000 | [diff] [blame] | 609 | } |
| 610 | proc do_realnum_test {name cmd expected} { |
| 611 | uplevel [list do_test $name [ |
| 612 | subst -nocommands { realnum_normalize [ $cmd ] } |
| 613 | ] [realnum_normalize $expected]] |
| 614 | } |
| 615 | |
dan | a3f5108 | 2010-09-30 18:43:14 +0000 | [diff] [blame] | 616 | proc fix_testname {varname} { |
| 617 | upvar $varname testname |
| 618 | if {[info exists ::testprefix] |
| 619 | && [string is digit [string range $testname 0 0]] |
| 620 | } { |
| 621 | set testname "${::testprefix}-$testname" |
| 622 | } |
| 623 | } |
dan | 153eda0 | 2010-06-21 07:45:47 +0000 | [diff] [blame] | 624 | |
dan | 57f7f4b | 2010-10-01 19:04:37 +0000 | [diff] [blame] | 625 | proc do_execsql_test {testname sql {result {}}} { |
dan | a3f5108 | 2010-09-30 18:43:14 +0000 | [diff] [blame] | 626 | fix_testname testname |
dan | 99ebad9 | 2011-06-13 09:11:01 +0000 | [diff] [blame] | 627 | uplevel do_test [list $testname] [list "execsql {$sql}"] [list [list {*}$result]] |
dan | 153eda0 | 2010-06-21 07:45:47 +0000 | [diff] [blame] | 628 | } |
| 629 | proc do_catchsql_test {testname sql result} { |
dan | a3f5108 | 2010-09-30 18:43:14 +0000 | [diff] [blame] | 630 | fix_testname testname |
dan | 99ebad9 | 2011-06-13 09:11:01 +0000 | [diff] [blame] | 631 | uplevel do_test [list $testname] [list "catchsql {$sql}"] [list $result] |
dan | 153eda0 | 2010-06-21 07:45:47 +0000 | [diff] [blame] | 632 | } |
dan | 3985479 | 2010-11-15 16:12:58 +0000 | [diff] [blame] | 633 | proc do_eqp_test {name sql res} { |
| 634 | uplevel do_execsql_test $name [list "EXPLAIN QUERY PLAN $sql"] [list $res] |
| 635 | } |
dan | 153eda0 | 2010-06-21 07:45:47 +0000 | [diff] [blame] | 636 | |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 637 | #------------------------------------------------------------------------- |
| 638 | # Usage: do_select_tests PREFIX ?SWITCHES? TESTLIST |
| 639 | # |
| 640 | # Where switches are: |
| 641 | # |
| 642 | # -errorformat FMTSTRING |
| 643 | # -count |
dan | af1dcab | 2010-09-20 19:17:53 +0000 | [diff] [blame] | 644 | # -query SQL |
dan | a16d106 | 2010-09-28 17:37:28 +0000 | [diff] [blame] | 645 | # -tclquery TCL |
dan | af7626f | 2010-09-23 18:47:36 +0000 | [diff] [blame] | 646 | # -repair TCL |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 647 | # |
| 648 | proc do_select_tests {prefix args} { |
| 649 | |
| 650 | set testlist [lindex $args end] |
| 651 | set switches [lrange $args 0 end-1] |
| 652 | |
| 653 | set errfmt "" |
| 654 | set countonly 0 |
dan | a16d106 | 2010-09-28 17:37:28 +0000 | [diff] [blame] | 655 | set tclquery "" |
dan | af7626f | 2010-09-23 18:47:36 +0000 | [diff] [blame] | 656 | set repair "" |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 657 | |
| 658 | for {set i 0} {$i < [llength $switches]} {incr i} { |
| 659 | set s [lindex $switches $i] |
| 660 | set n [string length $s] |
dan | af1dcab | 2010-09-20 19:17:53 +0000 | [diff] [blame] | 661 | if {$n>=2 && [string equal -length $n $s "-query"]} { |
dan | a16d106 | 2010-09-28 17:37:28 +0000 | [diff] [blame] | 662 | set tclquery [list execsql [lindex $switches [incr i]]] |
| 663 | } elseif {$n>=2 && [string equal -length $n $s "-tclquery"]} { |
| 664 | set tclquery [lindex $switches [incr i]] |
dan | af1dcab | 2010-09-20 19:17:53 +0000 | [diff] [blame] | 665 | } elseif {$n>=2 && [string equal -length $n $s "-errorformat"]} { |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 666 | set errfmt [lindex $switches [incr i]] |
dan | af7626f | 2010-09-23 18:47:36 +0000 | [diff] [blame] | 667 | } elseif {$n>=2 && [string equal -length $n $s "-repair"]} { |
| 668 | set repair [lindex $switches [incr i]] |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 669 | } elseif {$n>=2 && [string equal -length $n $s "-count"]} { |
| 670 | set countonly 1 |
| 671 | } else { |
| 672 | error "unknown switch: $s" |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | if {$countonly && $errfmt!=""} { |
| 677 | error "Cannot use -count and -errorformat together" |
| 678 | } |
| 679 | set nTestlist [llength $testlist] |
| 680 | if {$nTestlist%3 || $nTestlist==0 } { |
| 681 | error "SELECT test list contains [llength $testlist] elements" |
| 682 | } |
| 683 | |
dan | af7626f | 2010-09-23 18:47:36 +0000 | [diff] [blame] | 684 | eval $repair |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 685 | foreach {tn sql res} $testlist { |
dan | a16d106 | 2010-09-28 17:37:28 +0000 | [diff] [blame] | 686 | if {$tclquery != ""} { |
dan | af1dcab | 2010-09-20 19:17:53 +0000 | [diff] [blame] | 687 | execsql $sql |
dan | a16d106 | 2010-09-28 17:37:28 +0000 | [diff] [blame] | 688 | uplevel do_test ${prefix}.$tn [list $tclquery] [list [list {*}$res]] |
| 689 | } elseif {$countonly} { |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 690 | set nRow 0 |
| 691 | db eval $sql {incr nRow} |
| 692 | uplevel do_test ${prefix}.$tn [list [list set {} $nRow]] [list $res] |
| 693 | } elseif {$errfmt==""} { |
| 694 | uplevel do_execsql_test ${prefix}.${tn} [list $sql] [list [list {*}$res]] |
| 695 | } else { |
| 696 | set res [list 1 [string trim [format $errfmt {*}$res]]] |
| 697 | uplevel do_catchsql_test ${prefix}.${tn} [list $sql] [list $res] |
| 698 | } |
dan | af7626f | 2010-09-23 18:47:36 +0000 | [diff] [blame] | 699 | eval $repair |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 700 | } |
dan | af7626f | 2010-09-23 18:47:36 +0000 | [diff] [blame] | 701 | |
dan | 51f0698 | 2010-09-18 19:00:12 +0000 | [diff] [blame] | 702 | } |
| 703 | |
dan | b04757a | 2010-09-21 16:59:16 +0000 | [diff] [blame] | 704 | proc delete_all_data {} { |
| 705 | db eval {SELECT tbl_name AS t FROM sqlite_master WHERE type = 'table'} { |
| 706 | db eval "DELETE FROM '[string map {' ''} $t]'" |
| 707 | } |
| 708 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 709 | |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 710 | # Run an SQL script. |
| 711 | # Return the number of microseconds per statement. |
| 712 | # |
drh | 3590f15 | 2006-11-23 21:09:10 +0000 | [diff] [blame] | 713 | proc speed_trial {name numstmt units sql} { |
drh | dd92431 | 2007-03-31 22:34:16 +0000 | [diff] [blame] | 714 | puts -nonewline [format {%-21.21s } $name...] |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 715 | flush stdout |
| 716 | set speed [time {sqlite3_exec_nr db $sql}] |
| 717 | set tm [lindex $speed 0] |
danielk1977 | 0ee26d9 | 2008-02-08 18:25:29 +0000 | [diff] [blame] | 718 | if {$tm == 0} { |
| 719 | set rate [format %20s "many"] |
| 720 | } else { |
| 721 | set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]] |
| 722 | } |
drh | 3590f15 | 2006-11-23 21:09:10 +0000 | [diff] [blame] | 723 | set u2 $units/s |
danielk1977 | 0ee26d9 | 2008-02-08 18:25:29 +0000 | [diff] [blame] | 724 | puts [format {%12d uS %s %s} $tm $rate $u2] |
drh | dd92431 | 2007-03-31 22:34:16 +0000 | [diff] [blame] | 725 | global total_time |
| 726 | set total_time [expr {$total_time+$tm}] |
dan | a975b59 | 2010-10-08 16:09:43 +0000 | [diff] [blame] | 727 | lappend ::speed_trial_times $name $tm |
drh | dd92431 | 2007-03-31 22:34:16 +0000 | [diff] [blame] | 728 | } |
drh | 45c236d | 2008-03-22 01:08:00 +0000 | [diff] [blame] | 729 | proc speed_trial_tcl {name numstmt units script} { |
| 730 | puts -nonewline [format {%-21.21s } $name...] |
| 731 | flush stdout |
| 732 | set speed [time {eval $script}] |
| 733 | set tm [lindex $speed 0] |
| 734 | if {$tm == 0} { |
| 735 | set rate [format %20s "many"] |
| 736 | } else { |
| 737 | set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]] |
| 738 | } |
| 739 | set u2 $units/s |
| 740 | puts [format {%12d uS %s %s} $tm $rate $u2] |
| 741 | global total_time |
| 742 | set total_time [expr {$total_time+$tm}] |
dan | a975b59 | 2010-10-08 16:09:43 +0000 | [diff] [blame] | 743 | lappend ::speed_trial_times $name $tm |
drh | 45c236d | 2008-03-22 01:08:00 +0000 | [diff] [blame] | 744 | } |
drh | dd92431 | 2007-03-31 22:34:16 +0000 | [diff] [blame] | 745 | proc speed_trial_init {name} { |
| 746 | global total_time |
| 747 | set total_time 0 |
dan | a975b59 | 2010-10-08 16:09:43 +0000 | [diff] [blame] | 748 | set ::speed_trial_times [list] |
drh | bb810a9 | 2010-07-03 12:00:53 +0000 | [diff] [blame] | 749 | sqlite3 versdb :memory: |
| 750 | set vers [versdb one {SELECT sqlite_source_id()}] |
| 751 | versdb close |
| 752 | puts "SQLite $vers" |
drh | dd92431 | 2007-03-31 22:34:16 +0000 | [diff] [blame] | 753 | } |
| 754 | proc speed_trial_summary {name} { |
| 755 | global total_time |
| 756 | puts [format {%-21.21s %12d uS TOTAL} $name $total_time] |
dan | a975b59 | 2010-10-08 16:09:43 +0000 | [diff] [blame] | 757 | |
| 758 | if { 0 } { |
| 759 | sqlite3 versdb :memory: |
| 760 | set vers [lindex [versdb one {SELECT sqlite_source_id()}] 0] |
| 761 | versdb close |
| 762 | puts "CREATE TABLE IF NOT EXISTS time(version, script, test, us);" |
| 763 | foreach {test us} $::speed_trial_times { |
| 764 | puts "INSERT INTO time VALUES('$vers', '$name', '$test', $us);" |
| 765 | } |
| 766 | } |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 767 | } |
| 768 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 769 | # Run this routine last |
| 770 | # |
| 771 | proc finish_test {} { |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 772 | catch {db close} |
| 773 | catch {db2 close} |
| 774 | catch {db3 close} |
| 775 | if {0==[info exists ::SLAVE]} { finalize_testing } |
drh | a1b351a | 2001-09-14 16:42:12 +0000 | [diff] [blame] | 776 | } |
| 777 | proc finalize_testing {} { |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 778 | global sqlite_open_file_count |
| 779 | |
| 780 | set omitList [set_test_counter omit_list] |
danielk1977 | 2e588c7 | 2005-12-09 14:25:08 +0000 | [diff] [blame] | 781 | |
drh | 6e142f5 | 2000-06-08 13:36:40 +0000 | [diff] [blame] | 782 | catch {db close} |
danielk1977 | 2e588c7 | 2005-12-09 14:25:08 +0000 | [diff] [blame] | 783 | catch {db2 close} |
| 784 | catch {db3 close} |
| 785 | |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 786 | vfs_unlink_test |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 787 | sqlite3 db {} |
danielk1977 | cbb8496 | 2006-01-17 16:10:13 +0000 | [diff] [blame] | 788 | # sqlite3_clear_tsd_memdebug |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 789 | db close |
drh | 984bfaa | 2008-03-19 16:08:53 +0000 | [diff] [blame] | 790 | sqlite3_reset_auto_extension |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 791 | |
drh | 3a7fb7c | 2007-08-10 16:41:08 +0000 | [diff] [blame] | 792 | sqlite3_soft_heap_limit 0 |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 793 | set nTest [incr_ntest] |
| 794 | set nErr [set_test_counter errors] |
| 795 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 796 | puts "$nErr errors out of $nTest tests" |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 797 | if {$nErr>0} { |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 798 | puts "Failures on these tests: [set_test_counter fail_list]" |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 799 | } |
drh | cca17c3 | 2013-04-19 12:32:52 +0000 | [diff] [blame^] | 800 | foreach warning [set_test_counter warn_list] { |
| 801 | puts "Warning: $warning" |
| 802 | } |
danielk1977 | ee8b799 | 2009-03-26 17:13:06 +0000 | [diff] [blame] | 803 | run_thread_tests 1 |
drh | 521cc84 | 2008-04-15 02:36:33 +0000 | [diff] [blame] | 804 | if {[llength $omitList]>0} { |
| 805 | puts "Omitted test cases:" |
| 806 | set prec {} |
| 807 | foreach {rec} [lsort $omitList] { |
| 808 | if {$rec==$prec} continue |
| 809 | set prec $rec |
| 810 | puts [format { %-12s %s} [lindex $rec 0] [lindex $rec 1]] |
| 811 | } |
| 812 | } |
drh | 80788d8 | 2006-09-02 14:50:23 +0000 | [diff] [blame] | 813 | if {$nErr>0 && ![working_64bit_int]} { |
| 814 | puts "******************************************************************" |
| 815 | puts "N.B.: The version of TCL that you used to build this test harness" |
| 816 | puts "is defective in that it does not support 64-bit integers. Some or" |
| 817 | puts "all of the test failures above might be a result from this defect" |
| 818 | puts "in your TCL build." |
| 819 | puts "******************************************************************" |
drh | db25e38 | 2001-03-15 18:21:22 +0000 | [diff] [blame] | 820 | } |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 821 | if {$::cmdlinearg(binarylog)} { |
dan | fbefb89 | 2010-05-12 19:02:35 +0000 | [diff] [blame] | 822 | vfslog finalize binarylog |
danielk1977 | 374177e | 2008-05-08 15:58:06 +0000 | [diff] [blame] | 823 | } |
drh | 94e9203 | 2003-02-16 22:21:32 +0000 | [diff] [blame] | 824 | if {$sqlite_open_file_count} { |
| 825 | puts "$sqlite_open_file_count files were left open" |
| 826 | incr nErr |
| 827 | } |
drh | eafc43b | 2010-07-26 18:43:40 +0000 | [diff] [blame] | 828 | if {[lindex [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0] 1]>0 || |
| 829 | [sqlite3_memory_used]>0} { |
| 830 | puts "Unfreed memory: [sqlite3_memory_used] bytes in\ |
| 831 | [lindex [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0] 1] allocations" |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 832 | incr nErr |
drh | 2d7636e | 2008-02-16 16:21:45 +0000 | [diff] [blame] | 833 | ifcapable memdebug||mem5||(mem3&&debug) { |
drh | 4a50aac | 2007-08-23 02:47:53 +0000 | [diff] [blame] | 834 | puts "Writing unfreed memory log to \"./memleak.txt\"" |
| 835 | sqlite3_memdebug_dump ./memleak.txt |
| 836 | } |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 837 | } else { |
| 838 | puts "All memory allocations freed - no leaks" |
drh | 2d7636e | 2008-02-16 16:21:45 +0000 | [diff] [blame] | 839 | ifcapable memdebug||mem5 { |
drh | d2bb327 | 2007-10-15 19:34:32 +0000 | [diff] [blame] | 840 | sqlite3_memdebug_dump ./memusage.txt |
| 841 | } |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 842 | } |
drh | f714199 | 2008-06-19 00:16:08 +0000 | [diff] [blame] | 843 | show_memstats |
drh | 91fd4d4 | 2008-01-19 20:11:25 +0000 | [diff] [blame] | 844 | puts "Maximum memory usage: [sqlite3_memory_highwater 1] bytes" |
| 845 | puts "Current memory usage: [sqlite3_memory_highwater] bytes" |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 846 | if {[info commands sqlite3_memdebug_malloc_count] ne ""} { |
| 847 | puts "Number of malloc() : [sqlite3_memdebug_malloc_count] calls" |
| 848 | } |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 849 | if {$::cmdlinearg(malloctrace)} { |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 850 | puts "Writing mallocs.sql..." |
| 851 | memdebug_log_sql |
| 852 | sqlite3_memdebug_log stop |
| 853 | sqlite3_memdebug_log clear |
danielk1977 | dbdc4d4 | 2008-03-28 07:42:53 +0000 | [diff] [blame] | 854 | |
| 855 | if {[sqlite3_memory_used]>0} { |
| 856 | puts "Writing leaks.sql..." |
| 857 | sqlite3_memdebug_log sync |
| 858 | memdebug_log_sql leaks.sql |
| 859 | } |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 860 | } |
drh | d9910fe | 2006-10-04 11:55:49 +0000 | [diff] [blame] | 861 | foreach f [glob -nocomplain test.db-*-journal] { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 862 | forcedelete $f |
drh | d9910fe | 2006-10-04 11:55:49 +0000 | [diff] [blame] | 863 | } |
| 864 | foreach f [glob -nocomplain test.db-mj*] { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 865 | forcedelete $f |
drh | d9910fe | 2006-10-04 11:55:49 +0000 | [diff] [blame] | 866 | } |
drh | db25e38 | 2001-03-15 18:21:22 +0000 | [diff] [blame] | 867 | exit [expr {$nErr>0}] |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 868 | } |
| 869 | |
drh | f714199 | 2008-06-19 00:16:08 +0000 | [diff] [blame] | 870 | # Display memory statistics for analysis and debugging purposes. |
| 871 | # |
| 872 | proc show_memstats {} { |
| 873 | set x [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] |
drh | e50135e | 2008-08-05 17:53:22 +0000 | [diff] [blame] | 874 | set y [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] |
| 875 | set val [format {now %10d max %10d max-size %10d} \ |
| 876 | [lindex $x 1] [lindex $x 2] [lindex $y 2]] |
drh | f714199 | 2008-06-19 00:16:08 +0000 | [diff] [blame] | 877 | puts "Memory used: $val" |
drh | eafc43b | 2010-07-26 18:43:40 +0000 | [diff] [blame] | 878 | set x [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0] |
| 879 | set val [format {now %10d max %10d} [lindex $x 1] [lindex $x 2]] |
| 880 | puts "Allocation count: $val" |
drh | f714199 | 2008-06-19 00:16:08 +0000 | [diff] [blame] | 881 | set x [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] |
drh | e50135e | 2008-08-05 17:53:22 +0000 | [diff] [blame] | 882 | set y [sqlite3_status SQLITE_STATUS_PAGECACHE_SIZE 0] |
| 883 | set val [format {now %10d max %10d max-size %10d} \ |
| 884 | [lindex $x 1] [lindex $x 2] [lindex $y 2]] |
drh | f714199 | 2008-06-19 00:16:08 +0000 | [diff] [blame] | 885 | puts "Page-cache used: $val" |
| 886 | set x [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] |
| 887 | set val [format {now %10d max %10d} [lindex $x 1] [lindex $x 2]] |
| 888 | puts "Page-cache overflow: $val" |
| 889 | set x [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] |
| 890 | set val [format {now %10d max %10d} [lindex $x 1] [lindex $x 2]] |
| 891 | puts "Scratch memory used: $val" |
| 892 | set x [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] |
drh | e50135e | 2008-08-05 17:53:22 +0000 | [diff] [blame] | 893 | set y [sqlite3_status SQLITE_STATUS_SCRATCH_SIZE 0] |
| 894 | set val [format {now %10d max %10d max-size %10d} \ |
| 895 | [lindex $x 1] [lindex $x 2] [lindex $y 2]] |
drh | f714199 | 2008-06-19 00:16:08 +0000 | [diff] [blame] | 896 | puts "Scratch overflow: $val" |
drh | ec424a5 | 2008-07-25 15:39:03 +0000 | [diff] [blame] | 897 | ifcapable yytrackmaxstackdepth { |
| 898 | set x [sqlite3_status SQLITE_STATUS_PARSER_STACK 0] |
| 899 | set val [format { max %10d} [lindex $x 2]] |
| 900 | puts "Parser stack depth: $val" |
| 901 | } |
drh | f714199 | 2008-06-19 00:16:08 +0000 | [diff] [blame] | 902 | } |
| 903 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 904 | # A procedure to execute SQL |
| 905 | # |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 906 | proc execsql {sql {db db}} { |
drh | acbcdc4 | 2001-01-22 00:31:53 +0000 | [diff] [blame] | 907 | # puts "SQL = $sql" |
danielk1977 | 3bdca9c | 2006-01-17 09:35:01 +0000 | [diff] [blame] | 908 | uplevel [list $db eval $sql] |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 909 | } |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 910 | |
drh | adbca9c | 2001-09-27 15:11:53 +0000 | [diff] [blame] | 911 | # Execute SQL and catch exceptions. |
| 912 | # |
| 913 | proc catchsql {sql {db db}} { |
| 914 | # puts "SQL = $sql" |
dan | 81fa6dc | 2009-11-28 12:40:32 +0000 | [diff] [blame] | 915 | set r [catch [list uplevel [list $db eval $sql]] msg] |
drh | adbca9c | 2001-09-27 15:11:53 +0000 | [diff] [blame] | 916 | lappend r $msg |
| 917 | return $r |
| 918 | } |
| 919 | |
drh | 0409648 | 2001-11-09 22:41:44 +0000 | [diff] [blame] | 920 | # Do an VDBE code dump on the SQL given |
| 921 | # |
| 922 | proc explain {sql {db db}} { |
| 923 | puts "" |
danielk1977 | 287fb61 | 2008-01-04 19:10:28 +0000 | [diff] [blame] | 924 | puts "addr opcode p1 p2 p3 p4 p5 #" |
| 925 | puts "---- ------------ ------ ------ ------ --------------- -- -" |
drh | 0409648 | 2001-11-09 22:41:44 +0000 | [diff] [blame] | 926 | $db eval "explain $sql" {} { |
danielk1977 | 287fb61 | 2008-01-04 19:10:28 +0000 | [diff] [blame] | 927 | puts [format {%-4d %-12.12s %-6d %-6d %-6d % -17s %s %s} \ |
| 928 | $addr $opcode $p1 $p2 $p3 $p4 $p5 $comment |
| 929 | ] |
drh | 0409648 | 2001-11-09 22:41:44 +0000 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | |
drh | dafc0ce | 2008-04-17 19:14:02 +0000 | [diff] [blame] | 933 | # Show the VDBE program for an SQL statement but omit the Trace |
| 934 | # opcode at the beginning. This procedure can be used to prove |
| 935 | # that different SQL statements generate exactly the same VDBE code. |
| 936 | # |
| 937 | proc explain_no_trace {sql} { |
| 938 | set tr [db eval "EXPLAIN $sql"] |
| 939 | return [lrange $tr 7 end] |
| 940 | } |
| 941 | |
drh | 3aadb2e | 2000-05-31 17:59:25 +0000 | [diff] [blame] | 942 | # Another procedure to execute SQL. This one includes the field |
| 943 | # names in the returned list. |
| 944 | # |
| 945 | proc execsql2 {sql} { |
| 946 | set result {} |
| 947 | db eval $sql data { |
| 948 | foreach f $data(*) { |
| 949 | lappend result $f $data($f) |
| 950 | } |
| 951 | } |
| 952 | return $result |
| 953 | } |
drh | 17a6893 | 2001-01-31 13:28:08 +0000 | [diff] [blame] | 954 | |
drh | dde85d9 | 2003-03-01 19:45:34 +0000 | [diff] [blame] | 955 | # Use the non-callback API to execute multiple SQL statements |
| 956 | # |
| 957 | proc stepsql {dbptr sql} { |
| 958 | set sql [string trim $sql] |
| 959 | set r 0 |
| 960 | while {[string length $sql]>0} { |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 961 | if {[catch {sqlite3_prepare $dbptr $sql -1 sqltail} vm]} { |
drh | dde85d9 | 2003-03-01 19:45:34 +0000 | [diff] [blame] | 962 | return [list 1 $vm] |
| 963 | } |
| 964 | set sql [string trim $sqltail] |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 965 | # while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} { |
| 966 | # foreach v $VAL {lappend r $v} |
| 967 | # } |
| 968 | while {[sqlite3_step $vm]=="SQLITE_ROW"} { |
| 969 | for {set i 0} {$i<[sqlite3_data_count $vm]} {incr i} { |
| 970 | lappend r [sqlite3_column_text $vm $i] |
| 971 | } |
drh | dde85d9 | 2003-03-01 19:45:34 +0000 | [diff] [blame] | 972 | } |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 973 | if {[catch {sqlite3_finalize $vm} errmsg]} { |
drh | dde85d9 | 2003-03-01 19:45:34 +0000 | [diff] [blame] | 974 | return [list 1 $errmsg] |
| 975 | } |
| 976 | } |
| 977 | return $r |
| 978 | } |
| 979 | |
drh | 2150432 | 2002-06-25 13:16:02 +0000 | [diff] [blame] | 980 | # Do an integrity check of the entire database |
| 981 | # |
danielk1977 | 0410302 | 2009-02-03 16:51:24 +0000 | [diff] [blame] | 982 | proc integrity_check {name {db db}} { |
drh | 27d258a | 2004-10-30 20:23:09 +0000 | [diff] [blame] | 983 | ifcapable integrityck { |
danielk1977 | 0410302 | 2009-02-03 16:51:24 +0000 | [diff] [blame] | 984 | do_test $name [list execsql {PRAGMA integrity_check} $db] {ok} |
drh | 27d258a | 2004-10-30 20:23:09 +0000 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
drh | 433dccf | 2013-02-09 15:37:11 +0000 | [diff] [blame] | 988 | # Check the extended error code |
| 989 | # |
| 990 | proc verify_ex_errcode {name expected {db db}} { |
| 991 | do_test $name [list sqlite3_extended_errcode $db] $expected |
| 992 | } |
| 993 | |
dan | c6055c7 | 2011-04-28 18:46:46 +0000 | [diff] [blame] | 994 | |
| 995 | # Return true if the SQL statement passed as the second argument uses a |
| 996 | # statement transaction. |
| 997 | # |
| 998 | proc sql_uses_stmt {db sql} { |
| 999 | set stmt [sqlite3_prepare $db $sql -1 dummy] |
| 1000 | set uses [uses_stmt_journal $stmt] |
| 1001 | sqlite3_finalize $stmt |
| 1002 | return $uses |
| 1003 | } |
| 1004 | |
danielk1977 | db4e886 | 2008-01-16 08:24:46 +0000 | [diff] [blame] | 1005 | proc fix_ifcapable_expr {expr} { |
| 1006 | set ret "" |
| 1007 | set state 0 |
| 1008 | for {set i 0} {$i < [string length $expr]} {incr i} { |
| 1009 | set char [string range $expr $i $i] |
| 1010 | set newstate [expr {[string is alnum $char] || $char eq "_"}] |
| 1011 | if {$newstate && !$state} { |
| 1012 | append ret {$::sqlite_options(} |
| 1013 | } |
| 1014 | if {!$newstate && $state} { |
| 1015 | append ret ) |
| 1016 | } |
| 1017 | append ret $char |
| 1018 | set state $newstate |
| 1019 | } |
| 1020 | if {$state} {append ret )} |
| 1021 | return $ret |
| 1022 | } |
| 1023 | |
mistachkin | c60941f | 2012-09-13 01:51:02 +0000 | [diff] [blame] | 1024 | # Returns non-zero if the capabilities are present; zero otherwise. |
| 1025 | # |
| 1026 | proc capable {expr} { |
| 1027 | set e [fix_ifcapable_expr $expr]; return [expr ($e)] |
| 1028 | } |
| 1029 | |
drh | 27d258a | 2004-10-30 20:23:09 +0000 | [diff] [blame] | 1030 | # Evaluate a boolean expression of capabilities. If true, execute the |
| 1031 | # code. Omit the code if false. |
| 1032 | # |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 1033 | proc ifcapable {expr code {else ""} {elsecode ""}} { |
danielk1977 | db4e886 | 2008-01-16 08:24:46 +0000 | [diff] [blame] | 1034 | #regsub -all {[a-z_0-9]+} $expr {$::sqlite_options(&)} e2 |
| 1035 | set e2 [fix_ifcapable_expr $expr] |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 1036 | if ($e2) { |
| 1037 | set c [catch {uplevel 1 $code} r] |
| 1038 | } else { |
| 1039 | set c [catch {uplevel 1 $elsecode} r] |
| 1040 | } |
| 1041 | return -code $c $r |
drh | 2150432 | 2002-06-25 13:16:02 +0000 | [diff] [blame] | 1042 | } |
danielk1977 | 45901d6 | 2004-11-10 15:27:38 +0000 | [diff] [blame] | 1043 | |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 1044 | # This proc execs a seperate process that crashes midway through executing |
| 1045 | # the SQL script $sql on database test.db. |
| 1046 | # |
| 1047 | # The crash occurs during a sync() of file $crashfile. When the crash |
| 1048 | # occurs a random subset of all unsynced writes made by the process are |
| 1049 | # written into the files on disk. Argument $crashdelay indicates the |
| 1050 | # number of file syncs to wait before crashing. |
| 1051 | # |
| 1052 | # The return value is a list of two elements. The first element is a |
| 1053 | # boolean, indicating whether or not the process actually crashed or |
| 1054 | # reported some other error. The second element in the returned list is the |
| 1055 | # error message. This is "child process exited abnormally" if the crash |
mistachkin | 48864df | 2013-03-21 21:20:32 +0000 | [diff] [blame] | 1056 | # occurred. |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 1057 | # |
danielk1977 | f8940ae | 2007-08-23 11:07:10 +0000 | [diff] [blame] | 1058 | # crashsql -delay CRASHDELAY -file CRASHFILE ?-blocksize BLOCKSIZE? $sql |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 1059 | # |
| 1060 | proc crashsql {args} { |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 1061 | |
| 1062 | set blocksize "" |
| 1063 | set crashdelay 1 |
drh | cb1f0f6 | 2008-01-08 15:18:52 +0000 | [diff] [blame] | 1064 | set prngseed 0 |
drh | f858740 | 2008-01-08 16:03:49 +0000 | [diff] [blame] | 1065 | set tclbody {} |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 1066 | set crashfile "" |
danielk1977 | f8940ae | 2007-08-23 11:07:10 +0000 | [diff] [blame] | 1067 | set dc "" |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 1068 | set sql [lindex $args end] |
| 1069 | |
| 1070 | for {set ii 0} {$ii < [llength $args]-1} {incr ii 2} { |
| 1071 | set z [lindex $args $ii] |
| 1072 | set n [string length $z] |
| 1073 | set z2 [lindex $args [expr $ii+1]] |
| 1074 | |
| 1075 | if {$n>1 && [string first $z -delay]==0} {set crashdelay $z2} \ |
drh | cb1f0f6 | 2008-01-08 15:18:52 +0000 | [diff] [blame] | 1076 | elseif {$n>1 && [string first $z -seed]==0} {set prngseed $z2} \ |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 1077 | elseif {$n>1 && [string first $z -file]==0} {set crashfile $z2} \ |
drh | f858740 | 2008-01-08 16:03:49 +0000 | [diff] [blame] | 1078 | elseif {$n>1 && [string first $z -tclbody]==0} {set tclbody $z2} \ |
danielk1977 | 967a4a1 | 2007-08-20 14:23:44 +0000 | [diff] [blame] | 1079 | elseif {$n>1 && [string first $z -blocksize]==0} {set blocksize "-s $z2" } \ |
danielk1977 | f8940ae | 2007-08-23 11:07:10 +0000 | [diff] [blame] | 1080 | elseif {$n>1 && [string first $z -characteristics]==0} {set dc "-c {$z2}" } \ |
danielk1977 | 59a33f9 | 2007-03-17 10:26:59 +0000 | [diff] [blame] | 1081 | else { error "Unrecognized option: $z" } |
| 1082 | } |
| 1083 | |
| 1084 | if {$crashfile eq ""} { |
| 1085 | error "Compulsory option -file missing" |
| 1086 | } |
| 1087 | |
shaneh | f2c0882 | 2010-07-08 16:30:44 +0000 | [diff] [blame] | 1088 | # $crashfile gets compared to the native filename in |
| 1089 | # cfSync(), which can be different then what TCL uses by |
| 1090 | # default, so here we force it to the "nativename" format. |
mistachkin | f8a7846 | 2012-03-08 20:00:36 +0000 | [diff] [blame] | 1091 | set cfile [string map {\\ \\\\} [file nativename [file join [get_pwd] $crashfile]]] |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 1092 | |
| 1093 | set f [open crash.tcl w] |
danielk1977 | ca0c897 | 2007-09-01 09:02:53 +0000 | [diff] [blame] | 1094 | puts $f "sqlite3_crash_enable 1" |
danielk1977 | f8940ae | 2007-08-23 11:07:10 +0000 | [diff] [blame] | 1095 | puts $f "sqlite3_crashparams $blocksize $dc $crashdelay $cfile" |
drh | c7a3bb9 | 2009-02-05 16:31:45 +0000 | [diff] [blame] | 1096 | puts $f "sqlite3_test_control_pending_byte $::sqlite_pending_byte" |
danielk1977 | 95c8a54 | 2007-09-01 06:51:27 +0000 | [diff] [blame] | 1097 | puts $f "sqlite3 db test.db -vfs crash" |
danielk1977 | 933bbd6 | 2007-03-17 07:22:42 +0000 | [diff] [blame] | 1098 | |
| 1099 | # This block sets the cache size of the main database to 10 |
| 1100 | # pages. This is done in case the build is configured to omit |
| 1101 | # "PRAGMA cache_size". |
| 1102 | puts $f {db eval {SELECT * FROM sqlite_master;}} |
| 1103 | puts $f {set bt [btree_from_db db]} |
| 1104 | puts $f {btree_set_cache_size $bt 10} |
drh | cb1f0f6 | 2008-01-08 15:18:52 +0000 | [diff] [blame] | 1105 | if {$prngseed} { |
| 1106 | set seed [expr {$prngseed%10007+1}] |
| 1107 | # puts seed=$seed |
| 1108 | puts $f "db eval {SELECT randomblob($seed)}" |
| 1109 | } |
danielk1977 | 933bbd6 | 2007-03-17 07:22:42 +0000 | [diff] [blame] | 1110 | |
drh | f858740 | 2008-01-08 16:03:49 +0000 | [diff] [blame] | 1111 | if {[string length $tclbody]>0} { |
| 1112 | puts $f $tclbody |
| 1113 | } |
| 1114 | if {[string length $sql]>0} { |
| 1115 | puts $f "db eval {" |
| 1116 | puts $f "$sql" |
| 1117 | puts $f "}" |
| 1118 | } |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 1119 | close $f |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 1120 | set r [catch { |
drh | 9c06c95 | 2005-11-26 00:25:00 +0000 | [diff] [blame] | 1121 | exec [info nameofexec] crash.tcl >@stdout |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 1122 | } msg] |
shaneh | f2c0882 | 2010-07-08 16:30:44 +0000 | [diff] [blame] | 1123 | |
| 1124 | # Windows/ActiveState TCL returns a slightly different |
| 1125 | # error message. We map that to the expected message |
| 1126 | # so that we don't have to change all of the test |
| 1127 | # cases. |
| 1128 | if {$::tcl_platform(platform)=="windows"} { |
| 1129 | if {$msg=="child killed: unknown signal"} { |
| 1130 | set msg "child process exited abnormally" |
| 1131 | } |
| 1132 | } |
| 1133 | |
danielk1977 | aca790a | 2005-01-13 11:07:52 +0000 | [diff] [blame] | 1134 | lappend r $msg |
| 1135 | } |
| 1136 | |
dan | b88e24f | 2013-02-23 18:58:11 +0000 | [diff] [blame] | 1137 | proc run_ioerr_prep {} { |
| 1138 | set ::sqlite_io_error_pending 0 |
| 1139 | catch {db close} |
| 1140 | catch {db2 close} |
| 1141 | catch {forcedelete test.db} |
| 1142 | catch {forcedelete test.db-journal} |
| 1143 | catch {forcedelete test2.db} |
| 1144 | catch {forcedelete test2.db-journal} |
| 1145 | set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db] |
| 1146 | sqlite3_extended_result_codes $::DB $::ioerropts(-erc) |
| 1147 | if {[info exists ::ioerropts(-tclprep)]} { |
| 1148 | eval $::ioerropts(-tclprep) |
| 1149 | } |
| 1150 | if {[info exists ::ioerropts(-sqlprep)]} { |
| 1151 | execsql $::ioerropts(-sqlprep) |
| 1152 | } |
| 1153 | expr 0 |
| 1154 | } |
| 1155 | |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1156 | # Usage: do_ioerr_test <test number> <options...> |
| 1157 | # |
| 1158 | # This proc is used to implement test cases that check that IO errors |
| 1159 | # are correctly handled. The first argument, <test number>, is an integer |
| 1160 | # used to name the tests executed by this proc. Options are as follows: |
| 1161 | # |
| 1162 | # -tclprep TCL script to run to prepare test. |
| 1163 | # -sqlprep SQL script to run to prepare test. |
| 1164 | # -tclbody TCL script to run with IO error simulation. |
| 1165 | # -sqlbody TCL script to run with IO error simulation. |
| 1166 | # -exclude List of 'N' values not to test. |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 1167 | # -erc Use extended result codes |
drh | d5eb79e | 2007-03-15 12:17:42 +0000 | [diff] [blame] | 1168 | # -persist Make simulated I/O errors persistent |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1169 | # -start Value of 'N' to begin with (default 1) |
| 1170 | # |
| 1171 | # -cksum Boolean. If true, test that the database does |
| 1172 | # not change during the execution of the test case. |
| 1173 | # |
| 1174 | proc do_ioerr_test {testname args} { |
| 1175 | |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1176 | set ::ioerropts(-start) 1 |
| 1177 | set ::ioerropts(-cksum) 0 |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 1178 | set ::ioerropts(-erc) 0 |
drh | c2ee76c | 2007-01-04 14:58:14 +0000 | [diff] [blame] | 1179 | set ::ioerropts(-count) 100000000 |
drh | d5eb79e | 2007-03-15 12:17:42 +0000 | [diff] [blame] | 1180 | set ::ioerropts(-persist) 1 |
danielk1977 | 4abd544 | 2008-05-05 15:26:50 +0000 | [diff] [blame] | 1181 | set ::ioerropts(-ckrefcount) 0 |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 1182 | set ::ioerropts(-restoreprng) 1 |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1183 | array set ::ioerropts $args |
| 1184 | |
danielk1977 | 47cd39c | 2008-05-12 12:41:15 +0000 | [diff] [blame] | 1185 | # TEMPORARY: For 3.5.9, disable testing of extended result codes. There are |
| 1186 | # a couple of obscure IO errors that do not return them. |
| 1187 | set ::ioerropts(-erc) 0 |
dan | b88e24f | 2013-02-23 18:58:11 +0000 | [diff] [blame] | 1188 | |
| 1189 | # Create a single TCL script from the TCL and SQL specified |
| 1190 | # as the body of the test. |
| 1191 | set ::ioerrorbody {} |
| 1192 | if {[info exists ::ioerropts(-tclbody)]} { |
| 1193 | append ::ioerrorbody "$::ioerropts(-tclbody)\n" |
| 1194 | } |
| 1195 | if {[info exists ::ioerropts(-sqlbody)]} { |
| 1196 | append ::ioerrorbody "db eval {$::ioerropts(-sqlbody)}" |
| 1197 | } |
| 1198 | |
| 1199 | save_prng_state |
| 1200 | if {$::ioerropts(-cksum)} { |
| 1201 | run_ioerr_prep |
| 1202 | eval $::ioerrorbody |
| 1203 | set ::goodcksum [cksum] |
| 1204 | } |
danielk1977 | 47cd39c | 2008-05-12 12:41:15 +0000 | [diff] [blame] | 1205 | |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1206 | set ::go 1 |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 1207 | #reset_prng_state |
danielk1977 | ef165ce | 2009-04-06 17:50:03 +0000 | [diff] [blame] | 1208 | for {set n $::ioerropts(-start)} {$::go} {incr n} { |
danielk1977 | 92d4d7a | 2007-05-04 12:05:56 +0000 | [diff] [blame] | 1209 | set ::TN $n |
drh | c2ee76c | 2007-01-04 14:58:14 +0000 | [diff] [blame] | 1210 | incr ::ioerropts(-count) -1 |
| 1211 | if {$::ioerropts(-count)<0} break |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1212 | |
| 1213 | # Skip this IO error if it was specified with the "-exclude" option. |
| 1214 | if {[info exists ::ioerropts(-exclude)]} { |
| 1215 | if {[lsearch $::ioerropts(-exclude) $n]!=-1} continue |
| 1216 | } |
danielk1977 | 861f745 | 2008-06-05 11:39:11 +0000 | [diff] [blame] | 1217 | if {$::ioerropts(-restoreprng)} { |
| 1218 | restore_prng_state |
| 1219 | } |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1220 | |
| 1221 | # Delete the files test.db and test2.db, then execute the TCL and |
| 1222 | # SQL (in that order) to prepare for the test case. |
| 1223 | do_test $testname.$n.1 { |
dan | b88e24f | 2013-02-23 18:58:11 +0000 | [diff] [blame] | 1224 | run_ioerr_prep |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1225 | } {0} |
| 1226 | |
| 1227 | # Read the 'checksum' of the database. |
| 1228 | if {$::ioerropts(-cksum)} { |
dan | b88e24f | 2013-02-23 18:58:11 +0000 | [diff] [blame] | 1229 | set ::checksum [cksum] |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1230 | } |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 1231 | |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1232 | # Set the Nth IO error to fail. |
| 1233 | do_test $testname.$n.2 [subst { |
drh | d5eb79e | 2007-03-15 12:17:42 +0000 | [diff] [blame] | 1234 | set ::sqlite_io_error_persist $::ioerropts(-persist) |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1235 | set ::sqlite_io_error_pending $n |
| 1236 | }] $n |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1237 | |
dan | b88e24f | 2013-02-23 18:58:11 +0000 | [diff] [blame] | 1238 | # Execute the TCL script created for the body of this test. If |
| 1239 | # at least N IO operations performed by SQLite as a result of |
| 1240 | # the script, the Nth will fail. |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1241 | do_test $testname.$n.3 { |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 1242 | set ::sqlite_io_error_hit 0 |
| 1243 | set ::sqlite_io_error_hardhit 0 |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1244 | set r [catch $::ioerrorbody msg] |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 1245 | set ::errseen $r |
drh | e49f982 | 2006-09-15 12:29:16 +0000 | [diff] [blame] | 1246 | set rc [sqlite3_errcode $::DB] |
| 1247 | if {$::ioerropts(-erc)} { |
drh | 5f7b5bf | 2007-04-19 12:30:54 +0000 | [diff] [blame] | 1248 | # If we are in extended result code mode, make sure all of the |
| 1249 | # IOERRs we get back really do have their extended code values. |
| 1250 | # If an extended result code is returned, the sqlite3_errcode |
| 1251 | # TCLcommand will return a string of the form: SQLITE_IOERR+nnnn |
| 1252 | # where nnnn is a number |
drh | e49f982 | 2006-09-15 12:29:16 +0000 | [diff] [blame] | 1253 | if {[regexp {^SQLITE_IOERR} $rc] && ![regexp {IOERR\+\d} $rc]} { |
| 1254 | return $rc |
| 1255 | } |
| 1256 | } else { |
drh | 5f7b5bf | 2007-04-19 12:30:54 +0000 | [diff] [blame] | 1257 | # If we are not in extended result code mode, make sure no |
| 1258 | # extended error codes are returned. |
drh | e49f982 | 2006-09-15 12:29:16 +0000 | [diff] [blame] | 1259 | if {[regexp {\+\d} $rc]} { |
| 1260 | return $rc |
| 1261 | } |
| 1262 | } |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 1263 | # The test repeats as long as $::go is non-zero. $::go starts out |
| 1264 | # as 1. When a test runs to completion without hitting an I/O |
| 1265 | # error, that means there is no point in continuing with this test |
| 1266 | # case so set $::go to zero. |
| 1267 | # |
| 1268 | if {$::sqlite_io_error_pending>0} { |
| 1269 | set ::go 0 |
| 1270 | set q 0 |
| 1271 | set ::sqlite_io_error_pending 0 |
| 1272 | } else { |
| 1273 | set q 1 |
| 1274 | } |
| 1275 | |
drh | c9ac5ca | 2005-11-04 22:03:30 +0000 | [diff] [blame] | 1276 | set s [expr $::sqlite_io_error_hit==0] |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 1277 | if {$::sqlite_io_error_hit>$::sqlite_io_error_hardhit && $r==0} { |
| 1278 | set r 1 |
| 1279 | } |
danielk1977 | f2fa831 | 2006-01-24 13:09:33 +0000 | [diff] [blame] | 1280 | set ::sqlite_io_error_hit 0 |
drh | 5f7b5bf | 2007-04-19 12:30:54 +0000 | [diff] [blame] | 1281 | |
| 1282 | # One of two things must have happened. either |
| 1283 | # 1. We never hit the IO error and the SQL returned OK |
| 1284 | # 2. An IO error was hit and the SQL failed |
| 1285 | # |
dan | d41a29a | 2010-05-06 15:56:28 +0000 | [diff] [blame] | 1286 | #puts "s=$s r=$r q=$q" |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 1287 | expr { ($s && !$r && !$q) || (!$s && $r && $q) } |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1288 | } {1} |
| 1289 | |
danielk1977 | 80daec6 | 2008-05-12 10:57:02 +0000 | [diff] [blame] | 1290 | set ::sqlite_io_error_hit 0 |
| 1291 | set ::sqlite_io_error_pending 0 |
| 1292 | |
danielk1977 | 52b472a | 2008-05-05 16:23:55 +0000 | [diff] [blame] | 1293 | # Check that no page references were leaked. There should be |
| 1294 | # a single reference if there is still an active transaction, |
| 1295 | # or zero otherwise. |
| 1296 | # |
danielk1977 | 8162054 | 2008-06-07 05:19:37 +0000 | [diff] [blame] | 1297 | # UPDATE: If the IO error occurs after a 'BEGIN' but before any |
| 1298 | # locks are established on database files (i.e. if the error |
| 1299 | # occurs while attempting to detect a hot-journal file), then |
| 1300 | # there may 0 page references and an active transaction according |
| 1301 | # to [sqlite3_get_autocommit]. |
| 1302 | # |
danielk1977 | 4abd544 | 2008-05-05 15:26:50 +0000 | [diff] [blame] | 1303 | if {$::go && $::sqlite_io_error_hardhit && $::ioerropts(-ckrefcount)} { |
danielk1977 | 4abd544 | 2008-05-05 15:26:50 +0000 | [diff] [blame] | 1304 | do_test $testname.$n.4 { |
| 1305 | set bt [btree_from_db db] |
| 1306 | db_enter db |
| 1307 | array set stats [btree_pager_stats $bt] |
| 1308 | db_leave db |
danielk1977 | 8162054 | 2008-06-07 05:19:37 +0000 | [diff] [blame] | 1309 | set nRef $stats(ref) |
| 1310 | expr {$nRef == 0 || ([sqlite3_get_autocommit db]==0 && $nRef == 1)} |
| 1311 | } {1} |
danielk1977 | 4abd544 | 2008-05-05 15:26:50 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
danielk1977 | 52b472a | 2008-05-05 16:23:55 +0000 | [diff] [blame] | 1314 | # If there is an open database handle and no open transaction, |
| 1315 | # and the pager is not running in exclusive-locking mode, |
| 1316 | # check that the pager is in "unlocked" state. Theoretically, |
| 1317 | # if a call to xUnlock() failed due to an IO error the underlying |
| 1318 | # file may still be locked. |
| 1319 | # |
| 1320 | ifcapable pragma { |
| 1321 | if { [info commands db] ne "" |
danielk1977 | 0259fbe | 2008-05-05 17:14:53 +0000 | [diff] [blame] | 1322 | && $::ioerropts(-ckrefcount) |
danielk1977 | 52b472a | 2008-05-05 16:23:55 +0000 | [diff] [blame] | 1323 | && [db one {pragma locking_mode}] eq "normal" |
| 1324 | && [sqlite3_get_autocommit db] |
| 1325 | } { |
| 1326 | do_test $testname.$n.5 { |
| 1327 | set bt [btree_from_db db] |
| 1328 | db_enter db |
| 1329 | array set stats [btree_pager_stats $bt] |
| 1330 | db_leave db |
| 1331 | set stats(state) |
| 1332 | } 0 |
| 1333 | } |
| 1334 | } |
| 1335 | |
mistachkin | 48864df | 2013-03-21 21:20:32 +0000 | [diff] [blame] | 1336 | # If an IO error occurred, then the checksum of the database should |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1337 | # be the same as before the script that caused the IO error was run. |
danielk1977 | 52b472a | 2008-05-05 16:23:55 +0000 | [diff] [blame] | 1338 | # |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 1339 | if {$::go && $::sqlite_io_error_hardhit && $::ioerropts(-cksum)} { |
danielk1977 | 0259fbe | 2008-05-05 17:14:53 +0000 | [diff] [blame] | 1340 | do_test $testname.$n.6 { |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1341 | catch {db close} |
danielk1977 | a961339 | 2008-07-08 12:07:32 +0000 | [diff] [blame] | 1342 | catch {db2 close} |
drh | a34c62d | 2006-01-06 22:11:20 +0000 | [diff] [blame] | 1343 | set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db] |
dan | b88e24f | 2013-02-23 18:58:11 +0000 | [diff] [blame] | 1344 | set nowcksum [cksum] |
| 1345 | set res [expr {$nowcksum==$::checksum || $nowcksum==$::goodcksum}] |
| 1346 | if {$res==0} { |
| 1347 | puts "now=$nowcksum" |
| 1348 | puts "the=$::checksum" |
| 1349 | puts "fwd=$::goodcksum" |
| 1350 | } |
| 1351 | set res |
| 1352 | } 1 |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
drh | 1aa5af1 | 2008-03-07 19:51:14 +0000 | [diff] [blame] | 1355 | set ::sqlite_io_error_hardhit 0 |
danielk1977 | c4da5b9 | 2006-01-21 12:08:54 +0000 | [diff] [blame] | 1356 | set ::sqlite_io_error_pending 0 |
danielk1977 | 105afed | 2005-05-26 15:20:53 +0000 | [diff] [blame] | 1357 | if {[info exists ::ioerropts(-cleanup)]} { |
| 1358 | catch $::ioerropts(-cleanup) |
| 1359 | } |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1360 | } |
| 1361 | set ::sqlite_io_error_pending 0 |
drh | 6d54da0 | 2007-03-25 19:08:46 +0000 | [diff] [blame] | 1362 | set ::sqlite_io_error_persist 0 |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1363 | unset ::ioerropts |
| 1364 | } |
| 1365 | |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 1366 | # Return a checksum based on the contents of the main database associated |
| 1367 | # with connection $db |
danielk1977 | 32554c1 | 2005-01-22 03:39:39 +0000 | [diff] [blame] | 1368 | # |
| 1369 | proc cksum {{db db}} { |
| 1370 | set txt [$db eval { |
| 1371 | SELECT name, type, sql FROM sqlite_master order by name |
| 1372 | }]\n |
| 1373 | foreach tbl [$db eval { |
| 1374 | SELECT name FROM sqlite_master WHERE type='table' order by name |
| 1375 | }] { |
| 1376 | append txt [$db eval "SELECT * FROM $tbl"]\n |
| 1377 | } |
| 1378 | foreach prag {default_synchronous default_cache_size} { |
| 1379 | append txt $prag-[$db eval "PRAGMA $prag"]\n |
| 1380 | } |
| 1381 | set cksum [string length $txt]-[md5 $txt] |
| 1382 | # puts $cksum-[file size test.db] |
| 1383 | return $cksum |
| 1384 | } |
| 1385 | |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 1386 | # Generate a checksum based on the contents of the main and temp tables |
| 1387 | # database $db. If the checksum of two databases is the same, and the |
| 1388 | # integrity-check passes for both, the two databases are identical. |
| 1389 | # |
drh | 1db639c | 2008-01-17 02:36:28 +0000 | [diff] [blame] | 1390 | proc allcksum {{db db}} { |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 1391 | set ret [list] |
| 1392 | ifcapable tempdb { |
| 1393 | set sql { |
| 1394 | SELECT name FROM sqlite_master WHERE type = 'table' UNION |
| 1395 | SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION |
| 1396 | SELECT 'sqlite_master' UNION |
| 1397 | SELECT 'sqlite_temp_master' ORDER BY 1 |
| 1398 | } |
| 1399 | } else { |
| 1400 | set sql { |
| 1401 | SELECT name FROM sqlite_master WHERE type = 'table' UNION |
| 1402 | SELECT 'sqlite_master' ORDER BY 1 |
| 1403 | } |
| 1404 | } |
| 1405 | set tbllist [$db eval $sql] |
| 1406 | set txt {} |
| 1407 | foreach tbl $tbllist { |
| 1408 | append txt [$db eval "SELECT * FROM $tbl"] |
| 1409 | } |
| 1410 | foreach prag {default_cache_size} { |
| 1411 | append txt $prag-[$db eval "PRAGMA $prag"]\n |
| 1412 | } |
| 1413 | # puts txt=$txt |
| 1414 | return [md5 $txt] |
| 1415 | } |
| 1416 | |
drh | dc2c491 | 2009-02-04 22:46:47 +0000 | [diff] [blame] | 1417 | # Generate a checksum based on the contents of a single database with |
| 1418 | # a database connection. The name of the database is $dbname. |
| 1419 | # Examples of $dbname are "temp" or "main". |
| 1420 | # |
| 1421 | proc dbcksum {db dbname} { |
| 1422 | if {$dbname=="temp"} { |
| 1423 | set master sqlite_temp_master |
| 1424 | } else { |
| 1425 | set master $dbname.sqlite_master |
| 1426 | } |
| 1427 | set alltab [$db eval "SELECT name FROM $master WHERE type='table'"] |
| 1428 | set txt [$db eval "SELECT * FROM $master"]\n |
| 1429 | foreach tab $alltab { |
| 1430 | append txt [$db eval "SELECT * FROM $dbname.$tab"]\n |
| 1431 | } |
| 1432 | return [md5 $txt] |
| 1433 | } |
| 1434 | |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 1435 | proc memdebug_log_sql {{filename mallocs.sql}} { |
| 1436 | |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1437 | set data [sqlite3_memdebug_log dump] |
| 1438 | set nFrame [expr [llength [lindex $data 0]]-2] |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1439 | if {$nFrame < 0} { return "" } |
| 1440 | |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 1441 | set database temp |
| 1442 | |
danielk1977 | 6ab3a2e | 2009-02-19 14:39:25 +0000 | [diff] [blame] | 1443 | set tbl "CREATE TABLE ${database}.malloc(zTest, nCall, nByte, lStack);" |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1444 | |
| 1445 | set sql "" |
| 1446 | foreach e $data { |
danielk1977 | 6ab3a2e | 2009-02-19 14:39:25 +0000 | [diff] [blame] | 1447 | set nCall [lindex $e 0] |
| 1448 | set nByte [lindex $e 1] |
| 1449 | set lStack [lrange $e 2 end] |
| 1450 | append sql "INSERT INTO ${database}.malloc VALUES" |
| 1451 | append sql "('test', $nCall, $nByte, '$lStack');\n" |
| 1452 | foreach f $lStack { |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1453 | set frames($f) 1 |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | set tbl2 "CREATE TABLE ${database}.frame(frame INTEGER PRIMARY KEY, line);\n" |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 1458 | set tbl3 "CREATE TABLE ${database}.file(name PRIMARY KEY, content);\n" |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1459 | |
| 1460 | foreach f [array names frames] { |
| 1461 | set addr [format %x $f] |
| 1462 | set cmd "addr2line -e [info nameofexec] $addr" |
| 1463 | set line [eval exec $cmd] |
| 1464 | append sql "INSERT INTO ${database}.frame VALUES($f, '$line');\n" |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 1465 | |
| 1466 | set file [lindex [split $line :] 0] |
| 1467 | set files($file) 1 |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 1470 | foreach f [array names files] { |
| 1471 | set contents "" |
| 1472 | catch { |
| 1473 | set fd [open $f] |
| 1474 | set contents [read $fd] |
| 1475 | close $fd |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1476 | } |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 1477 | set contents [string map {' ''} $contents] |
| 1478 | append sql "INSERT INTO ${database}.file VALUES('$f', '$contents');\n" |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1479 | } |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1480 | |
danielk1977 | 35754ac | 2008-03-21 17:29:37 +0000 | [diff] [blame] | 1481 | set fd [open $filename w] |
| 1482 | puts $fd "BEGIN; ${tbl}${tbl2}${tbl3}${sql} ; COMMIT;" |
| 1483 | close $fd |
danielk1977 | 6f332c1 | 2008-03-21 14:22:44 +0000 | [diff] [blame] | 1484 | } |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 1485 | |
dan | f589450 | 2009-10-07 18:41:19 +0000 | [diff] [blame] | 1486 | # Drop all tables in database [db] |
| 1487 | proc drop_all_tables {{db db}} { |
shaneh | 4e7b32f | 2009-12-17 22:12:51 +0000 | [diff] [blame] | 1488 | ifcapable trigger&&foreignkey { |
| 1489 | set pk [$db one "PRAGMA foreign_keys"] |
| 1490 | $db eval "PRAGMA foreign_keys = OFF" |
| 1491 | } |
drh | 9a6ffc8 | 2010-02-15 18:03:20 +0000 | [diff] [blame] | 1492 | foreach {idx name file} [db eval {PRAGMA database_list}] { |
| 1493 | if {$idx==1} { |
| 1494 | set master sqlite_temp_master |
| 1495 | } else { |
| 1496 | set master $name.sqlite_master |
| 1497 | } |
| 1498 | foreach {t type} [$db eval " |
| 1499 | SELECT name, type FROM $master |
dan | a16d106 | 2010-09-28 17:37:28 +0000 | [diff] [blame] | 1500 | WHERE type IN('table', 'view') AND name NOT LIKE 'sqliteX_%' ESCAPE 'X' |
drh | 9a6ffc8 | 2010-02-15 18:03:20 +0000 | [diff] [blame] | 1501 | "] { |
dan | a16d106 | 2010-09-28 17:37:28 +0000 | [diff] [blame] | 1502 | $db eval "DROP $type \"$t\"" |
drh | 9a6ffc8 | 2010-02-15 18:03:20 +0000 | [diff] [blame] | 1503 | } |
dan | f589450 | 2009-10-07 18:41:19 +0000 | [diff] [blame] | 1504 | } |
shaneh | 4e7b32f | 2009-12-17 22:12:51 +0000 | [diff] [blame] | 1505 | ifcapable trigger&&foreignkey { |
| 1506 | $db eval "PRAGMA foreign_keys = $pk" |
| 1507 | } |
dan | f589450 | 2009-10-07 18:41:19 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
dan | 71cb518 | 2010-04-26 12:39:03 +0000 | [diff] [blame] | 1510 | #------------------------------------------------------------------------- |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1511 | # If a test script is executed with global variable $::G(perm:name) set to |
| 1512 | # "wal", then the tests are run in WAL mode. Otherwise, they should be run |
| 1513 | # in rollback mode. The following Tcl procs are used to make this less |
| 1514 | # intrusive: |
dan | 71cb518 | 2010-04-26 12:39:03 +0000 | [diff] [blame] | 1515 | # |
| 1516 | # wal_set_journal_mode ?DB? |
| 1517 | # |
| 1518 | # If running a WAL test, execute "PRAGMA journal_mode = wal" using |
| 1519 | # connection handle DB. Otherwise, this command is a no-op. |
| 1520 | # |
| 1521 | # wal_check_journal_mode TESTNAME ?DB? |
| 1522 | # |
| 1523 | # If running a WAL test, execute a tests case that fails if the main |
| 1524 | # database for connection handle DB is not currently a WAL database. |
| 1525 | # Otherwise (if not running a WAL permutation) this is a no-op. |
| 1526 | # |
| 1527 | # wal_is_wal_mode |
| 1528 | # |
| 1529 | # Returns true if this test should be run in WAL mode. False otherwise. |
| 1530 | # |
| 1531 | proc wal_is_wal_mode {} { |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1532 | expr {[permutation] eq "wal"} |
dan | 71cb518 | 2010-04-26 12:39:03 +0000 | [diff] [blame] | 1533 | } |
| 1534 | proc wal_set_journal_mode {{db db}} { |
| 1535 | if { [wal_is_wal_mode] } { |
| 1536 | $db eval "PRAGMA journal_mode = WAL" |
| 1537 | } |
| 1538 | } |
| 1539 | proc wal_check_journal_mode {testname {db db}} { |
| 1540 | if { [wal_is_wal_mode] } { |
| 1541 | $db eval { SELECT * FROM sqlite_master } |
| 1542 | do_test $testname [list $db eval "PRAGMA main.journal_mode"] {wal} |
| 1543 | } |
| 1544 | } |
| 1545 | |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1546 | proc permutation {} { |
| 1547 | set perm "" |
| 1548 | catch {set perm $::G(perm:name)} |
| 1549 | set perm |
| 1550 | } |
dan | cb79e51 | 2010-08-06 13:50:07 +0000 | [diff] [blame] | 1551 | proc presql {} { |
| 1552 | set presql "" |
| 1553 | catch {set presql $::G(perm:presql)} |
| 1554 | set presql |
| 1555 | } |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1556 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 1557 | #------------------------------------------------------------------------- |
| 1558 | # |
| 1559 | proc slave_test_script {script} { |
| 1560 | |
| 1561 | # Create the interpreter used to run the test script. |
| 1562 | interp create tinterp |
| 1563 | |
| 1564 | # Populate some global variables that tester.tcl expects to see. |
| 1565 | foreach {var value} [list \ |
| 1566 | ::argv0 $::argv0 \ |
| 1567 | ::argv {} \ |
| 1568 | ::SLAVE 1 \ |
| 1569 | ] { |
| 1570 | interp eval tinterp [list set $var $value] |
| 1571 | } |
| 1572 | |
| 1573 | # The alias used to access the global test counters. |
| 1574 | tinterp alias set_test_counter set_test_counter |
| 1575 | |
| 1576 | # Set up the ::cmdlinearg array in the slave. |
| 1577 | interp eval tinterp [list array set ::cmdlinearg [array get ::cmdlinearg]] |
| 1578 | |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1579 | # Set up the ::G array in the slave. |
| 1580 | interp eval tinterp [list array set ::G [array get ::G]] |
| 1581 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 1582 | # Load the various test interfaces implemented in C. |
| 1583 | load_testfixture_extensions tinterp |
| 1584 | |
| 1585 | # Run the test script. |
| 1586 | interp eval tinterp $script |
| 1587 | |
dan | ea5542d | 2010-07-06 11:26:15 +0000 | [diff] [blame] | 1588 | # Check if the interpreter call [run_thread_tests] |
| 1589 | if { [interp eval tinterp {info exists ::run_thread_tests_called}] } { |
| 1590 | set ::run_thread_tests_called 1 |
| 1591 | } |
| 1592 | |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 1593 | # Delete the interpreter used to run the test script. |
| 1594 | interp delete tinterp |
| 1595 | } |
| 1596 | |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1597 | proc slave_test_file {zFile} { |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 1598 | set tail [file tail $zFile] |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1599 | |
dan | 6a64d67 | 2011-04-04 15:38:16 +0000 | [diff] [blame] | 1600 | if {[info exists ::G(start:permutation)]} { |
| 1601 | if {[permutation] != $::G(start:permutation)} return |
| 1602 | unset ::G(start:permutation) |
| 1603 | } |
| 1604 | if {[info exists ::G(start:file)]} { |
| 1605 | if {$tail != $::G(start:file) && $tail!="$::G(start:file).test"} return |
| 1606 | unset ::G(start:file) |
| 1607 | } |
| 1608 | |
dan | 92d516a | 2010-07-05 14:54:48 +0000 | [diff] [blame] | 1609 | # Remember the value of the shared-cache setting. So that it is possible |
| 1610 | # to check afterwards that it was not modified by the test script. |
| 1611 | # |
| 1612 | ifcapable shared_cache { set scs [sqlite3_enable_shared_cache] } |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 1613 | |
dan | 92d516a | 2010-07-05 14:54:48 +0000 | [diff] [blame] | 1614 | # Run the test script in a slave interpreter. |
| 1615 | # |
dan | ea5542d | 2010-07-06 11:26:15 +0000 | [diff] [blame] | 1616 | unset -nocomplain ::run_thread_tests_called |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 1617 | reset_prng_state |
| 1618 | set ::sqlite_open_file_count 0 |
| 1619 | set time [time { slave_test_script [list source $zFile] }] |
| 1620 | set ms [expr [lindex $time 0] / 1000] |
| 1621 | |
dan | 92d516a | 2010-07-05 14:54:48 +0000 | [diff] [blame] | 1622 | # Test that all files opened by the test script were closed. Omit this |
| 1623 | # if the test script has "thread" in its name. The open file counter |
| 1624 | # is not thread-safe. |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 1625 | # |
dan | ea5542d | 2010-07-06 11:26:15 +0000 | [diff] [blame] | 1626 | if {[info exists ::run_thread_tests_called]==0} { |
dan | 92d516a | 2010-07-05 14:54:48 +0000 | [diff] [blame] | 1627 | do_test ${tail}-closeallfiles { expr {$::sqlite_open_file_count>0} } {0} |
| 1628 | } |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1629 | set ::sqlite_open_file_count 0 |
| 1630 | |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 1631 | # Test that the global "shared-cache" setting was not altered by |
| 1632 | # the test script. |
| 1633 | # |
| 1634 | ifcapable shared_cache { |
| 1635 | set res [expr {[sqlite3_enable_shared_cache] == $scs}] |
| 1636 | do_test ${tail}-sharedcachesetting [list set {} $res] 1 |
| 1637 | } |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1638 | |
dan | 92d516a | 2010-07-05 14:54:48 +0000 | [diff] [blame] | 1639 | # Add some info to the output. |
| 1640 | # |
dan | 0626dfc | 2010-06-15 06:56:37 +0000 | [diff] [blame] | 1641 | puts "Time: $tail $ms ms" |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 1642 | show_memstats |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
dan | 59257dc | 2010-08-04 11:34:31 +0000 | [diff] [blame] | 1645 | # Open a new connection on database test.db and execute the SQL script |
| 1646 | # supplied as an argument. Before returning, close the new conection and |
| 1647 | # restore the 4 byte fields starting at header offsets 28, 92 and 96 |
| 1648 | # to the values they held before the SQL was executed. This simulates |
| 1649 | # a write by a pre-3.7.0 client. |
| 1650 | # |
| 1651 | proc sql36231 {sql} { |
| 1652 | set B [hexio_read test.db 92 8] |
| 1653 | set A [hexio_read test.db 28 4] |
| 1654 | sqlite3 db36231 test.db |
| 1655 | catch { db36231 func a_string a_string } |
| 1656 | execsql $sql db36231 |
| 1657 | db36231 close |
| 1658 | hexio_write test.db 28 $A |
| 1659 | hexio_write test.db 92 $B |
| 1660 | return "" |
| 1661 | } |
dan | f589450 | 2009-10-07 18:41:19 +0000 | [diff] [blame] | 1662 | |
dan | ccc7ff4 | 2010-11-29 12:06:45 +0000 | [diff] [blame] | 1663 | proc db_save {} { |
| 1664 | foreach f [glob -nocomplain sv_test.db*] { forcedelete $f } |
| 1665 | foreach f [glob -nocomplain test.db*] { |
| 1666 | set f2 "sv_$f" |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 1667 | forcecopy $f $f2 |
dan | ccc7ff4 | 2010-11-29 12:06:45 +0000 | [diff] [blame] | 1668 | } |
| 1669 | } |
| 1670 | proc db_save_and_close {} { |
| 1671 | db_save |
| 1672 | catch { db close } |
| 1673 | return "" |
| 1674 | } |
| 1675 | proc db_restore {} { |
| 1676 | foreach f [glob -nocomplain test.db*] { forcedelete $f } |
| 1677 | foreach f2 [glob -nocomplain sv_test.db*] { |
| 1678 | set f [string range $f2 3 end] |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 1679 | forcecopy $f2 $f |
dan | ccc7ff4 | 2010-11-29 12:06:45 +0000 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | proc db_restore_and_reopen {{dbfile test.db}} { |
| 1683 | catch { db close } |
| 1684 | db_restore |
| 1685 | sqlite3 db $dbfile |
| 1686 | } |
| 1687 | proc db_delete_and_reopen {{file test.db}} { |
| 1688 | catch { db close } |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 1689 | foreach f [glob -nocomplain test.db*] { forcedelete $f } |
dan | ccc7ff4 | 2010-11-29 12:06:45 +0000 | [diff] [blame] | 1690 | sqlite3 db $file |
| 1691 | } |
| 1692 | |
danielk1977 | 45901d6 | 2004-11-10 15:27:38 +0000 | [diff] [blame] | 1693 | # If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set |
| 1694 | # to non-zero, then set the global variable $AUTOVACUUM to 1. |
| 1695 | set AUTOVACUUM $sqlite_options(default_autovacuum) |
danielk1977 | ee8b799 | 2009-03-26 17:13:06 +0000 | [diff] [blame] | 1696 | |
dan | 64b95bb | 2012-05-12 05:30:29 +0000 | [diff] [blame] | 1697 | # Make sure the FTS enhanced query syntax is disabled. |
| 1698 | set sqlite_fts3_enable_parentheses 0 |
| 1699 | |
danielk1977 | ee8b799 | 2009-03-26 17:13:06 +0000 | [diff] [blame] | 1700 | source $testdir/thread_common.tcl |
dan | ddf80eb | 2010-10-25 12:47:43 +0000 | [diff] [blame] | 1701 | source $testdir/malloc_common.tcl |