mallocA.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # 2007 April 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 contains additional out-of-memory checks (see malloc.tcl).
  12. #
  13. # $Id: mallocA.test,v 1.8 2008/02/18 22:24:58 drh Exp $
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. source $testdir/malloc_common.tcl
  17. set testprefix mallocA
  18. # Only run these tests if memory debugging is turned on.
  19. #
  20. if {!$MEMDEBUG} {
  21. puts "Skipping mallocA tests: not compiled with -DSQLITE_MEMDEBUG..."
  22. finish_test
  23. return
  24. }
  25. # Construct a test database
  26. #
  27. forcedelete test.db.bu
  28. db eval {
  29. CREATE TABLE t1(a COLLATE NOCASE,b,c);
  30. INSERT INTO t1 VALUES(1,2,3);
  31. INSERT INTO t1 VALUES(1,2,4);
  32. INSERT INTO t1 VALUES(2,3,4);
  33. CREATE INDEX t1i1 ON t1(a);
  34. CREATE INDEX t1i2 ON t1(b,c);
  35. CREATE TABLE t2(x,y,z);
  36. }
  37. db close
  38. copy_file test.db test.db.bu
  39. do_malloc_test mallocA-1 -testdb test.db.bu -sqlbody {
  40. ANALYZE
  41. }
  42. do_malloc_test mallocA-1.1 -testdb test.db.bu -sqlbody {
  43. ANALYZE t1
  44. }
  45. do_malloc_test mallocA-1.2 -testdb test.db.bu -sqlbody {
  46. ANALYZE main
  47. }
  48. do_malloc_test mallocA-1.3 -testdb test.db.bu -sqlbody {
  49. ANALYZE main.t1
  50. }
  51. ifcapable reindex {
  52. do_malloc_test mallocA-2 -testdb test.db.bu -sqlbody {
  53. REINDEX;
  54. }
  55. do_malloc_test mallocA-3 -testdb test.db.bu -sqlbody {
  56. REINDEX t1;
  57. }
  58. do_malloc_test mallocA-4 -testdb test.db.bu -sqlbody {
  59. REINDEX main.t1;
  60. }
  61. do_malloc_test mallocA-5 -testdb test.db.bu -sqlbody {
  62. REINDEX nocase;
  63. }
  64. }
  65. reset_db
  66. sqlite3_db_config_lookaside db 0 0 0
  67. do_execsql_test 6-prep {
  68. CREATE TABLE t1(a, b);
  69. CREATE INDEX i1 ON t1(a, b);
  70. INSERT INTO t1 VALUES('abc', 'w'); -- rowid=1
  71. INSERT INTO t1 VALUES('abc', 'x'); -- rowid=2
  72. INSERT INTO t1 VALUES('abc', 'y'); -- rowid=3
  73. INSERT INTO t1 VALUES('abc', 'z'); -- rowid=4
  74. INSERT INTO t1 VALUES('def', 'w'); -- rowid=5
  75. INSERT INTO t1 VALUES('def', 'x'); -- rowid=6
  76. INSERT INTO t1 VALUES('def', 'y'); -- rowid=7
  77. INSERT INTO t1 VALUES('def', 'z'); -- rowid=8
  78. ANALYZE;
  79. }
  80. do_faultsim_test 6.1 -faults oom* -body {
  81. execsql { SELECT rowid FROM t1 WHERE a='abc' AND b='x' }
  82. } -test {
  83. faultsim_test_result [list 0 2]
  84. }
  85. do_faultsim_test 6.2 -faults oom* -body {
  86. execsql { SELECT rowid FROM t1 WHERE a='abc' AND b<'y' }
  87. } -test {
  88. faultsim_test_result [list 0 {1 2}]
  89. }
  90. ifcapable stat3 {
  91. do_test 6.3-prep {
  92. execsql {
  93. PRAGMA writable_schema = 1;
  94. CREATE TABLE sqlite_stat4 AS
  95. SELECT tbl, idx, neq, nlt, ndlt, sqlite_record(sample) AS sample
  96. FROM sqlite_stat3;
  97. }
  98. } {}
  99. do_faultsim_test 6.3 -faults oom* -body {
  100. execsql {
  101. ANALYZE sqlite_master;
  102. SELECT rowid FROM t1 WHERE a='abc' AND b<'y';
  103. }
  104. } -test {
  105. faultsim_test_result [list 0 {1 2}]
  106. }
  107. }
  108. # Ensure that no file descriptors were leaked.
  109. do_test malloc-99.X {
  110. catch {db close}
  111. set sqlite_open_file_count
  112. } {0}
  113. forcedelete test.db.bu
  114. finish_test