mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
More changes for 2.0.7. (CVS 293)
FossilOrigin-Name: f8328a5f11801c5124f9a8dace22df3c1cfb2191
This commit is contained in:
173
test/malloc.test
173
test/malloc.test
@ -10,11 +10,11 @@
|
||||
#***********************************************************************
|
||||
# This file attempts to check the library in an out-of-memory situation.
|
||||
# When compiled with -DMEMORY_DEBUG=1, the SQLite library accepts a special
|
||||
# command (--malloc-fail=N) which causes the N-th malloc to fail. This
|
||||
# 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.3 2001/09/16 00:13:28 drh Exp $
|
||||
# $Id: malloc.test,v 1.4 2001/10/22 02:58:11 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -30,55 +30,164 @@ if {[info command sqlite_malloc_fail]==""} {
|
||||
for {set go 1; set i 1} {$go} {incr i} {
|
||||
do_test malloc-1.$i {
|
||||
sqlite_malloc_fail 0
|
||||
catch {execsql {DROP TABLE t1}}
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
sqlite_malloc_fail $i
|
||||
set v [catch {execsql {
|
||||
CREATE TABLE t1(
|
||||
a int, b float, c double, d text, e varchar(20),
|
||||
primary key(a,b,c)
|
||||
);
|
||||
CREATE INDEX i1 ON t1(a,b);
|
||||
INSERT INTO t1 VALUES(1,2.3,4.5,'hi','there');
|
||||
INSERT INTO t1 VALUES(6,7.0,0.8,'hello','out yonder');
|
||||
SELECT * FROM t1;
|
||||
SELECT avg(b) FROM t1 GROUP BY a HAVING b>20.0;
|
||||
DELETE FROM t1 WHERE a==6;
|
||||
SELECT count(*) FROM t1;
|
||||
}} msg]
|
||||
if {[lindex [sqlite_malloc_stat] 2]>0} {
|
||||
set v [catch {sqlite db test.db} msg]
|
||||
if {$v} {
|
||||
set msg ""
|
||||
} else {
|
||||
set v [catch {execsql {
|
||||
CREATE TABLE t1(
|
||||
a int, b float, c double, d text, e varchar(20),
|
||||
primary key(a,b,c)
|
||||
);
|
||||
CREATE INDEX i1 ON t1(a,b);
|
||||
INSERT INTO t1 VALUES(1,2.3,4.5,'hi','there');
|
||||
INSERT INTO t1 VALUES(6,7.0,0.8,'hello','out yonder');
|
||||
SELECT * FROM t1;
|
||||
SELECT avg(b) FROM t1 GROUP BY a HAVING b>20.0;
|
||||
DELETE FROM t1 WHERE a IN (SELECT min(a) FROM t1);
|
||||
SELECT count(*) FROM t1;
|
||||
}} msg]
|
||||
}
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
set v {1 1}
|
||||
} else {
|
||||
lappend v [expr {$msg=="" || $msg=="out of memory"}]
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
}
|
||||
|
||||
finish_test
|
||||
return
|
||||
|
||||
|
||||
set fd [open ./data.tmp w]
|
||||
for {set i 1} {$i<=40} {incr i} {
|
||||
puts $fd "$i\t[expr {$i*$i}]\t[expr {100-$i}]"
|
||||
for {set i 1} {$i<=20} {incr i} {
|
||||
puts $fd "$i\t[expr {$i*$i}]\t[expr {100-$i}] abcdefghijklmnopqrstuvwxyz"
|
||||
}
|
||||
close $fd
|
||||
|
||||
for {set go 1; set i 1} {$go} {incr i} {
|
||||
do_test malloc-2.$i {
|
||||
sqlite_malloc_fail 0
|
||||
catch {execsql {DROP TABLE t1}}
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
sqlite_malloc_fail $i
|
||||
set v [catch {execsql {
|
||||
CREATE TABLE t1(a int, b int, c int);
|
||||
CREATE INDEX i1 ON t1(a,b);
|
||||
COPY t1 FROM 'data.tmp';
|
||||
SELECT 'stuff', count(*) as 'other stuff' FROM t1;
|
||||
UPDATE t1 SET b=a WHERE a in (10,12,22);
|
||||
DROP INDEX i1;
|
||||
VACUUM t1;
|
||||
}} msg]
|
||||
if {[lindex [sqlite_malloc_stat] 2]>0} {
|
||||
set v [catch {sqlite db test.db} msg]
|
||||
if {$v} {
|
||||
set msg ""
|
||||
} else {
|
||||
set v [catch {execsql {
|
||||
CREATE TABLE t1(a int, b int, c int);
|
||||
CREATE INDEX i1 ON t1(a,b);
|
||||
COPY t1 FROM 'data.tmp';
|
||||
SELECT 'stuff', count(*) as 'other stuff', max(a+10) FROM t1;
|
||||
UPDATE t1 SET b=b||b||b||b;
|
||||
UPDATE t1 SET b=a WHERE a in (10,12,22);
|
||||
INSERT INTO t1(c,b,a) VALUES(20,10,5);
|
||||
INSERT INTO t1 SELECT * FROM t1
|
||||
WHERE a IN (SELECT a FROM t1 WHERE a<10);
|
||||
DELETE FROM t1 WHERE a>=10;
|
||||
DROP INDEX i1;
|
||||
DELETE FROM t1;
|
||||
}} msg]
|
||||
}
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
set v {1 1}
|
||||
} else {
|
||||
lappend v [expr {$msg=="" || $msg=="out of memory"}]
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
}
|
||||
|
||||
set fd [open ./data.tmp w]
|
||||
for {set i 1} {$i<=10} {incr i} {
|
||||
puts $fd "$i\t[expr {$i*$i}]\t[expr {100-$i}]"
|
||||
}
|
||||
close $fd
|
||||
|
||||
for {set go 1; set i 1} {$go} {incr i} {
|
||||
do_test malloc-3.$i {
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
sqlite_malloc_fail $i
|
||||
set v [catch {sqlite db test.db} msg]
|
||||
if {$v} {
|
||||
set msg ""
|
||||
} else {
|
||||
set v [catch {execsql {
|
||||
BEGIN TRANSACTION;
|
||||
CREATE TABLE t1(a int, b int, c int);
|
||||
CREATE INDEX i1 ON t1(a,b);
|
||||
COPY t1 FROM 'data.tmp';
|
||||
INSERT INTO t1(c,b,a) VALUES(20,10,5);
|
||||
DELETE FROM t1 WHERE a>=10;
|
||||
DROP INDEX i1;
|
||||
DELETE FROM t1;
|
||||
ROLLBACK;
|
||||
}} msg]
|
||||
}
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
set v {1 1}
|
||||
} else {
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
}
|
||||
for {set go 1; set i 1} {$go} {incr i} {
|
||||
do_test malloc-4.$i {
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
sqlite_malloc_fail $i
|
||||
set v [catch {sqlite db test.db} msg]
|
||||
if {$v} {
|
||||
set msg ""
|
||||
} else {
|
||||
set v [catch {execsql {
|
||||
BEGIN TRANSACTION;
|
||||
CREATE TABLE t1(a int, b int, c int);
|
||||
CREATE INDEX i1 ON t1(a,b);
|
||||
COPY t1 FROM 'data.tmp';
|
||||
UPDATE t1 SET b=a WHERE a in (10,12,22);
|
||||
INSERT INTO t1 SELECT * FROM t1
|
||||
WHERE a IN (SELECT a FROM t1 WHERE a<10);
|
||||
DROP INDEX i1;
|
||||
DELETE FROM t1;
|
||||
COMMIT;
|
||||
}} msg]
|
||||
}
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
set v {1 1}
|
||||
} else {
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
}
|
||||
|
Reference in New Issue
Block a user