xref: /sqlite-3.40.0/test/mallocI.test (revision 4e59344a)
1701bb3b4Sdrh# 2008 August 01
2701bb3b4Sdrh#
3701bb3b4Sdrh# The author disclaims copyright to this source code.  In place of
4701bb3b4Sdrh# a legal notice, here is a blessing:
5701bb3b4Sdrh#
6701bb3b4Sdrh#    May you do good and not evil.
7701bb3b4Sdrh#    May you find forgiveness for yourself and forgive others.
8701bb3b4Sdrh#    May you share freely, never taking more than you give.
9701bb3b4Sdrh#
10701bb3b4Sdrh#***********************************************************************
11701bb3b4Sdrh#
12701bb3b4Sdrh# This test script checks malloc failures in various obscure operations.
13701bb3b4Sdrh#
14f77a367dSdanielk1977# $Id: mallocI.test,v 1.3 2009/08/10 04:26:39 danielk1977 Exp $
15701bb3b4Sdrh
16701bb3b4Sdrhset testdir [file dirname $argv0]
17701bb3b4Sdrhsource $testdir/tester.tcl
18701bb3b4Sdrhsource $testdir/malloc_common.tcl
19701bb3b4Sdrh
20701bb3b4Sdrh# Malloc failures in a view.
21701bb3b4Sdrh#
22701bb3b4Sdrhdo_malloc_test mallocI-1 -sqlprep {
23701bb3b4Sdrh  CREATE TABLE t1(a,b,c,d);
24701bb3b4Sdrh  CREATE VIEW v1 AS SELECT a*b, c*d FROM t1 ORDER BY b-d;
25701bb3b4Sdrh} -sqlbody {
26701bb3b4Sdrh  SELECT * FROM v1
27701bb3b4Sdrh}
28701bb3b4Sdrh
29701bb3b4Sdrh# Malloc failure while trying to service a pragma on a TEMP database.
30701bb3b4Sdrh#
31701bb3b4Sdrhdo_malloc_test mallocI-2 -sqlbody {
32701bb3b4Sdrh  PRAGMA temp.page_size
33701bb3b4Sdrh}
34701bb3b4Sdrh
35701bb3b4Sdrh# Malloc failure while creating a table from a SELECT statement.
36701bb3b4Sdrh#
37701bb3b4Sdrhdo_malloc_test mallocI-3 -sqlprep {
38701bb3b4Sdrh  CREATE TABLE t1(a,b,c);
39701bb3b4Sdrh} -sqlbody {
40701bb3b4Sdrh  CREATE TABLE t2 AS SELECT b,c FROM t1;
41701bb3b4Sdrh}
42701bb3b4Sdrh
431a4eaf0bSdanielk1977# This tests that a malloc failure that occurs while passing the schema
441a4eaf0bSdanielk1977# does not result in a SHARED lock being left on the database file.
451a4eaf0bSdanielk1977#
461a4eaf0bSdanielk1977do_malloc_test mallocI-4 -tclprep {
471a4eaf0bSdanielk1977  sqlite3 db2 test.db
481a4eaf0bSdanielk1977  db2 eval {
491a4eaf0bSdanielk1977    CREATE TABLE t1(a, b, c);
501a4eaf0bSdanielk1977    CREATE TABLE t2(a, b, c);
511a4eaf0bSdanielk1977  }
521a4eaf0bSdanielk1977} -sqlbody {
531a4eaf0bSdanielk1977  SELECT * FROM t1
541a4eaf0bSdanielk1977} -cleanup {
551a4eaf0bSdanielk1977  do_test mallocI-4.$::n.2 {
561a4eaf0bSdanielk1977    # If this INSERT is possible then [db] does not hold a shared lock
571a4eaf0bSdanielk1977    # on the database file.
581a4eaf0bSdanielk1977    catchsql { INSERT INTO t1 VALUES(1, 2, 3) } db2
591a4eaf0bSdanielk1977  } {0 {}}
60aa9ecebcSshaneh  catch {db2 close}
611a4eaf0bSdanielk1977}
62f77a367dSdanielk1977catch { db2 close }
631a4eaf0bSdanielk1977
64*4e59344aSdando_faultsim_test mallocI-5 -faults oom* -prep {
65*4e59344aSdan  catch { db close }
66*4e59344aSdan  sqlite3 db test.db
67*4e59344aSdan  sqlite3_db_config_lookaside db 0 0 0
68*4e59344aSdan} -body {
69*4e59344aSdan  db eval { Select CAST(1 AS blob) }
70*4e59344aSdan} -test {
71*4e59344aSdan  faultsim_test_result {0 1}
72*4e59344aSdan}
73*4e59344aSdan
74*4e59344aSdan
75701bb3b4Sdrhfinish_test
76