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