1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Fix a typo in walfault.test.

FossilOrigin-Name: 232dbe8ecec16485be5c5995fdf7a0ed951c2097
This commit is contained in:
dan
2010-05-04 11:06:03 +00:00
parent 8d6ad1cc2c
commit ef37802545
8 changed files with 180 additions and 174 deletions

View File

@ -167,3 +167,157 @@ proc do_malloc_test {tn args} {
unset ::mallocopts
sqlite3_memdebug_fail -1
}
#-------------------------------------------------------------------------
# This proc is used to test a single SELECT statement. Parameter $name is
# passed a name for the test case (i.e. "fts3_malloc-1.4.1") and parameter
# $sql is passed the text of the SELECT statement. Parameter $result is
# set to the expected output if the SELECT statement is successfully
# executed using [db eval].
#
# Example:
#
# do_select_test testcase-1.1 "SELECT 1+1, 1+2" {1 2}
#
# If global variable DO_MALLOC_TEST is set to a non-zero value, or if
# it is not defined at all, then OOM testing is performed on the SELECT
# statement. Each OOM test case is said to pass if either (a) executing
# the SELECT statement succeeds and the results match those specified
# by parameter $result, or (b) TCL throws an "out of memory" error.
#
# If DO_MALLOC_TEST is defined and set to zero, then the SELECT statement
# is executed just once. In this case the test case passes if the results
# match the expected results passed via parameter $result.
#
proc do_select_test {name sql result} {
uplevel [list doPassiveTest 0 $name $sql [list 0 $result]]
}
proc do_restart_select_test {name sql result} {
uplevel [list doPassiveTest 1 $name $sql [list 0 $result]]
}
proc do_error_test {name sql error} {
uplevel [list doPassiveTest 0 $name $sql [list 1 $error]]
}
proc doPassiveTest {isRestart name sql catchres} {
if {![info exists ::DO_MALLOC_TEST]} { set ::DO_MALLOC_TEST 1 }
switch $::DO_MALLOC_TEST {
0 { # No malloc failures.
do_test $name [list set {} [uplevel [list catchsql $sql]]] $catchres
return
}
1 { # Simulate transient failures.
set nRepeat 1
set zName "transient"
set nStartLimit 100000
set nBackup 1
}
2 { # Simulate persistent failures.
set nRepeat 1
set zName "persistent"
set nStartLimit 100000
set nBackup 1
}
3 { # Simulate transient failures with extra brute force.
set nRepeat 100000
set zName "ridiculous"
set nStartLimit 1
set nBackup 10
}
}
# The set of acceptable results from running [catchsql $sql].
#
set answers [list {1 {out of memory}} $catchres]
set str [join $answers " OR "]
set nFail 1
for {set iLimit $nStartLimit} {$nFail} {incr iLimit} {
for {set iFail 1} {$nFail && $iFail<=$iLimit} {incr iFail} {
for {set iTest 0} {$iTest<$nBackup && ($iFail-$iTest)>0} {incr iTest} {
if {$isRestart} { sqlite3 db test.db }
sqlite3_memdebug_fail [expr $iFail-$iTest] -repeat $nRepeat
set res [uplevel [list catchsql $sql]]
if {[lsearch -exact $answers $res]>=0} { set res $str }
set testname "$name.$zName.$iFail"
do_test "$name.$zName.$iLimit.$iFail" [list set {} $res] $str
set nFail [sqlite3_memdebug_fail -1 -benigncnt nBenign]
}
}
}
}
#-------------------------------------------------------------------------
# Test a single write to the database. In this case a "write" is a
# DELETE, UPDATE or INSERT statement.
#
# If OOM testing is performed, there are several acceptable outcomes:
#
# 1) The write succeeds. No error is returned.
#
# 2) An "out of memory" exception is thrown and:
#
# a) The statement has no effect, OR
# b) The current transaction is rolled back, OR
# c) The statement succeeds. This can only happen if the connection
# is in auto-commit mode (after the statement is executed, so this
# includes COMMIT statements).
#
# If the write operation eventually succeeds, zero is returned. If a
# transaction is rolled back, non-zero is returned.
#
# Parameter $name is the name to use for the test case (or test cases).
# The second parameter, $tbl, should be the name of the database table
# being modified. Parameter $sql contains the SQL statement to test.
#
proc do_write_test {name tbl sql} {
if {![info exists ::DO_MALLOC_TEST]} { set ::DO_MALLOC_TEST 1 }
# Figure out an statement to get a checksum for table $tbl.
db eval "SELECT * FROM $tbl" V break
set cksumsql "SELECT md5sum([join [concat rowid $V(*)] ,]) FROM $tbl"
# Calculate the initial table checksum.
set cksum1 [db one $cksumsql]
if {$::DO_MALLOC_TEST } {
set answers [list {1 {out of memory}} {0 {}}]
if {$::DO_MALLOC_TEST==1} {
set modes {100000 transient}
} else {
set modes {1 persistent}
}
} else {
set answers [list {0 {}}]
set modes [list 0 nofail]
}
set str [join $answers " OR "]
foreach {nRepeat zName} $modes {
for {set iFail 1} 1 {incr iFail} {
if {$::DO_MALLOC_TEST} {sqlite3_memdebug_fail $iFail -repeat $nRepeat}
set res [uplevel [list catchsql $sql]]
set nFail [sqlite3_memdebug_fail -1 -benigncnt nBenign]
if {$nFail==0} {
do_test $name.$zName.$iFail [list set {} $res] {0 {}}
return
} else {
if {[lsearch $answers $res]>=0} {
set res $str
}
do_test $name.$zName.$iFail [list set {} $res] $str
set cksum2 [db one $cksumsql]
if {$cksum1 != $cksum2} return
}
}
}
}