mutex2.test 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # 2008 July 7
  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. # Test scripts for deliberate failures of mutex routines.
  13. #
  14. # $Id: mutex2.test,v 1.9 2008/10/07 15:25:49 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. ifcapable !mutex {
  18. finish_test
  19. return
  20. }
  21. # deinitialize
  22. #
  23. catch {db close}
  24. sqlite3_reset_auto_extension
  25. sqlite3_shutdown
  26. install_mutex_counters 1
  27. # Fix the mutex subsystem so that it will not initialize. In other words,
  28. # make it so that sqlite3_initialize() always fails.
  29. #
  30. do_test mutex2-1.1 {
  31. set ::disable_mutex_init 10
  32. sqlite3_initialize
  33. } {SQLITE_IOERR}
  34. do_test mutex2-1.1 {
  35. set ::disable_mutex_init 7
  36. sqlite3_initialize
  37. } {SQLITE_NOMEM}
  38. proc utf16 {str} {
  39. set r [encoding convertto unicode $str]
  40. append r "\x00\x00"
  41. return $r
  42. }
  43. # Now that sqlite3_initialize() is failing, try to run various APIs that
  44. # require that SQLite be initialized. Verify that they fail.
  45. #
  46. do_test mutex2-2.1 {
  47. set ::disable_mutex_init 7
  48. set rc [catch {sqlite db test.db} msg]
  49. lappend rc $msg
  50. } {1 {}}
  51. ifcapable utf16 {
  52. do_test mutex2-2.2 {
  53. set db2 [sqlite3_open16 [utf16 test.db] {}]
  54. } {0}
  55. do_test mutex2-2.3 {
  56. sqlite3_complete16 [utf16 {SELECT * FROM t1;}]
  57. } {7}
  58. }
  59. do_test mutex2-2.4 {
  60. sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3
  61. } {}
  62. ifcapable load_ext {
  63. do_test mutex2-2.5 {
  64. sqlite3_auto_extension_sqr
  65. } {7}
  66. }
  67. do_test mutex2-2.6 {
  68. sqlite3_reset_auto_extension
  69. } {}
  70. do_test mutex2-2.7 {
  71. sqlite3_malloc 10000
  72. } {0}
  73. do_test mutex2-2.8 {
  74. sqlite3_realloc 0 10000
  75. } {0}
  76. ifcapable threadsafe {
  77. do_test mutex2-2.9 {
  78. alloc_dealloc_mutex
  79. } {0}
  80. }
  81. do_test mutex2-2.10 {
  82. vfs_initfail_test
  83. } {}
  84. # Restore the system to a functional state
  85. #
  86. install_mutex_counters 0
  87. set disable_mutex_init 0
  88. autoinstall_test_functions
  89. # Mutex allocation works now.
  90. #
  91. do_test mutex2-3.1 {
  92. set ptr [alloc_dealloc_mutex]
  93. expr {$ptr!=0}
  94. } {1}
  95. finish_test