| OLD | NEW |
| 1 # 2008 June 18 | 1 # 2008 June 18 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #*********************************************************************** | 10 #*********************************************************************** |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 return | 25 return |
| 26 } | 26 } |
| 27 | 27 |
| 28 # This procedure constructs a new database in test.db. It fills | 28 # This procedure constructs a new database in test.db. It fills |
| 29 # this database with many small records (enough to force multiple | 29 # this database with many small records (enough to force multiple |
| 30 # rebalance operations in the btree-layer and to require a large | 30 # rebalance operations in the btree-layer and to require a large |
| 31 # page cache), verifies correct results, then returns. | 31 # page cache), verifies correct results, then returns. |
| 32 # | 32 # |
| 33 proc build_test_db {testname pragmas} { | 33 proc build_test_db {testname pragmas} { |
| 34 catch {db close} | 34 catch {db close} |
| 35 file delete -force test.db test.db-journal | 35 forcedelete test.db test.db-journal |
| 36 sqlite3 db test.db | 36 sqlite3 db test.db |
| 37 sqlite3_db_config_lookaside db 0 0 0 | 37 sqlite3_db_config_lookaside db 0 0 0 |
| 38 db eval $pragmas | 38 db eval $pragmas |
| 39 db eval { | 39 db eval { |
| 40 CREATE TABLE t1(x, y); | 40 CREATE TABLE t1(x, y); |
| 41 CREATE TABLE t2(a, b); | 41 CREATE TABLE t2(a, b); |
| 42 CREATE INDEX i1 ON t1(x,y); | 42 CREATE INDEX i1 ON t1(x,y); |
| 43 INSERT INTO t1 VALUES(1, 100); | 43 INSERT INTO t1 VALUES(1, 100); |
| 44 INSERT INTO t1 VALUES(2, 200); | 44 INSERT INTO t1 VALUES(2, 200); |
| 45 } | 45 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 61 sqlite3_status SQLITE_STATUS_MALLOC_SIZE 1 | 61 sqlite3_status SQLITE_STATUS_MALLOC_SIZE 1 |
| 62 sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1 | 62 sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1 |
| 63 sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 1 | 63 sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 1 |
| 64 sqlite3_status SQLITE_STATUS_PAGECACHE_SIZE 1 | 64 sqlite3_status SQLITE_STATUS_PAGECACHE_SIZE 1 |
| 65 sqlite3_status SQLITE_STATUS_SCRATCH_USED 1 | 65 sqlite3_status SQLITE_STATUS_SCRATCH_USED 1 |
| 66 sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 1 | 66 sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 1 |
| 67 sqlite3_status SQLITE_STATUS_SCRATCH_SIZE 1 | 67 sqlite3_status SQLITE_STATUS_SCRATCH_SIZE 1 |
| 68 sqlite3_status SQLITE_STATUS_PARSER_STACK 1 | 68 sqlite3_status SQLITE_STATUS_PARSER_STACK 1 |
| 69 } | 69 } |
| 70 | 70 |
| 71 set xtra_size 256 | 71 set xtra_size 290 |
| 72 | 72 |
| 73 # Test 1: Both PAGECACHE and SCRATCH are shut down. | 73 # Test 1: Both PAGECACHE and SCRATCH are shut down. |
| 74 # | 74 # |
| 75 db close | 75 db close |
| 76 sqlite3_shutdown | 76 sqlite3_shutdown |
| 77 sqlite3_config_lookaside 0 0 | 77 sqlite3_config_lookaside 0 0 |
| 78 sqlite3_initialize | 78 sqlite3_initialize |
| 79 reset_highwater_marks | 79 reset_highwater_marks |
| 80 build_test_db memsubsys1-1 {PRAGMA page_size=1024} | 80 build_test_db memsubsys1-1 {PRAGMA page_size=1024} |
| 81 do_test memsubsys1-1.3 { | 81 do_test memsubsys1-1.3 { |
| 82 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 82 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] |
| 83 } 0 | 83 } 0 |
| 84 do_test memsubsys1-1.4 { | 84 do_test memsubsys1-1.4 { |
| 85 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] | 85 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] |
| 86 } 0 | 86 } 0 |
| 87 set max_pagecache [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] | 87 set max_pagecache [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] |
| 88 #show_memstats | 88 #show_memstats |
| 89 | 89 |
| 90 # Test 2: Activate PAGECACHE with 20 pages | 90 # Test 2: Activate PAGECACHE with 20 pages |
| 91 # | 91 # |
| 92 db close | 92 db close |
| 93 sqlite3_shutdown | 93 sqlite3_shutdown |
| 94 sqlite3_config_pagecache [expr 1024+$xtra_size] 20 | 94 sqlite3_config_pagecache [expr 1024+$xtra_size] 20 |
| 95 sqlite3_initialize | 95 sqlite3_initialize |
| 96 reset_highwater_marks | 96 reset_highwater_marks |
| 97 build_test_db memsubsys1-2 {PRAGMA page_size=1024} | 97 build_test_db memsubsys1-2 {PRAGMA page_size=1024; PRAGMA mmap_size=0} |
| 98 #show_memstats | 98 #show_memstats |
| 99 set MEMORY_MANAGEMENT $sqlite_options(memorymanage) | 99 set MEMORY_MANAGEMENT $sqlite_options(memorymanage) |
| 100 do_test memsubsys1-2.3 { | 100 ifcapable !malloc_usable_size { |
| 101 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] | 101 do_test memsubsys1-2.3 { |
| 102 } [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024] | 102 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] |
| 103 } [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024] |
| 104 } |
| 103 do_test memsubsys1-2.4 { | 105 do_test memsubsys1-2.4 { |
| 104 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 106 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] |
| 105 } 20 | 107 } 20 |
| 106 do_test memsubsys1-2.5 { | 108 do_test memsubsys1-2.5 { |
| 107 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] | 109 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] |
| 108 } 0 | 110 } 0 |
| 109 | 111 |
| 110 # Test 3: Activate PAGECACHE with 20 pages but use the wrong page size | 112 # Test 3: Activate PAGECACHE with 20 pages but use the wrong page size |
| 111 # so that PAGECACHE is not used. | 113 # so that PAGECACHE is not used. |
| 112 # | 114 # |
| 113 db close | 115 db close |
| 114 sqlite3_shutdown | 116 sqlite3_shutdown |
| 115 sqlite3_config_pagecache [expr 512+$xtra_size] 20 | 117 sqlite3_config_pagecache [expr 512+$xtra_size] 20 |
| 116 sqlite3_initialize | 118 sqlite3_initialize |
| 117 reset_highwater_marks | 119 reset_highwater_marks |
| 118 build_test_db memsubsys1-3.1 {PRAGMA page_size=1024} | 120 build_test_db memsubsys1-3.1 {PRAGMA page_size=1024} |
| 119 #show_memstats | 121 #show_memstats |
| 120 do_test memsubsys1-3.1.3 { | 122 do_test memsubsys1-3.1.3 { |
| 121 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 123 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] |
| 122 } 0 | 124 } 0 |
| 123 do_test memsubsys1-3.1.4 { | 125 do_test memsubsys1-3.1.4 { |
| 124 set overflow [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] | 126 set overflow [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] |
| 125 } $max_pagecache | 127 # Note: The measured PAGECACHE_OVERFLOW is amount malloc() returns, not what |
| 128 # was requested. System malloc() implementations might (arbitrarily) return |
| 129 # slightly different oversize buffers, which can result in slightly different |
| 130 # PAGECACHE_OVERFLOW sizes between consecutive runs. So we cannot do an |
| 131 # exact comparison. Simply verify that the amount is within 5%. |
| 132 expr {$overflow>=$max_pagecache*0.95 && $overflow<=$max_pagecache*1.05} |
| 133 } 1 |
| 126 do_test memsubsys1-3.1.5 { | 134 do_test memsubsys1-3.1.5 { |
| 127 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] | 135 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] |
| 128 } 0 | 136 } 0 |
| 129 db close | 137 db close |
| 130 sqlite3_shutdown | 138 sqlite3_shutdown |
| 131 sqlite3_config_pagecache [expr 2048+$xtra_size] 20 | 139 sqlite3_config_pagecache [expr 2048+$xtra_size] 20 |
| 132 sqlite3_initialize | 140 sqlite3_initialize |
| 133 reset_highwater_marks | 141 reset_highwater_marks |
| 134 build_test_db memsubsys1-3.2 {PRAGMA page_size=2048} | 142 build_test_db memsubsys1-3.2 {PRAGMA page_size=2048} |
| 135 #show_memstats | 143 #show_memstats |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 308 |
| 301 db close | 309 db close |
| 302 sqlite3_shutdown | 310 sqlite3_shutdown |
| 303 sqlite3_config_memstatus 1 | 311 sqlite3_config_memstatus 1 |
| 304 sqlite3_config_pagecache 0 0 | 312 sqlite3_config_pagecache 0 0 |
| 305 sqlite3_config_scratch 0 0 | 313 sqlite3_config_scratch 0 0 |
| 306 sqlite3_config_lookaside 100 500 | 314 sqlite3_config_lookaside 100 500 |
| 307 sqlite3_initialize | 315 sqlite3_initialize |
| 308 autoinstall_test_functions | 316 autoinstall_test_functions |
| 309 finish_test | 317 finish_test |
| OLD | NEW |