ioerr6.test 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # 2012 December 18
  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. #
  12. set testdir [file dirname $argv0]
  13. source $testdir/tester.tcl
  14. source $testdir/malloc_common.tcl
  15. set ::testprefix ioerr6
  16. ifcapable !atomicwrite {
  17. puts "skipping tests - not compiled with SQLITE_ENABLE_ATOMIC_WRITE..."
  18. finish_test
  19. return
  20. }
  21. if {[permutation]=="inmemory_journal"} {
  22. # These tests will not work with in-memory journals (as persistent VFS
  23. # errors commencing after a transaction has started to write to the db
  24. # cannot be recovered from).
  25. finish_test
  26. return
  27. }
  28. faultsim_save_and_close
  29. do_test 1.1 {
  30. testvfs shmfault -default true
  31. shmfault devchar atomic
  32. sqlite3 db test.db
  33. execsql {
  34. CREATE TABLE t1(a, b);
  35. CREATE INDEX i1 ON t1(a, b);
  36. INSERT INTO t1 VALUES(1, 2);
  37. INSERT INTO t1 VALUES(2, 4);
  38. INSERT INTO t1 VALUES(3, 6);
  39. INSERT INTO t1 VALUES(4, 8);
  40. }
  41. # Cause the first call to xWrite() to fail with SQLITE_FULL.
  42. shmfault full 2 1
  43. catchsql { INSERT INTO t1 VALUES(5, 10) }
  44. } {1 {database or disk is full}}
  45. do_test 1.2 {
  46. execsql { PRAGMA integrity_check }
  47. } {ok}
  48. db close
  49. shmfault delete
  50. do_faultsim_test 2 -faults full* -prep {
  51. shmfault devchar atomic
  52. faultsim_restore
  53. sqlite3 db test.db
  54. } -body {
  55. db eval {
  56. CREATE TABLE t1(x PRIMARY KEY);
  57. INSERT INTO t1 VALUES('abc');
  58. }
  59. } -test {
  60. set res [db one { PRAGMA integrity_check }]
  61. if {$res != "ok"} {
  62. error "integrity check: $res"
  63. }
  64. }
  65. do_faultsim_test 3 -faults full* -prep {
  66. shmfault devchar atomic
  67. faultsim_restore
  68. sqlite3 db test.db
  69. } -body {
  70. db eval {
  71. CREATE TABLE t1(x);
  72. CREATE TABLE t2(x);
  73. }
  74. } -test {
  75. db eval { CREATE TABLE t3(x) }
  76. if {[db one { PRAGMA integrity_check }] != "ok"} {
  77. error "integrity check failed"
  78. }
  79. }
  80. finish_test