os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/incrvacuum_ioerr.test
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/incrvacuum_ioerr.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,181 @@
1.4 +# 2001 October 12
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this file is testing for correct handling of I/O errors
1.16 +# such as writes failing because the disk is full.
1.17 +#
1.18 +# The tests in this file use special facilities that are only
1.19 +# available in the SQLite test fixture.
1.20 +#
1.21 +# $Id: incrvacuum_ioerr.test,v 1.6 2008/07/12 14:52:20 drh Exp $
1.22 +
1.23 +set testdir [file dirname $argv0]
1.24 +source $testdir/tester.tcl
1.25 +
1.26 +# If this build of the library does not support auto-vacuum, omit this
1.27 +# whole file.
1.28 +ifcapable {!autovacuum} {
1.29 + finish_test
1.30 + return
1.31 +}
1.32 +
1.33 +do_ioerr_test incrvacuum-ioerr-1 -cksum 1 -sqlprep {
1.34 + PRAGMA auto_vacuum = 'incremental';
1.35 + CREATE TABLE abc(a);
1.36 + INSERT INTO abc VALUES(randstr(1500,1500));
1.37 +} -sqlbody {
1.38 + BEGIN;
1.39 + CREATE TABLE abc2(a);
1.40 + DELETE FROM abc;
1.41 + PRAGMA incremental_vacuum;
1.42 + COMMIT;
1.43 +}
1.44 +
1.45 +# do_ioerr_test incrvacuum-ioerr-3 -start 1 -cksum 1 -tclprep {
1.46 +# db eval {
1.47 +# PRAGMA auto_vacuum = 'full';
1.48 +# PRAGMA cache_size = 10;
1.49 +# BEGIN;
1.50 +# CREATE TABLE abc(a, UNIQUE(a));
1.51 +# }
1.52 +# for {set ii 0} {$ii < 25} {incr ii} {
1.53 +# db eval {INSERT INTO abc VALUES(randstr(1500,1500))}
1.54 +# }
1.55 +# db eval COMMIT
1.56 +# } -sqlbody {
1.57 +# BEGIN;
1.58 +# DELETE FROM abc WHERE (oid%3)==0;
1.59 +# INSERT INTO abc SELECT a || '1234567890' FROM abc WHERE oid%2;
1.60 +# CREATE INDEX abc_i ON abc(a);
1.61 +# DELETE FROM abc WHERE (oid%2)==0;
1.62 +# DROP INDEX abc_i;
1.63 +# COMMIT;
1.64 +# }
1.65 +
1.66 +do_ioerr_test incrvacuum-ioerr-2 -start 1 -cksum 1 -tclprep {
1.67 + db eval {
1.68 + PRAGMA auto_vacuum = 'full';
1.69 + PRAGMA cache_size = 10;
1.70 + BEGIN;
1.71 + CREATE TABLE abc(a, UNIQUE(a));
1.72 + }
1.73 + for {set ii 0} {$ii < 25} {incr ii} {
1.74 + db eval {INSERT INTO abc VALUES(randstr(1500,1500))}
1.75 + }
1.76 + db eval COMMIT
1.77 +} -sqlbody {
1.78 + BEGIN;
1.79 + PRAGMA incremental_vacuum;
1.80 + DELETE FROM abc WHERE (oid%3)==0;
1.81 + PRAGMA incremental_vacuum;
1.82 + INSERT INTO abc SELECT a || '1234567890' FROM abc WHERE oid%2;
1.83 + PRAGMA incremental_vacuum;
1.84 + CREATE INDEX abc_i ON abc(a);
1.85 + DELETE FROM abc WHERE (oid%2)==0;
1.86 + PRAGMA incremental_vacuum;
1.87 + DROP INDEX abc_i;
1.88 + PRAGMA incremental_vacuum;
1.89 + COMMIT;
1.90 +}
1.91 +
1.92 +do_ioerr_test incrvacuum-ioerr-3 -start 1 -cksum 1 -tclprep {
1.93 + db eval {
1.94 + PRAGMA auto_vacuum = 'incremental';
1.95 + BEGIN;
1.96 + CREATE TABLE a(i integer, b blob);
1.97 + INSERT INTO a VALUES(1, randstr(1500,1500));
1.98 + INSERT INTO a VALUES(2, randstr(1500,1500));
1.99 + }
1.100 + db eval COMMIT
1.101 + db eval {DELETE FROM a WHERE oid}
1.102 +} -sqlbody {
1.103 + PRAGMA incremental_vacuum(5);
1.104 +} -cleanup {
1.105 + sqlite3 db test.db
1.106 + integrity_check incrvacuum-ioerr-2.$n.integritycheck
1.107 + db close
1.108 +}
1.109 +
1.110 +
1.111 +ifcapable shared_cache {
1.112 +
1.113 + catch { db close }
1.114 + file delete -force test.db
1.115 + set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
1.116 +
1.117 + # Create two connections to a single shared-cache:
1.118 + #
1.119 + sqlite3 db1 test.db
1.120 + sqlite3 db2 test.db
1.121 +
1.122 + # Create a database with around 20 free pages.
1.123 + #
1.124 + do_test incrvacuum-ioerr-4.0 {
1.125 + execsql {
1.126 + PRAGMA page_size = 1024;
1.127 + PRAGMA locking_mode = exclusive;
1.128 + PRAGMA auto_vacuum = 'incremental';
1.129 + BEGIN;
1.130 + CREATE TABLE a(i integer, b blob);
1.131 + } db1
1.132 + for {set ii 0} {$ii < 20} {incr ii} {
1.133 + execsql { INSERT INTO a VALUES($ii, randstr(800,1500)); } db1
1.134 + }
1.135 + execsql COMMIT db1
1.136 + execsql {DELETE FROM a WHERE oid} db1
1.137 + } {}
1.138 +
1.139 + set ::rc 1
1.140 + for {set iTest 1} {$::rc && $iTest<2000} {incr iTest} {
1.141 +
1.142 + # Figure out how big the database is and how many free pages it
1.143 + # has before running incremental-vacuum.
1.144 + #
1.145 + set nPage [expr {[file size test.db]/1024}]
1.146 + set nFree [execsql {pragma freelist_count} db1]
1.147 +
1.148 + # Now run incremental-vacuum to vacuum 5 pages from the db file.
1.149 + # The iTest'th I/O call is set to fail.
1.150 + #
1.151 + set ::sqlite_io_error_pending $iTest
1.152 + set ::sqlite_io_error_persist 1
1.153 + do_test incrvacuum-ioerr-4.$iTest.1 {
1.154 + set ::rc [catch {execsql {pragma incremental_vacuum(5)} db1} msg]
1.155 + expr {$::rc==0 || $msg eq "disk I/O error"}
1.156 + } {1}
1.157 +
1.158 + set ::sqlite_io_error_pending 0
1.159 + set ::sqlite_io_error_persist 0
1.160 + set ::sqlite_io_error_hit 0
1.161 + set ::sqlite_io_error_hardhit 0
1.162 +
1.163 + set nFree2 [execsql {pragma freelist_count} db1]
1.164 + set nPage2 [expr {[file size test.db]/1024}]
1.165 +
1.166 + do_test incrvacuum-ioerr-4.$iTest.2 {
1.167 + set shrink [expr {$nPage-$nPage2}]
1.168 + expr {$shrink==0 || $shrink==5}
1.169 + } {1}
1.170 +
1.171 + do_test incrvacuum-ioerr-4.$iTest.3 {
1.172 + expr {$nPage - $nPage2}
1.173 + } [expr {$nFree - $nFree2}]
1.174 + }
1.175 +
1.176 + # Close the two database connections and restore the default
1.177 + # shared-cache mode setting.
1.178 + #
1.179 + db1 close
1.180 + db2 close
1.181 + sqlite3_enable_shared_cache $::enable_shared_cache
1.182 +}
1.183 +
1.184 +finish_test