mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
The malloc.test script now passes all tests with no errors. (CVS 4271)
FossilOrigin-Name: db818430e9ea4ef4a4af575784009d5acae785a3
This commit is contained in:
@ -8,20 +8,22 @@
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file attempts to check the library in an out-of-memory situation.
|
||||
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
|
||||
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail. This
|
||||
# special feature is used to see what happens in the library if a malloc
|
||||
# were to really fail due to an out-of-memory situation.
|
||||
#
|
||||
# $Id: malloc.test,v 1.43 2007/08/16 04:39:01 danielk1977 Exp $
|
||||
# This file attempts to check the behavior of the SQLite library in
|
||||
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1,
|
||||
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
|
||||
# which causes the N-th malloc to fail. This special feature is used
|
||||
# to see what happens in the library if a malloc were to really fail
|
||||
# due to an out-of-memory situation.
|
||||
#
|
||||
# $Id: malloc.test,v 1.44 2007/08/22 20:18:22 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
#
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
ifcapable !memdebug {
|
||||
puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
|
||||
finish_test
|
||||
return
|
||||
@ -182,7 +184,7 @@ do_malloc_test 7 -sqlprep {
|
||||
SELECT min(a) FROM t1 WHERE a<6 GROUP BY b;
|
||||
SELECT a FROM t1 WHERE a<6 ORDER BY a;
|
||||
SELECT b FROM t1 WHERE a>6;
|
||||
}
|
||||
}
|
||||
|
||||
# This block is designed to test that some malloc failures that may
|
||||
# occur in vdbeapi.c. Specifically, if a malloc failure that occurs
|
||||
@ -197,9 +199,10 @@ do_malloc_test 7 -sqlprep {
|
||||
# These tests only run if UTF-16 support is compiled in.
|
||||
#
|
||||
if {$::sqlite_options(utf16)} {
|
||||
set ::STMT {}
|
||||
do_malloc_test 8 -tclprep {
|
||||
set sql "SELECT '[string repeat abc 20]', '[string repeat def 20]', ?"
|
||||
set ::STMT [sqlite3_prepare $::DB $sql -1 X]
|
||||
set ::STMT [sqlite3_prepare db $sql -1 X]
|
||||
sqlite3_step $::STMT
|
||||
if { $::tcl_platform(byteOrder)=="littleEndian" } {
|
||||
set ::bomstr "\xFF\xFE"
|
||||
@ -214,12 +217,15 @@ if {$::sqlite_options(utf16)} {
|
||||
sqlite3_column_double $::STMT 1
|
||||
sqlite3_reset $::STMT
|
||||
sqlite3_bind_text16 $::STMT 1 $::bomstr 60
|
||||
catch {sqlite3_finalize $::STMT}
|
||||
if {[lindex [sqlite_malloc_stat] 2]<=0} {
|
||||
error "out of memory"
|
||||
}
|
||||
#catch {sqlite3_finalize $::STMT}
|
||||
#if {[lindex [sqlite_malloc_stat] 2]<=0} {
|
||||
# error "out of memory"
|
||||
#}
|
||||
} -cleanup {
|
||||
sqlite3_finalize $::STMT
|
||||
if {$::STMT!=""} {
|
||||
sqlite3_finalize $::STMT
|
||||
set ::STMT {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,8 +256,8 @@ do_malloc_test 10 -sqlprep {
|
||||
|
||||
# This block tests malloc() failures that occur within calls to
|
||||
# sqlite3_create_function().
|
||||
do_malloc_test 11 -tclbody {
|
||||
set rc [sqlite3_create_function $::DB]
|
||||
do_malloc_test 11 -tclbody {
|
||||
set rc [sqlite3_create_function db]
|
||||
if {[string match $rc SQLITE_NOMEM]} {
|
||||
error "out of memory"
|
||||
}
|
||||
@ -260,7 +266,7 @@ do_malloc_test 11 -tclbody {
|
||||
do_malloc_test 12 -tclbody {
|
||||
set sql16 [encoding convertto unicode "SELECT * FROM sqlite_master"]
|
||||
append sql16 "\00\00"
|
||||
set ::STMT [sqlite3_prepare16 $::DB $sql16 -1 DUMMY]
|
||||
set ::STMT [sqlite3_prepare16 db $sql16 -1 DUMMY]
|
||||
sqlite3_finalize $::STMT
|
||||
}
|
||||
|
||||
@ -320,9 +326,9 @@ proc string_compare {a b} {
|
||||
# Test for malloc() failures in sqlite3_create_collation() and
|
||||
# sqlite3_create_collation16().
|
||||
#
|
||||
do_malloc_test 15 -tclbody {
|
||||
do_malloc_test 15 -start 4 -tclbody {
|
||||
db collate string_compare string_compare
|
||||
if {[catch {add_test_collate $::DB 1 1 1} msg]} {
|
||||
if {[catch {add_test_collate db 1 1 1} msg]} {
|
||||
if {$msg=="SQLITE_NOMEM"} {set msg "out of memory"}
|
||||
error $msg
|
||||
}
|
||||
@ -423,7 +429,7 @@ do_malloc_test 19 -tclprep {
|
||||
} -tclbody {
|
||||
unset -nocomplain ::STMT
|
||||
set r [catch {
|
||||
set ::STMT [sqlite3_prepare $::DB {SELECT ?} -1 DUMMY]
|
||||
set ::STMT [sqlite3_prepare db {SELECT ?} -1 DUMMY]
|
||||
sqlite3_bind_text16 -static $::STMT 1 $static_string 112
|
||||
} msg]
|
||||
if {$r} {error [string range $msg 4 end]}
|
||||
@ -466,7 +472,7 @@ do_malloc_test 22 -tclbody {
|
||||
set ::STMT ""
|
||||
set r [catch {
|
||||
set ::STMT [
|
||||
sqlite3_prepare_v2 $::DB "SELECT * FROM sqlite_master" -1 DUMMY
|
||||
sqlite3_prepare_v2 db "SELECT * FROM sqlite_master" -1 DUMMY
|
||||
]
|
||||
} msg]
|
||||
if {$r} {error [string range $msg 4 end]}
|
||||
@ -484,5 +490,4 @@ do_test malloc-99.X {
|
||||
} {0}
|
||||
|
||||
puts open-file-count=$sqlite_open_file_count
|
||||
sqlite_malloc_fail 0
|
||||
finish_test
|
||||
|
@ -30,22 +30,25 @@ proc do_malloc_test {tn args} {
|
||||
if {[string is integer $tn]} {
|
||||
set tn malloc-$tn
|
||||
}
|
||||
if {[info exists ::mallocopts(-start)]} {
|
||||
set start $::mallocopts(-start)
|
||||
} else {
|
||||
set start 1
|
||||
}
|
||||
|
||||
set ::go 1
|
||||
for {set ::n 1} {$::go && $::n < 50000} {incr ::n} {
|
||||
for {set ::n $start} {$::go && $::n < 50000} {incr ::n} {
|
||||
do_test $tn.$::n {
|
||||
|
||||
# Remove all traces of database files test.db and test2.db from the files
|
||||
# system. Then open (empty database) "test.db" with the handle [db].
|
||||
#
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
catch {file delete -force test2.db}
|
||||
catch {file delete -force test2.db-journal}
|
||||
catch {sqlite3 db test.db}
|
||||
set ::DB [sqlite3_connection_pointer db]
|
||||
|
||||
# Execute any -tclprep and -sqlprep scripts.
|
||||
#
|
||||
@ -59,7 +62,7 @@ proc do_malloc_test {tn args} {
|
||||
# Now set the ${::n}th malloc() to fail and execute the -tclbody and
|
||||
# -sqlbody scripts.
|
||||
#
|
||||
sqlite_malloc_fail $::n
|
||||
sqlite3_memdebug_fail $::n 1
|
||||
set ::mallocbody {}
|
||||
if {[info exists ::mallocopts(-tclbody)]} {
|
||||
append ::mallocbody "$::mallocopts(-tclbody)\n"
|
||||
@ -68,28 +71,26 @@ proc do_malloc_test {tn args} {
|
||||
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
|
||||
}
|
||||
set v [catch $::mallocbody msg]
|
||||
set failFlag [sqlite3_memdebug_fail -1 0]
|
||||
set go [expr {$failFlag>0}]
|
||||
|
||||
# If the test fails (if $v!=0) and the database connection actually
|
||||
# exists, make sure the failure code is SQLITE_NOMEM.
|
||||
if {$v && [info command db]=="db" && [info exists ::mallocopts(-sqlbody)]
|
||||
&& [db errorcode]!=7} {
|
||||
set v 999
|
||||
}
|
||||
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
if {$failFlag==0} {
|
||||
if {$v} {
|
||||
puts "\nError message returned: $msg"
|
||||
set v2 $msg
|
||||
} else {
|
||||
set v {1 1}
|
||||
set v 1
|
||||
set v2 1
|
||||
}
|
||||
} elseif {!$v} {
|
||||
set v2 $msg
|
||||
} elseif {[info command db]=="" || [db errorcode]==7
|
||||
|| $msg=="out of memory"} {
|
||||
set v2 1
|
||||
} else {
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
set v2 $msg
|
||||
}
|
||||
lappend v $v2
|
||||
} {1 1}
|
||||
|
||||
if {[info exists ::mallocopts(-cleanup)]} {
|
||||
@ -98,4 +99,3 @@ proc do_malloc_test {tn args} {
|
||||
}
|
||||
unset ::mallocopts
|
||||
}
|
||||
|
||||
|
@ -10,14 +10,14 @@
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
# $Id: misc7.test,v 1.14 2007/06/27 23:52:18 drh Exp $
|
||||
# $Id: misc7.test,v 1.15 2007/08/22 20:18:22 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_test misc7-1 {
|
||||
c_misuse_test
|
||||
} {}
|
||||
#do_test misc7-1 {
|
||||
# c_misuse_test
|
||||
#} {}
|
||||
|
||||
do_test misc7-2 {
|
||||
c_realloc_test
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This file implements some common TCL routines used for regression
|
||||
# testing the SQLite library
|
||||
#
|
||||
# $Id: tester.tcl,v 1.84 2007/08/20 14:23:44 danielk1977 Exp $
|
||||
# $Id: tester.tcl,v 1.85 2007/08/22 20:18:22 drh Exp $
|
||||
|
||||
# Make sure tclsqlite3 was compiled correctly. Abort now with an
|
||||
# error message if not.
|
||||
@ -208,7 +208,9 @@ proc finalize_testing {} {
|
||||
sqlite3_soft_heap_limit 0
|
||||
incr nTest
|
||||
puts "$nErr errors out of $nTest tests"
|
||||
puts "Failures on these tests: $::failList"
|
||||
if {$nErr>0} {
|
||||
puts "Failures on these tests: $::failList"
|
||||
}
|
||||
if {$nErr>0 && ![working_64bit_int]} {
|
||||
puts "******************************************************************"
|
||||
puts "N.B.: The version of TCL that you used to build this test harness"
|
||||
@ -221,6 +223,13 @@ proc finalize_testing {} {
|
||||
puts "$sqlite_open_file_count files were left open"
|
||||
incr nErr
|
||||
}
|
||||
if {[sqlite3_memory_used]>0} {
|
||||
puts "Unfreed memory: [sqlite3_memory_used] bytes"
|
||||
incr nErr
|
||||
} else {
|
||||
puts "All memory allocations freed - no leaks"
|
||||
}
|
||||
puts "Maximum memory usage: [sqlite3_memory_highwater] bytes"
|
||||
foreach f [glob -nocomplain test.db-*-journal] {
|
||||
file delete -force $f
|
||||
}
|
||||
@ -562,8 +571,8 @@ proc copy_file {from to} {
|
||||
}
|
||||
}
|
||||
|
||||
# This command checks for outstanding calls to sqliteMalloc() from within
|
||||
# the current thread. A list is returned with one entry for each outstanding
|
||||
# This command checks for outstanding calls to sqlite3_malloc()
|
||||
# A list is returned with one entry for each outstanding
|
||||
# malloc. Each list entry is itself a list of 5 items, as follows:
|
||||
#
|
||||
# { <number-bytes> <file-name> <line-number> <test-case> <stack-dump> }
|
||||
|
Reference in New Issue
Block a user