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.7 2008/07/16 12:25:32 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 {}} 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} {} 63ifcapable load_ext { 64 do_test mutex2-2.5 { 65 sqlite3_auto_extension_sqr 66 } {7} 67} 68do_test mutex2-2.6 { 69 sqlite3_reset_auto_extension 70} {} 71do_test mutex2-2.7 { 72 sqlite3_malloc 10000 73} {0} 74do_test mutex2-2.8 { 75 sqlite3_realloc 0 10000 76} {0} 77do_test mutex2-2.9 { 78 alloc_dealloc_mutex 79} {0} 80do_test mutex2-2.10 { 81 vfs_initfail_test 82} {} 83 84# Restore the system to a functional state 85# 86install_mutex_counters 0 87set disable_mutex_init 0 88autoinstall_test_functions 89 90# Mutex allocation works now. 91# 92 93do_test mutex2-3.1 { 94 set ptr [alloc_dealloc_mutex] 95 expr {$ptr!=0} 96} {1} 97 98 99finish_test 100