xref: /sqlite-3.40.0/test/bigfile.test (revision befda465)
1d0d006e2Sdrh# 2002 November 30
2d0d006e2Sdrh#
3d0d006e2Sdrh# The author disclaims copyright to this source code.  In place of
4d0d006e2Sdrh# a legal notice, here is a blessing:
5d0d006e2Sdrh#
6d0d006e2Sdrh#    May you do good and not evil.
7d0d006e2Sdrh#    May you find forgiveness for yourself and forgive others.
8d0d006e2Sdrh#    May you share freely, never taking more than you give.
9d0d006e2Sdrh#
10d0d006e2Sdrh#***********************************************************************
11d0d006e2Sdrh# This file implements regression tests for SQLite library.  The
12d0d006e2Sdrh# focus of this script testing the ability of SQLite to handle database
13d0d006e2Sdrh# files larger than 4GB.
14d0d006e2Sdrh#
153c9cfa99Sshane# $Id: bigfile.test,v 1.12 2009/03/05 04:27:08 shane Exp $
16d0d006e2Sdrh#
17d0d006e2Sdrh
18ee3a77deSdrhif {[file exists skip-big-file]} return
19*befda465Sdrhif {$tcl_platform(os)=="Darwin"} return
20ee3a77deSdrh
21d0d006e2Sdrhset testdir [file dirname $argv0]
22d0d006e2Sdrhsource $testdir/tester.tcl
23d0d006e2Sdrh
2468928b6cSdan# Do not use a codec for this file, as the database is manipulated using
2568928b6cSdan# external methods (the [fake_big_file] and [hexio_write] commands).
2668928b6cSdan#
2768928b6cSdando_not_use_codec
2868928b6cSdan
2926c5d79fSdanielk1977# If SQLITE_DISABLE_LFS is defined, omit this file.
3026c5d79fSdanielk1977ifcapable !lfs {
3126c5d79fSdanielk1977  finish_test
3226c5d79fSdanielk1977  return
3326c5d79fSdanielk1977}
3426c5d79fSdanielk1977
355202560eSdrh# These tests only work for Tcl version 8.4 and later.  Prior to 8.4,
365202560eSdrh# Tcl was unable to handle large files.
375202560eSdrh#
385202560eSdrhscan $::tcl_version %f vx
395202560eSdrhif {$vx<8.4} return
405202560eSdrh
413ea64406Sdrh# Mac OS X does not handle large files efficiently.  So skip this test
423ea64406Sdrh# on that platform.
433ea64406Sdrhif {$tcl_platform(os)=="Darwin"} return
443ea64406Sdrh
45d0d006e2Sdrh# This is the md5 checksum of all the data in table t1 as created
46d0d006e2Sdrh# by the first test.  We will use this number to make sure that data
47d0d006e2Sdrh# never changes.
48d0d006e2Sdrh#
49d0d006e2Sdrhset MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf}
50d0d006e2Sdrh
51d0d006e2Sdrhdo_test bigfile-1.1 {
52d0d006e2Sdrh  execsql {
53d0d006e2Sdrh    BEGIN;
54d0d006e2Sdrh    CREATE TABLE t1(x);
55d0d006e2Sdrh    INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz');
56d0d006e2Sdrh    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
57d0d006e2Sdrh    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
58d0d006e2Sdrh    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
59d0d006e2Sdrh    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
60d0d006e2Sdrh    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
61d0d006e2Sdrh    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
62d0d006e2Sdrh    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
63d0d006e2Sdrh    COMMIT;
64d0d006e2Sdrh  }
65d0d006e2Sdrh  execsql {
66d0d006e2Sdrh    SELECT md5sum(x) FROM t1;
67d0d006e2Sdrh  }
68d0d006e2Sdrh} $::MAGIC_SUM
69d0d006e2Sdrh
70f33cb428Sdrh# Try to create a large file - a file that is larger than 2^32 bytes.
71f33cb428Sdrh# If this fails, it means that the system being tested does not support
72f33cb428Sdrh# large files.  So skip all of the remaining tests in this file.
73f33cb428Sdrh#
74d0d006e2Sdrhdb close
75f8a78464Smistachkinif {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} {
76f33cb428Sdrh  puts "**** Unable to create a file larger than 4096 MB. *****"
77f33cb428Sdrh  finish_test
78f33cb428Sdrh  return
79f33cb428Sdrh}
8043377f5aSdrhhexio_write test.db 28 00000000
81f33cb428Sdrh
82f33cb428Sdrhdo_test bigfile-1.2 {
83ef4ac8f9Sdrh  sqlite3 db test.db
84d0d006e2Sdrh  execsql {
85d0d006e2Sdrh    SELECT md5sum(x) FROM t1;
86d0d006e2Sdrh  }
87d0d006e2Sdrh} $::MAGIC_SUM
88d0d006e2Sdrh
89d0d006e2Sdrh# The previous test may fail on some systems because they are unable
90d0d006e2Sdrh# to handle large files.  If that is so, then skip all of the following
91d0d006e2Sdrh# tests.  We will know the above test failed because the "db" command
92d0d006e2Sdrh# does not exist.
93d0d006e2Sdrh#
943c9cfa99Sshaneif {[llength [info command db]]<=0} {
953c9cfa99Sshane  puts "**** Large file support appears to be broken. *****"
963c9cfa99Sshane  finish_test
973c9cfa99Sshane  return
983c9cfa99Sshane}
99d0d006e2Sdrh
100d0d006e2Sdrhdo_test bigfile-1.3 {
101d0d006e2Sdrh  execsql {
102d0d006e2Sdrh    CREATE TABLE t2 AS SELECT * FROM t1;
103d0d006e2Sdrh    SELECT md5sum(x) FROM t2;
104d0d006e2Sdrh  }
105d0d006e2Sdrh} $::MAGIC_SUM
106d0d006e2Sdrhdo_test bigfile-1.4 {
107d0d006e2Sdrh  db close
108ef4ac8f9Sdrh  sqlite3 db test.db
109d0d006e2Sdrh  execsql {
110d0d006e2Sdrh    SELECT md5sum(x) FROM t1;
111d0d006e2Sdrh  }
112d0d006e2Sdrh} $::MAGIC_SUM
113f33cb428Sdrh
114d0d006e2Sdrhdb close
115f8a78464Smistachkinif {[catch {fake_big_file 8192 [get_pwd]/test.db}]} {
116f33cb428Sdrh  puts "**** Unable to create a file larger than 8192 MB. *****"
117f33cb428Sdrh  finish_test
118f33cb428Sdrh  return
119f33cb428Sdrh}
12043377f5aSdrhhexio_write test.db 28 00000000
121f33cb428Sdrh
1223c9cfa99Sshanedo_test bigfile-1.5 {
123ef4ac8f9Sdrh  sqlite3 db test.db
124d0d006e2Sdrh  execsql {
125d0d006e2Sdrh    SELECT md5sum(x) FROM t1;
126d0d006e2Sdrh  }
127d0d006e2Sdrh} $::MAGIC_SUM
1283c9cfa99Sshanedo_test bigfile-1.6 {
1293c9cfa99Sshane  sqlite3 db test.db
1303c9cfa99Sshane  execsql {
1313c9cfa99Sshane    SELECT md5sum(x) FROM t2;
1323c9cfa99Sshane  }
1333c9cfa99Sshane} $::MAGIC_SUM
134d0d006e2Sdrhdo_test bigfile-1.7 {
135d0d006e2Sdrh  execsql {
136d0d006e2Sdrh    CREATE TABLE t3 AS SELECT * FROM t1;
137d0d006e2Sdrh    SELECT md5sum(x) FROM t3;
138d0d006e2Sdrh  }
139d0d006e2Sdrh} $::MAGIC_SUM
140d0d006e2Sdrhdo_test bigfile-1.8 {
141d0d006e2Sdrh  db close
142ef4ac8f9Sdrh  sqlite3 db test.db
143d0d006e2Sdrh  execsql {
144d0d006e2Sdrh    SELECT md5sum(x) FROM t1;
145d0d006e2Sdrh  }
146d0d006e2Sdrh} $::MAGIC_SUM
147d0d006e2Sdrhdo_test bigfile-1.9 {
148d0d006e2Sdrh  execsql {
149d0d006e2Sdrh    SELECT md5sum(x) FROM t2;
150d0d006e2Sdrh  }
151d0d006e2Sdrh} $::MAGIC_SUM
152f33cb428Sdrh
153d0d006e2Sdrhdb close
154f8a78464Smistachkinif {[catch {fake_big_file 16384 [get_pwd]/test.db}]} {
155f33cb428Sdrh  puts "**** Unable to create a file larger than 16384 MB. *****"
156f33cb428Sdrh  finish_test
157f33cb428Sdrh  return
158f33cb428Sdrh}
15943377f5aSdrhhexio_write test.db 28 00000000
160f33cb428Sdrh
1613c9cfa99Sshanedo_test bigfile-1.10 {
162ef4ac8f9Sdrh  sqlite3 db test.db
163d0d006e2Sdrh  execsql {
164d0d006e2Sdrh    SELECT md5sum(x) FROM t1;
165d0d006e2Sdrh  }
166d0d006e2Sdrh} $::MAGIC_SUM
1673c9cfa99Sshanedo_test bigfile-1.11 {
1683c9cfa99Sshane  sqlite3 db test.db
1693c9cfa99Sshane  execsql {
1703c9cfa99Sshane    SELECT md5sum(x) FROM t2;
1713c9cfa99Sshane  }
1723c9cfa99Sshane} $::MAGIC_SUM
173d0d006e2Sdrhdo_test bigfile-1.12 {
1743c9cfa99Sshane  sqlite3 db test.db
1753c9cfa99Sshane  execsql {
1763c9cfa99Sshane    SELECT md5sum(x) FROM t3;
1773c9cfa99Sshane  }
1783c9cfa99Sshane} $::MAGIC_SUM
1793c9cfa99Sshanedo_test bigfile-1.13 {
180d0d006e2Sdrh  execsql {
181d0d006e2Sdrh    CREATE TABLE t4 AS SELECT * FROM t1;
182d0d006e2Sdrh    SELECT md5sum(x) FROM t4;
183d0d006e2Sdrh  }
184d0d006e2Sdrh} $::MAGIC_SUM
1853c9cfa99Sshanedo_test bigfile-1.14 {
186d0d006e2Sdrh  db close
187ef4ac8f9Sdrh  sqlite3 db test.db
188d0d006e2Sdrh  execsql {
189d0d006e2Sdrh    SELECT md5sum(x) FROM t1;
190d0d006e2Sdrh  }
191d0d006e2Sdrh} $::MAGIC_SUM
192d0d006e2Sdrhdo_test bigfile-1.15 {
193d0d006e2Sdrh  execsql {
1943c9cfa99Sshane    SELECT md5sum(x) FROM t2;
195d0d006e2Sdrh  }
196d0d006e2Sdrh} $::MAGIC_SUM
197d0d006e2Sdrhdo_test bigfile-1.16 {
198d0d006e2Sdrh  execsql {
199d0d006e2Sdrh    SELECT md5sum(x) FROM t3;
200d0d006e2Sdrh  }
201d0d006e2Sdrh} $::MAGIC_SUM
202d0d006e2Sdrh
203d0d006e2Sdrhfinish_test
204