mmap2.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # 2013 March 20
  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. # This file tests the effect of the mmap() or mremap() system calls
  13. # returning an error on the library.
  14. #
  15. # If either mmap() or mremap() fails, SQLite should log an error
  16. # message, then continue accessing the database using read() and
  17. # write() exclusively.
  18. #
  19. set testdir [file dirname $argv0]
  20. source $testdir/tester.tcl
  21. set testprefix mmap2
  22. if {$::tcl_platform(platform)!="unix" || [test_syscall defaultvfs] != "unix"} {
  23. finish_test
  24. return
  25. }
  26. ifcapable !mmap {
  27. finish_test
  28. return
  29. }
  30. db close
  31. sqlite3_shutdown
  32. test_sqlite3_log xLog
  33. proc xLog {error_code msg} {
  34. if {[string match os_unix.c* $msg]} {
  35. lappend ::log $msg
  36. }
  37. }
  38. foreach syscall {mmap mremap} {
  39. test_syscall uninstall
  40. if {[catch {test_syscall install $syscall}]} continue
  41. for {set i 1} {$i < 20} {incr i} {
  42. reset_db
  43. execsql { PRAGMA mmap_size = 8000000 }
  44. test_syscall fault $i 1
  45. test_syscall errno $syscall ENOMEM
  46. set ::log ""
  47. do_execsql_test 1.$syscall.$i.1 {
  48. CREATE TABLE t1(a, b, UNIQUE(a, b));
  49. INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
  50. INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
  51. INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
  52. INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
  53. INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
  54. INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
  55. INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
  56. }
  57. set nFail [test_syscall fault 0 0]
  58. do_execsql_test 1.$syscall.$i.2 {
  59. SELECT count(*) FROM t1;
  60. PRAGMA integrity_check;
  61. } {64 ok}
  62. do_test 1.$syscall.$i.3 {
  63. expr {$nFail==0 || $nFail==1}
  64. } {1}
  65. do_test 1.$syscall.$i.4.nFail=$nFail {
  66. regexp ".*${syscall}.*" $::log
  67. } [expr $nFail>0]
  68. }
  69. }
  70. db close
  71. test_syscall uninstall
  72. sqlite3_shutdown
  73. test_sqlite3_log
  74. sqlite3_initialize
  75. finish_test