Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Increased test coverage. Some malloc tests now fail though this is believed to be an instrumentation problem not a real error. (CVS 2604) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
f786f37a5e31f42aaf81b3ad4a734f12 |
User & Date: | drh 2005-08-20 03:03:04.000 |
Context
2005-08-20
| ||
13:47 | More test coverage improvements. (CVS 2605) (check-in: e559e810a5 user: drh tags: trunk) | |
03:03 | Increased test coverage. Some malloc tests now fail though this is believed to be an instrumentation problem not a real error. (CVS 2604) (check-in: f786f37a5e user: drh tags: trunk) | |
2005-08-19
| ||
19:14 | Increase test coverage of alter.c to 100%. Fix bugs found in the process. (CVS 2603) (check-in: b550d04d43 user: drh tags: trunk) | |
Changes
Changes to src/attach.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2003 April 6 ** ** 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 contains code used to implement the ATTACH and DETACH commands. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2003 April 6 ** ** 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 contains code used to implement the ATTACH and DETACH commands. ** ** $Id: attach.c,v 1.34 2005/08/20 03:03:04 drh Exp $ */ #include "sqliteInt.h" /* ** This routine is called by the parser to process an ATTACH statement: ** ** ATTACH DATABASE filename AS dbname |
︙ | ︙ | |||
142 143 144 145 146 147 148 | int i = db->nDb - 1; assert( i>=2 ); if( db->aDb[i].pBt ){ sqlite3BtreeClose(db->aDb[i].pBt); db->aDb[i].pBt = 0; } sqlite3ResetInternalSchema(db, 0); | | | | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | int i = db->nDb - 1; assert( i>=2 ); if( db->aDb[i].pBt ){ sqlite3BtreeClose(db->aDb[i].pBt); db->aDb[i].pBt = 0; } sqlite3ResetInternalSchema(db, 0); assert( pParse->nErr>0 ); /* Always set by sqlite3ReadSchema() */ if( pParse->rc==SQLITE_OK ){ pParse->rc = SQLITE_ERROR; } } attach_end: sqliteFree(zFile); sqliteFree(zName); |
︙ | ︙ |
Changes to src/build.c.
︙ | ︙ | |||
18 19 20 21 22 23 24 | ** CREATE INDEX ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ** CREATE INDEX ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** ** $Id: build.c,v 1.342 2005/08/20 03:03:04 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** This routine is called when a new SQL statement is beginning to ** be parsed. Initialize the pParse structure as needed. |
︙ | ︙ | |||
196 197 198 199 200 201 202 | return 0; } p = sqlite3FindTable(pParse->db, zName, zDbase); if( p==0 ){ if( zDbase ){ sqlite3ErrorMsg(pParse, "no such table: %s.%s", zDbase, zName); | < < < | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | return 0; } p = sqlite3FindTable(pParse->db, zName, zDbase); if( p==0 ){ if( zDbase ){ sqlite3ErrorMsg(pParse, "no such table: %s.%s", zDbase, zName); }else{ sqlite3ErrorMsg(pParse, "no such table: %s", zName); } pParse->checkSchema = 1; } return p; } |
︙ | ︙ | |||
254 255 256 257 258 259 260 | */ static void sqliteDeleteIndex(sqlite3 *db, Index *p){ Index *pOld; assert( db!=0 && p->zName!=0 ); pOld = sqlite3HashInsert(&db->aDb[p->iDb].idxHash, p->zName, strlen(p->zName)+1, 0); | | < < < | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | */ static void sqliteDeleteIndex(sqlite3 *db, Index *p){ Index *pOld; assert( db!=0 && p->zName!=0 ); pOld = sqlite3HashInsert(&db->aDb[p->iDb].idxHash, p->zName, strlen(p->zName)+1, 0); assert( pOld==0 || pOld==p ); freeIndex(p); } /* ** For the index called zIdxName which is found in the database iDb, ** unlike that index from its Table then remove the index from ** the index hash table and free all memory structures associated |
︙ | ︙ | |||
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 | ** ** CREATE VIEW one AS SELECT * FROM two; ** CREATE VIEW two AS SELECT * FROM one; ** ** 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( pTable->nCol<0 ){ sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName); return 1; } /* If we get this far, it means we need to compute the table names. ** Note that the call to sqlite3ResultSetOfSelect() will expand any ** "*" elements in the results set of the view and will assign cursors ** to the elements of the FROM clause. But we do not want these changes ** to be permanent. So the computation is done on a copy of the SELECT ** statement that defines the view. | > > > | 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 | ** ** CREATE VIEW one AS SELECT * FROM two; ** CREATE VIEW two AS SELECT * FROM one; ** ** 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 ** "*" elements in the results set of the view and will assign cursors ** to the elements of the FROM clause. But we do not want these changes ** to be permanent. So the computation is done on a copy of the SELECT ** statement that defines the view. |
︙ | ︙ | |||
2066 2067 2068 2069 2070 2071 2072 | iDb = 1; } #endif if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && sqlite3FixSrcList(&sFix, pTblName) ){ | | > > | 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 | iDb = 1; } #endif if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && sqlite3FixSrcList(&sFix, pTblName) ){ /* 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); if( !pTab ) goto exit_create_index; assert( iDb==pTab->iDb ); }else{ assert( pName==0 ); |
︙ | ︙ |
Changes to src/util.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** ** $Id: util.c,v 1.143 2005/08/20 03:03:04 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> #include <ctype.h> #if SQLITE_MEMDEBUG>2 && defined(__GLIBC__) #include <execinfo.h> |
︙ | ︙ | |||
70 71 72 73 74 75 76 | ** Number of 32-bit guard words. This should probably be a multiple of ** 2 since on 64-bit machines we want the value returned by sqliteMalloc() ** to be 8-byte aligned. */ #define N_GUARD 2 /* | | | | < < < > > > | | | > > > > > > > > | > > > > > | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | ** Number of 32-bit guard words. This should probably be a multiple of ** 2 since on 64-bit machines we want the value returned by sqliteMalloc() ** to be 8-byte aligned. */ #define N_GUARD 2 /* ** Check for a simulated memory allocation failure. Return true if ** the failure should be simulated. Return false to proceed as normal. */ static int simulatedMallocFailure(int n, char *zFile, int line){ if( sqlite3_iMallocFail>=0 ){ sqlite3_iMallocFail--; if( sqlite3_iMallocFail==0 ){ sqlite3_malloc_failed++; #if SQLITE_MEMDEBUG>1 fprintf(stderr,"**** failed to allocate %d bytes at %s:%d\n", n, zFile,line); #endif sqlite3_iMallocFail = sqlite3_iMallocReset; return 1; } } 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); pi = malloc( (N_GUARD*2+1+k)*sizeof(int)); if( pi==0 ){ if( n>0 ) sqlite3_malloc_failed++; return 0; |
︙ | ︙ | |||
188 189 190 191 192 193 194 195 196 197 198 199 200 201 | void *p; if( oldP==0 ){ return sqlite3Malloc_(n,1,zFile,line); } if( n==0 ){ sqlite3Free_(oldP,zFile,line); return 0; } oldPi = oldP; oldPi -= N_GUARD+1; if( oldPi[0]!=0xdead1122 ){ fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)oldP); return 0; } | > > > | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | void *p; if( oldP==0 ){ return sqlite3Malloc_(n,1,zFile,line); } if( n==0 ){ sqlite3Free_(oldP,zFile,line); return 0; } if( simulatedMallocFailure(n, zFile, line) ){ return 0; } oldPi = oldP; oldPi -= N_GUARD+1; if( oldPi[0]!=0xdead1122 ){ fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)oldP); return 0; } |
︙ | ︙ |
Added test/attachmalloc.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 |
Changes to test/default.test.
︙ | ︙ | |||
8 9 10 11 12 13 14 | # May you share freely, never taking more than you give. # #************************************************************************* # This file implements regression tests for SQLite library. The # focus of this file is testing corner cases of the DEFAULT syntax # on table definitions. # | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # May you share freely, never taking more than you give. # #************************************************************************* # This file implements regression tests for SQLite library. The # focus of this file is testing corner cases of the DEFAULT syntax # on table definitions. # # $Id: default.test,v 1.2 2005/08/20 03:03:04 drh Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl ifcapable bloblit { do_test default-1.1 { |
︙ | ︙ | |||
36 37 38 39 40 41 42 | x INTEGER, y INTEGER DEFAULT NULL ); INSERT INTO t2(x) VALUES(1); SELECT * FROM t2; } } {1 {}} | > > > > > | > > > | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | x INTEGER, y INTEGER DEFAULT NULL ); INSERT INTO t2(x) VALUES(1); 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 |
Changes to test/fkey1.test.
︙ | ︙ | |||
48 49 50 51 52 53 54 55 56 57 58 | CREATE TABLE t3( a INTEGER REFERENCES t2, b INTEGER REFERENCES t1, FOREIGN KEY (a,b) REFERENCES t2(x,y) ); } } {} finish_test | > > > > > > > > > > > > > > > > > > > | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | CREATE TABLE t3( a INTEGER REFERENCES t2, b INTEGER REFERENCES t1, FOREIGN KEY (a,b) REFERENCES t2(x,y) ); } } {} 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; } } {} finish_test |
Changes to test/index3.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2005 February 14 # # 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 file is testing the CREATE INDEX statement. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2005 February 14 # # 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 file is testing the CREATE INDEX statement. # # $Id: index3.test,v 1.2 2005/08/20 03:03:04 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Ticket #1115. Make sure that when a UNIQUE index is created on a # non-unique column (or columns) that it fails and that it leaves no |
︙ | ︙ | |||
35 36 37 38 39 40 41 42 43 | CREATE UNIQUE INDEX i1 ON t1(a); } } {1 {indexed columns are not unique}} do_test index3-1.3 { catchsql COMMIT; } {0 {}} integrity_check index3-1.4 finish_test | > > > > > > > > > > > > > > > | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | CREATE UNIQUE INDEX i1 ON t1(a); } } {1 {indexed columns are not unique}} do_test index3-1.3 { catchsql COMMIT; } {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 |
Changes to test/temptable.test.
︙ | ︙ | |||
8 9 10 11 12 13 14 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. # # This file implements tests for temporary tables and indices. # | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. # # This file implements tests for temporary tables and indices. # # $Id: temptable.test,v 1.16 2005/08/20 03:03:04 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl ifcapable !tempdb { finish_test return |
︙ | ︙ | |||
399 400 401 402 403 404 405 406 | db close sqlite3 db test.db catchsql { SELECT * FROM t8,t9; } } {1 {no such table: t9}} finish_test | > > > > > > > | 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | db close sqlite3 db test.db catchsql { SELECT * FROM t8,t9; } } {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 |
Changes to test/view.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2002 February 26 # # 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 file is testing VIEW statements. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2002 February 26 # # 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 file is testing VIEW statements. # # $Id: view.test,v 1.27 2005/08/20 03:03:04 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Omit this entire file if the library is not configured with views enabled. ifcapable !view { finish_test return |
︙ | ︙ | |||
444 445 446 447 448 449 450 451 | # do_test view-12.1 { catchsql { CREATE VIEW v12 AS SELECT a FROM t1 WHERE b=? } } {1 {parameters are not allowed in views}} finish_test | > > > > > > > > > | 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | # do_test view-12.1 { catchsql { CREATE VIEW v12 AS SELECT a FROM t1 WHERE b=? } } {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 |