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