OLD | NEW |
(Empty) | |
| 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:presql)]} { |
| 28 finish_test |
| 29 return |
| 30 } |
| 31 |
| 32 test_set_config_pagecache 0 0 |
| 33 |
| 34 catch {db close} |
| 35 sqlite3_shutdown |
| 36 sqlite3_config_scratch 0 0 |
| 37 sqlite3_initialize |
| 38 autoinstall_test_functions |
| 39 sqlite3 db test.db |
| 40 |
| 41 # Make sure sqlite3_db_config() and sqlite3_db_status are working. |
| 42 # |
| 43 do_test lookaside-1.1 { |
| 44 catch {sqlite3_config_error db} |
| 45 } {0} |
| 46 |
| 47 do_test lookaside-1.2 { |
| 48 sqlite3_db_config_lookaside db 1 18 18 |
| 49 } {0} |
| 50 do_test lookaside-1.3.1 { |
| 51 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0 |
| 52 } {0 0 0} |
| 53 do_test lookaside-1.3.2 { |
| 54 sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0 |
| 55 } {0 0 0} |
| 56 do_test lookaside-1.3.3 { |
| 57 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0 |
| 58 } {0 0 0} |
| 59 do_test lookaside-1.3.4 { |
| 60 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0 |
| 61 } {0 0 0} |
| 62 |
| 63 do_test lookaside-1.4 { |
| 64 db eval {CREATE TABLE t1(w,x,y,z);} |
| 65 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break |
| 66 set p [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0] 2] |
| 67 set q [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0] 2] |
| 68 set r [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0] 2] |
| 69 expr {$x==0 && $y<$z && $z==18 && $p>0 && $q>0 && $r>0} |
| 70 } {0} |
| 71 do_test lookaside-1.5 { |
| 72 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break |
| 73 expr {$x==0 && $y<$z && $z==18} |
| 74 } {0} |
| 75 do_test lookaside-1.6 { |
| 76 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break |
| 77 expr {$x==0 && $y==$z && $y<18} |
| 78 } {1} |
| 79 do_test lookaside-1.7 { |
| 80 db cache flush |
| 81 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break |
| 82 expr {$x==0 && $y==0 && $z<18} |
| 83 } {1} |
| 84 do_test lookaside-1.8 { |
| 85 db cache flush |
| 86 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break |
| 87 expr {$x==0 && $y==0 && $z<18} |
| 88 } {1} |
| 89 do_test lookaside-1.9 { |
| 90 db cache flush |
| 91 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0 |
| 92 } {0 0 0} |
| 93 |
| 94 do_test lookaside-2.1 { |
| 95 sqlite3_db_config_lookaside db 0 100 1000 |
| 96 } {0} |
| 97 do_test lookaside-2.2 { |
| 98 db eval {CREATE TABLE t2(x);} |
| 99 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break |
| 100 expr {$x==0 && $y<$z && $z>10 && $z<100} |
| 101 } {1} |
| 102 do_test lookaside-2.3 { |
| 103 sqlite3_db_config_lookaside db 0 50 50 |
| 104 } {5} ;# SQLITE_BUSY |
| 105 do_test lookaside-2.4 { |
| 106 db cache flush |
| 107 sqlite3_db_config_lookaside db 0 50 50 |
| 108 } {0} ;# SQLITE_OK |
| 109 do_test lookaside-2.5 { |
| 110 sqlite3_db_config_lookaside db 0 -1 50 |
| 111 } {0} ;# SQLITE_OK |
| 112 do_test lookaside-2.6 { |
| 113 sqlite3_db_config_lookaside db 0 50 -1 |
| 114 } {0} ;# SQLITE_OK |
| 115 |
| 116 # sqlite3_db_status() with an invalid verb returns an error. |
| 117 # |
| 118 do_test lookaside-3.1 { |
| 119 sqlite3_db_status db 99999 0 |
| 120 } {1 0 0} |
| 121 |
| 122 # Test that an invalid verb on sqlite3_config() is detected and |
| 123 # reported as an error. |
| 124 # |
| 125 do_test lookaside-4.1 { |
| 126 db close |
| 127 sqlite3_shutdown |
| 128 catch sqlite3_config_error |
| 129 } {0} |
| 130 sqlite3_initialize |
| 131 autoinstall_test_functions |
| 132 |
| 133 test_restore_config_pagecache |
| 134 finish_test |
OLD | NEW |