2001-09-16 04:13:26 +04:00
|
|
|
# 2001 September 15
|
2000-05-30 00:41:49 +04:00
|
|
|
#
|
2001-09-16 04:13:26 +04:00
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
2000-05-30 00:41:49 +04:00
|
|
|
#
|
2001-09-16 04:13:26 +04:00
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
2000-05-30 00:41:49 +04:00
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements some common TCL routines used for regression
|
|
|
|
# testing the SQLite library
|
|
|
|
#
|
2009-04-09 05:23:49 +04:00
|
|
|
# $Id: tester.tcl,v 1.143 2009/04/09 01:23:49 drh Exp $
|
2001-04-06 20:13:42 +04:00
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
#-------------------------------------------------------------------------
|
2013-08-29 05:09:14 +04:00
|
|
|
# The commands provided by the code in this file to help with creating
|
2010-06-07 18:28:16 +04:00
|
|
|
# test cases are as follows:
|
2008-03-29 14:00:54 +03:00
|
|
|
#
|
2010-06-07 18:28:16 +04:00
|
|
|
# Commands to manipulate the db and the file-system at a high level:
|
|
|
|
#
|
2012-03-06 02:52:33 +04:00
|
|
|
# is_relative_file
|
2012-03-06 07:00:49 +04:00
|
|
|
# test_pwd
|
2012-03-09 00:00:36 +04:00
|
|
|
# get_pwd
|
2010-06-07 18:28:16 +04:00
|
|
|
# copy_file FROM TO
|
2011-08-02 04:57:34 +04:00
|
|
|
# delete_file FILENAME
|
2011-04-16 23:23:10 +04:00
|
|
|
# drop_all_tables ?DB?
|
2016-08-02 20:07:51 +03:00
|
|
|
# drop_all_indexes ?DB?
|
2011-08-02 04:57:34 +04:00
|
|
|
# forcecopy FROM TO
|
2010-06-07 18:28:16 +04:00
|
|
|
# forcedelete FILENAME
|
|
|
|
#
|
|
|
|
# Test the capability of the SQLite version built into the interpreter to
|
|
|
|
# determine if a specific test can be run:
|
|
|
|
#
|
2012-09-13 05:51:02 +04:00
|
|
|
# capable EXPR
|
2010-06-07 18:28:16 +04:00
|
|
|
# ifcapable EXPR
|
|
|
|
#
|
|
|
|
# Calulate checksums based on database contents:
|
|
|
|
#
|
|
|
|
# dbcksum DB DBNAME
|
|
|
|
# allcksum ?DB?
|
|
|
|
# cksum ?DB?
|
|
|
|
#
|
|
|
|
# Commands to execute/explain SQL statements:
|
|
|
|
#
|
2013-08-29 05:09:14 +04:00
|
|
|
# memdbsql SQL
|
2010-06-07 18:28:16 +04:00
|
|
|
# stepsql DB SQL
|
|
|
|
# execsql2 SQL
|
|
|
|
# explain_no_trace SQL
|
|
|
|
# explain SQL ?DB?
|
|
|
|
# catchsql SQL ?DB?
|
|
|
|
# execsql SQL ?DB?
|
|
|
|
#
|
|
|
|
# Commands to run test cases:
|
|
|
|
#
|
|
|
|
# do_ioerr_test TESTNAME ARGS...
|
|
|
|
# crashsql ARGS...
|
|
|
|
# integrity_check TESTNAME ?DB?
|
2013-02-09 19:37:11 +04:00
|
|
|
# verify_ex_errcode TESTNAME EXPECTED ?DB?
|
2010-06-07 18:28:16 +04:00
|
|
|
# do_test TESTNAME SCRIPT EXPECTED
|
2010-06-21 11:45:47 +04:00
|
|
|
# do_execsql_test TESTNAME SQL EXPECTED
|
|
|
|
# do_catchsql_test TESTNAME SQL EXPECTED
|
2014-01-24 18:37:44 +04:00
|
|
|
# do_timed_execsql_test TESTNAME SQL EXPECTED
|
2010-06-07 18:28:16 +04:00
|
|
|
#
|
2010-06-07 21:47:26 +04:00
|
|
|
# Commands providing a lower level interface to the global test counters:
|
2010-06-07 18:28:16 +04:00
|
|
|
#
|
|
|
|
# set_test_counter COUNTER ?VALUE?
|
2011-11-12 07:17:40 +04:00
|
|
|
# omit_test TESTNAME REASON ?APPEND?
|
2010-06-07 18:28:16 +04:00
|
|
|
# fail_test TESTNAME
|
|
|
|
# incr_ntest
|
|
|
|
#
|
|
|
|
# Command run at the end of each test file:
|
|
|
|
#
|
|
|
|
# finish_test
|
|
|
|
#
|
2010-06-07 21:47:26 +04:00
|
|
|
# Commands to help create test files that run with the "WAL" and other
|
|
|
|
# permutations (see file permutations.test):
|
2010-06-07 18:28:16 +04:00
|
|
|
#
|
|
|
|
# wal_is_wal_mode
|
|
|
|
# wal_set_journal_mode ?DB?
|
|
|
|
# wal_check_journal_mode TESTNAME?DB?
|
2010-06-07 21:47:26 +04:00
|
|
|
# permutation
|
2010-08-06 17:50:07 +04:00
|
|
|
# presql
|
2008-03-29 14:00:54 +03:00
|
|
|
#
|
2015-06-09 18:58:28 +03:00
|
|
|
# Command to test whether or not --verbose=1 was specified on the command
|
|
|
|
# line (returns 0 for not-verbose, 1 for verbose and 2 for "verbose in the
|
|
|
|
# output file only").
|
|
|
|
#
|
|
|
|
# verbose
|
|
|
|
#
|
2000-05-30 00:41:49 +04:00
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# Set the precision of FP arithmatic used by the interpreter. And
|
2010-06-07 18:28:16 +04:00
|
|
|
# configure SQLite to take database file locks on the page that begins
|
|
|
|
# 64KB into the database file instead of the one 1GB in. This means
|
|
|
|
# the code that handles that special case can be tested without creating
|
|
|
|
# very large database files.
|
|
|
|
#
|
2004-08-20 22:34:20 +04:00
|
|
|
set tcl_precision 15
|
2009-02-05 19:31:45 +03:00
|
|
|
sqlite3_test_control_pending_byte 0x0010000
|
2004-08-20 22:34:20 +04:00
|
|
|
|
2007-08-10 20:41:08 +04:00
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# If the pager codec is available, create a wrapper for the [sqlite3]
|
2010-06-07 18:28:16 +04:00
|
|
|
# command that appends "-key {xyzzy}" to the command line. i.e. this:
|
2007-08-23 06:47:53 +04:00
|
|
|
#
|
2010-06-07 18:28:16 +04:00
|
|
|
# sqlite3 db test.db
|
2007-08-23 06:47:53 +04:00
|
|
|
#
|
2010-06-07 18:28:16 +04:00
|
|
|
# becomes
|
2008-01-07 22:20:24 +03:00
|
|
|
#
|
2010-06-07 18:28:16 +04:00
|
|
|
# sqlite3 db test.db -key {xyzzy}
|
2004-02-11 05:18:05 +03:00
|
|
|
#
|
2010-06-07 21:47:26 +04:00
|
|
|
if {[info command sqlite_orig]==""} {
|
2004-06-19 04:16:31 +04:00
|
|
|
rename sqlite3 sqlite_orig
|
|
|
|
proc sqlite3 {args} {
|
2010-06-22 17:46:43 +04:00
|
|
|
if {[llength $args]>=2 && [string index [lindex $args 0] 0]!="-"} {
|
2010-06-07 21:47:26 +04:00
|
|
|
# This command is opening a new database connection.
|
|
|
|
#
|
|
|
|
if {[info exists ::G(perm:sqlite3_args)]} {
|
|
|
|
set args [concat $args $::G(perm:sqlite3_args)]
|
|
|
|
}
|
2010-06-22 17:46:43 +04:00
|
|
|
if {[sqlite_orig -has-codec] && ![info exists ::do_not_use_codec]} {
|
2010-06-07 21:47:26 +04:00
|
|
|
lappend args -key {xyzzy}
|
|
|
|
}
|
|
|
|
|
2010-06-09 23:01:02 +04:00
|
|
|
set res [uplevel 1 sqlite_orig $args]
|
2010-06-07 21:47:26 +04:00
|
|
|
if {[info exists ::G(perm:presql)]} {
|
|
|
|
[lindex $args 0] eval $::G(perm:presql)
|
|
|
|
}
|
2010-12-07 17:32:28 +03:00
|
|
|
if {[info exists ::G(perm:dbconfig)]} {
|
|
|
|
set ::dbhandle [lindex $args 0]
|
|
|
|
uplevel #0 $::G(perm:dbconfig)
|
|
|
|
}
|
2020-07-16 17:52:24 +03:00
|
|
|
[lindex $args 0] cache size 3
|
2010-06-09 23:01:02 +04:00
|
|
|
set res
|
2010-06-07 21:47:26 +04:00
|
|
|
} else {
|
2013-08-29 05:09:14 +04:00
|
|
|
# This command is not opening a new database connection. Pass the
|
2013-03-22 01:20:32 +04:00
|
|
|
# arguments through to the C implementation as the are.
|
2010-06-07 21:47:26 +04:00
|
|
|
#
|
|
|
|
uplevel 1 sqlite_orig $args
|
2004-02-11 05:18:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-02 04:57:34 +04:00
|
|
|
proc getFileRetries {} {
|
|
|
|
if {![info exists ::G(file-retries)]} {
|
|
|
|
#
|
|
|
|
# NOTE: Return the default number of retries for [file] operations. A
|
|
|
|
# value of zero or less here means "disabled".
|
|
|
|
#
|
2012-09-13 05:51:02 +04:00
|
|
|
return [expr {$::tcl_platform(platform) eq "windows" ? 50 : 0}]
|
2011-08-02 04:57:34 +04:00
|
|
|
}
|
|
|
|
return $::G(file-retries)
|
|
|
|
}
|
|
|
|
|
|
|
|
proc getFileRetryDelay {} {
|
|
|
|
if {![info exists ::G(file-retry-delay)]} {
|
|
|
|
#
|
|
|
|
# NOTE: Return the default number of milliseconds to wait when retrying
|
|
|
|
# failed [file] operations. A value of zero or less means "do not
|
|
|
|
# wait".
|
|
|
|
#
|
|
|
|
return 100; # TODO: Good default?
|
|
|
|
}
|
|
|
|
return $::G(file-retry-delay)
|
|
|
|
}
|
|
|
|
|
2012-03-09 00:00:36 +04:00
|
|
|
# Return the string representing the name of the current directory. On
|
|
|
|
# Windows, the result is "normalized" to whatever our parent command shell
|
|
|
|
# is using to prevent case-mismatch issues.
|
|
|
|
#
|
|
|
|
proc get_pwd {} {
|
|
|
|
if {$::tcl_platform(platform) eq "windows"} {
|
2012-03-09 00:28:31 +04:00
|
|
|
#
|
|
|
|
# NOTE: Cannot use [file normalize] here because it would alter the
|
|
|
|
# case of the result to what Tcl considers canonical, which would
|
|
|
|
# defeat the purpose of this procedure.
|
|
|
|
#
|
2021-01-18 22:27:56 +03:00
|
|
|
if {[info exists ::env(ComSpec)]} {
|
|
|
|
set comSpec $::env(ComSpec)
|
|
|
|
} else {
|
|
|
|
# NOTE: Hard-code the typical default value.
|
|
|
|
set comSpec {C:\Windows\system32\cmd.exe}
|
|
|
|
}
|
2012-03-09 00:28:31 +04:00
|
|
|
return [string map [list \\ /] \
|
2021-01-18 22:27:56 +03:00
|
|
|
[string trim [exec -- $comSpec /c echo %CD%]]]
|
2012-03-09 00:00:36 +04:00
|
|
|
} else {
|
|
|
|
return [pwd]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-02 04:57:34 +04:00
|
|
|
# Copy file $from into $to. This is used because some versions of
|
|
|
|
# TCL for windows (notably the 8.4.1 binary package shipped with the
|
|
|
|
# current mingw release) have a broken "file copy" command.
|
|
|
|
#
|
|
|
|
proc copy_file {from to} {
|
|
|
|
do_copy_file false $from $to
|
|
|
|
}
|
|
|
|
|
|
|
|
proc forcecopy {from to} {
|
|
|
|
do_copy_file true $from $to
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_copy_file {force from to} {
|
|
|
|
set nRetry [getFileRetries] ;# Maximum number of retries.
|
|
|
|
set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
|
|
|
|
|
|
|
|
# On windows, sometimes even a [file copy -force] can fail. The cause is
|
|
|
|
# usually "tag-alongs" - programs like anti-virus software, automatic backup
|
|
|
|
# tools and various explorer extensions that keep a file open a little longer
|
|
|
|
# than we expect, causing the delete to fail.
|
|
|
|
#
|
|
|
|
# The solution is to wait a short amount of time before retrying the copy.
|
|
|
|
#
|
|
|
|
if {$nRetry > 0} {
|
|
|
|
for {set i 0} {$i<$nRetry} {incr i} {
|
|
|
|
set rc [catch {
|
|
|
|
if {$force} {
|
|
|
|
file copy -force $from $to
|
|
|
|
} else {
|
|
|
|
file copy $from $to
|
|
|
|
}
|
|
|
|
} msg]
|
|
|
|
if {$rc==0} break
|
|
|
|
if {$nDelay > 0} { after $nDelay }
|
|
|
|
}
|
|
|
|
if {$rc} { error $msg }
|
|
|
|
} else {
|
|
|
|
if {$force} {
|
|
|
|
file copy -force $from $to
|
|
|
|
} else {
|
|
|
|
file copy $from $to
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 02:52:33 +04:00
|
|
|
# Check if a file name is relative
|
|
|
|
#
|
|
|
|
proc is_relative_file { file } {
|
|
|
|
return [expr {[file pathtype $file] != "absolute"}]
|
|
|
|
}
|
|
|
|
|
2012-03-06 07:00:49 +04:00
|
|
|
# If the VFS supports using the current directory, returns [pwd];
|
|
|
|
# otherwise, it returns only the provided suffix string (which is
|
|
|
|
# empty by default).
|
|
|
|
#
|
|
|
|
proc test_pwd { args } {
|
|
|
|
if {[llength $args] > 0} {
|
|
|
|
set suffix1 [lindex $args 0]
|
|
|
|
if {[llength $args] > 1} {
|
|
|
|
set suffix2 [lindex $args 1]
|
|
|
|
} else {
|
|
|
|
set suffix2 $suffix1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set suffix1 ""; set suffix2 ""
|
|
|
|
}
|
|
|
|
ifcapable curdir {
|
2012-03-09 00:22:42 +04:00
|
|
|
return "[get_pwd]$suffix1"
|
2012-03-06 07:00:49 +04:00
|
|
|
} else {
|
|
|
|
return $suffix2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-02 04:57:34 +04:00
|
|
|
# Delete a file or directory
|
|
|
|
#
|
|
|
|
proc delete_file {args} {
|
|
|
|
do_delete_file false {*}$args
|
|
|
|
}
|
|
|
|
|
|
|
|
proc forcedelete {args} {
|
|
|
|
do_delete_file true {*}$args
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_delete_file {force args} {
|
|
|
|
set nRetry [getFileRetries] ;# Maximum number of retries.
|
|
|
|
set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
|
|
|
|
|
|
|
|
foreach filename $args {
|
|
|
|
# On windows, sometimes even a [file delete -force] can fail just after
|
|
|
|
# a file is closed. The cause is usually "tag-alongs" - programs like
|
|
|
|
# anti-virus software, automatic backup tools and various explorer
|
|
|
|
# extensions that keep a file open a little longer than we expect, causing
|
|
|
|
# the delete to fail.
|
|
|
|
#
|
|
|
|
# The solution is to wait a short amount of time before retrying the
|
|
|
|
# delete.
|
|
|
|
#
|
|
|
|
if {$nRetry > 0} {
|
|
|
|
for {set i 0} {$i<$nRetry} {incr i} {
|
|
|
|
set rc [catch {
|
|
|
|
if {$force} {
|
|
|
|
file delete -force $filename
|
|
|
|
} else {
|
|
|
|
file delete $filename
|
|
|
|
}
|
|
|
|
} msg]
|
|
|
|
if {$rc==0} break
|
|
|
|
if {$nDelay > 0} { after $nDelay }
|
|
|
|
}
|
|
|
|
if {$rc} { error $msg }
|
|
|
|
} else {
|
|
|
|
if {$force} {
|
|
|
|
file delete -force $filename
|
|
|
|
} else {
|
|
|
|
file delete $filename
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
if {$::tcl_platform(platform) eq "windows"} {
|
|
|
|
proc do_remove_win32_dir {args} {
|
|
|
|
set nRetry [getFileRetries] ;# Maximum number of retries.
|
|
|
|
set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
|
|
|
|
|
|
|
|
foreach dirName $args {
|
|
|
|
# On windows, sometimes even a [remove_win32_dir] can fail just after
|
|
|
|
# a directory is emptied. The cause is usually "tag-alongs" - programs
|
|
|
|
# like anti-virus software, automatic backup tools and various explorer
|
|
|
|
# extensions that keep a file open a little longer than we expect,
|
|
|
|
# causing the delete to fail.
|
|
|
|
#
|
|
|
|
# The solution is to wait a short amount of time before retrying the
|
|
|
|
# removal.
|
|
|
|
#
|
|
|
|
if {$nRetry > 0} {
|
|
|
|
for {set i 0} {$i < $nRetry} {incr i} {
|
|
|
|
set rc [catch {
|
|
|
|
remove_win32_dir $dirName
|
|
|
|
} msg]
|
|
|
|
if {$rc == 0} break
|
|
|
|
if {$nDelay > 0} { after $nDelay }
|
|
|
|
}
|
|
|
|
if {$rc} { error $msg }
|
|
|
|
} else {
|
|
|
|
remove_win32_dir $dirName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_delete_win32_file {args} {
|
|
|
|
set nRetry [getFileRetries] ;# Maximum number of retries.
|
|
|
|
set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
|
|
|
|
|
|
|
|
foreach fileName $args {
|
|
|
|
# On windows, sometimes even a [delete_win32_file] can fail just after
|
|
|
|
# a file is closed. The cause is usually "tag-alongs" - programs like
|
|
|
|
# anti-virus software, automatic backup tools and various explorer
|
|
|
|
# extensions that keep a file open a little longer than we expect,
|
|
|
|
# causing the delete to fail.
|
|
|
|
#
|
|
|
|
# The solution is to wait a short amount of time before retrying the
|
|
|
|
# delete.
|
|
|
|
#
|
|
|
|
if {$nRetry > 0} {
|
|
|
|
for {set i 0} {$i < $nRetry} {incr i} {
|
|
|
|
set rc [catch {
|
|
|
|
delete_win32_file $fileName
|
|
|
|
} msg]
|
|
|
|
if {$rc == 0} break
|
|
|
|
if {$nDelay > 0} { after $nDelay }
|
|
|
|
}
|
|
|
|
if {$rc} { error $msg }
|
|
|
|
} else {
|
|
|
|
delete_win32_file $fileName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 13:44:42 +04:00
|
|
|
proc execpresql {handle args} {
|
|
|
|
trace remove execution $handle enter [list execpresql $handle]
|
|
|
|
if {[info exists ::G(perm:presql)]} {
|
|
|
|
$handle eval $::G(perm:presql)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-22 17:46:43 +04:00
|
|
|
# This command should be called after loading tester.tcl from within
|
|
|
|
# all test scripts that are incompatible with encryption codecs.
|
|
|
|
#
|
|
|
|
proc do_not_use_codec {} {
|
|
|
|
set ::do_not_use_codec 1
|
|
|
|
reset_db
|
|
|
|
}
|
2016-07-25 19:10:43 +03:00
|
|
|
unset -nocomplain do_not_use_codec
|
2010-06-22 17:46:43 +04:00
|
|
|
|
2016-03-14 20:05:04 +03:00
|
|
|
# Return true if the "reserved_bytes" integer on database files is non-zero.
|
|
|
|
#
|
|
|
|
proc nonzero_reserved_bytes {} {
|
|
|
|
return [sqlite3 -has-codec]
|
|
|
|
}
|
|
|
|
|
2016-02-15 22:38:17 +03:00
|
|
|
# Print a HELP message and exit
|
|
|
|
#
|
|
|
|
proc print_help_and_quit {} {
|
|
|
|
puts {Options:
|
|
|
|
--pause Wait for user input before continuing
|
|
|
|
--soft-heap-limit=N Set the soft-heap-limit to N
|
2019-11-14 20:46:32 +03:00
|
|
|
--hard-heap-limit=N Set the hard-heap-limit to N
|
2016-02-15 22:38:17 +03:00
|
|
|
--maxerror=N Quit after N errors
|
|
|
|
--verbose=(0|1) Control the amount of output. Default '1'
|
|
|
|
--output=FILE set --verbose=2 and output to FILE. Implies -q
|
|
|
|
-q Shorthand for --verbose=0
|
|
|
|
--help This message
|
|
|
|
}
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:47:26 +04:00
|
|
|
# The following block only runs the first time this file is sourced. It
|
|
|
|
# does not run in slave interpreters (since the ::cmdlinearg array is
|
|
|
|
# populated before the test script is run in slave interpreters).
|
2000-05-30 03:48:22 +04:00
|
|
|
#
|
2010-06-07 18:28:16 +04:00
|
|
|
if {[info exists cmdlinearg]==0} {
|
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# Parse any options specified in the $argv array. This script accepts the
|
|
|
|
# following options:
|
2010-06-07 18:28:16 +04:00
|
|
|
#
|
|
|
|
# --pause
|
|
|
|
# --soft-heap-limit=NN
|
2019-11-14 20:46:32 +03:00
|
|
|
# --hard-heap-limit=NN
|
2010-06-07 18:28:16 +04:00
|
|
|
# --maxerror=NN
|
|
|
|
# --malloctrace=N
|
|
|
|
# --backtrace=N
|
|
|
|
# --binarylog=N
|
2010-06-15 10:56:37 +04:00
|
|
|
# --soak=N
|
2011-08-02 04:57:34 +04:00
|
|
|
# --file-retries=N
|
|
|
|
# --file-retry-delay=N
|
2011-04-04 19:38:16 +04:00
|
|
|
# --start=[$permutation:]$testfile
|
2011-11-12 07:17:40 +04:00
|
|
|
# --match=$pattern
|
2015-06-09 18:58:28 +03:00
|
|
|
# --verbose=$val
|
|
|
|
# --output=$filename
|
2016-03-14 16:42:29 +03:00
|
|
|
# -q Reduce output
|
|
|
|
# --testdir=$dir Run tests in subdirectory $dir
|
2015-06-09 18:58:28 +03:00
|
|
|
# --help
|
2010-06-07 18:28:16 +04:00
|
|
|
#
|
|
|
|
set cmdlinearg(soft-heap-limit) 0
|
2019-11-14 20:46:32 +03:00
|
|
|
set cmdlinearg(hard-heap-limit) 0
|
2010-06-07 18:28:16 +04:00
|
|
|
set cmdlinearg(maxerror) 1000
|
|
|
|
set cmdlinearg(malloctrace) 0
|
|
|
|
set cmdlinearg(backtrace) 10
|
|
|
|
set cmdlinearg(binarylog) 0
|
2010-06-15 10:56:37 +04:00
|
|
|
set cmdlinearg(soak) 0
|
2011-08-02 04:57:34 +04:00
|
|
|
set cmdlinearg(file-retries) 0
|
|
|
|
set cmdlinearg(file-retry-delay) 0
|
2011-11-12 07:17:40 +04:00
|
|
|
set cmdlinearg(start) ""
|
|
|
|
set cmdlinearg(match) ""
|
2015-06-09 18:58:28 +03:00
|
|
|
set cmdlinearg(verbose) ""
|
|
|
|
set cmdlinearg(output) ""
|
2016-03-14 16:42:29 +03:00
|
|
|
set cmdlinearg(testdir) "testdir"
|
2010-06-07 18:28:16 +04:00
|
|
|
|
|
|
|
set leftover [list]
|
|
|
|
foreach a $argv {
|
|
|
|
switch -regexp -- $a {
|
|
|
|
{^-+pause$} {
|
2013-08-29 05:09:14 +04:00
|
|
|
# Wait for user input before continuing. This is to give the user an
|
2010-06-07 18:28:16 +04:00
|
|
|
# opportunity to connect profiling tools to the process.
|
|
|
|
puts -nonewline "Press RETURN to begin..."
|
|
|
|
flush stdout
|
|
|
|
gets stdin
|
|
|
|
}
|
|
|
|
{^-+soft-heap-limit=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(soft-heap-limit)} [split $a =] break
|
|
|
|
}
|
2019-11-14 20:46:32 +03:00
|
|
|
{^-+hard-heap-limit=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(hard-heap-limit)} [split $a =] break
|
|
|
|
}
|
2010-06-07 18:28:16 +04:00
|
|
|
{^-+maxerror=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(maxerror)} [split $a =] break
|
|
|
|
}
|
|
|
|
{^-+malloctrace=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(malloctrace)} [split $a =] break
|
|
|
|
if {$cmdlinearg(malloctrace)} {
|
2018-09-18 20:00:06 +03:00
|
|
|
if {0==$::sqlite_options(memdebug)} {
|
|
|
|
set err "Error: --malloctrace=1 requires an SQLITE_MEMDEBUG build"
|
|
|
|
puts stderr $err
|
|
|
|
exit 1
|
|
|
|
}
|
2010-06-07 18:28:16 +04:00
|
|
|
sqlite3_memdebug_log start
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{^-+backtrace=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(backtrace)} [split $a =] break
|
2017-01-25 20:44:13 +03:00
|
|
|
sqlite3_memdebug_backtrace $cmdlinearg(backtrace)
|
2010-06-07 18:28:16 +04:00
|
|
|
}
|
|
|
|
{^-+binarylog=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(binarylog)} [split $a =] break
|
2016-03-14 17:59:35 +03:00
|
|
|
set cmdlinearg(binarylog) [file normalize $cmdlinearg(binarylog)]
|
2010-06-07 18:28:16 +04:00
|
|
|
}
|
2010-06-15 10:56:37 +04:00
|
|
|
{^-+soak=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(soak)} [split $a =] break
|
|
|
|
set ::G(issoak) $cmdlinearg(soak)
|
|
|
|
}
|
2011-08-02 04:57:34 +04:00
|
|
|
{^-+file-retries=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(file-retries)} [split $a =] break
|
|
|
|
set ::G(file-retries) $cmdlinearg(file-retries)
|
|
|
|
}
|
|
|
|
{^-+file-retry-delay=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(file-retry-delay)} [split $a =] break
|
|
|
|
set ::G(file-retry-delay) $cmdlinearg(file-retry-delay)
|
|
|
|
}
|
2011-04-04 19:38:16 +04:00
|
|
|
{^-+start=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(start)} [split $a =] break
|
|
|
|
|
|
|
|
set ::G(start:file) $cmdlinearg(start)
|
|
|
|
if {[regexp {(.*):(.*)} $cmdlinearg(start) -> s.perm s.file]} {
|
|
|
|
set ::G(start:permutation) ${s.perm}
|
|
|
|
set ::G(start:file) ${s.file}
|
|
|
|
}
|
|
|
|
if {$::G(start:file) == ""} {unset ::G(start:file)}
|
|
|
|
}
|
2011-11-12 07:17:40 +04:00
|
|
|
{^-+match=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(match)} [split $a =] break
|
|
|
|
|
|
|
|
set ::G(match) $cmdlinearg(match)
|
|
|
|
if {$::G(match) == ""} {unset ::G(match)}
|
|
|
|
}
|
2015-06-09 18:58:28 +03:00
|
|
|
|
|
|
|
{^-+output=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(output)} [split $a =] break
|
2016-03-14 17:59:35 +03:00
|
|
|
set cmdlinearg(output) [file normalize $cmdlinearg(output)]
|
2015-06-09 18:58:28 +03:00
|
|
|
if {$cmdlinearg(verbose)==""} {
|
|
|
|
set cmdlinearg(verbose) 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{^-+verbose=.+$} {
|
|
|
|
foreach {dummy cmdlinearg(verbose)} [split $a =] break
|
|
|
|
if {$cmdlinearg(verbose)=="file"} {
|
|
|
|
set cmdlinearg(verbose) 2
|
|
|
|
} elseif {[string is boolean -strict $cmdlinearg(verbose)]==0} {
|
|
|
|
error "option --verbose= must be set to a boolean or to \"file\""
|
|
|
|
}
|
|
|
|
}
|
2016-03-14 16:42:29 +03:00
|
|
|
{^-+testdir=.*$} {
|
|
|
|
foreach {dummy cmdlinearg(testdir)} [split $a =] break
|
|
|
|
}
|
2016-02-15 22:38:17 +03:00
|
|
|
{.*help.*} {
|
|
|
|
print_help_and_quit
|
|
|
|
}
|
|
|
|
{^-q$} {
|
|
|
|
set cmdlinearg(output) test-out.txt
|
|
|
|
set cmdlinearg(verbose) 2
|
|
|
|
}
|
2015-06-09 18:58:28 +03:00
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
default {
|
2016-04-30 22:23:10 +03:00
|
|
|
if {[file tail $a]==$a} {
|
|
|
|
lappend leftover $a
|
|
|
|
} else {
|
|
|
|
lappend leftover [file normalize $a]
|
|
|
|
}
|
2010-06-07 18:28:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-14 17:28:43 +03:00
|
|
|
set testdir [file normalize $testdir]
|
2016-03-14 16:42:29 +03:00
|
|
|
set cmdlinearg(TESTFIXTURE_HOME) [pwd]
|
2016-03-14 20:05:04 +03:00
|
|
|
set cmdlinearg(INFO_SCRIPT) [file normalize [info script]]
|
2016-03-14 17:28:43 +03:00
|
|
|
set argv0 [file normalize $argv0]
|
2016-03-14 16:42:29 +03:00
|
|
|
if {$cmdlinearg(testdir)!=""} {
|
|
|
|
file mkdir $cmdlinearg(testdir)
|
|
|
|
cd $cmdlinearg(testdir)
|
|
|
|
}
|
2010-06-07 18:28:16 +04:00
|
|
|
set argv $leftover
|
|
|
|
|
2010-06-07 21:47:26 +04:00
|
|
|
# Install the malloc layer used to inject OOM errors. And the 'automatic'
|
|
|
|
# extensions. This only needs to be done once for the process.
|
|
|
|
#
|
2013-08-29 05:09:14 +04:00
|
|
|
sqlite3_shutdown
|
|
|
|
install_malloc_faultsim 1
|
2008-06-23 22:49:43 +04:00
|
|
|
sqlite3_initialize
|
2009-04-09 05:23:49 +04:00
|
|
|
autoinstall_test_functions
|
2010-06-07 18:28:16 +04:00
|
|
|
|
2010-06-07 21:47:26 +04:00
|
|
|
# If the --binarylog option was specified, create the logging VFS. This
|
|
|
|
# call installs the new VFS as the default for all SQLite connections.
|
|
|
|
#
|
2010-06-07 18:28:16 +04:00
|
|
|
if {$cmdlinearg(binarylog)} {
|
2010-05-12 23:02:35 +04:00
|
|
|
vfslog new binarylog {} vfslog.bin
|
2010-06-07 18:28:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Set the backtrace depth, if malloc tracing is enabled.
|
|
|
|
#
|
|
|
|
if {$cmdlinearg(malloctrace)} {
|
|
|
|
sqlite3_memdebug_backtrace $cmdlinearg(backtrace)
|
2008-07-12 19:55:54 +04:00
|
|
|
}
|
2015-06-09 18:58:28 +03:00
|
|
|
|
|
|
|
if {$cmdlinearg(output)!=""} {
|
|
|
|
puts "Copying output to file $cmdlinearg(output)"
|
|
|
|
set ::G(output_fd) [open $cmdlinearg(output) w]
|
|
|
|
fconfigure $::G(output_fd) -buffering line
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$cmdlinearg(verbose)==""} {
|
|
|
|
set cmdlinearg(verbose) 1
|
|
|
|
}
|
2019-04-01 20:24:20 +03:00
|
|
|
|
|
|
|
if {[info commands vdbe_coverage]!=""} {
|
|
|
|
vdbe_coverage start
|
|
|
|
}
|
2008-06-23 22:49:43 +04:00
|
|
|
}
|
2009-01-09 13:49:14 +03:00
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
# Update the soft-heap-limit each time this script is run. In that
|
|
|
|
# way if an individual test file changes the soft-heap-limit, it
|
|
|
|
# will be reset at the start of the next test file.
|
|
|
|
#
|
2019-11-14 20:46:32 +03:00
|
|
|
sqlite3_soft_heap_limit64 $cmdlinearg(soft-heap-limit)
|
|
|
|
sqlite3_hard_heap_limit64 $cmdlinearg(hard-heap-limit)
|
2010-06-07 18:28:16 +04:00
|
|
|
|
|
|
|
# Create a test database
|
|
|
|
#
|
2009-01-09 13:49:14 +03:00
|
|
|
proc reset_db {} {
|
|
|
|
catch {db close}
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete test.db
|
|
|
|
forcedelete test.db-journal
|
|
|
|
forcedelete test.db-wal
|
2009-01-09 13:49:14 +03:00
|
|
|
sqlite3 db ./test.db
|
|
|
|
set ::DB [sqlite3_connection_pointer db]
|
|
|
|
if {[info exists ::SETUP_SQL]} {
|
|
|
|
db eval $::SETUP_SQL
|
|
|
|
}
|
2002-03-07 01:01:34 +03:00
|
|
|
}
|
2009-01-09 13:49:14 +03:00
|
|
|
reset_db
|
2000-05-30 03:48:22 +04:00
|
|
|
|
|
|
|
# Abort early if this script has been run before.
|
|
|
|
#
|
2010-06-07 18:28:16 +04:00
|
|
|
if {[info exists TC(count)]} return
|
2000-05-30 03:48:22 +04:00
|
|
|
|
2010-09-10 17:22:59 +04:00
|
|
|
# Make sure memory statistics are enabled.
|
|
|
|
#
|
|
|
|
sqlite3_config_memstatus 1
|
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
# Initialize the test counters and set up commands to access them.
|
|
|
|
# Or, if this is a slave interpreter, set up aliases to write the
|
|
|
|
# counters in the parent interpreter.
|
2000-05-30 03:48:22 +04:00
|
|
|
#
|
2010-06-07 18:28:16 +04:00
|
|
|
if {0==[info exists ::SLAVE]} {
|
|
|
|
set TC(errors) 0
|
|
|
|
set TC(count) 0
|
|
|
|
set TC(fail_list) [list]
|
|
|
|
set TC(omit_list) [list]
|
2013-04-19 16:32:52 +04:00
|
|
|
set TC(warn_list) [list]
|
2010-06-07 18:28:16 +04:00
|
|
|
|
|
|
|
proc set_test_counter {counter args} {
|
|
|
|
if {[llength $args]} {
|
|
|
|
set ::TC($counter) [lindex $args 0]
|
|
|
|
}
|
|
|
|
set ::TC($counter)
|
|
|
|
}
|
2006-11-23 12:39:16 +03:00
|
|
|
}
|
2000-05-30 00:41:49 +04:00
|
|
|
|
2008-04-15 06:36:33 +04:00
|
|
|
# Record the fact that a sequence of tests were omitted.
|
|
|
|
#
|
2011-11-12 07:17:40 +04:00
|
|
|
proc omit_test {name reason {append 1}} {
|
2010-06-07 18:28:16 +04:00
|
|
|
set omitList [set_test_counter omit_list]
|
2011-11-12 07:17:40 +04:00
|
|
|
if {$append} {
|
|
|
|
lappend omitList [list $name $reason]
|
|
|
|
}
|
2010-06-07 18:28:16 +04:00
|
|
|
set_test_counter omit_list $omitList
|
|
|
|
}
|
|
|
|
|
|
|
|
# Record the fact that a test failed.
|
|
|
|
#
|
|
|
|
proc fail_test {name} {
|
|
|
|
set f [set_test_counter fail_list]
|
|
|
|
lappend f $name
|
|
|
|
set_test_counter fail_list $f
|
|
|
|
set_test_counter errors [expr [set_test_counter errors] + 1]
|
|
|
|
|
|
|
|
set nFail [set_test_counter errors]
|
|
|
|
if {$nFail>=$::cmdlinearg(maxerror)} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "*** Giving up..."
|
2010-06-07 18:28:16 +04:00
|
|
|
finalize_testing
|
|
|
|
}
|
2008-04-15 06:36:33 +04:00
|
|
|
}
|
|
|
|
|
2013-04-19 16:32:52 +04:00
|
|
|
# Remember a warning message to be displayed at the conclusion of all testing
|
|
|
|
#
|
|
|
|
proc warning {msg {append 1}} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Warning: $msg"
|
2013-04-19 16:32:52 +04:00
|
|
|
set warnList [set_test_counter warn_list]
|
|
|
|
if {$append} {
|
|
|
|
lappend warnList $msg
|
|
|
|
}
|
|
|
|
set_test_counter warn_list $warnList
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
# Increment the number of tests run
|
|
|
|
#
|
|
|
|
proc incr_ntest {} {
|
|
|
|
set_test_counter count [expr [set_test_counter count] + 1]
|
|
|
|
}
|
|
|
|
|
2015-06-09 18:58:28 +03:00
|
|
|
# Return true if --verbose=1 was specified on the command line. Otherwise,
|
|
|
|
# return false.
|
|
|
|
#
|
|
|
|
proc verbose {} {
|
|
|
|
return $::cmdlinearg(verbose)
|
|
|
|
}
|
|
|
|
|
|
|
|
# Use the following commands instead of [puts] for test output within
|
|
|
|
# this file. Test scripts can still use regular [puts], which is directed
|
|
|
|
# to stdout and, if one is open, the --output file.
|
|
|
|
#
|
|
|
|
# output1: output that should be printed if --verbose=1 was specified.
|
|
|
|
# output2: output that should be printed unconditionally.
|
|
|
|
# output2_if_no_verbose: output that should be printed only if --verbose=0.
|
|
|
|
#
|
|
|
|
proc output1 {args} {
|
|
|
|
set v [verbose]
|
|
|
|
if {$v==1} {
|
|
|
|
uplevel output2 $args
|
|
|
|
} elseif {$v==2} {
|
|
|
|
uplevel puts [lrange $args 0 end-1] $::G(output_fd) [lrange $args end end]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
proc output2 {args} {
|
|
|
|
set nArg [llength $args]
|
|
|
|
uplevel puts $args
|
|
|
|
}
|
|
|
|
proc output2_if_no_verbose {args} {
|
|
|
|
set v [verbose]
|
|
|
|
if {$v==0} {
|
|
|
|
uplevel output2 $args
|
|
|
|
} elseif {$v==2} {
|
|
|
|
uplevel puts [lrange $args 0 end-1] stdout [lrange $args end end]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Override the [puts] command so that if no channel is explicitly
|
|
|
|
# specified the string is written to both stdout and to the file
|
|
|
|
# specified by "--output=", if any.
|
|
|
|
#
|
|
|
|
proc puts_override {args} {
|
|
|
|
set nArg [llength $args]
|
|
|
|
if {$nArg==1 || ($nArg==2 && [string first [lindex $args 0] -nonewline]==0)} {
|
|
|
|
uplevel puts_original $args
|
|
|
|
if {[info exists ::G(output_fd)]} {
|
|
|
|
uplevel puts [lrange $args 0 end-1] $::G(output_fd) [lrange $args end end]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# A channel was explicitly specified.
|
|
|
|
uplevel puts_original $args
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rename puts puts_original
|
|
|
|
proc puts {args} { uplevel puts_override $args }
|
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# Invoke the do_test procedure to run a single test
|
2000-05-30 00:41:49 +04:00
|
|
|
#
|
2016-07-09 20:47:01 +03:00
|
|
|
# The $expected parameter is the expected result. The result is the return
|
|
|
|
# value from the last TCL command in $cmd.
|
|
|
|
#
|
|
|
|
# Normally, $expected must match exactly. But if $expected is of the form
|
|
|
|
# "/regexp/" then regular expression matching is used. If $expected is
|
|
|
|
# "~/regexp/" then the regular expression must NOT match. If $expected is
|
|
|
|
# of the form "#/value-list/" then each term in value-list must be numeric
|
|
|
|
# and must approximately match the corresponding numeric term in $result.
|
|
|
|
# Values must match within 10%. Or if the $expected term is A..B then the
|
|
|
|
# $result term must be in between A and B.
|
|
|
|
#
|
2000-05-30 00:41:49 +04:00
|
|
|
proc do_test {name cmd expected} {
|
2010-06-07 18:28:16 +04:00
|
|
|
global argv cmdlinearg
|
|
|
|
|
2010-11-01 20:38:24 +03:00
|
|
|
fix_testname name
|
|
|
|
|
2007-08-23 06:47:53 +04:00
|
|
|
sqlite3_memdebug_settitle $name
|
2010-06-07 18:28:16 +04:00
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# if {[llength $argv]==0} {
|
2010-07-05 18:54:48 +04:00
|
|
|
# set go 1
|
|
|
|
# } else {
|
|
|
|
# set go 0
|
|
|
|
# foreach pattern $argv {
|
|
|
|
# if {[string match $pattern $name]} {
|
|
|
|
# set go 1
|
|
|
|
# break
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# }
|
2010-06-07 21:47:26 +04:00
|
|
|
|
2010-07-03 17:59:01 +04:00
|
|
|
if {[info exists ::G(perm:prefix)]} {
|
|
|
|
set name "$::G(perm:prefix)$name"
|
2010-06-07 21:47:26 +04:00
|
|
|
}
|
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
incr_ntest
|
2015-06-09 18:58:28 +03:00
|
|
|
output1 -nonewline $name...
|
2000-05-30 00:41:49 +04:00
|
|
|
flush stdout
|
2011-11-12 07:17:40 +04:00
|
|
|
|
|
|
|
if {![info exists ::G(match)] || [string match $::G(match) $name]} {
|
|
|
|
if {[catch {uplevel #0 "$cmd;\n"} result]} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2_if_no_verbose -nonewline $name...
|
|
|
|
output2 "\nError: $result"
|
2011-11-12 07:17:40 +04:00
|
|
|
fail_test $name
|
|
|
|
} else {
|
2020-03-20 23:54:28 +03:00
|
|
|
if {[permutation]=="maindbname"} {
|
|
|
|
set result [string map [list [string tolower ICECUBE] main] $result]
|
|
|
|
}
|
2016-07-09 20:47:01 +03:00
|
|
|
if {[regexp {^[~#]?/.*/$} $expected]} {
|
2013-05-30 23:28:34 +04:00
|
|
|
# "expected" is of the form "/PATTERN/" then the result if correct if
|
|
|
|
# regular expression PATTERN matches the result. "~/PATTERN/" means
|
|
|
|
# the regular expression must not match.
|
2012-04-27 05:08:02 +04:00
|
|
|
if {[string index $expected 0]=="~"} {
|
2013-11-13 19:32:15 +04:00
|
|
|
set re [string range $expected 2 end-1]
|
|
|
|
if {[string index $re 0]=="*"} {
|
|
|
|
# If the regular expression begins with * then treat it as a glob instead
|
|
|
|
set ok [string match $re $result]
|
|
|
|
} else {
|
|
|
|
set re [string map {# {[-0-9.]+}} $re]
|
|
|
|
set ok [regexp $re $result]
|
|
|
|
}
|
|
|
|
set ok [expr {!$ok}]
|
2016-07-09 20:47:01 +03:00
|
|
|
} elseif {[string index $expected 0]=="#"} {
|
|
|
|
# Numeric range value comparison. Each term of the $result is matched
|
|
|
|
# against one term of $expect. Both $result and $expected terms must be
|
|
|
|
# numeric. The values must match within 10%. Or if $expected is of the
|
|
|
|
# form A..B then the $result term must be between A and B.
|
|
|
|
set e2 [string range $expected 2 end-1]
|
|
|
|
foreach i $result j $e2 {
|
|
|
|
if {[regexp {^(-?\d+)\.\.(-?\d)$} $j all A B]} {
|
|
|
|
set ok [expr {$i+0>=$A && $i+0<=$B}]
|
|
|
|
} else {
|
|
|
|
set ok [expr {$i+0>=0.9*$j && $i+0<=1.1*$j}]
|
|
|
|
}
|
|
|
|
if {!$ok} break
|
|
|
|
}
|
|
|
|
if {$ok && [llength $result]!=[llength $e2]} {set ok 0}
|
2012-04-27 05:08:02 +04:00
|
|
|
} else {
|
2013-11-13 19:32:15 +04:00
|
|
|
set re [string range $expected 1 end-1]
|
|
|
|
if {[string index $re 0]=="*"} {
|
|
|
|
# If the regular expression begins with * then treat it as a glob instead
|
|
|
|
set ok [string match $re $result]
|
|
|
|
} else {
|
|
|
|
set re [string map {# {[-0-9.]+}} $re]
|
|
|
|
set ok [regexp $re $result]
|
|
|
|
}
|
2012-04-27 05:08:02 +04:00
|
|
|
}
|
2013-05-30 23:28:34 +04:00
|
|
|
} elseif {[regexp {^~?\*.*\*$} $expected]} {
|
|
|
|
# "expected" is of the form "*GLOB*" then the result if correct if
|
|
|
|
# glob pattern GLOB matches the result. "~/GLOB/" means
|
|
|
|
# the glob must not match.
|
|
|
|
if {[string index $expected 0]=="~"} {
|
|
|
|
set e [string range $expected 1 end]
|
|
|
|
set ok [expr {![string match $e $result]}]
|
|
|
|
} else {
|
|
|
|
set ok [string match $expected $result]
|
|
|
|
}
|
2012-04-27 05:08:02 +04:00
|
|
|
} else {
|
|
|
|
set ok [expr {[string compare $result $expected]==0}]
|
|
|
|
}
|
|
|
|
if {!$ok} {
|
2012-09-13 05:51:02 +04:00
|
|
|
# if {![info exists ::testprefix] || $::testprefix eq ""} {
|
|
|
|
# error "no test prefix"
|
|
|
|
# }
|
2015-11-13 00:42:40 +03:00
|
|
|
output1 ""
|
2015-11-13 03:03:14 +03:00
|
|
|
output2 "! $name expected: \[$expected\]\n! $name got: \[$result\]"
|
2012-04-27 05:08:02 +04:00
|
|
|
fail_test $name
|
|
|
|
} else {
|
2015-06-09 18:58:28 +03:00
|
|
|
output1 " Ok"
|
2012-04-27 05:08:02 +04:00
|
|
|
}
|
2011-11-12 07:17:40 +04:00
|
|
|
}
|
2000-05-30 00:41:49 +04:00
|
|
|
} else {
|
2015-06-09 18:58:28 +03:00
|
|
|
output1 " Omitted"
|
2011-11-12 07:17:40 +04:00
|
|
|
omit_test $name "pattern mismatch" 0
|
2000-05-30 00:41:49 +04:00
|
|
|
}
|
2007-04-13 07:23:21 +04:00
|
|
|
flush stdout
|
2000-05-30 00:41:49 +04:00
|
|
|
}
|
2010-09-30 22:43:14 +04:00
|
|
|
|
2015-01-18 08:35:01 +03:00
|
|
|
proc dumpbytes {s} {
|
|
|
|
set r ""
|
|
|
|
for {set i 0} {$i < [string length $s]} {incr i} {
|
|
|
|
if {$i > 0} {append r " "}
|
|
|
|
append r [format %02X [scan [string index $s $i] %c]]
|
|
|
|
}
|
|
|
|
return $r
|
|
|
|
}
|
|
|
|
|
2012-04-24 16:46:05 +04:00
|
|
|
proc catchcmd {db {cmd ""}} {
|
|
|
|
global CLI
|
|
|
|
set out [open cmds.txt w]
|
|
|
|
puts $out $cmd
|
|
|
|
close $out
|
|
|
|
set line "exec $CLI $db < cmds.txt"
|
|
|
|
set rc [catch { eval $line } msg]
|
|
|
|
list $rc $msg
|
|
|
|
}
|
|
|
|
|
2015-01-18 08:35:01 +03:00
|
|
|
proc catchcmdex {db {cmd ""}} {
|
|
|
|
global CLI
|
|
|
|
set out [open cmds.txt w]
|
|
|
|
fconfigure $out -encoding binary -translation binary
|
|
|
|
puts -nonewline $out $cmd
|
|
|
|
close $out
|
|
|
|
set line "exec -keepnewline -- $CLI $db < cmds.txt"
|
|
|
|
set chans [list stdin stdout stderr]
|
|
|
|
foreach chan $chans {
|
|
|
|
catch {
|
|
|
|
set modes($chan) [fconfigure $chan]
|
|
|
|
fconfigure $chan -encoding binary -translation binary -buffering none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set rc [catch { eval $line } msg]
|
|
|
|
foreach chan $chans {
|
|
|
|
catch {
|
|
|
|
eval fconfigure [list $chan] $modes($chan)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# puts [dumpbytes $msg]
|
|
|
|
list $rc $msg
|
|
|
|
}
|
|
|
|
|
2011-06-21 23:30:19 +04:00
|
|
|
proc filepath_normalize {p} {
|
|
|
|
# test cases should be written to assume "unix"-like file paths
|
2011-06-21 23:39:59 +04:00
|
|
|
if {$::tcl_platform(platform)!="unix"} {
|
2021-02-03 22:38:40 +03:00
|
|
|
string map [list \\ / \{/ / .db\} .db] \
|
|
|
|
[regsub -nocase -all {[a-z]:[/\\]+} $p {/}]
|
2011-06-21 23:38:16 +04:00
|
|
|
} {
|
|
|
|
set p
|
2011-06-21 23:30:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
proc do_filepath_test {name cmd expected} {
|
|
|
|
uplevel [list do_test $name [
|
|
|
|
subst -nocommands { filepath_normalize [ $cmd ] }
|
|
|
|
] [filepath_normalize $expected]]
|
|
|
|
}
|
|
|
|
|
2011-05-05 23:44:22 +04:00
|
|
|
proc realnum_normalize {r} {
|
2011-06-20 21:41:41 +04:00
|
|
|
# different TCL versions display floating point values differently.
|
|
|
|
string map {1.#INF inf Inf inf .0e e} [regsub -all {(e[+-])0+} $r {\1}]
|
2011-05-05 23:44:22 +04:00
|
|
|
}
|
|
|
|
proc do_realnum_test {name cmd expected} {
|
|
|
|
uplevel [list do_test $name [
|
|
|
|
subst -nocommands { realnum_normalize [ $cmd ] }
|
|
|
|
] [realnum_normalize $expected]]
|
|
|
|
}
|
|
|
|
|
2010-09-30 22:43:14 +04:00
|
|
|
proc fix_testname {varname} {
|
|
|
|
upvar $varname testname
|
2013-08-29 05:09:14 +04:00
|
|
|
if {[info exists ::testprefix]
|
2010-09-30 22:43:14 +04:00
|
|
|
&& [string is digit [string range $testname 0 0]]
|
|
|
|
} {
|
|
|
|
set testname "${::testprefix}-$testname"
|
|
|
|
}
|
|
|
|
}
|
2011-04-16 23:23:10 +04:00
|
|
|
|
|
|
|
proc normalize_list {L} {
|
|
|
|
set L2 [list]
|
|
|
|
foreach l $L {lappend L2 $l}
|
|
|
|
set L2
|
|
|
|
}
|
2013-08-29 19:08:38 +04:00
|
|
|
|
2017-02-04 20:33:30 +03:00
|
|
|
# Either:
|
|
|
|
#
|
|
|
|
# do_execsql_test TESTNAME SQL ?RES?
|
|
|
|
# do_execsql_test -db DB TESTNAME SQL ?RES?
|
|
|
|
#
|
|
|
|
proc do_execsql_test {args} {
|
|
|
|
set db db
|
|
|
|
if {[lindex $args 0]=="-db"} {
|
|
|
|
set db [lindex $args 1]
|
|
|
|
set args [lrange $args 2 end]
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[llength $args]==2} {
|
|
|
|
foreach {testname sql} $args {}
|
|
|
|
set result ""
|
|
|
|
} elseif {[llength $args]==3} {
|
|
|
|
foreach {testname sql result} $args {}
|
2019-01-14 22:13:30 +03:00
|
|
|
|
|
|
|
# With some versions of Tcl on windows, if $result is all whitespace but
|
|
|
|
# contains some CR/LF characters, the [list {*}$result] below returns a
|
|
|
|
# copy of $result instead of a zero length string. Not clear exactly why
|
|
|
|
# this is. The following is a workaround.
|
|
|
|
if {[llength $result]==0} { set result "" }
|
2017-02-04 20:33:30 +03:00
|
|
|
} else {
|
|
|
|
error [string trim {
|
|
|
|
wrong # args: should be "do_execsql_test ?-db DB? testname sql ?result?"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
|
2010-09-30 22:43:14 +04:00
|
|
|
fix_testname testname
|
2017-02-04 20:33:30 +03:00
|
|
|
|
|
|
|
uplevel do_test \
|
|
|
|
[list $testname] \
|
|
|
|
[list "execsql {$sql} $db"] \
|
|
|
|
[list [list {*}$result]]
|
2010-06-21 11:45:47 +04:00
|
|
|
}
|
2017-02-04 20:33:30 +03:00
|
|
|
|
2010-06-21 11:45:47 +04:00
|
|
|
proc do_catchsql_test {testname sql result} {
|
2010-09-30 22:43:14 +04:00
|
|
|
fix_testname testname
|
2011-06-13 13:11:01 +04:00
|
|
|
uplevel do_test [list $testname] [list "catchsql {$sql}"] [list $result]
|
2010-06-21 11:45:47 +04:00
|
|
|
}
|
2014-01-24 18:37:44 +04:00
|
|
|
proc do_timed_execsql_test {testname sql {result {}}} {
|
|
|
|
fix_testname testname
|
|
|
|
uplevel do_test [list $testname] [list "execsql_timed {$sql}"]\
|
|
|
|
[list [list {*}$result]]
|
|
|
|
}
|
2018-05-02 17:24:34 +03:00
|
|
|
|
|
|
|
# Run an EXPLAIN QUERY PLAN $sql in database "db". Then rewrite the output
|
|
|
|
# as an ASCII-art graph and return a string that is that graph.
|
|
|
|
#
|
|
|
|
# Hexadecimal literals in the output text are converted into "xxxxxx" since those
|
|
|
|
# literals are pointer values that might very from one run of the test to the
|
|
|
|
# next, yet we want the output to be consistent.
|
|
|
|
#
|
|
|
|
proc query_plan_graph {sql} {
|
|
|
|
db eval "EXPLAIN QUERY PLAN $sql" {
|
|
|
|
set dx($id) $detail
|
|
|
|
lappend cx($parent) $id
|
|
|
|
}
|
|
|
|
set a "\n QUERY PLAN\n"
|
|
|
|
append a [append_graph " " dx cx 0]
|
2018-07-10 22:48:35 +03:00
|
|
|
regsub -all { 0x[A-F0-9]+\y} $a { xxxxxx} a
|
|
|
|
regsub -all {(MATERIALIZE|CO-ROUTINE|SUBQUERY) \d+\y} $a {\1 xxxxxx} a
|
|
|
|
return $a
|
2018-05-02 17:24:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Helper routine for [query_plan_graph SQL]:
|
|
|
|
#
|
|
|
|
# Output rows of the graph that are children of $level.
|
|
|
|
#
|
|
|
|
# prefix: Prepend to every output line
|
|
|
|
#
|
|
|
|
# dxname: Name of an array variable that stores text describe
|
|
|
|
# The description for $id is $dx($id)
|
|
|
|
#
|
|
|
|
# cxname: Name of an array variable holding children of item.
|
|
|
|
# Children of $id are $cx($id)
|
|
|
|
#
|
|
|
|
# level: Render all lines that are children of $level
|
|
|
|
#
|
|
|
|
proc append_graph {prefix dxname cxname level} {
|
|
|
|
upvar $dxname dx $cxname cx
|
|
|
|
set a ""
|
|
|
|
set x $cx($level)
|
|
|
|
set n [llength $x]
|
|
|
|
for {set i 0} {$i<$n} {incr i} {
|
|
|
|
set id [lindex $x $i]
|
|
|
|
if {$i==$n-1} {
|
|
|
|
set p1 "`--"
|
|
|
|
set p2 " "
|
|
|
|
} else {
|
|
|
|
set p1 "|--"
|
|
|
|
set p2 "| "
|
|
|
|
}
|
|
|
|
append a $prefix$p1$dx($id)\n
|
|
|
|
if {[info exists cx($id)]} {
|
|
|
|
append a [append_graph "$prefix$p2" dx cx $id]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $a
|
|
|
|
}
|
|
|
|
|
|
|
|
# Do an EXPLAIN QUERY PLAN test on input $sql with expected results $res
|
|
|
|
#
|
|
|
|
# If $res begins with a "\s+QUERY PLAN\n" then it is assumed to be the
|
|
|
|
# complete graph which must match the output of [query_plan_graph $sql]
|
|
|
|
# exactly.
|
|
|
|
#
|
|
|
|
# If $res does not begin with "\s+QUERY PLAN\n" then take it is a string
|
|
|
|
# that must be found somewhere in the query plan output.
|
|
|
|
#
|
2010-11-15 19:12:58 +03:00
|
|
|
proc do_eqp_test {name sql res} {
|
2018-05-02 17:24:34 +03:00
|
|
|
if {[regexp {^\s+QUERY PLAN\n} $res]} {
|
|
|
|
uplevel do_test $name [list [list query_plan_graph $sql]] [list $res]
|
|
|
|
} else {
|
|
|
|
if {[string index $res 0]!="/"} {
|
|
|
|
set res "/*$res*/"
|
|
|
|
}
|
|
|
|
uplevel do_execsql_test $name [list "EXPLAIN QUERY PLAN $sql"] [list $res]
|
|
|
|
}
|
2010-11-15 19:12:58 +03:00
|
|
|
}
|
2010-06-21 11:45:47 +04:00
|
|
|
|
2018-05-02 17:24:34 +03:00
|
|
|
|
2010-09-18 23:00:12 +04:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# Usage: do_select_tests PREFIX ?SWITCHES? TESTLIST
|
|
|
|
#
|
|
|
|
# Where switches are:
|
|
|
|
#
|
|
|
|
# -errorformat FMTSTRING
|
|
|
|
# -count
|
2010-09-20 23:17:53 +04:00
|
|
|
# -query SQL
|
2010-09-28 21:37:28 +04:00
|
|
|
# -tclquery TCL
|
2010-09-23 22:47:36 +04:00
|
|
|
# -repair TCL
|
2010-09-18 23:00:12 +04:00
|
|
|
#
|
|
|
|
proc do_select_tests {prefix args} {
|
|
|
|
|
|
|
|
set testlist [lindex $args end]
|
|
|
|
set switches [lrange $args 0 end-1]
|
|
|
|
|
|
|
|
set errfmt ""
|
|
|
|
set countonly 0
|
2010-09-28 21:37:28 +04:00
|
|
|
set tclquery ""
|
2010-09-23 22:47:36 +04:00
|
|
|
set repair ""
|
2010-09-18 23:00:12 +04:00
|
|
|
|
|
|
|
for {set i 0} {$i < [llength $switches]} {incr i} {
|
|
|
|
set s [lindex $switches $i]
|
|
|
|
set n [string length $s]
|
2010-09-20 23:17:53 +04:00
|
|
|
if {$n>=2 && [string equal -length $n $s "-query"]} {
|
2010-09-28 21:37:28 +04:00
|
|
|
set tclquery [list execsql [lindex $switches [incr i]]]
|
|
|
|
} elseif {$n>=2 && [string equal -length $n $s "-tclquery"]} {
|
|
|
|
set tclquery [lindex $switches [incr i]]
|
2010-09-20 23:17:53 +04:00
|
|
|
} elseif {$n>=2 && [string equal -length $n $s "-errorformat"]} {
|
2010-09-18 23:00:12 +04:00
|
|
|
set errfmt [lindex $switches [incr i]]
|
2010-09-23 22:47:36 +04:00
|
|
|
} elseif {$n>=2 && [string equal -length $n $s "-repair"]} {
|
|
|
|
set repair [lindex $switches [incr i]]
|
2010-09-18 23:00:12 +04:00
|
|
|
} elseif {$n>=2 && [string equal -length $n $s "-count"]} {
|
|
|
|
set countonly 1
|
|
|
|
} else {
|
|
|
|
error "unknown switch: $s"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$countonly && $errfmt!=""} {
|
|
|
|
error "Cannot use -count and -errorformat together"
|
|
|
|
}
|
|
|
|
set nTestlist [llength $testlist]
|
|
|
|
if {$nTestlist%3 || $nTestlist==0 } {
|
|
|
|
error "SELECT test list contains [llength $testlist] elements"
|
|
|
|
}
|
|
|
|
|
2010-09-23 22:47:36 +04:00
|
|
|
eval $repair
|
2010-09-18 23:00:12 +04:00
|
|
|
foreach {tn sql res} $testlist {
|
2010-09-28 21:37:28 +04:00
|
|
|
if {$tclquery != ""} {
|
2010-09-20 23:17:53 +04:00
|
|
|
execsql $sql
|
2010-09-28 21:37:28 +04:00
|
|
|
uplevel do_test ${prefix}.$tn [list $tclquery] [list [list {*}$res]]
|
|
|
|
} elseif {$countonly} {
|
2010-09-18 23:00:12 +04:00
|
|
|
set nRow 0
|
|
|
|
db eval $sql {incr nRow}
|
|
|
|
uplevel do_test ${prefix}.$tn [list [list set {} $nRow]] [list $res]
|
|
|
|
} elseif {$errfmt==""} {
|
|
|
|
uplevel do_execsql_test ${prefix}.${tn} [list $sql] [list [list {*}$res]]
|
|
|
|
} else {
|
|
|
|
set res [list 1 [string trim [format $errfmt {*}$res]]]
|
|
|
|
uplevel do_catchsql_test ${prefix}.${tn} [list $sql] [list $res]
|
|
|
|
}
|
2010-09-23 22:47:36 +04:00
|
|
|
eval $repair
|
2010-09-18 23:00:12 +04:00
|
|
|
}
|
2010-09-23 22:47:36 +04:00
|
|
|
|
2010-09-18 23:00:12 +04:00
|
|
|
}
|
|
|
|
|
2010-09-21 20:59:16 +04:00
|
|
|
proc delete_all_data {} {
|
|
|
|
db eval {SELECT tbl_name AS t FROM sqlite_master WHERE type = 'table'} {
|
|
|
|
db eval "DELETE FROM '[string map {' ''} $t]'"
|
|
|
|
}
|
|
|
|
}
|
2000-05-30 00:41:49 +04:00
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# Run an SQL script.
|
2006-11-23 12:39:16 +03:00
|
|
|
# Return the number of microseconds per statement.
|
|
|
|
#
|
2006-11-24 00:09:10 +03:00
|
|
|
proc speed_trial {name numstmt units sql} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 -nonewline [format {%-21.21s } $name...]
|
2006-11-23 12:39:16 +03:00
|
|
|
flush stdout
|
|
|
|
set speed [time {sqlite3_exec_nr db $sql}]
|
|
|
|
set tm [lindex $speed 0]
|
2008-02-08 21:25:29 +03:00
|
|
|
if {$tm == 0} {
|
|
|
|
set rate [format %20s "many"]
|
|
|
|
} else {
|
|
|
|
set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]
|
|
|
|
}
|
2006-11-24 00:09:10 +03:00
|
|
|
set u2 $units/s
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 [format {%12d uS %s %s} $tm $rate $u2]
|
2007-04-01 02:34:16 +04:00
|
|
|
global total_time
|
|
|
|
set total_time [expr {$total_time+$tm}]
|
2010-10-08 20:09:43 +04:00
|
|
|
lappend ::speed_trial_times $name $tm
|
2007-04-01 02:34:16 +04:00
|
|
|
}
|
2008-03-22 04:08:00 +03:00
|
|
|
proc speed_trial_tcl {name numstmt units script} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 -nonewline [format {%-21.21s } $name...]
|
2008-03-22 04:08:00 +03:00
|
|
|
flush stdout
|
|
|
|
set speed [time {eval $script}]
|
|
|
|
set tm [lindex $speed 0]
|
|
|
|
if {$tm == 0} {
|
|
|
|
set rate [format %20s "many"]
|
|
|
|
} else {
|
|
|
|
set rate [format %20.5f [expr {1000000.0*$numstmt/$tm}]]
|
|
|
|
}
|
|
|
|
set u2 $units/s
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 [format {%12d uS %s %s} $tm $rate $u2]
|
2008-03-22 04:08:00 +03:00
|
|
|
global total_time
|
|
|
|
set total_time [expr {$total_time+$tm}]
|
2010-10-08 20:09:43 +04:00
|
|
|
lappend ::speed_trial_times $name $tm
|
2008-03-22 04:08:00 +03:00
|
|
|
}
|
2007-04-01 02:34:16 +04:00
|
|
|
proc speed_trial_init {name} {
|
|
|
|
global total_time
|
|
|
|
set total_time 0
|
2010-10-08 20:09:43 +04:00
|
|
|
set ::speed_trial_times [list]
|
2010-07-03 16:00:53 +04:00
|
|
|
sqlite3 versdb :memory:
|
|
|
|
set vers [versdb one {SELECT sqlite_source_id()}]
|
|
|
|
versdb close
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "SQLite $vers"
|
2007-04-01 02:34:16 +04:00
|
|
|
}
|
|
|
|
proc speed_trial_summary {name} {
|
|
|
|
global total_time
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 [format {%-21.21s %12d uS TOTAL} $name $total_time]
|
2010-10-08 20:09:43 +04:00
|
|
|
|
|
|
|
if { 0 } {
|
|
|
|
sqlite3 versdb :memory:
|
|
|
|
set vers [lindex [versdb one {SELECT sqlite_source_id()}] 0]
|
|
|
|
versdb close
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "CREATE TABLE IF NOT EXISTS time(version, script, test, us);"
|
2010-10-08 20:09:43 +04:00
|
|
|
foreach {test us} $::speed_trial_times {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "INSERT INTO time VALUES('$vers', '$name', '$test', $us);"
|
2010-10-08 20:09:43 +04:00
|
|
|
}
|
|
|
|
}
|
2006-11-23 12:39:16 +03:00
|
|
|
}
|
|
|
|
|
2000-05-30 00:41:49 +04:00
|
|
|
# Run this routine last
|
|
|
|
#
|
|
|
|
proc finish_test {} {
|
2010-06-07 18:28:16 +04:00
|
|
|
catch {db close}
|
2014-07-31 21:35:40 +04:00
|
|
|
catch {db1 close}
|
2010-06-07 18:28:16 +04:00
|
|
|
catch {db2 close}
|
|
|
|
catch {db3 close}
|
|
|
|
if {0==[info exists ::SLAVE]} { finalize_testing }
|
2001-09-14 20:42:12 +04:00
|
|
|
}
|
|
|
|
proc finalize_testing {} {
|
2010-06-07 18:28:16 +04:00
|
|
|
global sqlite_open_file_count
|
|
|
|
|
|
|
|
set omitList [set_test_counter omit_list]
|
2005-12-09 17:25:08 +03:00
|
|
|
|
2000-06-08 17:36:40 +04:00
|
|
|
catch {db close}
|
2005-12-09 17:25:08 +03:00
|
|
|
catch {db2 close}
|
|
|
|
catch {db3 close}
|
|
|
|
|
2007-10-23 18:49:59 +04:00
|
|
|
vfs_unlink_test
|
2006-01-12 02:40:33 +03:00
|
|
|
sqlite3 db {}
|
2006-01-17 19:10:13 +03:00
|
|
|
# sqlite3_clear_tsd_memdebug
|
2006-01-12 02:40:33 +03:00
|
|
|
db close
|
2008-03-19 19:08:53 +03:00
|
|
|
sqlite3_reset_auto_extension
|
2010-06-07 18:28:16 +04:00
|
|
|
|
2019-11-14 20:46:32 +03:00
|
|
|
sqlite3_soft_heap_limit64 0
|
|
|
|
sqlite3_hard_heap_limit64 0
|
2010-06-07 18:28:16 +04:00
|
|
|
set nTest [incr_ntest]
|
|
|
|
set nErr [set_test_counter errors]
|
|
|
|
|
2013-05-23 00:49:02 +04:00
|
|
|
set nKnown 0
|
|
|
|
if {[file readable known-problems.txt]} {
|
|
|
|
set fd [open known-problems.txt]
|
|
|
|
set content [read $fd]
|
|
|
|
close $fd
|
|
|
|
foreach x $content {set known_error($x) 1}
|
|
|
|
foreach x [set_test_counter fail_list] {
|
|
|
|
if {[info exists known_error($x)]} {incr nKnown}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if {$nKnown>0} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "[expr {$nErr-$nKnown}] new errors and $nKnown known errors\
|
2013-05-23 00:49:02 +04:00
|
|
|
out of $nTest tests"
|
|
|
|
} else {
|
2016-01-07 05:06:55 +03:00
|
|
|
set cpuinfo {}
|
|
|
|
if {[catch {exec hostname} hname]==0} {set cpuinfo [string trim $hname]}
|
|
|
|
append cpuinfo " $::tcl_platform(os)"
|
|
|
|
append cpuinfo " [expr {$::tcl_platform(pointerSize)*8}]-bit"
|
|
|
|
append cpuinfo " [string map {E -e} $::tcl_platform(byteOrder)]"
|
|
|
|
output2 "SQLite [sqlite3 -sourceid]"
|
|
|
|
output2 "$nErr errors out of $nTest tests on $cpuinfo"
|
2013-05-23 00:49:02 +04:00
|
|
|
}
|
|
|
|
if {$nErr>$nKnown} {
|
2015-11-13 03:03:14 +03:00
|
|
|
output2 -nonewline "!Failures on these tests:"
|
2013-05-23 00:49:02 +04:00
|
|
|
foreach x [set_test_counter fail_list] {
|
2015-06-09 18:58:28 +03:00
|
|
|
if {![info exists known_error($x)]} {output2 -nonewline " $x"}
|
2013-05-23 00:49:02 +04:00
|
|
|
}
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 ""
|
2007-08-23 00:18:21 +04:00
|
|
|
}
|
2013-04-19 16:32:52 +04:00
|
|
|
foreach warning [set_test_counter warn_list] {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Warning: $warning"
|
2013-04-19 16:32:52 +04:00
|
|
|
}
|
2009-03-26 20:13:06 +03:00
|
|
|
run_thread_tests 1
|
2008-04-15 06:36:33 +04:00
|
|
|
if {[llength $omitList]>0} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Omitted test cases:"
|
2008-04-15 06:36:33 +04:00
|
|
|
set prec {}
|
|
|
|
foreach {rec} [lsort $omitList] {
|
|
|
|
if {$rec==$prec} continue
|
|
|
|
set prec $rec
|
2015-11-13 00:42:40 +03:00
|
|
|
output2 [format {. %-12s %s} [lindex $rec 0] [lindex $rec 1]]
|
2008-04-15 06:36:33 +04:00
|
|
|
}
|
|
|
|
}
|
2006-09-02 18:50:23 +04:00
|
|
|
if {$nErr>0 && ![working_64bit_int]} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "******************************************************************"
|
|
|
|
output2 "N.B.: The version of TCL that you used to build this test harness"
|
|
|
|
output2 "is defective in that it does not support 64-bit integers. Some or"
|
|
|
|
output2 "all of the test failures above might be a result from this defect"
|
|
|
|
output2 "in your TCL build."
|
|
|
|
output2 "******************************************************************"
|
2001-03-15 21:21:22 +03:00
|
|
|
}
|
2010-06-07 18:28:16 +04:00
|
|
|
if {$::cmdlinearg(binarylog)} {
|
2010-05-12 23:02:35 +04:00
|
|
|
vfslog finalize binarylog
|
2008-05-08 19:58:06 +04:00
|
|
|
}
|
2003-02-17 01:21:32 +03:00
|
|
|
if {$sqlite_open_file_count} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "$sqlite_open_file_count files were left open"
|
2003-02-17 01:21:32 +03:00
|
|
|
incr nErr
|
|
|
|
}
|
2010-07-26 22:43:40 +04:00
|
|
|
if {[lindex [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0] 1]>0 ||
|
|
|
|
[sqlite3_memory_used]>0} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Unfreed memory: [sqlite3_memory_used] bytes in\
|
2010-07-26 22:43:40 +04:00
|
|
|
[lindex [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0] 1] allocations"
|
2007-08-23 00:18:21 +04:00
|
|
|
incr nErr
|
2018-09-18 20:00:06 +03:00
|
|
|
ifcapable mem5||(mem3&&debug) {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Writing unfreed memory log to \"./memleak.txt\""
|
2007-08-23 06:47:53 +04:00
|
|
|
sqlite3_memdebug_dump ./memleak.txt
|
|
|
|
}
|
2007-08-23 00:18:21 +04:00
|
|
|
} else {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "All memory allocations freed - no leaks"
|
2018-09-18 20:00:06 +03:00
|
|
|
ifcapable mem5 {
|
2007-10-15 23:34:32 +04:00
|
|
|
sqlite3_memdebug_dump ./memusage.txt
|
|
|
|
}
|
2007-08-23 00:18:21 +04:00
|
|
|
}
|
2008-06-19 04:16:08 +04:00
|
|
|
show_memstats
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Maximum memory usage: [sqlite3_memory_highwater 1] bytes"
|
|
|
|
output2 "Current memory usage: [sqlite3_memory_highwater] bytes"
|
2008-02-13 21:25:27 +03:00
|
|
|
if {[info commands sqlite3_memdebug_malloc_count] ne ""} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Number of malloc() : [sqlite3_memdebug_malloc_count] calls"
|
2008-02-13 21:25:27 +03:00
|
|
|
}
|
2010-06-07 18:28:16 +04:00
|
|
|
if {$::cmdlinearg(malloctrace)} {
|
2018-09-18 20:00:06 +03:00
|
|
|
output2 "Writing mallocs.tcl..."
|
|
|
|
memdebug_log_sql mallocs.tcl
|
2008-03-21 20:29:37 +03:00
|
|
|
sqlite3_memdebug_log stop
|
|
|
|
sqlite3_memdebug_log clear
|
2008-03-28 10:42:53 +03:00
|
|
|
if {[sqlite3_memory_used]>0} {
|
2018-09-18 20:00:06 +03:00
|
|
|
output2 "Writing leaks.tcl..."
|
2008-03-28 10:42:53 +03:00
|
|
|
sqlite3_memdebug_log sync
|
2018-09-18 20:00:06 +03:00
|
|
|
memdebug_log_sql leaks.tcl
|
2008-03-28 10:42:53 +03:00
|
|
|
}
|
2008-03-21 20:29:37 +03:00
|
|
|
}
|
2019-04-01 20:24:20 +03:00
|
|
|
if {[info commands vdbe_coverage]!=""} {
|
|
|
|
vdbe_coverage_report
|
|
|
|
}
|
2006-10-04 15:55:49 +04:00
|
|
|
foreach f [glob -nocomplain test.db-*-journal] {
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete $f
|
2006-10-04 15:55:49 +04:00
|
|
|
}
|
|
|
|
foreach f [glob -nocomplain test.db-mj*] {
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete $f
|
2006-10-04 15:55:49 +04:00
|
|
|
}
|
2001-03-15 21:21:22 +03:00
|
|
|
exit [expr {$nErr>0}]
|
2000-05-30 00:41:49 +04:00
|
|
|
}
|
|
|
|
|
2019-04-01 20:24:20 +03:00
|
|
|
proc vdbe_coverage_report {} {
|
|
|
|
puts "Writing vdbe coverage report to vdbe_coverage.txt"
|
|
|
|
set lSrc [list]
|
|
|
|
set iLine 0
|
|
|
|
if {[file exists ../sqlite3.c]} {
|
|
|
|
set fd [open ../sqlite3.c]
|
|
|
|
set iLine
|
|
|
|
while { ![eof $fd] } {
|
|
|
|
set line [gets $fd]
|
|
|
|
incr iLine
|
|
|
|
if {[regexp {^/\** Begin file (.*\.c) \**/} $line -> file]} {
|
|
|
|
lappend lSrc [list $iLine $file]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
set fd [open vdbe_coverage.txt w]
|
|
|
|
foreach miss [vdbe_coverage report] {
|
2019-04-01 21:43:09 +03:00
|
|
|
foreach {line branch never} $miss {}
|
2019-04-01 20:24:20 +03:00
|
|
|
set nextfile ""
|
|
|
|
while {[llength $lSrc]>0 && [lindex $lSrc 0 0] < $line} {
|
|
|
|
set nextfile [lindex $lSrc 0 1]
|
|
|
|
set lSrc [lrange $lSrc 1 end]
|
|
|
|
}
|
|
|
|
if {$nextfile != ""} {
|
|
|
|
puts $fd ""
|
|
|
|
puts $fd "### $nextfile ###"
|
|
|
|
}
|
2019-04-01 21:43:09 +03:00
|
|
|
puts $fd "Vdbe branch $line: never $never (path $branch)"
|
2019-04-01 20:24:20 +03:00
|
|
|
}
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
|
2008-06-19 04:16:08 +04:00
|
|
|
# Display memory statistics for analysis and debugging purposes.
|
|
|
|
#
|
|
|
|
proc show_memstats {} {
|
|
|
|
set x [sqlite3_status SQLITE_STATUS_MEMORY_USED 0]
|
2008-08-05 21:53:22 +04:00
|
|
|
set y [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0]
|
|
|
|
set val [format {now %10d max %10d max-size %10d} \
|
|
|
|
[lindex $x 1] [lindex $x 2] [lindex $y 2]]
|
2015-06-09 18:58:28 +03:00
|
|
|
output1 "Memory used: $val"
|
2010-07-26 22:43:40 +04:00
|
|
|
set x [sqlite3_status SQLITE_STATUS_MALLOC_COUNT 0]
|
|
|
|
set val [format {now %10d max %10d} [lindex $x 1] [lindex $x 2]]
|
2015-06-09 18:58:28 +03:00
|
|
|
output1 "Allocation count: $val"
|
2008-06-19 04:16:08 +04:00
|
|
|
set x [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0]
|
2008-08-05 21:53:22 +04:00
|
|
|
set y [sqlite3_status SQLITE_STATUS_PAGECACHE_SIZE 0]
|
|
|
|
set val [format {now %10d max %10d max-size %10d} \
|
|
|
|
[lindex $x 1] [lindex $x 2] [lindex $y 2]]
|
2015-06-09 18:58:28 +03:00
|
|
|
output1 "Page-cache used: $val"
|
2008-06-19 04:16:08 +04:00
|
|
|
set x [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0]
|
|
|
|
set val [format {now %10d max %10d} [lindex $x 1] [lindex $x 2]]
|
2015-06-09 18:58:28 +03:00
|
|
|
output1 "Page-cache overflow: $val"
|
2008-07-25 19:39:03 +04:00
|
|
|
ifcapable yytrackmaxstackdepth {
|
|
|
|
set x [sqlite3_status SQLITE_STATUS_PARSER_STACK 0]
|
|
|
|
set val [format { max %10d} [lindex $x 2]]
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Parser stack depth: $val"
|
2008-07-25 19:39:03 +04:00
|
|
|
}
|
2008-06-19 04:16:08 +04:00
|
|
|
}
|
|
|
|
|
2000-05-30 00:41:49 +04:00
|
|
|
# A procedure to execute SQL
|
|
|
|
#
|
2001-04-04 15:48:57 +04:00
|
|
|
proc execsql {sql {db db}} {
|
2001-01-22 03:31:53 +03:00
|
|
|
# puts "SQL = $sql"
|
2006-01-17 12:35:01 +03:00
|
|
|
uplevel [list $db eval $sql]
|
2000-05-30 00:41:49 +04:00
|
|
|
}
|
2014-01-24 18:37:44 +04:00
|
|
|
proc execsql_timed {sql {db db}} {
|
|
|
|
set tm [time {
|
|
|
|
set x [uplevel [list $db eval $sql]]
|
|
|
|
} 1]
|
|
|
|
set tm [lindex $tm 0]
|
2015-06-09 18:58:28 +03:00
|
|
|
output1 -nonewline " ([expr {$tm*0.001}]ms) "
|
2014-01-24 18:37:44 +04:00
|
|
|
set x
|
|
|
|
}
|
2000-05-31 21:59:25 +04:00
|
|
|
|
2001-09-27 19:11:53 +04:00
|
|
|
# Execute SQL and catch exceptions.
|
|
|
|
#
|
|
|
|
proc catchsql {sql {db db}} {
|
|
|
|
# puts "SQL = $sql"
|
2009-11-28 15:40:32 +03:00
|
|
|
set r [catch [list uplevel [list $db eval $sql]] msg]
|
2001-09-27 19:11:53 +04:00
|
|
|
lappend r $msg
|
|
|
|
return $r
|
|
|
|
}
|
|
|
|
|
2001-11-10 01:41:44 +03:00
|
|
|
# Do an VDBE code dump on the SQL given
|
|
|
|
#
|
|
|
|
proc explain {sql {db db}} {
|
2015-06-11 02:02:38 +03:00
|
|
|
output2 ""
|
|
|
|
output2 "addr opcode p1 p2 p3 p4 p5 #"
|
|
|
|
output2 "---- ------------ ------ ------ ------ --------------- -- -"
|
2001-11-10 01:41:44 +03:00
|
|
|
$db eval "explain $sql" {} {
|
2015-06-11 02:02:38 +03:00
|
|
|
output2 [format {%-4d %-12.12s %-6d %-6d %-6d % -17s %s %s} \
|
2008-01-04 22:10:28 +03:00
|
|
|
$addr $opcode $p1 $p2 $p3 $p4 $p5 $comment
|
|
|
|
]
|
2001-11-10 01:41:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:19:22 +04:00
|
|
|
proc explain_i {sql {db db}} {
|
2015-06-11 02:02:38 +03:00
|
|
|
output2 ""
|
|
|
|
output2 "addr opcode p1 p2 p3 p4 p5 #"
|
|
|
|
output2 "---- ------------ ------ ------ ------ ---------------- -- -"
|
2013-11-05 18:19:22 +04:00
|
|
|
|
|
|
|
|
2013-11-06 18:52:40 +04:00
|
|
|
# Set up colors for the different opcodes. Scheme is as follows:
|
|
|
|
#
|
|
|
|
# Red: Opcodes that write to a b-tree.
|
|
|
|
# Blue: Opcodes that reposition or seek a cursor.
|
|
|
|
# Green: The ResultRow opcode.
|
|
|
|
#
|
2014-03-03 20:48:47 +04:00
|
|
|
if { [catch {fconfigure stdout -mode}]==0 } {
|
|
|
|
set R "\033\[31;1m" ;# Red fg
|
|
|
|
set G "\033\[32;1m" ;# Green fg
|
|
|
|
set B "\033\[34;1m" ;# Red fg
|
|
|
|
set D "\033\[39;0m" ;# Default fg
|
|
|
|
} else {
|
|
|
|
set R ""
|
|
|
|
set G ""
|
|
|
|
set B ""
|
|
|
|
set D ""
|
|
|
|
}
|
2013-11-06 18:52:40 +04:00
|
|
|
foreach opcode {
|
2016-07-26 21:06:08 +03:00
|
|
|
Seek SeekGE SeekGT SeekLE SeekLT NotFound Last Rewind
|
2013-11-12 16:30:09 +04:00
|
|
|
NoConflict Next Prev VNext VPrev VFilter
|
2016-07-26 21:06:08 +03:00
|
|
|
SorterSort SorterNext NextIfOpen
|
2013-11-06 18:52:40 +04:00
|
|
|
} {
|
|
|
|
set color($opcode) $B
|
|
|
|
}
|
|
|
|
foreach opcode {ResultRow} {
|
|
|
|
set color($opcode) $G
|
|
|
|
}
|
|
|
|
foreach opcode {IdxInsert Insert Delete IdxDelete} {
|
|
|
|
set color($opcode) $R
|
|
|
|
}
|
|
|
|
|
2013-11-05 20:39:31 +04:00
|
|
|
set bSeenGoto 0
|
2013-11-05 18:19:22 +04:00
|
|
|
$db eval "explain $sql" {} {
|
|
|
|
set x($addr) 0
|
|
|
|
set op($addr) $opcode
|
|
|
|
|
2013-11-05 20:39:31 +04:00
|
|
|
if {$opcode == "Goto" && ($bSeenGoto==0 || ($p2 > $addr+10))} {
|
|
|
|
set linebreak($p2) 1
|
|
|
|
set bSeenGoto 1
|
2013-11-05 18:19:22 +04:00
|
|
|
}
|
|
|
|
|
2016-07-26 21:06:08 +03:00
|
|
|
if {$opcode=="Once"} {
|
|
|
|
for {set i $addr} {$i<$p2} {incr i} {
|
|
|
|
set star($i) $addr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 16:30:09 +04:00
|
|
|
if {$opcode=="Next" || $opcode=="Prev"
|
|
|
|
|| $opcode=="VNext" || $opcode=="VPrev"
|
2016-07-26 21:06:08 +03:00
|
|
|
|| $opcode=="SorterNext" || $opcode=="NextIfOpen"
|
2013-11-12 16:30:09 +04:00
|
|
|
} {
|
2013-11-05 18:19:22 +04:00
|
|
|
for {set i $p2} {$i<$addr} {incr i} {
|
|
|
|
incr x($i) 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$opcode == "Goto" && $p2<$addr && $op($p2)=="Yield"} {
|
|
|
|
for {set i [expr $p2+1]} {$i<$addr} {incr i} {
|
|
|
|
incr x($i) 2
|
|
|
|
}
|
|
|
|
}
|
2013-11-05 20:39:31 +04:00
|
|
|
|
|
|
|
if {$opcode == "Halt" && $comment == "End of coroutine"} {
|
|
|
|
set linebreak([expr $addr+1]) 1
|
|
|
|
}
|
2013-11-05 18:19:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$db eval "explain $sql" {} {
|
2013-11-05 20:39:31 +04:00
|
|
|
if {[info exists linebreak($addr)]} {
|
2015-06-11 02:02:38 +03:00
|
|
|
output2 ""
|
2013-11-05 18:19:22 +04:00
|
|
|
}
|
|
|
|
set I [string repeat " " $x($addr)]
|
2013-11-06 18:52:40 +04:00
|
|
|
|
2016-07-26 21:06:08 +03:00
|
|
|
if {[info exists star($addr)]} {
|
|
|
|
set ii [expr $x($star($addr))]
|
|
|
|
append I " "
|
|
|
|
set I [string replace $I $ii $ii *]
|
|
|
|
}
|
|
|
|
|
2013-11-06 18:52:40 +04:00
|
|
|
set col ""
|
|
|
|
catch { set col $color($opcode) }
|
|
|
|
|
2015-06-11 02:02:38 +03:00
|
|
|
output2 [format {%-4d %s%s%-12.12s%s %-6d %-6d %-6d % -17s %s %s} \
|
2013-11-06 18:52:40 +04:00
|
|
|
$addr $I $col $opcode $D $p1 $p2 $p3 $p4 $p5 $comment
|
2013-11-05 18:19:22 +04:00
|
|
|
]
|
|
|
|
}
|
2015-06-11 02:02:38 +03:00
|
|
|
output2 "---- ------------ ------ ------ ------ ---------------- -- -"
|
2013-11-05 18:19:22 +04:00
|
|
|
}
|
|
|
|
|
2008-04-17 23:14:02 +04:00
|
|
|
# Show the VDBE program for an SQL statement but omit the Trace
|
|
|
|
# opcode at the beginning. This procedure can be used to prove
|
|
|
|
# that different SQL statements generate exactly the same VDBE code.
|
|
|
|
#
|
|
|
|
proc explain_no_trace {sql} {
|
|
|
|
set tr [db eval "EXPLAIN $sql"]
|
|
|
|
return [lrange $tr 7 end]
|
|
|
|
}
|
|
|
|
|
2000-05-31 21:59:25 +04:00
|
|
|
# Another procedure to execute SQL. This one includes the field
|
|
|
|
# names in the returned list.
|
|
|
|
#
|
|
|
|
proc execsql2 {sql} {
|
|
|
|
set result {}
|
|
|
|
db eval $sql data {
|
|
|
|
foreach f $data(*) {
|
|
|
|
lappend result $f $data($f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result
|
|
|
|
}
|
2001-01-31 16:28:08 +03:00
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# Use a temporary in-memory database to execute SQL statements
|
|
|
|
#
|
|
|
|
proc memdbsql {sql} {
|
|
|
|
sqlite3 memdb :memory:
|
|
|
|
set result [memdb eval $sql]
|
|
|
|
memdb close
|
|
|
|
return $result
|
|
|
|
}
|
|
|
|
|
2003-03-01 22:45:34 +03:00
|
|
|
# Use the non-callback API to execute multiple SQL statements
|
|
|
|
#
|
|
|
|
proc stepsql {dbptr sql} {
|
|
|
|
set sql [string trim $sql]
|
|
|
|
set r 0
|
|
|
|
while {[string length $sql]>0} {
|
2004-05-21 05:47:26 +04:00
|
|
|
if {[catch {sqlite3_prepare $dbptr $sql -1 sqltail} vm]} {
|
2003-03-01 22:45:34 +03:00
|
|
|
return [list 1 $vm]
|
|
|
|
}
|
|
|
|
set sql [string trim $sqltail]
|
2004-06-15 06:44:18 +04:00
|
|
|
# while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} {
|
|
|
|
# foreach v $VAL {lappend r $v}
|
|
|
|
# }
|
|
|
|
while {[sqlite3_step $vm]=="SQLITE_ROW"} {
|
|
|
|
for {set i 0} {$i<[sqlite3_data_count $vm]} {incr i} {
|
|
|
|
lappend r [sqlite3_column_text $vm $i]
|
|
|
|
}
|
2003-03-01 22:45:34 +03:00
|
|
|
}
|
2004-05-21 14:08:53 +04:00
|
|
|
if {[catch {sqlite3_finalize $vm} errmsg]} {
|
2003-03-01 22:45:34 +03:00
|
|
|
return [list 1 $errmsg]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $r
|
|
|
|
}
|
|
|
|
|
2002-06-25 17:16:02 +04:00
|
|
|
# Do an integrity check of the entire database
|
|
|
|
#
|
2009-02-03 19:51:24 +03:00
|
|
|
proc integrity_check {name {db db}} {
|
2004-10-31 00:23:09 +04:00
|
|
|
ifcapable integrityck {
|
2009-02-03 19:51:24 +03:00
|
|
|
do_test $name [list execsql {PRAGMA integrity_check} $db] {ok}
|
2004-10-31 00:23:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 19:37:11 +04:00
|
|
|
# Check the extended error code
|
|
|
|
#
|
|
|
|
proc verify_ex_errcode {name expected {db db}} {
|
|
|
|
do_test $name [list sqlite3_extended_errcode $db] $expected
|
|
|
|
}
|
|
|
|
|
2011-04-28 22:46:46 +04:00
|
|
|
|
|
|
|
# Return true if the SQL statement passed as the second argument uses a
|
|
|
|
# statement transaction.
|
|
|
|
#
|
|
|
|
proc sql_uses_stmt {db sql} {
|
|
|
|
set stmt [sqlite3_prepare $db $sql -1 dummy]
|
|
|
|
set uses [uses_stmt_journal $stmt]
|
|
|
|
sqlite3_finalize $stmt
|
|
|
|
return $uses
|
|
|
|
}
|
|
|
|
|
2008-01-16 11:24:46 +03:00
|
|
|
proc fix_ifcapable_expr {expr} {
|
|
|
|
set ret ""
|
|
|
|
set state 0
|
|
|
|
for {set i 0} {$i < [string length $expr]} {incr i} {
|
|
|
|
set char [string range $expr $i $i]
|
|
|
|
set newstate [expr {[string is alnum $char] || $char eq "_"}]
|
|
|
|
if {$newstate && !$state} {
|
|
|
|
append ret {$::sqlite_options(}
|
|
|
|
}
|
|
|
|
if {!$newstate && $state} {
|
|
|
|
append ret )
|
|
|
|
}
|
|
|
|
append ret $char
|
|
|
|
set state $newstate
|
|
|
|
}
|
|
|
|
if {$state} {append ret )}
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2012-09-13 05:51:02 +04:00
|
|
|
# Returns non-zero if the capabilities are present; zero otherwise.
|
|
|
|
#
|
|
|
|
proc capable {expr} {
|
|
|
|
set e [fix_ifcapable_expr $expr]; return [expr ($e)]
|
|
|
|
}
|
|
|
|
|
2004-10-31 00:23:09 +04:00
|
|
|
# Evaluate a boolean expression of capabilities. If true, execute the
|
|
|
|
# code. Omit the code if false.
|
|
|
|
#
|
2005-01-21 06:12:14 +03:00
|
|
|
proc ifcapable {expr code {else ""} {elsecode ""}} {
|
2008-01-16 11:24:46 +03:00
|
|
|
#regsub -all {[a-z_0-9]+} $expr {$::sqlite_options(&)} e2
|
|
|
|
set e2 [fix_ifcapable_expr $expr]
|
2005-01-21 06:12:14 +03:00
|
|
|
if ($e2) {
|
|
|
|
set c [catch {uplevel 1 $code} r]
|
|
|
|
} else {
|
|
|
|
set c [catch {uplevel 1 $elsecode} r]
|
|
|
|
}
|
|
|
|
return -code $c $r
|
2002-06-25 17:16:02 +04:00
|
|
|
}
|
2004-11-10 18:27:38 +03:00
|
|
|
|
2005-01-13 14:07:52 +03:00
|
|
|
# This proc execs a seperate process that crashes midway through executing
|
|
|
|
# the SQL script $sql on database test.db.
|
|
|
|
#
|
|
|
|
# The crash occurs during a sync() of file $crashfile. When the crash
|
|
|
|
# occurs a random subset of all unsynced writes made by the process are
|
|
|
|
# written into the files on disk. Argument $crashdelay indicates the
|
|
|
|
# number of file syncs to wait before crashing.
|
|
|
|
#
|
|
|
|
# The return value is a list of two elements. The first element is a
|
|
|
|
# boolean, indicating whether or not the process actually crashed or
|
|
|
|
# reported some other error. The second element in the returned list is the
|
|
|
|
# error message. This is "child process exited abnormally" if the crash
|
2013-03-22 01:20:32 +04:00
|
|
|
# occurred.
|
2005-01-13 14:07:52 +03:00
|
|
|
#
|
2007-08-23 15:07:10 +04:00
|
|
|
# crashsql -delay CRASHDELAY -file CRASHFILE ?-blocksize BLOCKSIZE? $sql
|
2007-03-17 13:26:59 +03:00
|
|
|
#
|
|
|
|
proc crashsql {args} {
|
|
|
|
|
|
|
|
set blocksize ""
|
|
|
|
set crashdelay 1
|
2008-01-08 18:18:52 +03:00
|
|
|
set prngseed 0
|
2013-12-10 00:42:03 +04:00
|
|
|
set opendb { sqlite3 db test.db -vfs crash }
|
2008-01-08 19:03:49 +03:00
|
|
|
set tclbody {}
|
2007-03-17 13:26:59 +03:00
|
|
|
set crashfile ""
|
2007-08-23 15:07:10 +04:00
|
|
|
set dc ""
|
2017-03-02 17:51:47 +03:00
|
|
|
set dfltvfs 0
|
2007-03-17 13:26:59 +03:00
|
|
|
set sql [lindex $args end]
|
2013-08-29 05:09:14 +04:00
|
|
|
|
2007-03-17 13:26:59 +03:00
|
|
|
for {set ii 0} {$ii < [llength $args]-1} {incr ii 2} {
|
|
|
|
set z [lindex $args $ii]
|
|
|
|
set n [string length $z]
|
|
|
|
set z2 [lindex $args [expr $ii+1]]
|
|
|
|
|
|
|
|
if {$n>1 && [string first $z -delay]==0} {set crashdelay $z2} \
|
2013-12-10 00:42:03 +04:00
|
|
|
elseif {$n>1 && [string first $z -opendb]==0} {set opendb $z2} \
|
2008-01-08 18:18:52 +03:00
|
|
|
elseif {$n>1 && [string first $z -seed]==0} {set prngseed $z2} \
|
2007-03-17 13:26:59 +03:00
|
|
|
elseif {$n>1 && [string first $z -file]==0} {set crashfile $z2} \
|
2008-01-08 19:03:49 +03:00
|
|
|
elseif {$n>1 && [string first $z -tclbody]==0} {set tclbody $z2} \
|
2007-08-20 18:23:44 +04:00
|
|
|
elseif {$n>1 && [string first $z -blocksize]==0} {set blocksize "-s $z2" } \
|
2017-03-02 17:51:47 +03:00
|
|
|
elseif {$n>1 && [string first $z -characteristics]==0} {set dc "-c {$z2}" }\
|
|
|
|
elseif {$n>1 && [string first $z -dfltvfs]==0} {set dfltvfs $z2 }\
|
2007-03-17 13:26:59 +03:00
|
|
|
else { error "Unrecognized option: $z" }
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$crashfile eq ""} {
|
|
|
|
error "Compulsory option -file missing"
|
|
|
|
}
|
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# $crashfile gets compared to the native filename in
|
2010-07-08 20:30:44 +04:00
|
|
|
# cfSync(), which can be different then what TCL uses by
|
|
|
|
# default, so here we force it to the "nativename" format.
|
2012-03-09 00:00:36 +04:00
|
|
|
set cfile [string map {\\ \\\\} [file nativename [file join [get_pwd] $crashfile]]]
|
2005-01-13 14:07:52 +03:00
|
|
|
|
|
|
|
set f [open crash.tcl w]
|
2021-01-07 19:29:34 +03:00
|
|
|
puts $f "sqlite3_initialize ; sqlite3_shutdown"
|
|
|
|
puts $f "catch { install_malloc_faultsim 1 }"
|
2017-03-02 17:51:47 +03:00
|
|
|
puts $f "sqlite3_crash_enable 1 $dfltvfs"
|
2007-08-23 15:07:10 +04:00
|
|
|
puts $f "sqlite3_crashparams $blocksize $dc $crashdelay $cfile"
|
2009-02-05 19:31:45 +03:00
|
|
|
puts $f "sqlite3_test_control_pending_byte $::sqlite_pending_byte"
|
2021-01-07 19:29:34 +03:00
|
|
|
puts $f "autoinstall_test_functions"
|
2007-03-17 10:22:42 +03:00
|
|
|
|
|
|
|
# This block sets the cache size of the main database to 10
|
|
|
|
# pages. This is done in case the build is configured to omit
|
|
|
|
# "PRAGMA cache_size".
|
2015-04-17 11:36:05 +03:00
|
|
|
if {$opendb!=""} {
|
|
|
|
puts $f $opendb
|
|
|
|
puts $f {db eval {SELECT * FROM sqlite_master;}}
|
|
|
|
puts $f {set bt [btree_from_db db]}
|
|
|
|
puts $f {btree_set_cache_size $bt 10}
|
|
|
|
}
|
2013-12-10 00:42:03 +04:00
|
|
|
|
2008-01-08 18:18:52 +03:00
|
|
|
if {$prngseed} {
|
|
|
|
set seed [expr {$prngseed%10007+1}]
|
|
|
|
# puts seed=$seed
|
|
|
|
puts $f "db eval {SELECT randomblob($seed)}"
|
|
|
|
}
|
2007-03-17 10:22:42 +03:00
|
|
|
|
2008-01-08 19:03:49 +03:00
|
|
|
if {[string length $tclbody]>0} {
|
|
|
|
puts $f $tclbody
|
|
|
|
}
|
|
|
|
if {[string length $sql]>0} {
|
|
|
|
puts $f "db eval {"
|
|
|
|
puts $f "$sql"
|
|
|
|
puts $f "}"
|
|
|
|
}
|
2005-01-13 14:07:52 +03:00
|
|
|
close $f
|
|
|
|
set r [catch {
|
2021-01-07 19:29:34 +03:00
|
|
|
exec [info nameofexec] crash.tcl >@stdout 2>@stdout
|
2005-01-13 14:07:52 +03:00
|
|
|
} msg]
|
2013-08-29 05:09:14 +04:00
|
|
|
|
2017-07-22 23:12:31 +03:00
|
|
|
# Windows/ActiveState TCL returns a slightly different
|
|
|
|
# error message. We map that to the expected message
|
|
|
|
# so that we don't have to change all of the test
|
|
|
|
# cases.
|
|
|
|
if {$::tcl_platform(platform)=="windows"} {
|
|
|
|
if {$msg=="child killed: unknown signal"} {
|
|
|
|
set msg "child process exited abnormally"
|
|
|
|
}
|
|
|
|
}
|
2020-11-23 18:30:16 +03:00
|
|
|
if {$r && [string match {*ERROR: LeakSanitizer*} $msg]} {
|
|
|
|
set msg "child process exited abnormally"
|
|
|
|
}
|
2017-07-22 23:12:31 +03:00
|
|
|
|
|
|
|
lappend r $msg
|
|
|
|
}
|
|
|
|
|
|
|
|
# crash_on_write ?-devchar DEVCHAR? CRASHDELAY SQL
|
|
|
|
#
|
|
|
|
proc crash_on_write {args} {
|
|
|
|
|
|
|
|
set nArg [llength $args]
|
|
|
|
if {$nArg<2 || $nArg%2} {
|
|
|
|
error "bad args: $args"
|
|
|
|
}
|
|
|
|
set zSql [lindex $args end]
|
|
|
|
set nDelay [lindex $args end-1]
|
|
|
|
|
|
|
|
set devchar {}
|
|
|
|
for {set ii 0} {$ii < $nArg-2} {incr ii 2} {
|
|
|
|
set opt [lindex $args $ii]
|
|
|
|
switch -- [lindex $args $ii] {
|
|
|
|
-devchar {
|
|
|
|
set devchar [lindex $args [expr $ii+1]]
|
|
|
|
}
|
|
|
|
|
|
|
|
default { error "unrecognized option: $opt" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set f [open crash.tcl w]
|
|
|
|
puts $f "sqlite3_crash_on_write $nDelay"
|
|
|
|
puts $f "sqlite3_test_control_pending_byte $::sqlite_pending_byte"
|
|
|
|
puts $f "sqlite3 db test.db -vfs writecrash"
|
|
|
|
puts $f "db eval {$zSql}"
|
|
|
|
puts $f "set {} {}"
|
|
|
|
|
|
|
|
close $f
|
|
|
|
set r [catch {
|
|
|
|
exec [info nameofexec] crash.tcl >@stdout
|
|
|
|
} msg]
|
|
|
|
|
2010-07-08 20:30:44 +04:00
|
|
|
# Windows/ActiveState TCL returns a slightly different
|
|
|
|
# error message. We map that to the expected message
|
|
|
|
# so that we don't have to change all of the test
|
|
|
|
# cases.
|
|
|
|
if {$::tcl_platform(platform)=="windows"} {
|
|
|
|
if {$msg=="child killed: unknown signal"} {
|
|
|
|
set msg "child process exited abnormally"
|
|
|
|
}
|
|
|
|
}
|
2013-08-29 05:09:14 +04:00
|
|
|
|
2005-01-13 14:07:52 +03:00
|
|
|
lappend r $msg
|
|
|
|
}
|
|
|
|
|
2013-02-23 22:58:11 +04:00
|
|
|
proc run_ioerr_prep {} {
|
|
|
|
set ::sqlite_io_error_pending 0
|
|
|
|
catch {db close}
|
|
|
|
catch {db2 close}
|
|
|
|
catch {forcedelete test.db}
|
|
|
|
catch {forcedelete test.db-journal}
|
|
|
|
catch {forcedelete test2.db}
|
|
|
|
catch {forcedelete test2.db-journal}
|
|
|
|
set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
|
|
|
|
sqlite3_extended_result_codes $::DB $::ioerropts(-erc)
|
|
|
|
if {[info exists ::ioerropts(-tclprep)]} {
|
|
|
|
eval $::ioerropts(-tclprep)
|
|
|
|
}
|
|
|
|
if {[info exists ::ioerropts(-sqlprep)]} {
|
|
|
|
execsql $::ioerropts(-sqlprep)
|
|
|
|
}
|
|
|
|
expr 0
|
|
|
|
}
|
|
|
|
|
2005-01-22 06:39:39 +03:00
|
|
|
# Usage: do_ioerr_test <test number> <options...>
|
|
|
|
#
|
|
|
|
# This proc is used to implement test cases that check that IO errors
|
2013-08-29 05:09:14 +04:00
|
|
|
# are correctly handled. The first argument, <test number>, is an integer
|
2005-01-22 06:39:39 +03:00
|
|
|
# used to name the tests executed by this proc. Options are as follows:
|
|
|
|
#
|
|
|
|
# -tclprep TCL script to run to prepare test.
|
|
|
|
# -sqlprep SQL script to run to prepare test.
|
|
|
|
# -tclbody TCL script to run with IO error simulation.
|
|
|
|
# -sqlbody TCL script to run with IO error simulation.
|
|
|
|
# -exclude List of 'N' values not to test.
|
2006-09-15 11:28:50 +04:00
|
|
|
# -erc Use extended result codes
|
2007-03-15 15:17:42 +03:00
|
|
|
# -persist Make simulated I/O errors persistent
|
2005-01-22 06:39:39 +03:00
|
|
|
# -start Value of 'N' to begin with (default 1)
|
|
|
|
#
|
|
|
|
# -cksum Boolean. If true, test that the database does
|
|
|
|
# not change during the execution of the test case.
|
|
|
|
#
|
|
|
|
proc do_ioerr_test {testname args} {
|
|
|
|
|
|
|
|
set ::ioerropts(-start) 1
|
|
|
|
set ::ioerropts(-cksum) 0
|
2006-09-15 11:28:50 +04:00
|
|
|
set ::ioerropts(-erc) 0
|
2007-01-04 17:58:14 +03:00
|
|
|
set ::ioerropts(-count) 100000000
|
2007-03-15 15:17:42 +03:00
|
|
|
set ::ioerropts(-persist) 1
|
2008-05-05 19:26:50 +04:00
|
|
|
set ::ioerropts(-ckrefcount) 0
|
2008-06-05 15:39:11 +04:00
|
|
|
set ::ioerropts(-restoreprng) 1
|
2005-01-22 06:39:39 +03:00
|
|
|
array set ::ioerropts $args
|
|
|
|
|
2008-05-12 16:41:15 +04:00
|
|
|
# TEMPORARY: For 3.5.9, disable testing of extended result codes. There are
|
|
|
|
# a couple of obscure IO errors that do not return them.
|
|
|
|
set ::ioerropts(-erc) 0
|
2013-08-29 05:09:14 +04:00
|
|
|
|
2013-02-23 22:58:11 +04:00
|
|
|
# Create a single TCL script from the TCL and SQL specified
|
|
|
|
# as the body of the test.
|
|
|
|
set ::ioerrorbody {}
|
|
|
|
if {[info exists ::ioerropts(-tclbody)]} {
|
|
|
|
append ::ioerrorbody "$::ioerropts(-tclbody)\n"
|
|
|
|
}
|
|
|
|
if {[info exists ::ioerropts(-sqlbody)]} {
|
|
|
|
append ::ioerrorbody "db eval {$::ioerropts(-sqlbody)}"
|
|
|
|
}
|
|
|
|
|
|
|
|
save_prng_state
|
|
|
|
if {$::ioerropts(-cksum)} {
|
|
|
|
run_ioerr_prep
|
|
|
|
eval $::ioerrorbody
|
|
|
|
set ::goodcksum [cksum]
|
|
|
|
}
|
2008-05-12 16:41:15 +04:00
|
|
|
|
2005-01-22 06:39:39 +03:00
|
|
|
set ::go 1
|
2008-01-16 20:46:38 +03:00
|
|
|
#reset_prng_state
|
2009-04-06 21:50:03 +04:00
|
|
|
for {set n $::ioerropts(-start)} {$::go} {incr n} {
|
2007-05-04 16:05:56 +04:00
|
|
|
set ::TN $n
|
2007-01-04 17:58:14 +03:00
|
|
|
incr ::ioerropts(-count) -1
|
|
|
|
if {$::ioerropts(-count)<0} break
|
2013-08-29 05:09:14 +04:00
|
|
|
|
2005-01-22 06:39:39 +03:00
|
|
|
# Skip this IO error if it was specified with the "-exclude" option.
|
|
|
|
if {[info exists ::ioerropts(-exclude)]} {
|
|
|
|
if {[lsearch $::ioerropts(-exclude) $n]!=-1} continue
|
|
|
|
}
|
2008-06-05 15:39:11 +04:00
|
|
|
if {$::ioerropts(-restoreprng)} {
|
|
|
|
restore_prng_state
|
|
|
|
}
|
2005-01-22 06:39:39 +03:00
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# Delete the files test.db and test2.db, then execute the TCL and
|
2005-01-22 06:39:39 +03:00
|
|
|
# SQL (in that order) to prepare for the test case.
|
|
|
|
do_test $testname.$n.1 {
|
2013-02-23 22:58:11 +04:00
|
|
|
run_ioerr_prep
|
2005-01-22 06:39:39 +03:00
|
|
|
} {0}
|
|
|
|
|
|
|
|
# Read the 'checksum' of the database.
|
|
|
|
if {$::ioerropts(-cksum)} {
|
2013-02-23 22:58:11 +04:00
|
|
|
set ::checksum [cksum]
|
2005-01-22 06:39:39 +03:00
|
|
|
}
|
2008-01-16 20:46:38 +03:00
|
|
|
|
2005-01-22 06:39:39 +03:00
|
|
|
# Set the Nth IO error to fail.
|
|
|
|
do_test $testname.$n.2 [subst {
|
2007-03-15 15:17:42 +03:00
|
|
|
set ::sqlite_io_error_persist $::ioerropts(-persist)
|
2005-01-22 06:39:39 +03:00
|
|
|
set ::sqlite_io_error_pending $n
|
|
|
|
}] $n
|
|
|
|
|
2013-02-23 22:58:11 +04:00
|
|
|
# Execute the TCL script created for the body of this test. If
|
2013-08-29 05:09:14 +04:00
|
|
|
# at least N IO operations performed by SQLite as a result of
|
2013-02-23 22:58:11 +04:00
|
|
|
# the script, the Nth will fail.
|
2005-01-22 06:39:39 +03:00
|
|
|
do_test $testname.$n.3 {
|
2008-03-07 22:51:14 +03:00
|
|
|
set ::sqlite_io_error_hit 0
|
|
|
|
set ::sqlite_io_error_hardhit 0
|
2005-01-22 06:39:39 +03:00
|
|
|
set r [catch $::ioerrorbody msg]
|
2008-03-07 22:51:14 +03:00
|
|
|
set ::errseen $r
|
2006-09-15 16:29:16 +04:00
|
|
|
set rc [sqlite3_errcode $::DB]
|
|
|
|
if {$::ioerropts(-erc)} {
|
2007-04-19 16:30:54 +04:00
|
|
|
# If we are in extended result code mode, make sure all of the
|
|
|
|
# IOERRs we get back really do have their extended code values.
|
|
|
|
# If an extended result code is returned, the sqlite3_errcode
|
|
|
|
# TCLcommand will return a string of the form: SQLITE_IOERR+nnnn
|
|
|
|
# where nnnn is a number
|
2006-09-15 16:29:16 +04:00
|
|
|
if {[regexp {^SQLITE_IOERR} $rc] && ![regexp {IOERR\+\d} $rc]} {
|
|
|
|
return $rc
|
|
|
|
}
|
|
|
|
} else {
|
2007-04-19 16:30:54 +04:00
|
|
|
# If we are not in extended result code mode, make sure no
|
|
|
|
# extended error codes are returned.
|
2006-09-15 16:29:16 +04:00
|
|
|
if {[regexp {\+\d} $rc]} {
|
|
|
|
return $rc
|
|
|
|
}
|
|
|
|
}
|
2008-01-16 20:46:38 +03:00
|
|
|
# The test repeats as long as $::go is non-zero. $::go starts out
|
|
|
|
# as 1. When a test runs to completion without hitting an I/O
|
|
|
|
# error, that means there is no point in continuing with this test
|
|
|
|
# case so set $::go to zero.
|
|
|
|
#
|
|
|
|
if {$::sqlite_io_error_pending>0} {
|
|
|
|
set ::go 0
|
|
|
|
set q 0
|
|
|
|
set ::sqlite_io_error_pending 0
|
|
|
|
} else {
|
|
|
|
set q 1
|
|
|
|
}
|
|
|
|
|
2005-11-05 01:03:30 +03:00
|
|
|
set s [expr $::sqlite_io_error_hit==0]
|
2008-03-07 22:51:14 +03:00
|
|
|
if {$::sqlite_io_error_hit>$::sqlite_io_error_hardhit && $r==0} {
|
|
|
|
set r 1
|
|
|
|
}
|
2006-01-24 16:09:33 +03:00
|
|
|
set ::sqlite_io_error_hit 0
|
2007-04-19 16:30:54 +04:00
|
|
|
|
|
|
|
# One of two things must have happened. either
|
|
|
|
# 1. We never hit the IO error and the SQL returned OK
|
|
|
|
# 2. An IO error was hit and the SQL failed
|
|
|
|
#
|
2010-05-06 19:56:28 +04:00
|
|
|
#puts "s=$s r=$r q=$q"
|
2008-01-16 20:46:38 +03:00
|
|
|
expr { ($s && !$r && !$q) || (!$s && $r && $q) }
|
2005-01-22 06:39:39 +03:00
|
|
|
} {1}
|
|
|
|
|
2008-05-12 14:57:02 +04:00
|
|
|
set ::sqlite_io_error_hit 0
|
|
|
|
set ::sqlite_io_error_pending 0
|
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# Check that no page references were leaked. There should be
|
|
|
|
# a single reference if there is still an active transaction,
|
2008-05-05 20:23:55 +04:00
|
|
|
# or zero otherwise.
|
|
|
|
#
|
2008-06-07 09:19:37 +04:00
|
|
|
# UPDATE: If the IO error occurs after a 'BEGIN' but before any
|
2013-08-29 05:09:14 +04:00
|
|
|
# locks are established on database files (i.e. if the error
|
2008-06-07 09:19:37 +04:00
|
|
|
# occurs while attempting to detect a hot-journal file), then
|
|
|
|
# there may 0 page references and an active transaction according
|
|
|
|
# to [sqlite3_get_autocommit].
|
|
|
|
#
|
2008-05-05 19:26:50 +04:00
|
|
|
if {$::go && $::sqlite_io_error_hardhit && $::ioerropts(-ckrefcount)} {
|
|
|
|
do_test $testname.$n.4 {
|
|
|
|
set bt [btree_from_db db]
|
|
|
|
db_enter db
|
|
|
|
array set stats [btree_pager_stats $bt]
|
|
|
|
db_leave db
|
2008-06-07 09:19:37 +04:00
|
|
|
set nRef $stats(ref)
|
|
|
|
expr {$nRef == 0 || ([sqlite3_get_autocommit db]==0 && $nRef == 1)}
|
|
|
|
} {1}
|
2008-05-05 19:26:50 +04:00
|
|
|
}
|
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# If there is an open database handle and no open transaction,
|
2008-05-05 20:23:55 +04:00
|
|
|
# and the pager is not running in exclusive-locking mode,
|
|
|
|
# check that the pager is in "unlocked" state. Theoretically,
|
|
|
|
# if a call to xUnlock() failed due to an IO error the underlying
|
|
|
|
# file may still be locked.
|
|
|
|
#
|
|
|
|
ifcapable pragma {
|
|
|
|
if { [info commands db] ne ""
|
2008-05-05 21:14:53 +04:00
|
|
|
&& $::ioerropts(-ckrefcount)
|
2008-05-05 20:23:55 +04:00
|
|
|
&& [db one {pragma locking_mode}] eq "normal"
|
|
|
|
&& [sqlite3_get_autocommit db]
|
|
|
|
} {
|
|
|
|
do_test $testname.$n.5 {
|
|
|
|
set bt [btree_from_db db]
|
|
|
|
db_enter db
|
|
|
|
array set stats [btree_pager_stats $bt]
|
|
|
|
db_leave db
|
|
|
|
set stats(state)
|
|
|
|
} 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 01:20:32 +04:00
|
|
|
# If an IO error occurred, then the checksum of the database should
|
2005-01-22 06:39:39 +03:00
|
|
|
# be the same as before the script that caused the IO error was run.
|
2008-05-05 20:23:55 +04:00
|
|
|
#
|
2008-03-07 22:51:14 +03:00
|
|
|
if {$::go && $::sqlite_io_error_hardhit && $::ioerropts(-cksum)} {
|
2008-05-05 21:14:53 +04:00
|
|
|
do_test $testname.$n.6 {
|
2005-01-22 06:39:39 +03:00
|
|
|
catch {db close}
|
2008-07-08 16:07:32 +04:00
|
|
|
catch {db2 close}
|
2006-01-07 01:11:20 +03:00
|
|
|
set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
|
2013-02-23 22:58:11 +04:00
|
|
|
set nowcksum [cksum]
|
|
|
|
set res [expr {$nowcksum==$::checksum || $nowcksum==$::goodcksum}]
|
|
|
|
if {$res==0} {
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "now=$nowcksum"
|
|
|
|
output2 "the=$::checksum"
|
|
|
|
output2 "fwd=$::goodcksum"
|
2013-02-23 22:58:11 +04:00
|
|
|
}
|
|
|
|
set res
|
|
|
|
} 1
|
2005-01-22 06:39:39 +03:00
|
|
|
}
|
|
|
|
|
2008-03-07 22:51:14 +03:00
|
|
|
set ::sqlite_io_error_hardhit 0
|
2006-01-21 15:08:54 +03:00
|
|
|
set ::sqlite_io_error_pending 0
|
2005-05-26 19:20:53 +04:00
|
|
|
if {[info exists ::ioerropts(-cleanup)]} {
|
|
|
|
catch $::ioerropts(-cleanup)
|
|
|
|
}
|
2005-01-22 06:39:39 +03:00
|
|
|
}
|
|
|
|
set ::sqlite_io_error_pending 0
|
2007-03-25 23:08:46 +04:00
|
|
|
set ::sqlite_io_error_persist 0
|
2005-01-22 06:39:39 +03:00
|
|
|
unset ::ioerropts
|
|
|
|
}
|
|
|
|
|
2008-01-16 20:46:38 +03:00
|
|
|
# Return a checksum based on the contents of the main database associated
|
|
|
|
# with connection $db
|
2005-01-22 06:39:39 +03:00
|
|
|
#
|
|
|
|
proc cksum {{db db}} {
|
|
|
|
set txt [$db eval {
|
|
|
|
SELECT name, type, sql FROM sqlite_master order by name
|
|
|
|
}]\n
|
|
|
|
foreach tbl [$db eval {
|
|
|
|
SELECT name FROM sqlite_master WHERE type='table' order by name
|
|
|
|
}] {
|
|
|
|
append txt [$db eval "SELECT * FROM $tbl"]\n
|
|
|
|
}
|
|
|
|
foreach prag {default_synchronous default_cache_size} {
|
|
|
|
append txt $prag-[$db eval "PRAGMA $prag"]\n
|
|
|
|
}
|
|
|
|
set cksum [string length $txt]-[md5 $txt]
|
|
|
|
# puts $cksum-[file size test.db]
|
|
|
|
return $cksum
|
|
|
|
}
|
|
|
|
|
2008-01-16 20:46:38 +03:00
|
|
|
# Generate a checksum based on the contents of the main and temp tables
|
|
|
|
# database $db. If the checksum of two databases is the same, and the
|
|
|
|
# integrity-check passes for both, the two databases are identical.
|
|
|
|
#
|
2008-01-17 05:36:28 +03:00
|
|
|
proc allcksum {{db db}} {
|
2008-01-16 20:46:38 +03:00
|
|
|
set ret [list]
|
|
|
|
ifcapable tempdb {
|
|
|
|
set sql {
|
|
|
|
SELECT name FROM sqlite_master WHERE type = 'table' UNION
|
|
|
|
SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION
|
|
|
|
SELECT 'sqlite_master' UNION
|
|
|
|
SELECT 'sqlite_temp_master' ORDER BY 1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set sql {
|
|
|
|
SELECT name FROM sqlite_master WHERE type = 'table' UNION
|
|
|
|
SELECT 'sqlite_master' ORDER BY 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set tbllist [$db eval $sql]
|
|
|
|
set txt {}
|
|
|
|
foreach tbl $tbllist {
|
|
|
|
append txt [$db eval "SELECT * FROM $tbl"]
|
|
|
|
}
|
|
|
|
foreach prag {default_cache_size} {
|
|
|
|
append txt $prag-[$db eval "PRAGMA $prag"]\n
|
|
|
|
}
|
|
|
|
# puts txt=$txt
|
|
|
|
return [md5 $txt]
|
2009-02-05 01:46:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate a checksum based on the contents of a single database with
|
2013-08-29 05:09:14 +04:00
|
|
|
# a database connection. The name of the database is $dbname.
|
2009-02-05 01:46:47 +03:00
|
|
|
# Examples of $dbname are "temp" or "main".
|
|
|
|
#
|
|
|
|
proc dbcksum {db dbname} {
|
|
|
|
if {$dbname=="temp"} {
|
|
|
|
set master sqlite_temp_master
|
|
|
|
} else {
|
|
|
|
set master $dbname.sqlite_master
|
|
|
|
}
|
|
|
|
set alltab [$db eval "SELECT name FROM $master WHERE type='table'"]
|
|
|
|
set txt [$db eval "SELECT * FROM $master"]\n
|
|
|
|
foreach tab $alltab {
|
|
|
|
append txt [$db eval "SELECT * FROM $dbname.$tab"]\n
|
|
|
|
}
|
|
|
|
return [md5 $txt]
|
2008-01-16 20:46:38 +03:00
|
|
|
}
|
|
|
|
|
2018-09-18 20:00:06 +03:00
|
|
|
proc memdebug_log_sql {filename} {
|
2008-03-21 20:29:37 +03:00
|
|
|
|
2008-03-21 17:22:44 +03:00
|
|
|
set data [sqlite3_memdebug_log dump]
|
|
|
|
set nFrame [expr [llength [lindex $data 0]]-2]
|
|
|
|
if {$nFrame < 0} { return "" }
|
|
|
|
|
2008-03-21 20:29:37 +03:00
|
|
|
set database temp
|
|
|
|
|
2009-02-19 17:39:25 +03:00
|
|
|
set tbl "CREATE TABLE ${database}.malloc(zTest, nCall, nByte, lStack);"
|
2008-03-21 17:22:44 +03:00
|
|
|
|
|
|
|
set sql ""
|
|
|
|
foreach e $data {
|
2009-02-19 17:39:25 +03:00
|
|
|
set nCall [lindex $e 0]
|
|
|
|
set nByte [lindex $e 1]
|
|
|
|
set lStack [lrange $e 2 end]
|
|
|
|
append sql "INSERT INTO ${database}.malloc VALUES"
|
|
|
|
append sql "('test', $nCall, $nByte, '$lStack');\n"
|
|
|
|
foreach f $lStack {
|
2008-03-21 17:22:44 +03:00
|
|
|
set frames($f) 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set tbl2 "CREATE TABLE ${database}.frame(frame INTEGER PRIMARY KEY, line);\n"
|
2008-03-21 20:29:37 +03:00
|
|
|
set tbl3 "CREATE TABLE ${database}.file(name PRIMARY KEY, content);\n"
|
2008-03-21 17:22:44 +03:00
|
|
|
|
2019-02-05 19:53:26 +03:00
|
|
|
set pid [pid]
|
|
|
|
|
2008-03-21 17:22:44 +03:00
|
|
|
foreach f [array names frames] {
|
|
|
|
set addr [format %x $f]
|
2019-02-05 19:53:26 +03:00
|
|
|
set cmd "eu-addr2line --pid=$pid $addr"
|
2008-03-21 17:22:44 +03:00
|
|
|
set line [eval exec $cmd]
|
|
|
|
append sql "INSERT INTO ${database}.frame VALUES($f, '$line');\n"
|
|
|
|
|
2008-03-21 20:29:37 +03:00
|
|
|
set file [lindex [split $line :] 0]
|
|
|
|
set files($file) 1
|
2008-03-21 17:22:44 +03:00
|
|
|
}
|
|
|
|
|
2008-03-21 20:29:37 +03:00
|
|
|
foreach f [array names files] {
|
|
|
|
set contents ""
|
|
|
|
catch {
|
|
|
|
set fd [open $f]
|
|
|
|
set contents [read $fd]
|
|
|
|
close $fd
|
2008-03-21 17:22:44 +03:00
|
|
|
}
|
2008-03-21 20:29:37 +03:00
|
|
|
set contents [string map {' ''} $contents]
|
|
|
|
append sql "INSERT INTO ${database}.file VALUES('$f', '$contents');\n"
|
2008-03-21 17:22:44 +03:00
|
|
|
}
|
|
|
|
|
2018-09-18 20:00:06 +03:00
|
|
|
set escaped "BEGIN; ${tbl}${tbl2}${tbl3}${sql} ; COMMIT;"
|
|
|
|
set escaped [string map [list "{" "\\{" "}" "\\}"] $escaped]
|
|
|
|
|
2008-03-21 20:29:37 +03:00
|
|
|
set fd [open $filename w]
|
2018-09-18 20:00:06 +03:00
|
|
|
puts $fd "set BUILTIN {"
|
|
|
|
puts $fd $escaped
|
|
|
|
puts $fd "}"
|
|
|
|
puts $fd {set BUILTIN [string map [list "\\{" "{" "\\}" "}"] $BUILTIN]}
|
|
|
|
set mtv [open $::testdir/malloctraceviewer.tcl]
|
|
|
|
set txt [read $mtv]
|
|
|
|
close $mtv
|
|
|
|
puts $fd $txt
|
2008-03-21 20:29:37 +03:00
|
|
|
close $fd
|
2008-03-21 17:22:44 +03:00
|
|
|
}
|
2008-01-16 20:46:38 +03:00
|
|
|
|
2009-10-07 22:41:19 +04:00
|
|
|
# Drop all tables in database [db]
|
|
|
|
proc drop_all_tables {{db db}} {
|
2009-12-18 01:12:51 +03:00
|
|
|
ifcapable trigger&&foreignkey {
|
|
|
|
set pk [$db one "PRAGMA foreign_keys"]
|
|
|
|
$db eval "PRAGMA foreign_keys = OFF"
|
|
|
|
}
|
2010-02-15 21:03:20 +03:00
|
|
|
foreach {idx name file} [db eval {PRAGMA database_list}] {
|
|
|
|
if {$idx==1} {
|
|
|
|
set master sqlite_temp_master
|
|
|
|
} else {
|
|
|
|
set master $name.sqlite_master
|
|
|
|
}
|
|
|
|
foreach {t type} [$db eval "
|
|
|
|
SELECT name, type FROM $master
|
2010-09-28 21:37:28 +04:00
|
|
|
WHERE type IN('table', 'view') AND name NOT LIKE 'sqliteX_%' ESCAPE 'X'
|
2010-02-15 21:03:20 +03:00
|
|
|
"] {
|
2010-09-28 21:37:28 +04:00
|
|
|
$db eval "DROP $type \"$t\""
|
2010-02-15 21:03:20 +03:00
|
|
|
}
|
2009-10-07 22:41:19 +04:00
|
|
|
}
|
2009-12-18 01:12:51 +03:00
|
|
|
ifcapable trigger&&foreignkey {
|
|
|
|
$db eval "PRAGMA foreign_keys = $pk"
|
|
|
|
}
|
2009-10-07 22:41:19 +04:00
|
|
|
}
|
|
|
|
|
2016-08-02 20:07:51 +03:00
|
|
|
# Drop all auxiliary indexes from the main database opened by handle [db].
|
|
|
|
#
|
|
|
|
proc drop_all_indexes {{db db}} {
|
|
|
|
set L [$db eval {
|
|
|
|
SELECT name FROM sqlite_master WHERE type='index' AND sql LIKE 'create%'
|
|
|
|
}]
|
|
|
|
foreach idx $L { $db eval "DROP INDEX $idx" }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-26 16:39:03 +04:00
|
|
|
#-------------------------------------------------------------------------
|
2010-06-07 21:47:26 +04:00
|
|
|
# If a test script is executed with global variable $::G(perm:name) set to
|
2013-08-29 05:09:14 +04:00
|
|
|
# "wal", then the tests are run in WAL mode. Otherwise, they should be run
|
|
|
|
# in rollback mode. The following Tcl procs are used to make this less
|
2010-06-07 21:47:26 +04:00
|
|
|
# intrusive:
|
2010-04-26 16:39:03 +04:00
|
|
|
#
|
|
|
|
# wal_set_journal_mode ?DB?
|
|
|
|
#
|
|
|
|
# If running a WAL test, execute "PRAGMA journal_mode = wal" using
|
|
|
|
# connection handle DB. Otherwise, this command is a no-op.
|
|
|
|
#
|
|
|
|
# wal_check_journal_mode TESTNAME ?DB?
|
|
|
|
#
|
|
|
|
# If running a WAL test, execute a tests case that fails if the main
|
|
|
|
# database for connection handle DB is not currently a WAL database.
|
|
|
|
# Otherwise (if not running a WAL permutation) this is a no-op.
|
|
|
|
#
|
|
|
|
# wal_is_wal_mode
|
2013-08-29 05:09:14 +04:00
|
|
|
#
|
2010-04-26 16:39:03 +04:00
|
|
|
# Returns true if this test should be run in WAL mode. False otherwise.
|
2013-08-29 05:09:14 +04:00
|
|
|
#
|
2010-04-26 16:39:03 +04:00
|
|
|
proc wal_is_wal_mode {} {
|
2010-06-07 21:47:26 +04:00
|
|
|
expr {[permutation] eq "wal"}
|
2010-04-26 16:39:03 +04:00
|
|
|
}
|
|
|
|
proc wal_set_journal_mode {{db db}} {
|
|
|
|
if { [wal_is_wal_mode] } {
|
|
|
|
$db eval "PRAGMA journal_mode = WAL"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
proc wal_check_journal_mode {testname {db db}} {
|
|
|
|
if { [wal_is_wal_mode] } {
|
|
|
|
$db eval { SELECT * FROM sqlite_master }
|
|
|
|
do_test $testname [list $db eval "PRAGMA main.journal_mode"] {wal}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 21:54:49 +03:00
|
|
|
proc wal_is_capable {} {
|
|
|
|
ifcapable !wal { return 0 }
|
|
|
|
if {[permutation]=="journaltest"} { return 0 }
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:47:26 +04:00
|
|
|
proc permutation {} {
|
|
|
|
set perm ""
|
|
|
|
catch {set perm $::G(perm:name)}
|
|
|
|
set perm
|
|
|
|
}
|
2010-08-06 17:50:07 +04:00
|
|
|
proc presql {} {
|
|
|
|
set presql ""
|
|
|
|
catch {set presql $::G(perm:presql)}
|
|
|
|
set presql
|
|
|
|
}
|
2010-06-07 21:47:26 +04:00
|
|
|
|
2016-02-04 20:31:03 +03:00
|
|
|
proc isquick {} {
|
|
|
|
set ret 0
|
|
|
|
catch {set ret $::G(isquick)}
|
|
|
|
set ret
|
|
|
|
}
|
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
proc slave_test_script {script} {
|
|
|
|
|
|
|
|
# Create the interpreter used to run the test script.
|
|
|
|
interp create tinterp
|
|
|
|
|
|
|
|
# Populate some global variables that tester.tcl expects to see.
|
|
|
|
foreach {var value} [list \
|
|
|
|
::argv0 $::argv0 \
|
|
|
|
::argv {} \
|
|
|
|
::SLAVE 1 \
|
|
|
|
] {
|
|
|
|
interp eval tinterp [list set $var $value]
|
|
|
|
}
|
|
|
|
|
2015-06-09 18:58:28 +03:00
|
|
|
# If output is being copied into a file, share the file-descriptor with
|
|
|
|
# the interpreter.
|
|
|
|
if {[info exists ::G(output_fd)]} {
|
|
|
|
interp share {} $::G(output_fd) tinterp
|
|
|
|
}
|
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
# The alias used to access the global test counters.
|
|
|
|
tinterp alias set_test_counter set_test_counter
|
|
|
|
|
|
|
|
# Set up the ::cmdlinearg array in the slave.
|
|
|
|
interp eval tinterp [list array set ::cmdlinearg [array get ::cmdlinearg]]
|
|
|
|
|
2010-06-07 21:47:26 +04:00
|
|
|
# Set up the ::G array in the slave.
|
|
|
|
interp eval tinterp [list array set ::G [array get ::G]]
|
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
# Load the various test interfaces implemented in C.
|
|
|
|
load_testfixture_extensions tinterp
|
|
|
|
|
|
|
|
# Run the test script.
|
|
|
|
interp eval tinterp $script
|
|
|
|
|
2010-07-06 15:26:15 +04:00
|
|
|
# Check if the interpreter call [run_thread_tests]
|
|
|
|
if { [interp eval tinterp {info exists ::run_thread_tests_called}] } {
|
|
|
|
set ::run_thread_tests_called 1
|
|
|
|
}
|
|
|
|
|
2010-06-07 18:28:16 +04:00
|
|
|
# Delete the interpreter used to run the test script.
|
|
|
|
interp delete tinterp
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:47:26 +04:00
|
|
|
proc slave_test_file {zFile} {
|
2010-06-15 10:56:37 +04:00
|
|
|
set tail [file tail $zFile]
|
|
|
|
|
2011-04-04 19:38:16 +04:00
|
|
|
if {[info exists ::G(start:permutation)]} {
|
|
|
|
if {[permutation] != $::G(start:permutation)} return
|
|
|
|
unset ::G(start:permutation)
|
|
|
|
}
|
|
|
|
if {[info exists ::G(start:file)]} {
|
|
|
|
if {$tail != $::G(start:file) && $tail!="$::G(start:file).test"} return
|
|
|
|
unset ::G(start:file)
|
|
|
|
}
|
|
|
|
|
2010-07-05 18:54:48 +04:00
|
|
|
# Remember the value of the shared-cache setting. So that it is possible
|
|
|
|
# to check afterwards that it was not modified by the test script.
|
|
|
|
#
|
|
|
|
ifcapable shared_cache { set scs [sqlite3_enable_shared_cache] }
|
2010-06-15 10:56:37 +04:00
|
|
|
|
2010-07-05 18:54:48 +04:00
|
|
|
# Run the test script in a slave interpreter.
|
|
|
|
#
|
2010-07-06 15:26:15 +04:00
|
|
|
unset -nocomplain ::run_thread_tests_called
|
2010-06-15 10:56:37 +04:00
|
|
|
reset_prng_state
|
|
|
|
set ::sqlite_open_file_count 0
|
|
|
|
set time [time { slave_test_script [list source $zFile] }]
|
|
|
|
set ms [expr [lindex $time 0] / 1000]
|
2010-06-07 21:47:26 +04:00
|
|
|
|
2010-07-05 18:54:48 +04:00
|
|
|
# Test that all files opened by the test script were closed. Omit this
|
|
|
|
# if the test script has "thread" in its name. The open file counter
|
|
|
|
# is not thread-safe.
|
2010-06-15 10:56:37 +04:00
|
|
|
#
|
2010-07-06 15:26:15 +04:00
|
|
|
if {[info exists ::run_thread_tests_called]==0} {
|
2010-07-05 18:54:48 +04:00
|
|
|
do_test ${tail}-closeallfiles { expr {$::sqlite_open_file_count>0} } {0}
|
|
|
|
}
|
2010-06-07 21:47:26 +04:00
|
|
|
set ::sqlite_open_file_count 0
|
|
|
|
|
2013-08-29 05:09:14 +04:00
|
|
|
# Test that the global "shared-cache" setting was not altered by
|
2010-06-15 10:56:37 +04:00
|
|
|
# the test script.
|
|
|
|
#
|
2013-08-29 05:09:14 +04:00
|
|
|
ifcapable shared_cache {
|
2010-06-15 10:56:37 +04:00
|
|
|
set res [expr {[sqlite3_enable_shared_cache] == $scs}]
|
|
|
|
do_test ${tail}-sharedcachesetting [list set {} $res] 1
|
|
|
|
}
|
2010-06-07 21:47:26 +04:00
|
|
|
|
2010-07-05 18:54:48 +04:00
|
|
|
# Add some info to the output.
|
|
|
|
#
|
2015-06-09 18:58:28 +03:00
|
|
|
output2 "Time: $tail $ms ms"
|
2010-06-07 21:47:26 +04:00
|
|
|
show_memstats
|
2010-06-07 18:28:16 +04:00
|
|
|
}
|
|
|
|
|
2010-08-04 15:34:31 +04:00
|
|
|
# Open a new connection on database test.db and execute the SQL script
|
|
|
|
# supplied as an argument. Before returning, close the new conection and
|
|
|
|
# restore the 4 byte fields starting at header offsets 28, 92 and 96
|
|
|
|
# to the values they held before the SQL was executed. This simulates
|
|
|
|
# a write by a pre-3.7.0 client.
|
|
|
|
#
|
|
|
|
proc sql36231 {sql} {
|
|
|
|
set B [hexio_read test.db 92 8]
|
|
|
|
set A [hexio_read test.db 28 4]
|
|
|
|
sqlite3 db36231 test.db
|
|
|
|
catch { db36231 func a_string a_string }
|
|
|
|
execsql $sql db36231
|
|
|
|
db36231 close
|
|
|
|
hexio_write test.db 28 $A
|
|
|
|
hexio_write test.db 92 $B
|
|
|
|
return ""
|
|
|
|
}
|
2009-10-07 22:41:19 +04:00
|
|
|
|
2010-11-29 15:06:45 +03:00
|
|
|
proc db_save {} {
|
|
|
|
foreach f [glob -nocomplain sv_test.db*] { forcedelete $f }
|
|
|
|
foreach f [glob -nocomplain test.db*] {
|
|
|
|
set f2 "sv_$f"
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy $f $f2
|
2010-11-29 15:06:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
proc db_save_and_close {} {
|
|
|
|
db_save
|
|
|
|
catch { db close }
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
proc db_restore {} {
|
|
|
|
foreach f [glob -nocomplain test.db*] { forcedelete $f }
|
|
|
|
foreach f2 [glob -nocomplain sv_test.db*] {
|
|
|
|
set f [string range $f2 3 end]
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy $f2 $f
|
2010-11-29 15:06:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
proc db_restore_and_reopen {{dbfile test.db}} {
|
|
|
|
catch { db close }
|
|
|
|
db_restore
|
|
|
|
sqlite3 db $dbfile
|
|
|
|
}
|
|
|
|
proc db_delete_and_reopen {{file test.db}} {
|
|
|
|
catch { db close }
|
2011-08-02 04:57:34 +04:00
|
|
|
foreach f [glob -nocomplain test.db*] { forcedelete $f }
|
2010-11-29 15:06:45 +03:00
|
|
|
sqlite3 db $file
|
|
|
|
}
|
|
|
|
|
2015-07-24 17:17:17 +03:00
|
|
|
# Close any connections named [db], [db2] or [db3]. Then use sqlite3_config
|
|
|
|
# to configure the size of the PAGECACHE allocation using the parameters
|
|
|
|
# provided to this command. Save the old PAGECACHE parameters in a global
|
|
|
|
# variable so that [test_restore_config_pagecache] can restore the previous
|
|
|
|
# configuration.
|
|
|
|
#
|
|
|
|
# Before returning, reopen connection [db] on file test.db.
|
|
|
|
#
|
|
|
|
proc test_set_config_pagecache {sz nPg} {
|
|
|
|
catch {db close}
|
|
|
|
catch {db2 close}
|
|
|
|
catch {db3 close}
|
|
|
|
|
|
|
|
sqlite3_shutdown
|
|
|
|
set ::old_pagecache_config [sqlite3_config_pagecache $sz $nPg]
|
|
|
|
sqlite3_initialize
|
|
|
|
autoinstall_test_functions
|
2015-07-24 21:22:29 +03:00
|
|
|
reset_db
|
2015-07-24 17:17:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Close any connections named [db], [db2] or [db3]. Then use sqlite3_config
|
|
|
|
# to configure the size of the PAGECACHE allocation to the size saved in
|
|
|
|
# the global variable by an earlier call to [test_set_config_pagecache].
|
|
|
|
#
|
|
|
|
# Before returning, reopen connection [db] on file test.db.
|
|
|
|
#
|
|
|
|
proc test_restore_config_pagecache {} {
|
|
|
|
catch {db close}
|
|
|
|
catch {db2 close}
|
|
|
|
catch {db3 close}
|
|
|
|
|
|
|
|
sqlite3_shutdown
|
|
|
|
eval sqlite3_config_pagecache $::old_pagecache_config
|
|
|
|
unset ::old_pagecache_config
|
|
|
|
sqlite3_initialize
|
|
|
|
autoinstall_test_functions
|
|
|
|
sqlite3 db test.db
|
|
|
|
}
|
|
|
|
|
2017-12-19 20:42:13 +03:00
|
|
|
proc test_binary_name {nm} {
|
2016-03-15 12:55:44 +03:00
|
|
|
if {$::tcl_platform(platform)=="windows"} {
|
2016-03-19 17:53:36 +03:00
|
|
|
set ret "$nm.exe"
|
2016-03-15 12:55:44 +03:00
|
|
|
} else {
|
2016-03-19 17:53:36 +03:00
|
|
|
set ret $nm
|
2016-03-15 12:55:44 +03:00
|
|
|
}
|
2017-12-19 20:42:13 +03:00
|
|
|
file normalize [file join $::cmdlinearg(TESTFIXTURE_HOME) $ret]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc test_find_binary {nm} {
|
|
|
|
set ret [test_binary_name $nm]
|
2016-03-15 12:55:44 +03:00
|
|
|
if {![file executable $ret]} {
|
|
|
|
finish_test
|
2016-03-19 18:13:59 +03:00
|
|
|
return ""
|
2016-03-15 12:55:44 +03:00
|
|
|
}
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2016-03-19 17:53:36 +03:00
|
|
|
# Find the name of the 'shell' executable (e.g. "sqlite3.exe") to use for
|
|
|
|
# the tests in shell[1-5].test. If no such executable can be found, invoke
|
|
|
|
# [finish_test ; return] in the callers context.
|
|
|
|
#
|
|
|
|
proc test_find_cli {} {
|
2016-03-19 20:48:12 +03:00
|
|
|
set prog [test_find_binary sqlite3]
|
2016-03-19 18:13:59 +03:00
|
|
|
if {$prog==""} { return -code return }
|
|
|
|
return $prog
|
2016-03-19 17:53:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Find the name of the 'sqldiff' executable (e.g. "sqlite3.exe") to use for
|
|
|
|
# the tests in sqldiff tests. If no such executable can be found, invoke
|
|
|
|
# [finish_test ; return] in the callers context.
|
|
|
|
#
|
|
|
|
proc test_find_sqldiff {} {
|
2016-03-19 18:13:59 +03:00
|
|
|
set prog [test_find_binary sqldiff]
|
|
|
|
if {$prog==""} { return -code return }
|
|
|
|
return $prog
|
2016-03-19 17:53:36 +03:00
|
|
|
}
|
|
|
|
|
2018-02-07 21:02:50 +03:00
|
|
|
# Call sqlite3_expanded_sql() on all statements associated with database
|
|
|
|
# connection $db. This sometimes finds use-after-free bugs if run with
|
|
|
|
# valgrind or address-sanitizer.
|
|
|
|
proc expand_all_sql {db} {
|
|
|
|
set stmt ""
|
|
|
|
while {[set stmt [sqlite3_next_stmt $db $stmt]]!=""} {
|
|
|
|
sqlite3_expanded_sql $stmt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 17:53:36 +03:00
|
|
|
|
2004-11-10 18:27:38 +03:00
|
|
|
# If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set
|
|
|
|
# to non-zero, then set the global variable $AUTOVACUUM to 1.
|
|
|
|
set AUTOVACUUM $sqlite_options(default_autovacuum)
|
2009-03-26 20:13:06 +03:00
|
|
|
|
2012-05-12 09:30:29 +04:00
|
|
|
# Make sure the FTS enhanced query syntax is disabled.
|
|
|
|
set sqlite_fts3_enable_parentheses 0
|
|
|
|
|
2013-11-29 19:06:27 +04:00
|
|
|
# During testing, assume that all database files are well-formed. The
|
|
|
|
# few test cases that deliberately corrupt database files should rescind
|
|
|
|
# this setting by invoking "database_can_be_corrupt"
|
|
|
|
#
|
|
|
|
database_never_corrupt
|
2020-07-23 00:05:23 +03:00
|
|
|
extra_schema_checks 1
|
2013-11-29 19:06:27 +04:00
|
|
|
|
2009-03-26 20:13:06 +03:00
|
|
|
source $testdir/thread_common.tcl
|
2010-10-25 16:47:43 +04:00
|
|
|
source $testdir/malloc_common.tcl
|