sl@0: # 2008 July 7 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # sl@0: # Test scripts for deliberate failures of mutex routines. sl@0: # sl@0: # $Id: mutex2.test,v 1.8 2008/07/19 13:43:24 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # deinitialize sl@0: # sl@0: catch {db close} sl@0: sqlite3_reset_auto_extension sl@0: sqlite3_shutdown sl@0: install_mutex_counters 1 sl@0: sl@0: # Fix the mutex subsystem so that it will not initialize. In other words, sl@0: # make it so that sqlite3_initialize() always fails. sl@0: # sl@0: do_test mutex2-1.1 { sl@0: set ::disable_mutex_init 10 sl@0: sqlite3_initialize sl@0: } {SQLITE_IOERR} sl@0: do_test mutex2-1.1 { sl@0: set ::disable_mutex_init 7 sl@0: sqlite3_initialize sl@0: } {SQLITE_NOMEM} sl@0: sl@0: proc utf16 {str} { sl@0: set r [encoding convertto unicode $str] sl@0: append r "\x00\x00" sl@0: return $r sl@0: } sl@0: sl@0: # Now that sqlite3_initialize() is failing, try to run various APIs that sl@0: # require that SQLite be initialized. Verify that they fail. sl@0: # sl@0: do_test mutex2-2.1 { sl@0: set ::disable_mutex_init 7 sl@0: set rc [catch {sqlite db test.db} msg] sl@0: lappend rc $msg sl@0: } {1 {}} sl@0: ifcapable utf16 { sl@0: do_test mutex2-2.2 { sl@0: set db2 [sqlite3_open16 [utf16 test.db] {}] sl@0: } {0} sl@0: do_test mutex2-2.3 { sl@0: sqlite3_complete16 [utf16 {SELECT * FROM t1;}] sl@0: } {7} sl@0: } sl@0: do_test mutex2-2.4 { sl@0: sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3 sl@0: } {} sl@0: ifcapable load_ext { sl@0: do_test mutex2-2.5 { sl@0: sqlite3_auto_extension_sqr sl@0: } {7} sl@0: } sl@0: do_test mutex2-2.6 { sl@0: sqlite3_reset_auto_extension sl@0: } {} sl@0: do_test mutex2-2.7 { sl@0: sqlite3_malloc 10000 sl@0: } {0} sl@0: do_test mutex2-2.8 { sl@0: sqlite3_realloc 0 10000 sl@0: } {0} sl@0: ifcapable threadsafe { sl@0: do_test mutex2-2.9 { sl@0: alloc_dealloc_mutex sl@0: } {0} sl@0: } sl@0: do_test mutex2-2.10 { sl@0: vfs_initfail_test sl@0: } {} sl@0: sl@0: # Restore the system to a functional state sl@0: # sl@0: install_mutex_counters 0 sl@0: set disable_mutex_init 0 sl@0: autoinstall_test_functions sl@0: sl@0: # Mutex allocation works now. sl@0: # sl@0: sl@0: do_test mutex2-3.1 { sl@0: set ptr [alloc_dealloc_mutex] sl@0: expr {$ptr!=0} sl@0: } {1} sl@0: sl@0: sl@0: finish_test