1 # 2009 January 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 file is testing the handling of OOM errors by the 13 # sqlite3_backup_XXX APIs. 14 # 15 # $Id: backup_malloc.test,v 1.2 2009/02/04 22:46:47 drh Exp $ 16 17 set testdir [file dirname $argv0] 18 source $testdir/tester.tcl 19 20 source $testdir/malloc_common.tcl 21 22 do_malloc_test backup_malloc-1 -tclprep { 23 execsql { 24 PRAGMA cache_size = 10; 25 BEGIN; 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); 36 COMMIT; 37 } 38 sqlite3 db2 test2.db 39 execsql { PRAGMA cache_size = 10 } db2 40 } -tclbody { 41 42 # Create a backup object. 43 # 44 set rc [catch {sqlite3_backup B db2 main db main}] 45 if {$rc && [sqlite3_errcode db2] == "SQLITE_NOMEM"} { 46 error "out of memory" 47 } 48 49 # Run the backup process some. 50 # 51 set rc [B step 50] 52 if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} { 53 error "out of memory" 54 } 55 56 # Update the database. 57 # 58 execsql { UPDATE t1 SET a = a + 1 } 59 60 # Finish doing the backup. 61 # 62 set rc [B step 5000] 63 if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} { 64 error "out of memory" 65 } 66 67 # Finalize the backup. 68 B finish 69 } -cleanup { 70 catch { B finish } 71 catch { db2 close } 72 } 73 74 do_malloc_test backup_malloc-2 -tclprep { 75 sqlite3 db2 test2.db 76 } -tclbody { 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")} { 80 error "out of memory" 81 } 82 } -cleanup { 83 catch { B finish } 84 db2 close 85 } 86 87 finish_test 88