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

Added the SQLITE_TESTCTRL_RESERVE option to sqlite3_test_control().

Simplifications to btree.c to facilitate structural coverage testing. (CVS 6894)

FossilOrigin-Name: cfbeda1b3126503e9631471ce4713e25b007859f
This commit is contained in:
drh
2009-07-15 11:26:44 +00:00
parent c27ae614dd
commit c046e3edeb
5 changed files with 47 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
C Add\scomments\sand\sassert()\sstatements\sto\sshow\sthat\sthe\sreturn\svalue\sfrom\nsqlite3BtreeKeySize()\sand\ssqlite3BtreeData()\susually\sdo\snot\smatter.\nTicket\s#3968.\s\sAlso\sremove\sa\sNEVER()\smacro\sthat\scan\ssometimes\sbe\strue\s-\ndiscovered\swhile\stesting\sthe\sprevious\schange.\s(CVS\s6893) C Added\sthe\sSQLITE_TESTCTRL_RESERVE\soption\sto\ssqlite3_test_control().\nSimplifications\sto\sbtree.c\sto\sfacilitate\sstructural\scoverage\stesting.\s(CVS\s6894)
D 2009-07-14T18:35:45 D 2009-07-15T11:26:44
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in df9359da7a726ccb67a45db905c5447d5c00c6ef F Makefile.in df9359da7a726ccb67a45db905c5447d5c00c6ef
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -106,7 +106,7 @@ F src/auth.c 802a9439dfa0b8c208b10055cba400e82ef18025
F src/backup.c 6f1c2d9862c8a3feb7739dfcca02c1f5352e37f3 F src/backup.c 6f1c2d9862c8a3feb7739dfcca02c1f5352e37f3
F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119 F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119
F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c
F src/btree.c dcdf6af667dfeae23eaf8fac7ace3caeed632c8b F src/btree.c b5a8d21f6b21ab0068910d881b38a3c54ba7214d
F src/btree.h e53a10fd31d16c60a86f03c9467a6f470aa3683b F src/btree.h e53a10fd31d16c60a86f03c9467a6f470aa3683b
F src/btreeInt.h a568bf057aa249eb06fd31358b4393a5ac88c118 F src/btreeInt.h a568bf057aa249eb06fd31358b4393a5ac88c118
F src/build.c 867028ee9f63f7bc8eb8d4a720bb98cf9b9a12b4 F src/build.c 867028ee9f63f7bc8eb8d4a720bb98cf9b9a12b4
@@ -126,7 +126,7 @@ F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0
F src/legacy.c 54a11649f27ae55f4fcd6e6b5ba836f839cb8704 F src/legacy.c 54a11649f27ae55f4fcd6e6b5ba836f839cb8704
F src/lempar.c 0c4d1ab0a5ef2b0381eb81a732c54f68f27a574d F src/lempar.c 0c4d1ab0a5ef2b0381eb81a732c54f68f27a574d
F src/loadext.c 0e88a335665db0b2fb4cece3e49dcb65d832635a F src/loadext.c 0e88a335665db0b2fb4cece3e49dcb65d832635a
F src/main.c 9f6d91815233b517c1bdf16fd8fa838d10d2c015 F src/main.c 4e6d1c2418983cebed436be2996a067f9e1bfe5d
F src/malloc.c 16907f3b9d3f56e2c69d763ff18d9ee49e7433cd F src/malloc.c 16907f3b9d3f56e2c69d763ff18d9ee49e7433cd
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270 F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270
@@ -161,7 +161,7 @@ F src/resolve.c 4a61d03e49b15440878096e6030863fc628828f0
F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f
F src/select.c 71748b8e244112cf73df9446c4246c192276c30d F src/select.c 71748b8e244112cf73df9446c4246c192276c30d
F src/shell.c db2643650b9268df89a4bedca3f1c6d9e786f1bb F src/shell.c db2643650b9268df89a4bedca3f1c6d9e786f1bb
F src/sqlite.h.in ccc67f14d5661240d05eadb8ab308aa637b0630c F src/sqlite.h.in 92a8960ca178cfbd73ce71cca65829c6262137ac
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
F src/sqliteInt.h c638fff6a05bb1c546f361e8527385fef0638917 F src/sqliteInt.h c638fff6a05bb1c546f361e8527385fef0638917
F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
@@ -740,7 +740,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
P 17749fa5480069cc4909acd992ab26d10afb279d P 0c710c1be537127511d95b5b261c7bf26e1bc952
R 35cb54a841da615cb5c38b8f0cb072f6 R fa83113fa396566b08a5d7758ddff6ee
U drh U drh
Z 3ca0e11ecfb15e2cf3df9913240d628c Z 0062b335ba599f8c6b5dce4f0649d58c

View File

@@ -1 +1 @@
0c710c1be537127511d95b5b261c7bf26e1bc952 cfbeda1b3126503e9631471ce4713e25b007859f

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** May you share freely, never taking more than you give.
** **
************************************************************************* *************************************************************************
** $Id: btree.c,v 1.687 2009/07/14 17:48:06 drh Exp $ ** $Id: btree.c,v 1.688 2009/07/15 11:26:44 drh Exp $
** **
** This file implements a external (disk-based) database using BTrees. ** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information. ** See the header comment on "btreeInt.h" for additional information.
@@ -1200,7 +1200,7 @@ static int freeSpace(MemPage *pPage, int start, int size){
assert( pPage->pBt!=0 ); assert( pPage->pBt!=0 );
assert( sqlite3PagerIswriteable(pPage->pDbPage) ); assert( sqlite3PagerIswriteable(pPage->pDbPage) );
assert( start>=pPage->hdrOffset+6+(pPage->leaf?0:4) ); assert( start>=pPage->hdrOffset+6+pPage->childPtrSize );
assert( (start + size)<=pPage->pBt->usableSize ); assert( (start + size)<=pPage->pBt->usableSize );
assert( sqlite3_mutex_held(pPage->pBt->mutex) ); assert( sqlite3_mutex_held(pPage->pBt->mutex) );
assert( size>=0 ); /* Minimum cell size is 4 */ assert( size>=0 ); /* Minimum cell size is 4 */
@@ -4885,7 +4885,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
** is possible to add the page as a new free-list leaf. ** is possible to add the page as a new free-list leaf.
*/ */
if( nFree!=0 ){ if( nFree!=0 ){
int nLeaf; /* Initial number of leaf cells on trunk page */ u32 nLeaf; /* Initial number of leaf cells on trunk page */
iTrunk = get4byte(&pPage1->aData[32]); iTrunk = get4byte(&pPage1->aData[32]);
rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0); rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
@@ -4894,7 +4894,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
} }
nLeaf = get4byte(&pTrunk->aData[4]); nLeaf = get4byte(&pTrunk->aData[4]);
if( nLeaf<0 ){ if( nLeaf > pBt->usableSize/4 - 2 ){
rc = SQLITE_CORRUPT_BKPT; rc = SQLITE_CORRUPT_BKPT;
goto freepage_out; goto freepage_out;
} }
@@ -4908,7 +4908,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
** 3.6.0, databases with freelist trunk pages holding more than ** 3.6.0, databases with freelist trunk pages holding more than
** usableSize/4 - 8 entries will be reported as corrupt. In order ** usableSize/4 - 8 entries will be reported as corrupt. In order
** to maintain backwards compatibility with older versions of SQLite, ** to maintain backwards compatibility with older versions of SQLite,
** we will contain to restrict the number of entries to usableSize/4 - 8 ** we will continue to restrict the number of entries to usableSize/4 - 8
** for now. At some point in the future (once everyone has upgraded ** for now. At some point in the future (once everyone has upgraded
** to 3.6.0 or later) we should consider fixing the conditional above ** to 3.6.0 or later) we should consider fixing the conditional above
** to read "usableSize/4-2" instead of "usableSize/4-8". ** to read "usableSize/4-2" instead of "usableSize/4-8".
@@ -4935,9 +4935,11 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
** first trunk in the free-list is full. Either way, the page being freed ** first trunk in the free-list is full. Either way, the page being freed
** will become the new first trunk page in the free-list. ** will become the new first trunk page in the free-list.
*/ */
if( ((!pPage) && (0 != (rc = btreeGetPage(pBt, iPage, &pPage, 0)))) if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
|| (0 != (rc = sqlite3PagerWrite(pPage->pDbPage))) goto freepage_out;
){ }
rc = sqlite3PagerWrite(pPage->pDbPage);
if( rc!=SQLITE_OK ){
goto freepage_out; goto freepage_out;
} }
put4byte(pPage->aData, iTrunk); put4byte(pPage->aData, iTrunk);
@@ -5185,7 +5187,7 @@ static int dropCell(MemPage *pPage, int idx, int sz){
data = pPage->aData; data = pPage->aData;
ptr = &data[pPage->cellOffset + 2*idx]; ptr = &data[pPage->cellOffset + 2*idx];
pc = get2byte(ptr); pc = get2byte(ptr);
if( (pc<pPage->hdrOffset+6+(pPage->leaf?0:4)) if( NEVER(pc<pPage->hdrOffset+6+pPage->childPtrSize)
|| (pc+sz>pPage->pBt->usableSize) ){ || (pc+sz>pPage->pBt->usableSize) ){
return SQLITE_CORRUPT_BKPT; return SQLITE_CORRUPT_BKPT;
} }
@@ -6866,7 +6868,8 @@ int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
** a no-op). */ ** a no-op). */
invalidateIncrblobCursors(p, iTable, 0, 1); invalidateIncrblobCursors(p, iTable, 0, 1);
if( SQLITE_OK==(rc = saveAllCursors(pBt, (Pgno)iTable, 0)) ){ rc = saveAllCursors(pBt, (Pgno)iTable, 0);
if( SQLITE_OK==rc ){
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange); rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
} }
sqlite3BtreeLeave(p); sqlite3BtreeLeave(p);
@@ -6906,8 +6909,10 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){
** need to move another root-page to fill a gap left by the deleted ** need to move another root-page to fill a gap left by the deleted
** root page. If an open cursor was using this page a problem would ** root page. If an open cursor was using this page a problem would
** occur. ** occur.
**
** This error is caught long before control reaches this point.
*/ */
if( pBt->pCursor ){ if( NEVER(pBt->pCursor) ){
sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db); sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
return SQLITE_LOCKED_SHAREDCACHE; return SQLITE_LOCKED_SHAREDCACHE;
} }
@@ -6989,7 +6994,10 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){
} }
#endif #endif
}else{ }else{
/* If sqlite3BtreeDropTable was called on page 1. */ /* If sqlite3BtreeDropTable was called on page 1.
** This really never should happen except in a corrupt
** database.
*/
zeroPage(pPage, PTF_INTKEY|PTF_LEAF ); zeroPage(pPage, PTF_INTKEY|PTF_LEAF );
releasePage(pPage); releasePage(pPage);
} }

View File

@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be ** other files are for internal use by SQLite and should not be
** accessed by users of the library. ** accessed by users of the library.
** **
** $Id: main.c,v 1.560 2009/06/26 15:14:55 drh Exp $ ** $Id: main.c,v 1.561 2009/07/15 11:26:44 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -2245,6 +2245,21 @@ int sqlite3_test_control(int op, ...){
rc = ALWAYS(x); rc = ALWAYS(x);
break; break;
} }
/* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
**
** Set the nReserve size to N for the main database on the database
** connection db.
*/
case SQLITE_TESTCTRL_RESERVE: {
sqlite3 *db = va_arg(ap, sqlite3*);
int x = va_arg(ap,int);
sqlite3_mutex_enter(db->mutex);
sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
sqlite3_mutex_leave(db->mutex);
break;
}
} }
va_end(ap); va_end(ap);
#endif /* SQLITE_OMIT_BUILTIN_TEST */ #endif /* SQLITE_OMIT_BUILTIN_TEST */

View File

@@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as ** the version number) and changes its name to "sqlite3.h" as
** part of the build process. ** part of the build process.
** **
** @(#) $Id: sqlite.h.in,v 1.458 2009/06/19 22:50:31 drh Exp $ ** @(#) $Id: sqlite.h.in,v 1.459 2009/07/15 11:26:44 drh Exp $
*/ */
#ifndef _SQLITE3_H_ #ifndef _SQLITE3_H_
#define _SQLITE3_H_ #define _SQLITE3_H_
@@ -4945,6 +4945,7 @@ int sqlite3_test_control(int op, ...);
#define SQLITE_TESTCTRL_PENDING_BYTE 11 #define SQLITE_TESTCTRL_PENDING_BYTE 11
#define SQLITE_TESTCTRL_ASSERT 12 #define SQLITE_TESTCTRL_ASSERT 12
#define SQLITE_TESTCTRL_ALWAYS 13 #define SQLITE_TESTCTRL_ALWAYS 13
#define SQLITE_TESTCTRL_RESERVE 14
/* /*
** CAPI3REF: SQLite Runtime Status {H17200} <S60200> ** CAPI3REF: SQLite Runtime Status {H17200} <S60200>