drh | 701bb3b | 2008-08-02 03:50:39 +0000 | [diff] [blame] | 1 | # 2008 August 01 |
| 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 | # |
| 12 | # This test script checks malloc failures in various obscure operations. |
| 13 | # |
danielk1977 | f77a367 | 2009-08-10 04:26:39 +0000 | [diff] [blame] | 14 | # $Id: mallocI.test,v 1.3 2009/08/10 04:26:39 danielk1977 Exp $ |
drh | 701bb3b | 2008-08-02 03:50:39 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | source $testdir/malloc_common.tcl |
| 19 | |
| 20 | # Malloc failures in a view. |
| 21 | # |
| 22 | do_malloc_test mallocI-1 -sqlprep { |
| 23 | CREATE TABLE t1(a,b,c,d); |
| 24 | CREATE VIEW v1 AS SELECT a*b, c*d FROM t1 ORDER BY b-d; |
| 25 | } -sqlbody { |
| 26 | SELECT * FROM v1 |
| 27 | } |
| 28 | |
| 29 | # Malloc failure while trying to service a pragma on a TEMP database. |
| 30 | # |
| 31 | do_malloc_test mallocI-2 -sqlbody { |
| 32 | PRAGMA temp.page_size |
| 33 | } |
| 34 | |
| 35 | # Malloc failure while creating a table from a SELECT statement. |
| 36 | # |
| 37 | do_malloc_test mallocI-3 -sqlprep { |
| 38 | CREATE TABLE t1(a,b,c); |
| 39 | } -sqlbody { |
| 40 | CREATE TABLE t2 AS SELECT b,c FROM t1; |
| 41 | } |
| 42 | |
danielk1977 | 1a4eaf0 | 2009-07-29 06:04:56 +0000 | [diff] [blame] | 43 | # This tests that a malloc failure that occurs while passing the schema |
| 44 | # does not result in a SHARED lock being left on the database file. |
| 45 | # |
| 46 | do_malloc_test mallocI-4 -tclprep { |
| 47 | sqlite3 db2 test.db |
| 48 | db2 eval { |
| 49 | CREATE TABLE t1(a, b, c); |
| 50 | CREATE TABLE t2(a, b, c); |
| 51 | } |
| 52 | } -sqlbody { |
| 53 | SELECT * FROM t1 |
| 54 | } -cleanup { |
| 55 | do_test mallocI-4.$::n.2 { |
| 56 | # If this INSERT is possible then [db] does not hold a shared lock |
| 57 | # on the database file. |
| 58 | catchsql { INSERT INTO t1 VALUES(1, 2, 3) } db2 |
| 59 | } {0 {}} |
shaneh | aa9eceb | 2010-07-07 20:00:04 +0000 | [diff] [blame] | 60 | catch {db2 close} |
danielk1977 | 1a4eaf0 | 2009-07-29 06:04:56 +0000 | [diff] [blame] | 61 | } |
danielk1977 | f77a367 | 2009-08-10 04:26:39 +0000 | [diff] [blame] | 62 | catch { db2 close } |
danielk1977 | 1a4eaf0 | 2009-07-29 06:04:56 +0000 | [diff] [blame] | 63 | |
drh | 701bb3b | 2008-08-02 03:50:39 +0000 | [diff] [blame] | 64 | finish_test |