1
0

mmapfault.test 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # 2013-05-23
  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. ifcapable !mmap {
  16. finish_test
  17. return
  18. }
  19. set testprefix mmapfault
  20. set a_string_counter 1
  21. proc a_string {n} {
  22. global a_string_counter
  23. incr a_string_counter
  24. string range [string repeat "${a_string_counter}." $n] 1 $n
  25. }
  26. db func a_string a_string
  27. do_test 1-pre {
  28. execsql {
  29. CREATE TABLE t1(a UNIQUE, b UNIQUE);
  30. INSERT INTO t1 VALUES(a_string(200), a_string(300));
  31. INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
  32. INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
  33. }
  34. faultsim_save_and_close
  35. } {}
  36. do_faultsim_test 1 -prep {
  37. faultsim_restore_and_reopen
  38. db func a_string a_string
  39. breakpoint
  40. execsql {
  41. PRAGMA mmap_size = 1000000;
  42. PRAGMA cache_size = 5;
  43. BEGIN;
  44. INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
  45. INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
  46. INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
  47. INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
  48. }
  49. } -body {
  50. execsql { INSERT INTO t1 VALUES(a_string(200), a_string(300)) }
  51. } -test {
  52. faultsim_test_result {0 {}}
  53. if {[sqlite3_get_autocommit db]} {
  54. sqlite3 db2 test.db
  55. set nRow [db2 one {SELECT count(*) FROM t1}]
  56. if {$nRow!=4} { error "Database content appears incorrect (1)" }
  57. db2 close
  58. }
  59. execsql { INSERT INTO t1 VALUES(a_string(201), a_string(301)) }
  60. set nRow [db one {SELECT count(*) FROM t1}]
  61. if {$nRow!=5 && $nRow!=66 && $nRow!=65} {
  62. error "Database content appears incorrect (2) ($nRow)"
  63. }
  64. catch { execsql COMMIT }
  65. }
  66. finish_test