]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Changes to the way one of the WAL/OOM tests works.
authordan <dan@noemail.net>
Mon, 31 May 2010 06:38:34 +0000 (06:38 +0000)
committerdan <dan@noemail.net>
Mon, 31 May 2010 06:38:34 +0000 (06:38 +0000)
FossilOrigin-Name: 15abbc34168f7a5bd418254c2b16aac97029e6ea

manifest
manifest.uuid
test/malloc_common.tcl
test/walfault.test

index 2b150606e501af8a584625f0f112e1a4c17f0930..a45dddeda68fcd9de66e18c4cdffbc7d5951be0c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\stests\sto\sfkey2.test\sto\scheck\sthat\sON\sCONFLICT\sclauses\sdo\snot\saffect\sSQLite's\sbehaviour\swhen\san\sFK\sconstraint\sis\sviolated.
-D 2010-05-29T08:40:38
+C Changes\sto\sthe\sway\sone\sof\sthe\sWAL/OOM\stests\sworks.
+D 2010-05-31T06:38:35
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -506,7 +506,7 @@ F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb
 F test/mallocI.test e3ea401904d010cb7c1e4b2ee8803f4a9f5b999d
 F test/mallocJ.test b5d1839da331d96223e5f458856f8ffe1366f62e
 F test/mallocK.test d79968641d1b70d88f6c01bdb9a7eb4a55582cc9
-F test/malloc_common.tcl f95c4d3459877e64c2d856b8a9c39210f9968ddf
+F test/malloc_common.tcl d92de40a5583f977a7c1bd3a25d8f66d75e55263
 F test/manydb.test b3d3bc4c25657e7f68d157f031eb4db7b3df0d3c
 F test/memdb.test 0825155b2290e900264daaaf0334b6dfe69ea498
 F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217
@@ -767,7 +767,7 @@ F test/walbak.test e7650a26eb4b8abeca9b145b1af1e63026dde432
 F test/walcksum.test 4efa8fb88c32bed8288ea4385a9cc113a5c8f0bf
 F test/walcrash.test f6d5fb2bb108876f04848720a488065d9deef69f
 F test/walcrash2.test 14585ad1a2c85da2de721caa3b4deeea55213008
-F test/walfault.test f71d4c9a13d4e27086aef55f1e0e94734ffa2f6a
+F test/walfault.test 690350d02057409b695a3694f048780f2c5e21f4
 F test/walhook.test 67e675127f4acb72f061a12667ce6e5460b06b78
 F test/walmode.test 6ca9d710cc9f6545b913abcded6d6b0b15641048
 F test/walslow.test d21625e2e99e11c032ce949e8a94661576548933
@@ -815,7 +815,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 60c22bde52121993d4bea11eef38ab285c737e2c
-R 132966a7c0563e76b2849379585e861e
+P e9e5b1001986348ef0f88c19de87b94559a5451e
+R f3f15c95e56f90189266a174fb626d53
 U dan
-Z 9c5f2213670b38101b8556211a758e4d
+Z 4fade6b535eae7f88d92509f7fe17c62
index 5bfdadacff2dea66242f1aeeb64dbf1ac10a1059..e3f39cee603a38965ac0d3c3c41ec01e1f6375fc 100644 (file)
@@ -1 +1 @@
-e9e5b1001986348ef0f88c19de87b94559a5451e
\ No newline at end of file
+15abbc34168f7a5bd418254c2b16aac97029e6ea
\ No newline at end of file
index a72238d7fe28c758d3aa2488da230170f497e429..992f545f293cf3f1c9b62fb4fcf8eba0672bd1b3 100644 (file)
@@ -23,6 +23,91 @@ ifcapable builtin_test {
   return 0
 }
 
+# The following procs are used as [do_faultsim_test] when injecting OOM
+# faults into test cases.
+#
+proc oom_injectstart {nRepeat iFail} {
+  sqlite3_memdebug_fail $iFail -repeat $nRepeat
+}
+proc oom_injectstop {} {
+  sqlite3_memdebug_fail -1
+}
+
+# This command is only useful when used by the -test script of a 
+# [do_faultsim_test] test case.
+#
+proc faultsim_test_result {args} {
+  upvar testrc testrc testresult testresult testnfail testnfail
+  set t [list $testrc $testresult]
+  set r [concat $args [list {1 {out of memory}}]]
+  if { ($testnfail==0 && $t != [lindex $r 0]) || [lsearch $r $t]<0 } {
+    error "nfail=$testnfail rc=$testrc result=$testresult"
+  }
+}
+
+# Usage do_faultsim_test NAME ?OPTIONS...? 
+#
+# The first argument, <test number>, is used as a prefix of the test names
+# taken by tests executed by this command. Options are as follows. All
+# options take a single argument.
+#
+#     -injectstart      Script to enable fault-injection.
+#
+#     -injectstop       Script to disable fault-injection.
+#
+#     -prep             Script to execute before -body.
+#
+#     -body             Script to execute (with fault injection).
+#
+#     -test             Script to execute after -body.
+#
+proc do_faultsim_test {testname args} {
+
+  set DEFAULT(-injectstart) {oom_injectstart 0}
+  set DEFAULT(-injectstop)  {oom_injectstop}
+  set DEFAULT(-prep)        ""
+  set DEFAULT(-body)        ""
+  set DEFAULT(-test)        ""
+
+  array set O [array get DEFAULT]
+  array set O $args
+  foreach o [array names O] {
+    if {[info exists DEFAULT($o)]==0} { error "unknown option: $o" }
+  }
+
+  proc faultsim_test_proc {testrc testresult testnfail} $O(-test)
+
+  set stop 0
+  for {set iFail 1} {!$stop} {incr iFail} {
+
+    # Evaluate the -prep script.
+    #
+    eval $O(-prep)
+
+    # Start the fault-injection. Run the -body script. Stop the fault
+    # injection. Local var $nfail is set to the total number of faults 
+    # injected into the system this trial.
+    #
+    eval $O(-injectstart) $iFail
+    set rc [catch $O(-body) res]
+    set nfail [eval $O(-injectstop)]
+
+    # Run the -test script. If it throws no error, consider this trial
+    # sucessful. If it does throw an error, cause a [do_test] test to
+    # fail (and print out the unexpected exception thrown by the -test
+    # script at the same time).
+    #
+    set rc [catch [list faultsim_test_proc $rc $res $nfail] res]
+    if {$rc == 0} {set res ok}
+    do_test $testname.$iFail [list list $rc $res] {0 ok}
+
+    # If no faults where injected this trial, don't bother running
+    # any more. This test is finished.
+    #
+    if {$nfail==0} { set stop 1 }
+  }
+}
+
 # Usage: do_malloc_test <test number> <options...>
 #
 # The first argument, <test number>, is an integer used to name the
index 9d41e50fd58beac8757ef2d391a9598dba9b19d5..3b0395e05fad11f6b6759fcc328d118f005926c0 100644 (file)
@@ -19,11 +19,34 @@ source $testdir/malloc_common.tcl
 
 ifcapable !wal {finish_test ; return }
 
-do_malloc_test walfault-oom-1 -sqlbody {
-  PRAGMA journal_mode = WAL;
-  CREATE TABLE t1(a, b);
-  INSERT INTO t1 VALUES(1, 2);
-  PRAGMA wal_checkpoint;
+do_faultsim_test walfault-oom-1 -prep {
+  catch { db close }
+  file delete -force test.db test.db-wal test.db-journal
+  sqlite3 db test.db
+} -body {
+  db eval { PRAGMA main.journal_mode = WAL }
+} -test {
+
+  faultsim_test_result {0 wal}
+
+  # Test that the connection that encountered an error as part of 
+  # "PRAGMA journal_mode = WAL" and a new connection use the same
+  # journal mode when accessing the database.
+  #
+  # If "PRAGMA journal_mode" is executed immediately, connection [db] (the 
+  # one that hit the error in journal_mode="WAL") might return "wal" even 
+  # if it failed to switch the database to WAL mode. This is not considered 
+  # a problem. When it tries to read the database, connection [db] correctly 
+  # recognizes that it is a rollback database and switches back to a 
+  # rollback compatible journal mode.
+  #
+  set jm  [db one  {SELECT * FROM sqlite_master ; PRAGMA main.journal_mode}]
+  sqlite3 db2 test.db
+  set jm2 [db2 one {SELECT * FROM sqlite_master ; PRAGMA main.journal_mode}]
+  db2 close
+
+  if { $jm!=$jm2 } { error "Journal modes do not match: $jm $jm2" }
+  if { $testrc==0 && $jm!="wal" } { error "Journal mode is not WAL" }
 }
 
 do_malloc_test walfault-oom-2 -tclprep {