/ Check-in [5bfc9625]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove the malloc2.test script since it was designed for use in versions of SQLite that predate SQLite's ability to recover from out-of-memory errors automatically. Removing this script causes no reduction in test coverage and removes potential problems reported by ticket #3213. (CVS 5409)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5bfc962533995530a0ef0875556f9f46e8dbf68b
User & Date: drh 2008-07-14 15:11:20
Context
2008-07-14
15:37
Have the rtree extension publish two virtual table types: "rtree" and "rtree_i32". rtree_i32 stores coordinate data as 32-bit signed integers. rtree uses 32-bit real (floating point) values. (CVS 5410) check-in: c060a9a6 user: danielk1977 tags: trunk
15:11
Remove the malloc2.test script since it was designed for use in versions of SQLite that predate SQLite's ability to recover from out-of-memory errors automatically. Removing this script causes no reduction in test coverage and removes potential problems reported by ticket #3213. (CVS 5409) check-in: 5bfc9625 user: drh tags: trunk
12:52
Write sqlite3_initialize() calls in sqlite3_malloc() within SQLITE_OMIT_AUTOINIT. Ticket #3217. (CVS 5408) check-in: 4961b0bb user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/all.test.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: all.test,v 1.56 2008/06/21 19:20:13 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
rename finish_test really_finish_test
proc finish_test {} {
  # no-op
}
................................................................................

# Files to include in the test.  If this list is empty then everything
# that is not in the EXCLUDE list is run.
#
set INCLUDE {
}

# Test files btree2.test and btree4.test don't work if the 
# SQLITE_DEFAULT_AUTOVACUUM macro is defined to true (because they depend
# on tables being allocated starting at page 2).
#
ifcapable default_autovacuum {
  lappend EXCLUDE btree2.test
  lappend EXCLUDE btree4.test
}

for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
  if {$Counter%2} {
    set ::SETUP_SQL {PRAGMA default_synchronous=off;}
  } else {
    catch {unset ::SETUP_SQL}
  }
  foreach testfile [lsort -dictionary [glob $testdir/*.test]] {







|







 







<
<
<
<
<
<
<
<
<







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
70
71
72
73
74
75
76









77
78
79
80
81
82
83
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: all.test,v 1.57 2008/07/14 15:11:20 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
rename finish_test really_finish_test
proc finish_test {} {
  # no-op
}
................................................................................

# Files to include in the test.  If this list is empty then everything
# that is not in the EXCLUDE list is run.
#
set INCLUDE {
}










for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
  if {$Counter%2} {
    set ::SETUP_SQL {PRAGMA default_synchronous=off;}
  } else {
    catch {unset ::SETUP_SQL}
  }
  foreach testfile [lsort -dictionary [glob $testdir/*.test]] {

Changes to test/capi3d.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
60
61
62
63
64
65
66

67
68
69
70
71
72
73
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  
#
# This file is devoted to testing the sqlite3_next_stmt interface.
#
# $Id: capi3d.test,v 1.1 2008/06/19 02:52:25 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create N prepared statements against database connection db
# and return a list of all the generated prepared statements.
................................................................................
  }
  return $outlist
}

# Database initially has no prepared statements.
#
do_test capi3d-1.1 {

  sqlite3_next_stmt db 0
} {}

# Run the following tests for between 1 and 100 prepared statements.
#
for {set i 1} {$i<=100} {incr i} {
  set stmtlist [make_prepared_statements $i]







|







 







>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  
#
# This file is devoted to testing the sqlite3_next_stmt interface.
#
# $Id: capi3d.test,v 1.2 2008/07/14 15:11:20 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create N prepared statements against database connection db
# and return a list of all the generated prepared statements.
................................................................................
  }
  return $outlist
}

# Database initially has no prepared statements.
#
do_test capi3d-1.1 {
  db cache flush
  sqlite3_next_stmt db 0
} {}

# Run the following tests for between 1 and 100 prepared statements.
#
for {set i 1} {$i<=100} {incr i} {
  set stmtlist [make_prepared_statements $i]

Deleted test/malloc2.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# 2005 March 18
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file attempts to check that the library can recover from a malloc()
# failure when sqlite3_global_recover() is invoked.
#
# (Later:) The sqlite3_global_recover() interface is now a no-op.
# Recovery from malloc() failures is automatic.  But we keep these
# tests around because you can never have too many test cases.
#
# $Id: malloc2.test,v 1.13 2008/06/19 18:17:50 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl

# Only run these tests if memory debugging is turned on.
#
if {!$MEMDEBUG} {
   puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
   finish_test
   return
}

sqlite3_extended_result_codes db 1

proc do_malloc2_test {tn args} {
  array set ::mallocopts $args
  set sum [allcksum db]
  save_prng_state

  for {set ::n 1} {true} {incr ::n} {

    # Run the SQL. Malloc number $::n is set to fail. A malloc() failure
    # may or may not be reported.
    restore_prng_state
    sqlite3_memdebug_fail $::n -repeat 1
    do_test malloc2-$tn.$::n.2 {
      set res [catchsql [string trim $::mallocopts(-sql)]]
      set rc [expr { 
        0==[string compare $res {1 {out of memory}}] ||
        [db errorcode] == 3082 ||
        0==[lindex $res 0]
      }]
      if {$rc!=1} {
        puts "Error: $res"
      }
      set rc
    } {1}

    # If $::n is greater than the number of malloc() calls required to
    # execute the SQL, then this test is finished. Break out of the loop.
    set nFail [sqlite3_memdebug_fail -1 -benigncnt nBenign]
    incr nFail [expr {-1*$nBenign}]
    if {$nFail==0} break

    # Nothing should work now, because the allocator should refuse to
    # allocate any memory.
    #
    # Update: SQLite now automatically recovers from a malloc() failure.
    # So the statement in the test below would work. 
    if 0 {
      do_test malloc2-$tn.$::n.3 {
        catchsql {SELECT 'nothing should work'}
      } {1 {out of memory}}
    }

    # Recover from the malloc failure.
    #
    # Update: The new malloc() failure handling means that a transaction may
    # still be active even if a malloc() has failed. But when these tests were
    # written this was not the case. So do a manual ROLLBACK here so that the
    # tests pass.
    do_test malloc2-$tn.$::n.4 {
      sqlite3_global_recover
      catch {
        execsql {
          ROLLBACK;
        }
      }
      expr 0
    } {0}

    # Checksum the database.
    do_test malloc2-$tn.$::n.5 {
      allcksum db
    } $sum

    integrity_check malloc2-$tn.$::n.6
    if {$::nErr>1} return
  }
  unset ::mallocopts
}

do_test malloc2.1.setup {
  execsql {
    CREATE TABLE abc(a, b, c);
    INSERT INTO abc VALUES(10, 20, 30);
    INSERT INTO abc VALUES(40, 50, 60);
    CREATE INDEX abc_i ON abc(a, b, c);
  }
} {}
do_malloc2_test 1.1 -sql {
  SELECT * FROM abc;
}
do_malloc2_test 1.2 -sql {
  UPDATE abc SET c = c+10;
}
do_malloc2_test 1.3 -sql {
  INSERT INTO abc VALUES(70, 80, 90);
}
do_malloc2_test 1.4 -sql {
  DELETE FROM abc;
}
do_test malloc2.1.5 {
  execsql {
    SELECT * FROM abc;
  }
} {}

do_test malloc2.2.setup {
  execsql {
    CREATE TABLE def(a, b, c);
    CREATE INDEX def_i1 ON def(a);
    CREATE INDEX def_i2 ON def(c);
    BEGIN;
  }
  for {set i 0} {$i<20} {incr i} {
    execsql {
    INSERT INTO def VALUES(randstr(300,300),randstr(300,300),randstr(300,300));
    }
  }
  execsql {
    COMMIT;
  }
} {}
do_malloc2_test 2 -sql {
  BEGIN;
  UPDATE def SET a = randstr(100,100) WHERE (oid%9)==0;
  INSERT INTO def SELECT * FROM def WHERE (oid%13)==0;

  CREATE INDEX def_i3 ON def(b);

  UPDATE def SET a = randstr(100,100) WHERE (oid%9)==1;
  INSERT INTO def SELECT * FROM def WHERE (oid%13)==1;

  CREATE TABLE def2 AS SELECT * FROM def;
  DROP TABLE def;
  CREATE TABLE def AS SELECT * FROM def2;
  DROP TABLE def2;

  DELETE FROM def WHERE (oid%9)==2;
  INSERT INTO def SELECT * FROM def WHERE (oid%13)==2;
  COMMIT;
}

ifcapable tempdb {
  do_test malloc2.3.setup {
    execsql {
      CREATE TEMP TABLE ghi(a, b, c);
      BEGIN;
    }
    for {set i 0} {$i<20} {incr i} {
      execsql {
        INSERT INTO ghi VALUES(
            randstr(300,300), randstr(300,300), randstr(300,300)
        );
      }
    }
    execsql {
      COMMIT;
    }
  } {}
  do_malloc2_test 3 -sql {
    BEGIN;
    CREATE INDEX ghi_i1 ON ghi(a);
    UPDATE def SET a = randstr(100,100) WHERE (oid%2)==0;
    UPDATE ghi SET a = randstr(100,100) WHERE (oid%2)==0;
    COMMIT;
  }
}

############################################################################
# The test cases below are to increase the code coverage in btree.c and 
# pager.c of this test file. The idea is that each malloc() that occurs in
# these two source files should be made to fail at least once.
#
catchsql {
  DROP TABLE ghi;
}
do_malloc2_test 4.1 -sql {
  SELECT * FROM def ORDER BY oid ASC;
  SELECT * FROM def ORDER BY oid DESC;
}
do_malloc2_test 4.2 -sql {
  PRAGMA cache_size = 10;
  BEGIN;

  -- This will put about 25 pages on the free list.
  DELETE FROM def WHERE 1;

  -- Allocate 32 new root pages. This will exercise the 'extract specific 
  -- page from the freelist' code when in auto-vacuum mode (see the
  -- allocatePage() routine in btree.c).
  CREATE TABLE t1(a UNIQUE, b UNIQUE, c UNIQUE);
  CREATE TABLE t2(a UNIQUE, b UNIQUE, c UNIQUE);
  CREATE TABLE t3(a UNIQUE, b UNIQUE, c UNIQUE);
  CREATE TABLE t4(a UNIQUE, b UNIQUE, c UNIQUE);
  CREATE TABLE t5(a UNIQUE, b UNIQUE, c UNIQUE);
  CREATE TABLE t6(a UNIQUE, b UNIQUE, c UNIQUE);
  CREATE TABLE t7(a UNIQUE, b UNIQUE, c UNIQUE);
  CREATE TABLE t8(a UNIQUE, b UNIQUE, c UNIQUE);

  ROLLBACK;
}

########################################################################
# Test that the global linked list of database handles works. An assert()
# will fail if there is some problem.
do_test malloc2-5 {
  sqlite3 db1 test.db
  sqlite3 db2 test.db
  sqlite3 db3 test.db
  sqlite3 db4 test.db
  sqlite3 db5 test.db

  sqlite3_extended_result_codes db1 1
  sqlite3_extended_result_codes db2 1
  sqlite3_extended_result_codes db3 1
  sqlite3_extended_result_codes db4 1
  sqlite3_extended_result_codes db5 1

  # Close the head of the list:
  db5 close
  
  # Close the end of the list:
  db1 close

  # Close a handle from the middle of the list:
  db3 close

  # Close the other two. Then open and close one more database, to make
  # sure the head of the list was set back to NULL.
  db2 close
  db4 close
  sqlite db1 test.db
  db1 close
} {}

########################################################################
# Check that if a statement is active sqlite3_global_recover doesn't reset
# the sqlite3_malloc_failed variable.
#
# Update: There is now no sqlite3_malloc_failed variable, so these tests 
# are not run.
#
# do_test malloc2-6.1 {
#   set ::STMT [sqlite3_prepare $::DB {SELECT * FROM def} -1 DUMMY]
#   sqlite3_step $::STMT
# } {SQLITE_ROW}
# do_test malloc2-6.2 {
#   sqlite3 db1 test.db
#   sqlite_malloc_fail 100
#   catchsql {
#     SELECT * FROM def;
#   } db1
# } {1 {out of memory}}
# do_test malloc2-6.3 {
#   sqlite3_global_recover
# } {SQLITE_BUSY}
# do_test malloc2-6.4 {
#   catchsql {
#     SELECT 'hello';
#   }
# } {1 {out of memory}}
# do_test malloc2-6.5 {
#   sqlite3_reset $::STMT
# } {SQLITE_OK}
# do_test malloc2-6.6 {
#   sqlite3_global_recover
# } {SQLITE_OK}
# do_test malloc2-6.7 {
#   catchsql {
#     SELECT 'hello';
#   }
# } {0 hello}
# do_test malloc2-6.8 {
#   sqlite3_step $::STMT
# } {SQLITE_ERROR}
# do_test malloc2-6.9 {
#   sqlite3_finalize $::STMT
# } {SQLITE_SCHEMA}
# do_test malloc2-6.10 {
#   db1 close
# } {}

########################################################################
# Check that if an in-memory database is being used it is not possible
# to recover from a malloc() failure.
#
# Update: An in-memory database can now survive a malloc() failure, so these
# tests are not run.
#
# ifcapable memorydb {
#   do_test malloc2-7.1 {
#     sqlite3 db1 :memory:
#     list
#   } {}
#   do_test malloc2-7.2 {
#     sqlite_malloc_fail 100
#     catchsql {
#       SELECT * FROM def;
#     } 
#   } {1 {out of memory}}
#   do_test malloc2-7.3 {
#     sqlite3_global_recover
#   } {SQLITE_ERROR}
#   do_test malloc2-7.4 {
#     catchsql {
#       SELECT 'hello';
#     }
#   } {1 {out of memory}}
#   do_test malloc2-7.5 {
#     db1 close
#   } {}
#   do_test malloc2-7.6 {
#     sqlite3_global_recover
#   } {SQLITE_OK}
#   do_test malloc2-7.7 {
#     catchsql {
#       SELECT 'hello';
#     }
#   } {0 hello}
# }

finish_test
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<