mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Fix problems with some "crashsql" tests.
FossilOrigin-Name: 0c8e2ede5c325aa7fef8e8587057ec8c865fc7cf3e974a2733066fbac640b983
This commit is contained in:
@ -29,7 +29,7 @@ ifcapable !crashtest||!memorymanage {
|
||||
db close
|
||||
|
||||
for {set ii 0} {$ii < 10} {incr ii} {
|
||||
for {set jj 50} {$jj < 100} {incr jj} {
|
||||
for {set jj 1} {$jj < 100} {incr jj} {
|
||||
|
||||
# Set up the database so that it is an auto-vacuum database
|
||||
# containing a single table (root page 3) with a single row.
|
||||
@ -47,6 +47,14 @@ for {set ii 0} {$ii < 10} {incr ii} {
|
||||
do_test crash5-$ii.$jj.1 {
|
||||
crashsql -delay 1 -file test.db-journal -seed $ii -tclbody [join [list \
|
||||
[list set iFail $jj] {
|
||||
proc get_pwd {} {
|
||||
if {$::tcl_platform(platform) eq "windows"} {
|
||||
return [string map [list \\ /] \
|
||||
[string trim [exec -- $::env(ComSpec) /c echo %CD%]]]
|
||||
} else {
|
||||
return [pwd]
|
||||
}
|
||||
}
|
||||
sqlite3_crashparams 0 [file join [get_pwd] test.db-journal]
|
||||
|
||||
# Begin a transaction and evaluate a "CREATE INDEX" statement
|
||||
@ -61,36 +69,39 @@ for {set ii 0} {$ii < 10} {incr ii} {
|
||||
#
|
||||
db eval BEGIN
|
||||
sqlite3_memdebug_fail $iFail -repeat 0
|
||||
catch {db eval { CREATE UNIQUE INDEX i1 ON t1(a); }} msg
|
||||
# puts "$n $msg ac=[sqlite3_get_autocommit db]"
|
||||
set rc [catch {db eval { CREATE UNIQUE INDEX i1 ON t1(a); }} msg]
|
||||
# puts "$msg ac=[sqlite3_get_autocommit db] iFail=$iFail"
|
||||
# puts "fail=[sqlite3_memdebug_fail -1]"
|
||||
|
||||
# If the transaction is still active (it may not be if the malloc()
|
||||
# failure occurred in the OS layer), write to the database. Make sure
|
||||
# page 4 is among those written.
|
||||
#
|
||||
if {![sqlite3_get_autocommit db]} {
|
||||
db eval {
|
||||
DELETE FROM t1; -- This will put page 4 on the free list.
|
||||
INSERT INTO t1 VALUES('111111111', '2222222222', '33333333');
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 2
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 4
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 8
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 16
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 32
|
||||
INSERT INTO t1 SELECT * FROM t1 WHERE rowid%2; -- 48
|
||||
if {$rc} {
|
||||
# If the transaction is still active (it may not be if the malloc()
|
||||
# failure occurred in the OS layer), write to the database. Make sure
|
||||
# page 4 is among those written.
|
||||
#
|
||||
if {![sqlite3_get_autocommit db]} {
|
||||
db eval {
|
||||
DELETE FROM t1; -- This will put page 4 on the free list.
|
||||
INSERT INTO t1 VALUES('111111111', '2222222222', '33333333');
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 2
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 4
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 8
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 16
|
||||
INSERT INTO t1 SELECT * FROM t1; -- 32
|
||||
INSERT INTO t1 SELECT * FROM t1 WHERE rowid%2; -- 48
|
||||
}
|
||||
}
|
||||
|
||||
# If the right malloc() failed during the 'CREATE INDEX' above and
|
||||
# the transaction was not rolled back, then the sqlite cache now
|
||||
# has a dirty page 4 that it incorrectly believes is already safely
|
||||
# in the synced part of the journal file. When
|
||||
# sqlite3_release_memory() is called sqlite tries to free memory
|
||||
# by writing page 4 out to the db file. If it crashes later on,
|
||||
# before syncing the journal... Corruption!
|
||||
#
|
||||
sqlite3_crashparams 1 [file join [get_pwd] test.db-journal]
|
||||
sqlite3_release_memory 8092
|
||||
}
|
||||
|
||||
# If the right malloc() failed during the 'CREATE INDEX' above and
|
||||
# the transaction was not rolled back, then the sqlite cache now
|
||||
# has a dirty page 4 that it incorrectly believes is already safely
|
||||
# in the synced part of the journal file. When
|
||||
# sqlite3_release_memory() is called sqlite tries to free memory
|
||||
# by writing page 4 out to the db file. If it crashes later on,
|
||||
# before syncing the journal... Corruption!
|
||||
#
|
||||
sqlite3_crashparams 1 [file join [get_pwd] test.db-journal]
|
||||
sqlite3_release_memory 8092
|
||||
}]] {}
|
||||
expr 1
|
||||
} {1}
|
||||
|
@ -1689,9 +1689,12 @@ proc crashsql {args} {
|
||||
set cfile [string map {\\ \\\\} [file nativename [file join [get_pwd] $crashfile]]]
|
||||
|
||||
set f [open crash.tcl w]
|
||||
puts $f "sqlite3_initialize ; sqlite3_shutdown"
|
||||
puts $f "catch { install_malloc_faultsim 1 }"
|
||||
puts $f "sqlite3_crash_enable 1 $dfltvfs"
|
||||
puts $f "sqlite3_crashparams $blocksize $dc $crashdelay $cfile"
|
||||
puts $f "sqlite3_test_control_pending_byte $::sqlite_pending_byte"
|
||||
puts $f "autoinstall_test_functions"
|
||||
|
||||
# This block sets the cache size of the main database to 10
|
||||
# pages. This is done in case the build is configured to omit
|
||||
@ -1719,7 +1722,7 @@ proc crashsql {args} {
|
||||
}
|
||||
close $f
|
||||
set r [catch {
|
||||
exec [info nameofexec] crash.tcl >@stdout
|
||||
exec [info nameofexec] crash.tcl >@stdout 2>@stdout
|
||||
} msg]
|
||||
|
||||
# Windows/ActiveState TCL returns a slightly different
|
||||
|
Reference in New Issue
Block a user