diff options
author | drh <drh@noemail.net> | 2005-08-20 03:03:04 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2005-08-20 03:03:04 +0000 |
commit | 85c23c61e22215061ea35e024b401bc91a4799da (patch) | |
tree | 3440df6277ce632376b8a402246111c6cabbdd04 | |
parent | 0bbaa1ba9ac1fa0cc45a7becc76c84e6558bd848 (diff) | |
download | sqlite-85c23c61e22215061ea35e024b401bc91a4799da.tar.gz sqlite-85c23c61e22215061ea35e024b401bc91a4799da.zip |
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
-rw-r--r-- | manifest | 27 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/attach.c | 6 | ||||
-rw-r--r-- | src/build.c | 17 | ||||
-rw-r--r-- | src/util.c | 34 | ||||
-rw-r--r-- | test/attachmalloc.test | 118 | ||||
-rw-r--r-- | test/default.test | 10 | ||||
-rw-r--r-- | test/fkey1.test | 19 | ||||
-rw-r--r-- | test/index3.test | 17 | ||||
-rw-r--r-- | test/temptable.test | 9 | ||||
-rw-r--r-- | test/view.test | 11 |
11 files changed, 231 insertions, 39 deletions
@@ -1,5 +1,5 @@ -C Increase\stest\scoverage\sof\salter.c\sto\s100%.\s\sFix\sbugs\sfound\sin\sthe\sprocess.\s(CVS\s2603) -D 2005-08-19T19:14:13 +C Increased\stest\scoverage.\s\sSome\smalloc\stests\snow\sfail\sthough\sthis\sis\sbelieved\nto\sbe\san\sinstrumentation\sproblem\snot\sa\sreal\serror.\s(CVS\s2604) +D 2005-08-20T03:03:04 F Makefile.in b109ddb46a5550d0732dcd6caca01c123f6d5cdd F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -30,11 +30,11 @@ F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a F src/alter.c 26d755f2143719dd3f5b8aaf6cbe3c7f95332528 F src/analyze.c 3ab32927f4d3067ead10e4c4f6fb61b2a93479cc -F src/attach.c 3615dbe960cbee4aa5ea300b8a213dad36527b0f +F src/attach.c 4b21689700a72ae281fa85dbaff06b2a62bd49ee F src/auth.c 31e2304bef67f44d635655f44234387ea7d21454 F src/btree.c 667227e4375d8bf6abd748cf6bad7a2004bf5d87 F src/btree.h 41a71ce027db9ddee72cb43df2316bbe3a1d92af -F src/build.c bc7b4791f2eb3c5e1671f9df83902030e3bcb995 +F src/build.c 55e7e915a538bb25b1b7448cfb9189cccba554b2 F src/callback.c 9a1162c8f9dae9fad6d548339669aacb5f6cf76b F src/complete.c 4de937dfdd4c79a501772ab2035b26082f337a79 F src/date.c 7444b0900a28da77e57e3337a636873cff0ae940 @@ -78,7 +78,7 @@ F src/tokenize.c aa02aa217d8afa3effafca112cd7f18b4c2c3b71 F src/trigger.c f51dec15921629591cb98bf2e350018e268b109a F src/update.c a9d2c5f504212d62da1b094476f1389c0e02f83f F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c -F src/util.c f66b47d937bde79d458a18665b67a98dbba5108f +F src/util.c f4678297585c69811724468554393b898548e9c6 F src/vacuum.c 829d9e1a6d7c094b80e0899686670932eafd768c F src/vdbe.c 69f33e22c7d0a64b23fbb69e6da95a1bb6869032 F src/vdbe.h 3b29a9af6c7a64ed692bef1fc5f61338f40d2f67 @@ -98,6 +98,7 @@ F test/analyze.test a1206c7430606ffa20bcbb220c87c2873f5efdd4 F test/attach.test f320e98bcca68d100cab7666a0c9a93ac5f236bd F test/attach2.test 3396c012a39ddf7ba6b528d80bd79554168aa115 F test/attach3.test 63013383adc4380af69779f34f4af19bd49f7cbe +F test/attachmalloc.test eb099a3aa44be5adb12b65ef0d13fcd11f1c403b F test/auth.test 973ae7274eae32c4453fbbcbd0ec2b80c5b1eeb3 F test/autoinc.test 395fbac8bc158d3599995c73bfb15c418a5429f0 F test/autovacuum.test cf2719b17659f7a011202ad05905654cedf26023 @@ -134,7 +135,7 @@ F test/corrupt2.test 88342570828f2b8cbbd8369eff3891f5c0bdd5ba F test/crash.test f38b980a0508655d08c957a6dd27d66bca776504 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/date.test 30ca15e608a45d868fd419c901795382efe27020 -F test/default.test 648b12a9153095448f4d61aca73b273592673cb4 +F test/default.test 252298e42a680146b1dd64f563b95bdf088d94fb F test/delete.test 33e1670049364fc3604217a6c2eda042a47115ab F test/delete2.test e382b6a97787197eb8b93dd4ccd37797c3725ea3 F test/diskfull.test ba27afd587af1216f92d2bb00132cbc0e39354fc @@ -142,13 +143,13 @@ F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52 F test/enc2.test d1ab077b84f4d3099246915422b1ab6b81481e0a F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837 F test/expr.test 71b8cba7fe5c228147c93e530e098144565aaa46 -F test/fkey1.test 81bb13caaa78f58d7d191d7f535529f7c91d821a +F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce F test/func.test 8f9165f0454b03f35c1f35668d516a96cbf4a41b F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda F test/in.test cead6165aebbe0d451bb2263a307173acfeb6240 F test/index.test 51e01a0928b4b61228917ddd8c6c0e2466547f6f F test/index2.test 9ad98243fd7fe833795a9cc662f371f0eed4ff4f -F test/index3.test 72bd07b508022db688ec536c460345d24a3912e3 +F test/index3.test f66718cd92ce1216819d47e6a156755e4b2c4ca1 F test/insert.test b0a89e1568fe9890758f8f2b43b68e840e8f1a1a F test/insert2.test 792ad079f59c7e14cf9397712725224e2112c838 F test/insert3.test c67f0240b1c17e71fa2ed8bb6de064928f549f95 @@ -208,7 +209,7 @@ F test/subselect.test 3f3f7a940dc3195c3139f4d530385cb54665d614 F test/table.test d0e05ede3f6e5a8b79f8661ddcc4618cf7e69f8a F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1 F test/tclsqlite.test a8d9afe680c466881a40252a86ef0fca457ab08c -F test/temptable.test c71eeffe8af807f76eafdc5a39824639a1e301df +F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b F test/tester.tcl 98ecdc5723b3b2be5a8a5c3a7f38fa53031466ee F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35 F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b @@ -231,7 +232,7 @@ F test/utf16.test 5fb019e09601774743858ef7380b6c02103ff120 F test/vacuum.test 5d4857ae2afc9c20d0edb8acc58bdc8d630126a9 F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 -F test/view.test 3c79232a2ee45918c62a0cf90411525899404a76 +F test/view.test ce0f0ad39fa4a3572acffcf1e634850ee151aae0 F test/where.test b6ab0f64adc5fbb4259f284b19da6cd9aeadc711 F test/where2.test 503e2e2b6abe14c5c10222e72d08ef84c1bf1ffb F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b @@ -296,7 +297,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 4281a838f2f531af24b008d2834e8318798472c5 -R e46f0078da7fdd3d7209c1df240c1e04 +P b550d04d43a92f33a01438ae03df14678db3cdee +R 67d7b59d35705cacc80cadb289e8be20 U drh -Z ff386666acb3fed8a078593bb81d2165 +Z 534f3c24965d5feaf73a5d09d58f869d diff --git a/manifest.uuid b/manifest.uuid index 1916c9d5b..af83769d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b550d04d43a92f33a01438ae03df14678db3cdee
\ No newline at end of file +f786f37a5e31f42aaf81b3ad4a734f12855da69e
\ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 92366508e..f548aa5eb 100644 --- a/src/attach.c +++ b/src/attach.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.33 2005/03/16 12:15:21 danielk1977 Exp $ +** $Id: attach.c,v 1.34 2005/08/20 03:03:04 drh Exp $ */ #include "sqliteInt.h" @@ -146,8 +146,8 @@ void sqlite3Attach( db->aDb[i].pBt = 0; } sqlite3ResetInternalSchema(db, 0); - if( 0==pParse->nErr ){ - pParse->nErr++; + assert( pParse->nErr>0 ); /* Always set by sqlite3ReadSchema() */ + if( pParse->rc==SQLITE_OK ){ pParse->rc = SQLITE_ERROR; } } diff --git a/src/build.c b/src/build.c index 197ce9cb6..50ad5262d 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.341 2005/08/18 18:15:06 drh Exp $ +** $Id: build.c,v 1.342 2005/08/20 03:03:04 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -200,9 +200,6 @@ Table *sqlite3LocateTable(Parse *pParse, const char *zName, const char *zDbase){ if( p==0 ){ if( zDbase ){ sqlite3ErrorMsg(pParse, "no such table: %s.%s", zDbase, zName); - }else if( sqlite3FindTable(pParse->db, zName, 0)!=0 ){ - sqlite3ErrorMsg(pParse, "table \"%s\" is not in database \"%s\"", - zName, zDbase); }else{ sqlite3ErrorMsg(pParse, "no such table: %s", zName); } @@ -258,10 +255,7 @@ static void sqliteDeleteIndex(sqlite3 *db, Index *p){ assert( db!=0 && p->zName!=0 ); pOld = sqlite3HashInsert(&db->aDb[p->iDb].idxHash, p->zName, strlen(p->zName)+1, 0); - if( pOld!=0 && pOld!=p ){ - sqlite3HashInsert(&db->aDb[p->iDb].idxHash, pOld->zName, - strlen(pOld->zName)+1, pOld); - } + assert( pOld==0 || pOld==p ); freeIndex(p); } @@ -1522,10 +1516,13 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ ** Actually, this error is caught previously and so the following test ** should always fail. But we will leave it in place just to be safe. */ +#if 0 if( pTable->nCol<0 ){ sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName); return 1; } +#endif + assert( pTable->nCol>=0 ); /* If we get this far, it means we need to compute the table names. ** Note that the call to sqlite3ResultSetOfSelect() will expand any @@ -2070,7 +2067,9 @@ void sqlite3CreateIndex( if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && sqlite3FixSrcList(&sFix, pTblName) ){ - goto exit_create_index; + /* Because the parser constructs pTblName from a single identifier, + ** sqlite3FixSrcList can never fail. */ + assert(0); } pTab = sqlite3LocateTable(pParse, pTblName->a[0].zName, pTblName->a[0].zDatabase); diff --git a/src/util.c b/src/util.c index 80ac67437..53748cd21 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.142 2005/08/13 18:15:43 drh Exp $ +** $Id: util.c,v 1.143 2005/08/20 03:03:04 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> @@ -74,13 +74,10 @@ static int memcnt = 0; #define N_GUARD 2 /* -** Allocate new memory and set it to zero. Return NULL if -** no memory is available. +** Check for a simulated memory allocation failure. Return true if +** the failure should be simulated. Return false to proceed as normal. */ -void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){ - void *p; - int *pi; - int i, k; +static int simulatedMallocFailure(int n, char *zFile, int line){ if( sqlite3_iMallocFail>=0 ){ sqlite3_iMallocFail--; if( sqlite3_iMallocFail==0 ){ @@ -90,10 +87,26 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){ n, zFile,line); #endif sqlite3_iMallocFail = sqlite3_iMallocReset; - return 0; + return 1; } } - if( n==0 ) return 0; + return 0; +} + +/* +** Allocate new memory and set it to zero. Return NULL if +** no memory is available. +*/ +void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){ + void *p; + int *pi; + int i, k; + if( n==0 ){ + return 0; + } + if( simulatedMallocFailure(n, zFile, line) ){ + return 0; + } sqlite3_memUsed += n; if( sqlite3_memMax<sqlite3_memUsed ) sqlite3_memMax = sqlite3_memUsed; k = (n+sizeof(int)-1)/sizeof(int); @@ -193,6 +206,9 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){ sqlite3Free_(oldP,zFile,line); return 0; } + if( simulatedMallocFailure(n, zFile, line) ){ + return 0; + } oldPi = oldP; oldPi -= N_GUARD+1; if( oldPi[0]!=0xdead1122 ){ diff --git a/test/attachmalloc.test b/test/attachmalloc.test new file mode 100644 index 000000000..707e4ff5e --- /dev/null +++ b/test/attachmalloc.test @@ -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 diff --git a/test/default.test b/test/default.test index 06e9e3679..9a2ab1afe 100644 --- a/test/default.test +++ b/test/default.test @@ -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 diff --git a/test/fkey1.test b/test/fkey1.test index d730d154e..8a06b0596 100644 --- a/test/fkey1.test +++ b/test/fkey1.test @@ -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; + } +} {} + diff --git a/test/index3.test b/test/index3.test index b744574f7..c6c6ff4e0 100644 --- a/test/index3.test +++ b/test/index3.test @@ -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 diff --git a/test/temptable.test b/test/temptable.test index 9a3218983..dae1db62e 100644 --- a/test/temptable.test +++ b/test/temptable.test @@ -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 diff --git a/test/view.test b/test/view.test index 9c13ad54a..22b740949 100644 --- a/test/view.test +++ b/test/view.test @@ -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 |