sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | # 2008 September 15 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # |
| 12 | # This file is focused on testing the pcache module. |
| 13 | # |
| 14 | # $Id: pcache2.test,v 1.5 2009/07/18 14:36:24 danielk1977 Exp $ |
| 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
| 19 | test_set_config_pagecache 0 0 |
| 20 | |
| 21 | # Set up a pcache memory pool so that we can easily track how many |
| 22 | # pages are being used for cache. |
| 23 | # |
| 24 | do_test pcache2-1.1 { |
| 25 | db close |
| 26 | sqlite3_reset_auto_extension |
| 27 | sqlite3_shutdown |
| 28 | sqlite3_config_pagecache 6000 100 |
| 29 | sqlite3_config singlethread |
| 30 | sqlite3_initialize |
| 31 | autoinstall_test_functions |
| 32 | sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1 |
| 33 | sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0 |
| 34 | } {0 0 0} |
| 35 | |
| 36 | # Open up two database connections to separate files. |
| 37 | # |
| 38 | do_test pcache2-1.2 { |
| 39 | forcedelete test.db test.db-journal |
| 40 | sqlite3 db test.db |
| 41 | db eval {PRAGMA cache_size=10; SELECT 1 FROM sqlite_master;} |
| 42 | lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1 |
| 43 | } {2} |
| 44 | do_test pcache2-1.3 { |
| 45 | forcedelete test2.db test2.db-journal |
| 46 | sqlite3 db2 test2.db |
| 47 | db2 eval {PRAGMA cache_size=50; SELECT 1 FROM sqlite_master;} |
| 48 | lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1 |
| 49 | } {4} |
| 50 | |
| 51 | |
| 52 | # Make lots of changes on the first connection. Verify that the |
| 53 | # page cache usage does not grow to consume the page space set aside |
| 54 | # for the second connection. |
| 55 | # |
| 56 | do_test pcache2-1.4 { |
| 57 | db eval { |
| 58 | CREATE TABLE t1(a,b); |
| 59 | CREATE TABLE t2(x,y); |
| 60 | INSERT INTO t1 VALUES(1, zeroblob(800)); |
| 61 | INSERT INTO t1 VALUES(2, zeroblob(800)); |
| 62 | INSERT INTO t2 SELECT * FROM t1; |
| 63 | INSERT INTO t1 SELECT x+2, y FROM t2; |
| 64 | INSERT INTO t2 SELECT a+10, b FROM t1; |
| 65 | INSERT INTO t1 SELECT x+10, y FROM t2; |
| 66 | INSERT INTO t2 SELECT a+100, b FROM t1; |
| 67 | INSERT INTO t1 SELECT x+100, y FROM t2; |
| 68 | INSERT INTO t2 SELECT a+1000, b FROM t1; |
| 69 | INSERT INTO t1 SELECT x+1000, y FROM t2; |
| 70 | } |
| 71 | sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0 |
| 72 | } {0 13 13} |
| 73 | |
| 74 | # Check that a small (1KB) bulk cache allocation is handled. |
| 75 | # |
| 76 | do_test pcache2-2.1 { |
| 77 | catch {db2 close} |
| 78 | db close |
| 79 | sqlite3_reset_auto_extension |
| 80 | sqlite3_shutdown |
| 81 | sqlite3_config_pagecache 0 -1 |
| 82 | sqlite3_config singlethread |
| 83 | sqlite3_initialize |
| 84 | autoinstall_test_functions |
| 85 | } {0} |
| 86 | |
| 87 | reset_db |
| 88 | do_execsql_test pcache2-2.2 { |
| 89 | PRAGMA page_size = 4096; |
| 90 | CREATE TABLE t1(x); |
| 91 | } |
| 92 | |
| 93 | db close |
| 94 | catch {db2 close} |
| 95 | sqlite3_reset_auto_extension |
| 96 | sqlite3_shutdown |
| 97 | sqlite3_config_pagecache 0 0 |
| 98 | sqlite3_config serialized |
| 99 | sqlite3_initialize |
| 100 | autoinstall_test_functions |
| 101 | |
| 102 | test_restore_config_pagecache |
| 103 | finish_test |