3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing the handling of OOM errors by the
13 # sqlite3_backup_XXX APIs.
15 # $Id: backup_malloc.test,v 1.2 2009/02/04 22:46:47 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 source $testdir/malloc_common.tcl
22 do_malloc_test backup_malloc-1 -tclprep {
24 PRAGMA cache_size = 10;
26 CREATE TABLE t1(a, b);
27 INSERT INTO t1 VALUES(1, randstr(1000,1000));
28 INSERT INTO t1 SELECT a+ 1, randstr(1000,1000) FROM t1;
29 INSERT INTO t1 SELECT a+ 2, randstr(1000,1000) FROM t1;
30 INSERT INTO t1 SELECT a+ 4, randstr(1000,1000) FROM t1;
31 INSERT INTO t1 SELECT a+ 8, randstr(1000,1000) FROM t1;
32 INSERT INTO t1 SELECT a+16, randstr(1000,1000) FROM t1;
33 INSERT INTO t1 SELECT a+32, randstr(1000,1000) FROM t1;
34 INSERT INTO t1 SELECT a+64, randstr(1000,1000) FROM t1;
35 CREATE INDEX i1 ON t1(b);
39 execsql { PRAGMA cache_size = 10 } db2
42 # Create a backup object.
44 set rc [catch {sqlite3_backup B db2 main db main}]
45 if {$rc && [sqlite3_errcode db2] == "SQLITE_NOMEM"} {
49 # Run the backup process some.
52 if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} {
56 # Update the database.
58 execsql { UPDATE t1 SET a = a + 1 }
60 # Finish doing the backup.
63 if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} {
67 # Finalize the backup.
74 do_malloc_test backup_malloc-2 -tclprep {
77 set rc [catch {sqlite3_backup B db2 temp db main}]
78 set errcode [sqlite3_errcode db2]
79 if {$rc && ($errcode == "SQLITE_NOMEM" || $errcode == "SQLITE_IOERR_NOMEM")} {
89 PRAGMA page_size = 16384;
91 CREATE TABLE t1(a, b);
92 INSERT INTO t1 VALUES(1, 2);
96 do_faultsim_test 3 -faults oom* -prep {
103 sqlite3_backup B db2 main db main
107 if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} {
108 error "out of memory"
112 faultsim_test_result {0 {}}
113 faultsim_integrity_check
115 # Finalize the backup.