backup_malloc.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. source $testdir/malloc_common.tcl
  19. do_malloc_test backup_malloc-1 -tclprep {
  20. execsql {
  21. PRAGMA cache_size = 10;
  22. BEGIN;
  23. CREATE TABLE t1(a, b);
  24. INSERT INTO t1 VALUES(1, randstr(1000,1000));
  25. INSERT INTO t1 SELECT a+ 1, randstr(1000,1000) FROM t1;
  26. INSERT INTO t1 SELECT a+ 2, randstr(1000,1000) FROM t1;
  27. INSERT INTO t1 SELECT a+ 4, randstr(1000,1000) FROM t1;
  28. INSERT INTO t1 SELECT a+ 8, randstr(1000,1000) FROM t1;
  29. INSERT INTO t1 SELECT a+16, randstr(1000,1000) FROM t1;
  30. INSERT INTO t1 SELECT a+32, randstr(1000,1000) FROM t1;
  31. INSERT INTO t1 SELECT a+64, randstr(1000,1000) FROM t1;
  32. CREATE INDEX i1 ON t1(b);
  33. COMMIT;
  34. }
  35. sqlite3 db2 test2.db
  36. execsql { PRAGMA cache_size = 10 } db2
  37. } -tclbody {
  38. # Create a backup object.
  39. #
  40. set rc [catch {sqlite3_backup B db2 main db main}]
  41. if {$rc && [sqlite3_errcode db2] == "SQLITE_NOMEM"} {
  42. error "out of memory"
  43. }
  44. # Run the backup process some.
  45. #
  46. set rc [B step 50]
  47. if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} {
  48. error "out of memory"
  49. }
  50. # Update the database.
  51. #
  52. execsql { UPDATE t1 SET a = a + 1 }
  53. # Finish doing the backup.
  54. #
  55. set rc [B step 5000]
  56. if {$rc == "SQLITE_NOMEM" || $rc == "SQLITE_IOERR_NOMEM"} {
  57. error "out of memory"
  58. }
  59. # Finalize the backup.
  60. B finish
  61. } -cleanup {
  62. catch { B finish }
  63. catch { db2 close }
  64. }
  65. do_malloc_test backup_malloc-2 -tclprep {
  66. sqlite3 db2 test2.db
  67. } -tclbody {
  68. set rc [catch {sqlite3_backup B db2 temp db main}]
  69. set errcode [sqlite3_errcode db2]
  70. if {$rc && ($errcode == "SQLITE_NOMEM" || $errcode == "SQLITE_IOERR_NOMEM")} {
  71. error "out of memory"
  72. }
  73. } -cleanup {
  74. catch { B finish }
  75. db2 close
  76. }
  77. finish_test