1 # 2002 November 30 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 # This file implements regression tests for SQLite library. The 12 # focus of this script testing the ability of SQLite to handle database 13 # files larger than 4GB. 14 # 15 # $Id: bigfile.test,v 1.12 2009/03/05 04:27:08 shane Exp $ 16 # 17 18 set testdir [file dirname $argv0] 19 source $testdir/tester.tcl 20 21 # Do not use a codec for this file, as the database is manipulated using 22 # external methods (the [fake_big_file] and [hexio_write] commands). 23 # 24 do_not_use_codec 25 26 # If SQLITE_DISABLE_LFS is defined, omit this file. 27 ifcapable !lfs { 28 finish_test 29 return 30 } 31 32 # These tests only work for Tcl version 8.4 and later. Prior to 8.4, 33 # Tcl was unable to handle large files. 34 # 35 scan $::tcl_version %f vx 36 if {$vx<8.4} return 37 38 # Mac OS X does not handle large files efficiently. So skip this test 39 # on that platform. 40 if {$tcl_platform(os)=="Darwin"} return 41 42 # This is the md5 checksum of all the data in table t1 as created 43 # by the first test. We will use this number to make sure that data 44 # never changes. 45 # 46 set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf} 47 48 do_test bigfile-1.1 { 49 execsql { 50 BEGIN; 51 CREATE TABLE t1(x); 52 INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz'); 53 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 54 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 55 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 56 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 57 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 58 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 59 INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; 60 COMMIT; 61 } 62 execsql { 63 SELECT md5sum(x) FROM t1; 64 } 65 } $::MAGIC_SUM 66 67 # Try to create a large file - a file that is larger than 2^32 bytes. 68 # If this fails, it means that the system being tested does not support 69 # large files. So skip all of the remaining tests in this file. 70 # 71 db close 72 if {[catch {fake_big_file 4096 [pwd]/test.db} msg]} { 73 puts "**** Unable to create a file larger than 4096 MB. *****" 74 finish_test 75 return 76 } 77 hexio_write test.db 28 00000000 78 79 do_test bigfile-1.2 { 80 sqlite3 db test.db 81 execsql { 82 SELECT md5sum(x) FROM t1; 83 } 84 } $::MAGIC_SUM 85 86 # The previous test may fail on some systems because they are unable 87 # to handle large files. If that is so, then skip all of the following 88 # tests. We will know the above test failed because the "db" command 89 # does not exist. 90 # 91 if {[llength [info command db]]<=0} { 92 puts "**** Large file support appears to be broken. *****" 93 finish_test 94 return 95 } 96 97 do_test bigfile-1.3 { 98 execsql { 99 CREATE TABLE t2 AS SELECT * FROM t1; 100 SELECT md5sum(x) FROM t2; 101 } 102 } $::MAGIC_SUM 103 do_test bigfile-1.4 { 104 db close 105 sqlite3 db test.db 106 execsql { 107 SELECT md5sum(x) FROM t1; 108 } 109 } $::MAGIC_SUM 110 111 db close 112 if {[catch {fake_big_file 8192 [pwd]/test.db}]} { 113 puts "**** Unable to create a file larger than 8192 MB. *****" 114 finish_test 115 return 116 } 117 hexio_write test.db 28 00000000 118 119 do_test bigfile-1.5 { 120 sqlite3 db test.db 121 execsql { 122 SELECT md5sum(x) FROM t1; 123 } 124 } $::MAGIC_SUM 125 do_test bigfile-1.6 { 126 sqlite3 db test.db 127 execsql { 128 SELECT md5sum(x) FROM t2; 129 } 130 } $::MAGIC_SUM 131 do_test bigfile-1.7 { 132 execsql { 133 CREATE TABLE t3 AS SELECT * FROM t1; 134 SELECT md5sum(x) FROM t3; 135 } 136 } $::MAGIC_SUM 137 do_test bigfile-1.8 { 138 db close 139 sqlite3 db test.db 140 execsql { 141 SELECT md5sum(x) FROM t1; 142 } 143 } $::MAGIC_SUM 144 do_test bigfile-1.9 { 145 execsql { 146 SELECT md5sum(x) FROM t2; 147 } 148 } $::MAGIC_SUM 149 150 db close 151 if {[catch {fake_big_file 16384 [pwd]/test.db}]} { 152 puts "**** Unable to create a file larger than 16384 MB. *****" 153 finish_test 154 return 155 } 156 hexio_write test.db 28 00000000 157 158 do_test bigfile-1.10 { 159 sqlite3 db test.db 160 execsql { 161 SELECT md5sum(x) FROM t1; 162 } 163 } $::MAGIC_SUM 164 do_test bigfile-1.11 { 165 sqlite3 db test.db 166 execsql { 167 SELECT md5sum(x) FROM t2; 168 } 169 } $::MAGIC_SUM 170 do_test bigfile-1.12 { 171 sqlite3 db test.db 172 execsql { 173 SELECT md5sum(x) FROM t3; 174 } 175 } $::MAGIC_SUM 176 do_test bigfile-1.13 { 177 execsql { 178 CREATE TABLE t4 AS SELECT * FROM t1; 179 SELECT md5sum(x) FROM t4; 180 } 181 } $::MAGIC_SUM 182 do_test bigfile-1.14 { 183 db close 184 sqlite3 db test.db 185 execsql { 186 SELECT md5sum(x) FROM t1; 187 } 188 } $::MAGIC_SUM 189 do_test bigfile-1.15 { 190 execsql { 191 SELECT md5sum(x) FROM t2; 192 } 193 } $::MAGIC_SUM 194 do_test bigfile-1.16 { 195 execsql { 196 SELECT md5sum(x) FROM t3; 197 } 198 } $::MAGIC_SUM 199 200 finish_test 201