gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/lookaside.test (about) 1 # 2008 August 01 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 # Tests for the lookaside memory allocator. 13 # 14 # $Id: lookaside.test,v 1.10 2009/04/09 01:23:49 drh Exp $ 15 16 set testdir [file dirname $argv0] 17 source $testdir/tester.tcl 18 19 ifcapable !lookaside { 20 finish_test 21 return 22 } 23 24 # The tests in this file configure the lookaside allocator after a 25 # connection is opened. This will not work if there is any "presql" 26 # configured (SQL run within the [sqlite3] wrapper in tester.tcl). 27 if {[info exists ::G(perm:dbconfig)] && $::G(perm:dbconfig)!=""} { 28 finish_test 29 return 30 } 31 32 test_set_config_pagecache 0 0 33 34 catch {db close} 35 sqlite3_shutdown 36 sqlite3_initialize 37 autoinstall_test_functions 38 39 sqlite3 db test.db 40 db cache size 4 41 42 # Make sure sqlite3_db_config() and sqlite3_db_status are working. 43 # 44 do_test lookaside-1.1 { 45 catch {sqlite3_config_error db} 46 } {0} 47 48 do_test lookaside-1.2 { 49 sqlite3_db_config_lookaside db 1 18 18 50 } {0} 51 do_test lookaside-1.3.1 { 52 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0 53 } {0 0 0} 54 do_test lookaside-1.3.2 { 55 sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0 56 } {0 0 0} 57 do_test lookaside-1.3.3 { 58 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0 59 } {0 0 0} 60 do_test lookaside-1.3.4 { 61 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0 62 } {0 0 0} 63 64 do_test lookaside-1.4 { 65 db eval {CREATE TABLE t1(w,x,y,z);} 66 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break 67 set p [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0] 2] 68 set q [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0] 2] 69 set r [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0] 2] 70 expr {$x==0 && $y<$z && $z==18 && $p>0 && $q>0 && $r>0} 71 } {0} 72 do_test lookaside-1.5 { 73 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break 74 expr {$x==0 && $y<$z && $z==18} 75 } {0} 76 do_test lookaside-1.6 { 77 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break 78 expr {$x==0 && $y==$z && $y<18} 79 } {1} 80 do_test lookaside-1.7 { 81 db cache flush 82 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break 83 expr {$x==0 && $y==0 && $z<18} 84 } {1} 85 do_test lookaside-1.8 { 86 db cache flush 87 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break 88 expr {$x==0 && $y==0 && $z<18} 89 } {1} 90 do_test lookaside-1.9 { 91 db cache flush 92 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0 93 } {0 0 0} 94 95 do_test lookaside-2.1 { 96 sqlite3_db_config_lookaside db 0 100 1000 97 } {0} 98 do_test lookaside-2.2 { 99 db eval {CREATE TABLE t2(x);} 100 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break 101 expr {$x==0 && $y<$z && $z>10 && $z<100} 102 } {1} 103 do_test lookaside-2.3 { 104 db eval {SELECT 1} 105 sqlite3_db_config_lookaside db 0 50 50 106 } {5} ;# SQLITE_BUSY 107 do_test lookaside-2.4 { 108 db cache flush 109 sqlite3_db_config_lookaside db 0 50 50 110 } {0} ;# SQLITE_OK 111 do_test lookaside-2.5 { 112 sqlite3_db_config_lookaside db 0 -1 50 113 } {0} ;# SQLITE_OK 114 do_test lookaside-2.6 { 115 sqlite3_db_config_lookaside db 0 50 -1 116 } {0} ;# SQLITE_OK 117 118 # sqlite3_db_status() with an invalid verb returns an error. 119 # 120 do_test lookaside-3.1 { 121 sqlite3_db_status db 99999 0 122 } {1 0 0} 123 124 # Test that an invalid verb on sqlite3_config() is detected and 125 # reported as an error. 126 # 127 do_test lookaside-4.1 { 128 db close 129 sqlite3_shutdown 130 catch sqlite3_config_error 131 } {0} 132 sqlite3_initialize 133 autoinstall_test_functions 134 135 test_restore_config_pagecache 136 finish_test