xref: /illumos-gate/usr/src/lib/libsqlite/test/bigfile.test (revision d48be21240dfd051b689384ce2b23479d757f2d8)
1#
2# 2002 November 30
3#
4# The author disclaims copyright to this source code.  In place of
5# a legal notice, here is a blessing:
6#
7#    May you do good and not evil.
8#    May you find forgiveness for yourself and forgive others.
9#    May you share freely, never taking more than you give.
10#
11#***********************************************************************
12# This file implements regression tests for SQLite library.  The
13# focus of this script testing the ability of SQLite to handle database
14# files larger than 4GB.
15#
16# $Id: bigfile.test,v 1.3 2003/12/19 12:31:22 drh Exp $
17#
18
19set testdir [file dirname $argv0]
20source $testdir/tester.tcl
21
22# These tests only work for Tcl version 8.4 and later.  Prior to 8.4,
23# Tcl was unable to handle large files.
24#
25scan $::tcl_version %f vx
26if {$vx<8.4} return
27
28# This is the md5 checksum of all the data in table t1 as created
29# by the first test.  We will use this number to make sure that data
30# never changes.
31#
32set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf}
33
34do_test bigfile-1.1 {
35  execsql {
36    BEGIN;
37    CREATE TABLE t1(x);
38    INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz');
39    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
40    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
41    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
42    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
43    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
44    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
45    INSERT INTO t1 SELECT rowid || ' ' || x FROM t1;
46    COMMIT;
47  }
48  execsql {
49    SELECT md5sum(x) FROM t1;
50  }
51} $::MAGIC_SUM
52
53# Try to create a large file - a file that is larger than 2^32 bytes.
54# If this fails, it means that the system being tested does not support
55# large files.  So skip all of the remaining tests in this file.
56#
57db close
58if {[catch {fake_big_file 4096 test.db}]} {
59  puts "**** Unable to create a file larger than 4096 MB. *****"
60  finish_test
61  return
62}
63
64do_test bigfile-1.2 {
65  sqlite db test.db
66  execsql {
67    SELECT md5sum(x) FROM t1;
68  }
69} $::MAGIC_SUM
70
71# The previous test may fail on some systems because they are unable
72# to handle large files.  If that is so, then skip all of the following
73# tests.  We will know the above test failed because the "db" command
74# does not exist.
75#
76if {[llength [info command db]]>0} {
77
78do_test bigfile-1.3 {
79  execsql {
80    CREATE TABLE t2 AS SELECT * FROM t1;
81    SELECT md5sum(x) FROM t2;
82  }
83} $::MAGIC_SUM
84do_test bigfile-1.4 {
85  db close
86  sqlite db test.db
87  execsql {
88    SELECT md5sum(x) FROM t1;
89  }
90} $::MAGIC_SUM
91do_test bigfile-1.5 {
92  execsql {
93    SELECT md5sum(x) FROM t2;
94  }
95} $::MAGIC_SUM
96
97db close
98if {[catch {fake_big_file 8192 test.db}]} {
99  puts "**** Unable to create a file larger than 8192 MB. *****"
100  finish_test
101  return
102}
103
104do_test bigfile-1.6 {
105  sqlite db test.db
106  execsql {
107    SELECT md5sum(x) FROM t1;
108  }
109} $::MAGIC_SUM
110do_test bigfile-1.7 {
111  execsql {
112    CREATE TABLE t3 AS SELECT * FROM t1;
113    SELECT md5sum(x) FROM t3;
114  }
115} $::MAGIC_SUM
116do_test bigfile-1.8 {
117  db close
118  sqlite db test.db
119  execsql {
120    SELECT md5sum(x) FROM t1;
121  }
122} $::MAGIC_SUM
123do_test bigfile-1.9 {
124  execsql {
125    SELECT md5sum(x) FROM t2;
126  }
127} $::MAGIC_SUM
128do_test bigfile-1.10 {
129  execsql {
130    SELECT md5sum(x) FROM t3;
131  }
132} $::MAGIC_SUM
133
134db close
135if {[catch {fake_big_file 16384 test.db}]} {
136  puts "**** Unable to create a file larger than 16384 MB. *****"
137  finish_test
138  return
139}
140
141do_test bigfile-1.11 {
142  sqlite db test.db
143  execsql {
144    SELECT md5sum(x) FROM t1;
145  }
146} $::MAGIC_SUM
147do_test bigfile-1.12 {
148  execsql {
149    CREATE TABLE t4 AS SELECT * FROM t1;
150    SELECT md5sum(x) FROM t4;
151  }
152} $::MAGIC_SUM
153do_test bigfile-1.13 {
154  db close
155  sqlite db test.db
156  execsql {
157    SELECT md5sum(x) FROM t1;
158  }
159} $::MAGIC_SUM
160do_test bigfile-1.14 {
161  execsql {
162    SELECT md5sum(x) FROM t2;
163  }
164} $::MAGIC_SUM
165do_test bigfile-1.15 {
166  execsql {
167    SELECT md5sum(x) FROM t3;
168  }
169} $::MAGIC_SUM
170do_test bigfile-1.16 {
171  execsql {
172    SELECT md5sum(x) FROM t3;
173  }
174} $::MAGIC_SUM
175
176} ;# End of the "if( db command exists )"
177
178finish_test
179