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