From c396d4af5873b4e49399c7170b913b6632ae124b Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 2 Jul 2010 11:27:43 +0000 Subject: [PATCH] Additional test cases to cover branches in pager.c. FossilOrigin-Name: eddfb2b4062f8a8b907f0c7bc08a05c16692e900 --- manifest | 34 +++++-------- manifest.uuid | 2 +- src/os.c | 4 +- src/test_malloc.c | 20 ++++++++ test/pager1.test | 108 +++++++++++++++++++++++++++++++---------- test/pagerfault.test | 33 +++++++++++-- test/pagerfault2.test | 47 ++++++++++++++---- test/permutations.test | 1 + 8 files changed, 187 insertions(+), 62 deletions(-) diff --git a/manifest b/manifest index 231e442c7e..2b480879dd 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Add\sa\sNEVER\sto\ssqlite3PagerCommitPhaseTwo()\sbecause\sit\sis\snow\sno\slonger\npossible\sto\sinvoke\sthat\sfunction\swithout\sholding\sa\sRESERVED\slock. -D 2010-07-02T01:18:12 +C Additional\stest\scases\sto\scover\sbranches\sin\spager.c. +D 2010-07-02T11:27:43 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -153,7 +150,7 @@ F src/mutex_os2.c 6a62583e374ba3ac1a3fcc0da2bfdac7d3942689 F src/mutex_unix.c cf84466b4fdd2baa0d5a10bb19f08b2abc1ce42e F src/mutex_w32.c 1fe0e735897be20e09dd6f53c3fb516c6b48c0eb F src/notify.c cbfa66a836da3a51567209636e6a94059c137930 -F src/os.c 9c4a2f82a50306a33907678ec0187b6ad1486bfe +F src/os.c 1b3a1edf20587639d9d88bfebe018f7a6e7ba0ec F src/os.h d7775504a51e6e0d40315aa427b3e229ff9ff9ca F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_os2.c 665876d5eec7585226b0a1cf5e18098de2b2da19 @@ -203,7 +200,7 @@ F src/test_intarray.c d879bbf8e4ce085ab966d1f3c896a7c8b4f5fc99 F src/test_intarray.h 489edb9068bb926583445cb02589344961054207 F src/test_journal.c 044c1a53ec4dd6f0dde66727b154cd099f5f34d1 F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e -F src/test_malloc.c 2842c922b8e8d992aba722214952204ca025b411 +F src/test_malloc.c 4ab85f2b8ae3a237f4e6557b0a641181a19ffab1 F src/test_mutex.c ce06b59aca168cd8c520b77159a24352a7469bd3 F src/test_onefile.c fb979cecd57217fd49023ed5468d8c93429c4fbe F src/test_osinst.c f1e4194860aa7e2f2ed7375c6b1f23a4290dd98c @@ -538,15 +535,15 @@ F test/notify3.test b923ff67728f363378698fb27b5f41a5a1b4d9e0 F test/notnull.test cc7c78340328e6112a13c3e311a9ab3127114347 F test/null.test a8b09b8ed87852742343b33441a9240022108993 F test/openv2.test af02ed0a9cbc0d2a61b8f35171d4d117e588e4ec -F test/pager1.test 67de7de48695203bab435eca9e650fb5ec634da6 +F test/pager1.test 4984a90b28abb4dca597b92912558c36ea87350b F test/pager2.test f5c757c271ce642d36a393ecbfb3aef1c240dcef -F test/pagerfault.test 6ece6ceb6384e90ec526a65c4f4e8cd9b6dc7d61 -F test/pagerfault2.test 1287f123bd5d20452113739ed7755fd254e502f1 +F test/pagerfault.test 743952c5509244a71d66d67bf960d920793bb847 +F test/pagerfault2.test be9088b0daff0e63983138e0bde2311eb734f900 F test/pageropt.test 8146bf448cf09e87bb1867c2217b921fb5857806 F test/pagesize.test 76aa9f23ecb0741a4ed9d2e16c5fa82671f28efb F test/pcache.test 4118a183908ecaed343a06fcef3ba82e87e0129d F test/pcache2.test 0d85f2ab6963aee28c671d4c71bec038c00a1d16 -F test/permutations.test 81d93c4650073c332f9e4406e4b5d1e7f52c097f +F test/permutations.test e0f281e97b5d0064a04b9ceb48be27c57a0a35b5 F test/pragma.test a869b428b861f9dbbdb25461a104e8e830fc3026 F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea @@ -833,14 +830,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 95c69dfbddaf4367cd699dfe8fcf8e06030c1f53 -R 930bbf4b4a963aec35ed6b03fae686d4 -U drh -Z 540bd39ddc7176815db98ecf80c42f23 ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFMLT5joxKgR168RlERAlVIAJ42G6HI9TMCYeZcCnG5KLimD/q0MwCfUMqn -uE0Yc+lcE/Y/v45SPR8cU9U= -=OxES ------END PGP SIGNATURE----- +P 6ae7617298c70f8e03dd0ed73b8153d4871fb023 +R 83a0c7d4f2d6c19f7630fe52766d7d11 +U dan +Z 7699ffebb24a4e13d73e3bdae384a3cd diff --git a/manifest.uuid b/manifest.uuid index 2d5e538794..85e0009fae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6ae7617298c70f8e03dd0ed73b8153d4871fb023 \ No newline at end of file +eddfb2b4062f8a8b907f0c7bc08a05c16692e900 \ No newline at end of file diff --git a/src/os.c b/src/os.c index 8fa10a9c02..dea5f3803d 100644 --- a/src/os.c +++ b/src/os.c @@ -35,7 +35,9 @@ ** */ #if defined(SQLITE_TEST) && (SQLITE_OS_WIN==0) - #define DO_OS_MALLOC_TEST(x) if (!x || !sqlite3IsMemJournal(x)) { \ +int sqlite3_memdebug_vfs_oom_test = 1; + #define DO_OS_MALLOC_TEST(x) \ + if (sqlite3_memdebug_vfs_oom_test && (!x || !sqlite3IsMemJournal(x))) { \ void *pTstAlloc = sqlite3Malloc(10); \ if (!pTstAlloc) return SQLITE_IOERR_NOMEM; \ sqlite3_free(pTstAlloc); \ diff --git a/src/test_malloc.c b/src/test_malloc.c index d5f0a6df5a..1267f6e78f 100644 --- a/src/test_malloc.c +++ b/src/test_malloc.c @@ -1359,6 +1359,25 @@ static int test_install_memsys3( return TCL_OK; } +static int test_vfs_oom_test( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + extern int sqlite3_memdebug_vfs_oom_test; + if( objc>2 ){ + Tcl_WrongNumArgs(interp, 1, objv, "?INTEGER?"); + return TCL_ERROR; + }else if( objc==2 ){ + int iNew; + if( Tcl_GetIntFromObj(interp, objv[1], &iNew) ) return TCL_ERROR; + sqlite3_memdebug_vfs_oom_test = iNew; + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_memdebug_vfs_oom_test)); + return TCL_OK; +} + /* ** Register commands with the TCL interpreter. */ @@ -1396,6 +1415,7 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){ { "sqlite3_dump_memsys3", test_dump_memsys3 ,3 }, { "sqlite3_dump_memsys5", test_dump_memsys3 ,5 }, { "sqlite3_install_memsys3", test_install_memsys3 ,0 }, + { "sqlite3_memdebug_vfs_oom_test", test_vfs_oom_test ,0 }, }; int i; for(i=0; i40; } - recursive_select 64 {db eval COMMIT} + recursive_select 64 x2 {db eval COMMIT} execsql { PRAGMA integrity_check; SELECT count(*) FROM x1; @@ -2110,7 +2127,7 @@ do_test pager1-24.1.5 { DELETE FROM x1; INSERT INTO x1 SELECT * FROM x2; } - recursive_select 64 { db eval {CREATE TABLE x3(x, y, z)} } + recursive_select 64 x2 { db eval {CREATE TABLE x3(x, y, z)} } execsql { SELECT * FROM x3 } } {} @@ -2139,4 +2156,45 @@ do_test pager1-25-2 { db close } {} +#------------------------------------------------------------------------- +# Sector-size tests. +# +do_test pager1-26.1 { + testvfs tv -default 1 + tv sectorsize 4096 + faultsim_delete_and_reopen + db func a_string a_string + execsql { + PRAGMA page_size = 512; + CREATE TABLE tbl(a PRIMARY KEY, b UNIQUE); + BEGIN; + INSERT INTO tbl VALUES(a_string(25), a_string(600)); + INSERT INTO tbl SELECT a_string(25), a_string(600) FROM tbl; + INSERT INTO tbl SELECT a_string(25), a_string(600) FROM tbl; + INSERT INTO tbl SELECT a_string(25), a_string(600) FROM tbl; + INSERT INTO tbl SELECT a_string(25), a_string(600) FROM tbl; + INSERT INTO tbl SELECT a_string(25), a_string(600) FROM tbl; + INSERT INTO tbl SELECT a_string(25), a_string(600) FROM tbl; + INSERT INTO tbl SELECT a_string(25), a_string(600) FROM tbl; + COMMIT; + } +} {} +do_execsql_test pager1-26.1 { + UPDATE tbl SET b = a_string(550); +} {} +db close +tv delete + +#------------------------------------------------------------------------- +do_test pager1.27.1 { + faultsim_delete_and_reopen + sqlite3_pager_refcounts db + execsql { + BEGIN; + CREATE TABLE t1(a, b); + } + sqlite3_pager_refcounts db + execsql COMMIT +} {} + finish_test diff --git a/test/pagerfault.test b/test/pagerfault.test index 542bb30ce8..75b21a796e 100644 --- a/test/pagerfault.test +++ b/test/pagerfault.test @@ -545,6 +545,9 @@ do_faultsim_test pagerfault-11 -prep { faultsim_integrity_check } +} + + #------------------------------------------------------------------------- # Test fault injection when writing to a database file that resides on # a file-system with a sector-size larger than the database page-size. @@ -571,7 +574,8 @@ do_test pagerfault-12-pre1 { } faultsim_save_and_close } {} -do_faultsim_test pagerfault-12 -prep { + +do_faultsim_test pagerfault-12a -prep { faultsim_restore_and_reopen execsql { PRAGMA cache_size = 10 } db func a_string a_string; @@ -584,6 +588,31 @@ do_faultsim_test pagerfault-12 -prep { faultsim_integrity_check } +do_test pagerfault-12-pre2 { + faultsim_restore_and_reopen + execsql { + CREATE TABLE t2 AS SELECT * FROM t1 LIMIT 10; + } + faultsim_save_and_close +} {} +do_faultsim_test pagerfault-12b -prep { + faultsim_restore_and_reopen + db func a_string a_string; + execsql { SELECT * FROM t1 } +} -body { + set sql(1) { UPDATE t2 SET x = a_string(280) } + set sql(2) { UPDATE t1 SET x = a_string(280) WHERE rowid = 5 } + + db eval { SELECT rowid FROM t1 LIMIT 2 } { db eval $sql($rowid) } + +} -test { + faultsim_test_result {0 {}} + faultsim_integrity_check +} + +catch { db close } +ss_layer delete + #------------------------------------------------------------------------- # Test fault injection when SQLite opens a database where the size of the @@ -936,7 +965,5 @@ do_faultsim_test pagerfault-21 -prep { faultsim_test_result {0 {}} } -} - finish_test diff --git a/test/pagerfault2.test b/test/pagerfault2.test index 634e539e62..edc24bda7e 100644 --- a/test/pagerfault2.test +++ b/test/pagerfault2.test @@ -22,6 +22,8 @@ source $testdir/tester.tcl source $testdir/lock_common.tcl source $testdir/malloc_common.tcl +sqlite3_memdebug_vfs_oom_test 0 + set a_string_counter 1 proc a_string {n} { global a_string_counter @@ -30,37 +32,62 @@ proc a_string {n} { } db func a_string a_string - -# The following tests, pagerfault2-1.*, attempt to provoke OOM errors when -# manipulating the internal "bitvec" structures. Since bitvec structures -# only allocate memory very rarely, this requires fairly large databases. -# do_test pagerfault2-1-pre1 { faultsim_delete_and_reopen db func a_string a_string execsql { PRAGMA journal_mode = DELETE; + PRAGMA page_size = 1024; CREATE TABLE t1(a, b); INSERT INTO t1 VALUES(a_string(401), a_string(402)); } - for {set ii 0} {$ii < 14} {incr ii} { + for {set ii 0} {$ii < 13} {incr ii} { execsql { INSERT INTO t1 SELECT a_string(401), a_string(402) FROM t1 } } faultsim_save_and_close -} {} -do_faultsim_test pagerfault2-1.1 -faults oom* -prep { + file size test.db +} [expr 1024 * 8268] + +do_faultsim_test pagerfault2-1 -faults oom-transient -prep { faultsim_restore_and_reopen + sqlite3_db_config_lookaside db 0 256 4096 execsql { BEGIN; + SELECT * FROM t1; INSERT INTO t1 VALUES(5, 6); SAVEPOINT abc; - UPDATE t1 SET a = a||'x'; + UPDATE t1 SET a = a||'x' WHERE rowid<3700; } } -body { + execsql { UPDATE t1 SET a = a||'x' WHERE rowid>=3700 AND rowid<=4200 } execsql { ROLLBACK TO abc } } -test { faultsim_test_result {0 {}} - faultsim_integrity_check } +do_test pagerfault2-2-pre1 { + faultsim_restore_and_reopen + execsql { DELETE FROM t1 } + faultsim_save_and_close +} {} + +do_faultsim_test pagerfault2-2 -faults oom-transient -prep { + faultsim_restore_and_reopen + sqlite3_db_config_lookaside db 0 256 4096 + db func a_string a_string + + execsql { + PRAGMA cache_size = 20; + BEGIN; + INSERT INTO t1 VALUES(a_string(401), a_string(402)); + SAVEPOINT abc; + } +} -body { + execsql { INSERT INTO t1 VALUES (a_string(2000000), a_string(2500000)) } +} -test { + faultsim_test_result {0 {}} +} + +sqlite3_memdebug_vfs_oom_test 1 finish_test + diff --git a/test/permutations.test b/test/permutations.test index 3d11261078..453764e518 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -171,6 +171,7 @@ test_suite "coverage-pager" -description { pager1.test pager2.test pagerfault.test + pagerfault2.test walfault.test walbak.test journal2.test