]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add new test file e_walckpt.test. Still some tests to come.
authordan <dan@noemail.net>
Fri, 5 Dec 2014 20:46:19 +0000 (20:46 +0000)
committerdan <dan@noemail.net>
Fri, 5 Dec 2014 20:46:19 +0000 (20:46 +0000)
FossilOrigin-Name: e4db3db3a65ecfd4069a40d436aa7a5512d61a30

manifest
manifest.uuid
src/test1.c
test/e_walckpt.test [new file with mode: 0644]

index dc82a5106338cc47bf967cfe8fad550fdb8196a0..12cf54556006be18fc4c06db3b1c8a617fc35552 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Make\ssure\sthe\sWhereTerm\sobjects\sare\sfully\szeroed\swhen\sthey\sare\sallocated.
-D 2014-12-05T19:50:58.294
+C Add\snew\stest\sfile\se_walckpt.test.\sStill\ssome\stests\sto\scome.
+D 2014-12-05T20:46:19.108
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 6c4f961fa91d0b4fa121946a19f9e5eac2f2f809
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -238,7 +238,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c 81712116e826b0089bb221b018929536b2b5406f
 F src/table.c f142bba7903e93ca8d113a5b8877a108ad1a27dc
 F src/tclsqlite.c 0a874655dd39a9875e39c5d3c464db662171d228
-F src/test1.c c24d7f67252348d756773a6dbe23a61b4552f709
+F src/test1.c ebb8cd3c94a2ac8851b7b0b1349284e73a8b4c7a
 F src/test2.c 98049e51a17dc62606a99a9eb95ee477f9996712
 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c
 F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df
@@ -478,6 +478,7 @@ F test/e_update.test 312cb8f5ccfe41515a6bb092f8ea562a9bd54d52
 F test/e_uri.test 5ae33760fb2039c61aa2d90886f1664664173585
 F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9
 F test/e_wal.test 0967f0b8f1dfda871dc7b9b5574198f1f4f7d69a
+F test/e_walckpt.test de5a8d86c5b95569309c6da796dbea870c22e003
 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
 F test/enc2.test 83437a79ba1545a55fb549309175c683fb334473
 F test/enc3.test 90683ad0e6ea587b9d5542ca93568af9a9858c40
@@ -1224,7 +1225,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 7ed3346e8c10dbf52fd44ab69900699d4f7ad3fd
-R 4b33ce7227bf5d27f48a35be658eb882
-U drh
-Z 1360efaa2c5f7305d23abadc41fbb137
+P fdb667335c2250239a66143aec4235325dec8274
+R 88cb63a8d2ff8042b23c5ce33c03986a
+U dan
+Z d1e87cf655be5398ea39ae6fc02beae8
index 437ab02c1f6f186b9904dd90fe38cb1c2b910524..786ddbf8ea201b03c611926947de516d30a79ff2 100644 (file)
@@ -1 +1 @@
-fdb667335c2250239a66143aec4235325dec8274
\ No newline at end of file
+e4db3db3a65ecfd4069a40d436aa7a5512d61a30
\ No newline at end of file
index 7839b30494afdb4602ffe9ea5eed7bcb251e3cf1..14ccacd863a5b05a2958b6f7f0fd38ca400f913d 100644 (file)
@@ -5704,15 +5704,17 @@ static int test_wal_checkpoint_v2(
   if( objc==4 ){
     zDb = Tcl_GetString(objv[3]);
   }
-  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
-   || Tcl_GetIndexFromObj(interp, objv[2], aMode, "mode", 0, &eMode) 
-  ){
+  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) || (
+      TCL_OK!=Tcl_GetIntFromObj(0, objv[2], &eMode)
+   && TCL_OK!=Tcl_GetIndexFromObj(interp, objv[2], aMode, "mode", 0, &eMode) 
+  )){
     return TCL_ERROR;
   }
 
   rc = sqlite3_wal_checkpoint_v2(db, zDb, eMode, &nLog, &nCkpt);
   if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
-    Tcl_SetResult(interp, (char *)sqlite3_errmsg(db), TCL_VOLATILE);
+    const char *zErrCode = sqlite3ErrName(rc);
+    Tcl_AppendResult(interp, zErrCode, " - ", (char *)sqlite3_errmsg(db), 0);
     return TCL_ERROR;
   }
 
diff --git a/test/e_walckpt.test b/test/e_walckpt.test
new file mode 100644 (file)
index 0000000..8b0aae7
--- /dev/null
@@ -0,0 +1,290 @@
+# 2014 December 04
+#
+# 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/lock_common.tcl
+source $testdir/wal_common.tcl
+set testprefix e_walckpt
+
+# The following two commands are used to determine if any of the files
+# "test.db", "test.db2" and "test.db3" are modified by a test case.
+#
+# The [save_db_hashes] command saves a hash of the current contents of
+# all three files in global variables. The [compare_db_hashes] compares
+# the current contents with the saved hashes and returns a list of the
+# files that have changed.
+#
+proc save_db_hashes {} {
+  global H
+  foreach f {test.db test.db2 test.db3} {
+    set H($f) 0
+    catch { set H($f) [md5file $f] }
+  }
+}
+proc compare_db_hashes {} {
+  global H
+  set ret [list]
+  foreach f {test.db test.db2 test.db3} {
+    set expect 0
+    catch { set expect [md5file $f] }
+    if {$H($f) != $expect} { lappend ret $f }
+  }
+  set ret
+}
+
+
+# The following tests are run 3 times, each using a different method of 
+# invoking a checkpoint:
+#
+#   1) Using sqlite3_wal_checkpoint_v2()
+#   2) Using "PRAGMA wal_checkpoint"
+#   3) Using sqlite3_wal_checkpoint() in place of checkpoint_v2(PASSIVE)
+#
+# Cases (2) and (3) are to show that the following statements are 
+# correct, respectively:
+#
+# EVIDENCE-OF: R-36706-10507 The PRAGMA wal_checkpoint command can be
+# used to invoke this interface from SQL.
+#
+# EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is
+# equivalent to
+# sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0).
+# 
+foreach {tn script} {
+  1 {
+    proc checkpoint {db mode args} {
+      eval sqlite3_wal_checkpoint_v2 [list $db] [list $mode] $args
+    }
+  }
+
+  2 {
+    proc checkpoint {db mode args} {
+      set sql "PRAGMA wal_checkpoint"
+      if {[llength $args] && [lindex $args 0]!=""} {
+        set sql "PRAGMA [lindex $args 0].wal_checkpoint"
+      }
+      set rc [catch { $db eval $sql } msg]
+      if {$rc} {
+        regsub {database} $msg {database:} msg
+        error "[sqlite3_errcode $db] - $msg"
+      }
+      set msg
+    }
+  }
+
+  3 {
+    proc checkpoint {db mode args} {
+      if {$mode == "passive"} {
+        set rc [eval sqlite3_wal_checkpoint [list $db] $args]
+        if {$rc != "SQLITE_OK"} {
+          error "$rc - [sqlite3_errmsg $db]"
+        }
+      } else {
+        eval sqlite3_wal_checkpoint_v2 [list $db] [list $mode] $args
+      }
+    }
+  }
+
+} {
+
+  eval $script
+
+  reset_db
+  forcedelete test.db2 test.db3 test.db4
+  execsql {
+    ATTACH 'test.db2' AS aux;
+    ATTACH 'test.db3' AS aux2;
+    ATTACH 'test.db4' AS aux3;
+    CREATE TABLE t1(x);
+    CREATE TABLE aux.t2(x);
+    CREATE TABLE aux2.t3(x);
+    CREATE TABLE aux3.t4(x);
+    PRAGMA main.journal_mode = WAL;
+    PRAGMA aux.journal_mode = WAL;
+    PRAGMA aux2.journal_mode = WAL;
+    /* Leave aux4 in rollback mode */
+  }
+
+  # EVIDENCE-OF: R-49787-09095 The sqlite3_wal_checkpoint_v2(D,X,M,L,C)
+  # interface runs a checkpoint operation on database X of database
+  # connection D in mode M. Status information is written back into
+  # integers pointed to by L and C.
+  #
+  #     Tests 1, 2 and 3 below verify the "on database X" part of the
+  #     above. Other parts of this requirement are tested below.
+  #
+  # EVIDENCE-OF: R-00653-06026 If parameter zDb is NULL or points to a
+  # zero length string, then the specified operation is attempted on all
+  # WAL databases attached to database connection db.
+  #
+  #     Tests 4 and 5 below test this.
+  #
+  foreach {tn2 zDb dblist} {
+    1 main  test.db
+    2 aux   test.db2
+    3 aux2  test.db3
+    4 ""    {test.db test.db2 test.db3}
+    5 -     {test.db test.db2 test.db3}
+    6 temp  {}
+  } {
+    do_test $tn.1.$tn2 {
+      execsql {
+        INSERT INTO t1 VALUES(1);
+        INSERT INTO t2 VALUES(2);
+        INSERT INTO t3 VALUES(3);
+      }
+      save_db_hashes
+
+      if {$zDb == "-"} {
+        checkpoint db passive
+      } else {
+        checkpoint db passive $zDb
+      }
+
+      compare_db_hashes
+    } $dblist
+  }
+
+  # EVIDENCE-OF: R-38207-48996 If zDb is not NULL (or a zero length
+  # string) and is not the name of any attached database, SQLITE_ERROR is
+  # returned to the caller.
+  do_test $tn.2.1 {
+    list [catch { checkpoint db passive notadb } msg] $msg
+  } {1 {SQLITE_ERROR - unknown database: notadb}}
+
+  # EVIDENCE-OF: R-14303-42483 If database zDb is the name of an attached
+  # database that is not in WAL mode, SQLITE_OK is returned and both
+  # *pnLog and *pnCkpt set to -1.
+  #
+  if {$tn==3} {
+    # With sqlite3_wal_checkpoint() the two output variables cannot be 
+    # tested. So just test that no error is returned when attempting to
+    # checkpoint a db in rollback mode.
+    do_test $tn.2.2.a { checkpoint db passive aux3 } {}
+  } else {
+    do_test $tn.2.2.b { checkpoint db passive aux3 } {0 -1 -1}
+  }
+
+  # EVIDENCE-OF: R-62028-47212 All calls obtain an exclusive "checkpoint"
+  # lock on the database file.
+  db close
+  testvfs tvfs
+  tvfs filter xShmLock
+  tvfs script filelock
+  proc filelock {method file handle details} {
+    # Test for an exclusive checkpoint lock. A checkpoint lock locks a
+    # single byte starting at offset 1.
+    if {$details == "1 1 lock exclusive"} { set ::seen_checkpoint_lock 1 }
+  }
+  sqlite3 db test.db -vfs tvfs
+  do_test $tn.3.1 {
+    execsql { INSERT INTO t1 VALUES('xyz') }
+    unset -nocomplain ::seen_checkpoint_lock
+    checkpoint db passive
+    set ::seen_checkpoint_lock
+  } {1}
+  db close
+  tvfs delete
+  reset_db
+
+
+
+  #-----------------------------------------------------------------------
+  # EVIDENCE-OF: R-10421-19736 If any other process is running a
+  # checkpoint operation at the same time, the lock cannot be obtained and
+  # SQLITE_BUSY is returned.
+  #
+  # EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
+  # it will not be invoked in this case.
+  #
+  testvfs tvfs
+  tvfs filter xWrite
+  sqlite3 db test.db -vfs tvfs
+  sqlite3 db2 test.db -vfs tvfs
+
+  do_test $tn.3.2.1 {
+    db2 eval {
+      PRAGMA journal_mode = WAL;
+      CREATE TABLE t1(x, y);
+      INSERT INTO t1 VALUES(1,2);
+      INSERT INTO t1 VALUES(3,4);
+      INSERT INTO t1 VALUES(5,6);
+    }
+    file size test.db-wal
+  } [wal_file_size 5 1024]
+
+
+  # Connection [db] runs a checkpoint. During this checkpoint, each
+  # time it calls xWrite() to write a page into the database file, we
+  # attempt to start a checkpoint using [db2]. According to the 
+  # first requirement being tested, this should return SQLITE_BUSY. According
+  # to the second, the busy-handler belonging to [db2] should not be
+  # invoked.
+  #
+  set ::write_count 0
+  set ::write_errors [list]
+  proc busy_callback {args} {
+    lappend ::write_errors "busy handler called!"
+  }
+  proc write_callback {args} {
+    set rc [catch {checkpoint db2 passive} msg]
+    if {0==[regexp "database is locked" $msg] && $msg!="1 -1 -1"} {
+      lappend ::write_errors "$rc $msg"
+    } 
+    incr ::write_count
+  }
+  db2 busy busy_callback
+  tvfs script write_callback
+
+  do_test $tn.3.2.2 {
+    db eval {SELECT * FROM sqlite_master}
+    checkpoint db full
+    set ::write_count
+  } {2}
+
+  do_test $tn.3.2.3 {
+    set ::write_errors
+  } {}
+
+  db close
+  db2 close
+  tvfs delete
+
+}
+
+#-----------------------------------------------------------------------
+# EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
+# mode:
+#
+#   Valid checkpoint modes are 0, 1, 2 and 3.
+#
+sqlite3 db test.db
+foreach {tn mode res} {
+  0 -1001    {1 {SQLITE_MISUSE - not an error}}
+  1 -1       {1 {SQLITE_MISUSE - not an error}}
+  2  0       {0 {0 -1 -1}}
+  3  1       {0 {0 -1 -1}}
+  4  2       {0 {0 -1 -1}}
+  5  3       {0 {0 -1 -1}}
+  6  4       {1 {SQLITE_MISUSE - not an error}}
+  7  114     {1 {SQLITE_MISUSE - not an error}}
+  8  1000000 {1 {SQLITE_MISUSE - not an error}}
+} {
+  do_test 4.$tn {
+    list [catch "sqlite3_wal_checkpoint_v2 db $mode" msg] $msg
+  } $res
+}
+
+
+finish_test