crash6.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # 2001 September 15
  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 tests that rollback journals for databases that use a
  12. # page-size other than the default page-size can be rolled back Ok.
  13. #
  14. # $Id: crash6.test,v 1.2 2008/04/14 15:27:19 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. ifcapable !crashtest {
  18. finish_test
  19. return
  20. }
  21. for {set ii 0} {$ii < 10} {incr ii} {
  22. catch {db close}
  23. forcedelete test.db test.db-journal
  24. crashsql -delay 2 -file test.db {
  25. PRAGMA auto_vacuum=OFF;
  26. PRAGMA page_size=4096;
  27. BEGIN;
  28. CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
  29. COMMIT;
  30. BEGIN;
  31. CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f;
  32. COMMIT;
  33. }
  34. sqlite3 db test.db
  35. integrity_check crash6-1.$ii
  36. }
  37. for {set ii 0} {$ii < 10} {incr ii} {
  38. catch {db close}
  39. forcedelete test.db test.db-journal
  40. sqlite3 db test.db
  41. execsql {
  42. PRAGMA auto_vacuum=OFF;
  43. PRAGMA page_size=2048;
  44. BEGIN;
  45. CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
  46. COMMIT;
  47. }
  48. db close
  49. crashsql -delay 1 -file test.db {
  50. INSERT INTO abc VALUES(5, 6, 7);
  51. }
  52. sqlite3 db test.db
  53. integrity_check crash6-2.$ii
  54. }
  55. proc signature {} {
  56. return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
  57. }
  58. # Test case for crashing during database sync with page-size values
  59. # from 1024 to 8192.
  60. #
  61. for {set ii 0} {$ii < 30} {incr ii} {
  62. db close
  63. forcedelete test.db
  64. sqlite3 db test.db
  65. set pagesize [expr 1024 << ($ii % 4)]
  66. if {$pagesize>$::SQLITE_MAX_PAGE_SIZE} {
  67. set pagesize $::SQLITE_MAX_PAGE_SIZE
  68. }
  69. do_test crash6-3.$ii.0 {
  70. execsql "pragma page_size = $pagesize"
  71. execsql "pragma page_size"
  72. } $pagesize
  73. do_test crash6-3.$ii.1 {
  74. execsql BEGIN
  75. execsql {CREATE TABLE abc(a, b, c)}
  76. for {set n 0} {$n < 1000} {incr n} {
  77. execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"
  78. }
  79. execsql {
  80. INSERT INTO abc SELECT * FROM abc;
  81. INSERT INTO abc SELECT * FROM abc;
  82. INSERT INTO abc SELECT * FROM abc;
  83. INSERT INTO abc SELECT * FROM abc;
  84. INSERT INTO abc SELECT * FROM abc;
  85. }
  86. execsql COMMIT
  87. expr ([file size test.db] / 1024) > 450
  88. } {1}
  89. set sig [signature]
  90. db close
  91. do_test crash6-3.$ii.2 {
  92. crashsql -file test.db "
  93. BEGIN;
  94. SELECT random() FROM abc LIMIT $ii;
  95. INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
  96. DELETE FROM abc WHERE random()%2!=0;
  97. COMMIT;
  98. "
  99. } {1 {child process exited abnormally}}
  100. do_test crash6-3.$ii.3 {
  101. sqlite3 db test.db
  102. signature
  103. } $sig
  104. }
  105. finish_test