1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Increased test coverage. Some malloc tests now fail though this is believed

to be an instrumentation problem not a real error. (CVS 2604)

FossilOrigin-Name: f786f37a5e31f42aaf81b3ad4a734f12855da69e
This commit is contained in:
drh
2005-08-20 03:03:04 +00:00
parent 0bbaa1ba9a
commit 85c23c61e2
11 changed files with 231 additions and 39 deletions

118
test/attachmalloc.test Normal file
View File

@@ -0,0 +1,118 @@
# 2005 September 19
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# 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.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing the ATTACH statement and
# specifically out-of-memory conditions within that command.
#
# $Id: attachmalloc.test,v 1.1 2005/08/20 03:03:04 drh Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Usage: do_malloc_test <test name> <options...>
#
# The first argument, <test number>, is an integer 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 malloc failure simulation.
# -sqlbody TCL script to run with malloc failure simulation.
# -cleanup TCL script to run after the test.
#
# This command runs a series of tests to verify SQLite's ability
# to handle an out-of-memory condition gracefully. It is assumed
# that if this condition occurs a malloc() call will return a
# NULL pointer. Linux, for example, doesn't do that by default. See
# the "BUGS" section of malloc(3).
#
# Each iteration of a loop, the TCL commands in any argument passed
# to the -tclbody switch, followed by the SQL commands in any argument
# passed to the -sqlbody switch are executed. Each iteration the
# Nth call to sqliteMalloc() is made to fail, where N is increased
# each time the loop runs starting from 1. When all commands execute
# successfully, the loop ends.
#
proc do_malloc_test {tn args} {
array set ::mallocopts $args
set ::go 1
for {set ::n 1} {$::go} {incr ::n} {
do_test $tn.$::n {
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}
set ::DB [sqlite3 db test.db]
if {[info exists ::mallocopts(-tclprep)]} {
eval $::mallocopts(-tclprep)
}
if {[info exists ::mallocopts(-sqlprep)]} {
execsql $::mallocopts(-sqlprep)
}
sqlite_malloc_fail $::n
set ::mallocbody {}
if {[info exists ::mallocopts(-tclbody)]} {
append ::mallocbody "$::mallocopts(-tclbody)\n"
}
if {[info exists ::mallocopts(-sqlbody)]} {
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
}
set v [catch $::mallocbody 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}
sqlite_malloc_fail 0
if {[info exists ::mallocopts(-cleanup)]} {
catch $::mallocopts(-cleanup)
}
}
unset ::mallocopts
}
do_malloc_test attachmalloc-1 -tclprep {
db close
for {set i 2} {$i<=4} {incr i} {
file delete -force test$i.db
file delete -force test$i.db-journal
}
} -tclbody {
if {[catch {sqlite3 db test.db}]} {
error "out of memory"
}
} -sqlbody {
ATTACH 'test2.db' AS two;
CREATE TABLE two.t1(x);
ATTACH 'test3.db' AS three;
CREATE TABLE three.t1(x);
ATTACH 'test4.db' AS four;
CREATE TABLE four.t1(x);
}
finish_test

View File

@@ -12,7 +12,7 @@
# focus of this file is testing corner cases of the DEFAULT syntax
# on table definitions.
#
# $Id: default.test,v 1.1 2005/08/19 01:07:16 drh Exp $
# $Id: default.test,v 1.2 2005/08/20 03:03:04 drh Exp $
#
set testdir [file dirname $argv0]
@@ -40,5 +40,13 @@ do_test default-1.2 {
SELECT * FROM t2;
}
} {1 {}}
do_test default-1.3 {
catchsql {
CREATE TABLE t3(
x INTEGER,
y INTEGER DEFAULT (max(x,5))
)
}
} {1 {default value of column [y] is not constant}}
finish_test

View File

@@ -52,6 +52,25 @@ do_test fkey1-1.2 {
);
}
} {}
do_test fkey1-2.1 {
execsql {
CREATE TABLE t4(a integer primary key);
CREATE TABLE t5(x references t4);
CREATE TABLE t6(x references t4);
CREATE TABLE t7(x references t4);
CREATE TABLE t8(x references t4);
CREATE TABLE t9(x references t4);
CREATE TABLE t10(x references t4);
DROP TABLE t7;
DROP TABLE t9;
DROP TABLE t5;
DROP TABLE t8;
DROP TABLE t6;
DROP TABLE t10;
}
} {}

View File

@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the CREATE INDEX statement.
#
# $Id: index3.test,v 1.1 2005/02/14 20:48:19 drh Exp $
# $Id: index3.test,v 1.2 2005/08/20 03:03:04 drh Exp $
set testdir [file dirname $argv0]
@@ -40,4 +40,19 @@ do_test index3-1.3 {
} {0 {}}
integrity_check index3-1.4
# This test corrupts the database file so it must be the last test
# in the series.
#
do_test index3-99.1 {
execsql {
PRAGMA writable_schema=on;
UPDATE sqlite_master SET sql='nonsense';
}
db close
sqlite3 db test.db
catchsql {
DROP INDEX i1;
}
} {1 {malformed database schema - near "nonsense": syntax error}}
finish_test

View File

@@ -12,7 +12,7 @@
#
# This file implements tests for temporary tables and indices.
#
# $Id: temptable.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $
# $Id: temptable.test,v 1.16 2005/08/20 03:03:04 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -403,4 +403,11 @@ do_test temptable-6.8 {
}
} {1 {no such table: t9}}
do_test temptable-7.1 {
catchsql {
ATTACH 'test2.db' AS two;
CREATE TEMP TABLE two.abc(x,y);
}
} {1 {temporary table name must be unqualified}}
finish_test

View File

@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing VIEW statements.
#
# $Id: view.test,v 1.26 2005/07/08 17:13:47 drh Exp $
# $Id: view.test,v 1.27 2005/08/20 03:03:04 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -448,4 +448,13 @@ do_test view-12.1 {
}
} {1 {parameters are not allowed in views}}
do_test view-13.1 {
file delete -force test2.db
catchsql {
ATTACH 'test2.db' AS two;
CREATE TABLE two.t2(x,y);
CREATE VIEW v13 AS SELECT y FROM two.t2;
}
} {1 {view v13 cannot reference objects in database two}}
finish_test