16e09d69cSdan# 2010 July 28 26e09d69cSdan# 36e09d69cSdan# The author disclaims copyright to this source code. In place of 46e09d69cSdan# a legal notice, here is a blessing: 56e09d69cSdan# 66e09d69cSdan# May you do good and not evil. 76e09d69cSdan# May you find forgiveness for yourself and forgive others. 86e09d69cSdan# May you share freely, never taking more than you give. 96e09d69cSdan# 106e09d69cSdan#*********************************************************************** 116e09d69cSdan# 126e09d69cSdan 136e09d69cSdanset testdir [file dirname $argv0] 146e09d69cSdansource $testdir/tester.tcl 156e09d69cSdan 166e09d69cSdanfile_control_chunksize_test db main [expr 1024*1024] 176e09d69cSdan 186e09d69cSdando_test fallocate-1.1 { 196e09d69cSdan execsql { 206e09d69cSdan PRAGMA page_size = 1024; 216e09d69cSdan PRAGMA auto_vacuum = 1; 226e09d69cSdan CREATE TABLE t1(a, b); 236e09d69cSdan } 246e09d69cSdan file size test.db 256e09d69cSdan} [expr 1*1024*1024] 266e09d69cSdan 276e09d69cSdando_test fallocate-1.2 { 286e09d69cSdan execsql { INSERT INTO t1 VALUES(1, zeroblob(1024*900)) } 296e09d69cSdan file size test.db 306e09d69cSdan} [expr 1*1024*1024] 316e09d69cSdan 326e09d69cSdando_test fallocate-1.3 { 336e09d69cSdan execsql { INSERT INTO t1 VALUES(2, zeroblob(1024*900)) } 346e09d69cSdan file size test.db 356e09d69cSdan} [expr 2*1024*1024] 366e09d69cSdan 376e09d69cSdando_test fallocate-1.4 { 386e09d69cSdan execsql { DELETE FROM t1 WHERE a = 1 } 396e09d69cSdan file size test.db 406e09d69cSdan} [expr 1*1024*1024] 416e09d69cSdan 426e09d69cSdando_test fallocate-1.5 { 436e09d69cSdan execsql { DELETE FROM t1 WHERE a = 2 } 446e09d69cSdan file size test.db 456e09d69cSdan} [expr 1*1024*1024] 466e09d69cSdan 476e09d69cSdando_test fallocate-1.6 { 486e09d69cSdan execsql { PRAGMA freelist_count } 496e09d69cSdan} {0} 506e09d69cSdan 51502019c8Sdan# Start a write-transaction and read the "database file size" field from 52502019c8Sdan# the journal file. This field should be set to the number of pages in 53502019c8Sdan# the database file based on the size of the file on disk, not the actual 54502019c8Sdan# logical size of the database within the file. 55502019c8Sdan# 56502019c8Sdan# We need to check this to verify that if in the unlikely event a rollback 57502019c8Sdan# causes a database file to grow, the database grows to its previous size 58502019c8Sdan# on disk, not to the minimum size required to hold the database image. 59502019c8Sdan# 60502019c8Sdando_test fallocate-1.7 { 61502019c8Sdan execsql { BEGIN; INSERT INTO t1 VALUES(1, 2); } 624da30f88Sdan if {[permutation] != "inmemory_journal" 634da30f88Sdan && [permutation] != "atomic-batch-write" 6469aedc8dSdan && [atomic_batch_write test.db]==0 654da30f88Sdan } { 66502019c8Sdan hexio_get_int [hexio_read test.db-journal 16 4] 674f7b8d62Sdan } else { 684f7b8d62Sdan set {} 1024 694f7b8d62Sdan } 70502019c8Sdan} {1024} 71502019c8Sdando_test fallocate-1.8 { execsql { COMMIT } } {} 72502019c8Sdan 73*7c04c692Sdrhdo_test fallocate-1.8 { 74b8852ae0Sdan set nPg [db one {PRAGMA page_count}] 75b8852ae0Sdan set nFile [expr [file size test.db] / 1024] 76b8852ae0Sdan list [expr $nPg<100] [expr $nFile>100] 77b8852ae0Sdan} {1 1} 78b8852ae0Sdan 79*7c04c692Sdrhdo_execsql_test fallocate-1.9 { 80b8852ae0Sdan PRAGMA max_page_count = 100; 81*7c04c692Sdrh} {100} 82502019c8Sdan 83502019c8Sdan#------------------------------------------------------------------------- 84502019c8Sdan# The following tests - fallocate-2.* - test that things work in WAL 85502019c8Sdan# mode as well. 86502019c8Sdan# 874f7b8d62Sdanset skipwaltests [expr { 884f7b8d62Sdan [permutation]=="journaltest" || [permutation]=="inmemory_journal" 894f7b8d62Sdan}] 90dc110614Sdanifcapable !wal { set skipwaltests 1 } 91dc110614Sdan 92dc110614Sdanif {!$skipwaltests} { 93502019c8Sdan db close 94fda06befSmistachkin forcedelete test.db 95502019c8Sdan sqlite3 db test.db 96502019c8Sdan file_control_chunksize_test db main [expr 32*1024] 97502019c8Sdan 98502019c8Sdan do_test fallocate-2.1 { 99502019c8Sdan execsql { 100502019c8Sdan PRAGMA page_size = 1024; 101502019c8Sdan PRAGMA journal_mode = WAL; 102502019c8Sdan CREATE TABLE t1(a, b); 103502019c8Sdan } 104502019c8Sdan file size test.db 105502019c8Sdan } [expr 32*1024] 106502019c8Sdan 107502019c8Sdan do_test fallocate-2.2 { 108502019c8Sdan execsql { INSERT INTO t1 VALUES(1, zeroblob(35*1024)) } 109502019c8Sdan execsql { PRAGMA wal_checkpoint } 110502019c8Sdan file size test.db 111502019c8Sdan } [expr 64*1024] 112502019c8Sdan 113502019c8Sdan do_test fallocate-2.3 { 114502019c8Sdan execsql { DELETE FROM t1 } 115502019c8Sdan execsql { VACUUM } 116502019c8Sdan file size test.db 117502019c8Sdan } [expr 64*1024] 118502019c8Sdan 119502019c8Sdan do_test fallocate-2.4 { 120502019c8Sdan execsql { PRAGMA wal_checkpoint } 121502019c8Sdan file size test.db 122502019c8Sdan } [expr 32*1024] 123502019c8Sdan 124502019c8Sdan do_test fallocate-2.5 { 125502019c8Sdan execsql { 126502019c8Sdan INSERT INTO t1 VALUES(2, randomblob(35*1024)); 127502019c8Sdan PRAGMA wal_checkpoint; 128502019c8Sdan INSERT INTO t1 VALUES(3, randomblob(128)); 129502019c8Sdan DELETE FROM t1 WHERE a = 2; 130502019c8Sdan VACUUM; 131502019c8Sdan } 132502019c8Sdan file size test.db 133502019c8Sdan } [expr 64*1024] 134502019c8Sdan 135502019c8Sdan do_test fallocate-2.6 { 136502019c8Sdan sqlite3 db2 test.db 137502019c8Sdan execsql { BEGIN ; SELECT count(a) FROM t1 } db2 138502019c8Sdan execsql { 139502019c8Sdan INSERT INTO t1 VALUES(4, randomblob(128)); 140502019c8Sdan PRAGMA wal_checkpoint; 141502019c8Sdan } 142502019c8Sdan file size test.db 143502019c8Sdan } [expr 64*1024] 144502019c8Sdan 145502019c8Sdan do_test fallocate-2.7 { 146502019c8Sdan execsql { SELECT count(b) FROM t1 } db2 147502019c8Sdan } {1} 148502019c8Sdan 149502019c8Sdan do_test fallocate-2.8 { 150502019c8Sdan execsql { COMMIT } db2 151502019c8Sdan execsql { PRAGMA wal_checkpoint } 152502019c8Sdan file size test.db 153502019c8Sdan } [expr 32*1024] 154dc110614Sdan} 155dc110614Sdan 156502019c8Sdan 1576e09d69cSdanfinish_test 158