author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
# 2008 July 7 |
sl@0 | 2 |
# |
sl@0 | 3 |
# The author disclaims copyright to this source code. In place of |
sl@0 | 4 |
# a legal notice, here is a blessing: |
sl@0 | 5 |
# |
sl@0 | 6 |
# May you do good and not evil. |
sl@0 | 7 |
# May you find forgiveness for yourself and forgive others. |
sl@0 | 8 |
# May you share freely, never taking more than you give. |
sl@0 | 9 |
# |
sl@0 | 10 |
#*********************************************************************** |
sl@0 | 11 |
# |
sl@0 | 12 |
# Test scripts for deliberate failures of mutex routines. |
sl@0 | 13 |
# |
sl@0 | 14 |
# $Id: mutex2.test,v 1.8 2008/07/19 13:43:24 danielk1977 Exp $ |
sl@0 | 15 |
|
sl@0 | 16 |
set testdir [file dirname $argv0] |
sl@0 | 17 |
source $testdir/tester.tcl |
sl@0 | 18 |
|
sl@0 | 19 |
# deinitialize |
sl@0 | 20 |
# |
sl@0 | 21 |
catch {db close} |
sl@0 | 22 |
sqlite3_reset_auto_extension |
sl@0 | 23 |
sqlite3_shutdown |
sl@0 | 24 |
install_mutex_counters 1 |
sl@0 | 25 |
|
sl@0 | 26 |
# Fix the mutex subsystem so that it will not initialize. In other words, |
sl@0 | 27 |
# make it so that sqlite3_initialize() always fails. |
sl@0 | 28 |
# |
sl@0 | 29 |
do_test mutex2-1.1 { |
sl@0 | 30 |
set ::disable_mutex_init 10 |
sl@0 | 31 |
sqlite3_initialize |
sl@0 | 32 |
} {SQLITE_IOERR} |
sl@0 | 33 |
do_test mutex2-1.1 { |
sl@0 | 34 |
set ::disable_mutex_init 7 |
sl@0 | 35 |
sqlite3_initialize |
sl@0 | 36 |
} {SQLITE_NOMEM} |
sl@0 | 37 |
|
sl@0 | 38 |
proc utf16 {str} { |
sl@0 | 39 |
set r [encoding convertto unicode $str] |
sl@0 | 40 |
append r "\x00\x00" |
sl@0 | 41 |
return $r |
sl@0 | 42 |
} |
sl@0 | 43 |
|
sl@0 | 44 |
# Now that sqlite3_initialize() is failing, try to run various APIs that |
sl@0 | 45 |
# require that SQLite be initialized. Verify that they fail. |
sl@0 | 46 |
# |
sl@0 | 47 |
do_test mutex2-2.1 { |
sl@0 | 48 |
set ::disable_mutex_init 7 |
sl@0 | 49 |
set rc [catch {sqlite db test.db} msg] |
sl@0 | 50 |
lappend rc $msg |
sl@0 | 51 |
} {1 {}} |
sl@0 | 52 |
ifcapable utf16 { |
sl@0 | 53 |
do_test mutex2-2.2 { |
sl@0 | 54 |
set db2 [sqlite3_open16 [utf16 test.db] {}] |
sl@0 | 55 |
} {0} |
sl@0 | 56 |
do_test mutex2-2.3 { |
sl@0 | 57 |
sqlite3_complete16 [utf16 {SELECT * FROM t1;}] |
sl@0 | 58 |
} {7} |
sl@0 | 59 |
} |
sl@0 | 60 |
do_test mutex2-2.4 { |
sl@0 | 61 |
sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3 |
sl@0 | 62 |
} {} |
sl@0 | 63 |
ifcapable load_ext { |
sl@0 | 64 |
do_test mutex2-2.5 { |
sl@0 | 65 |
sqlite3_auto_extension_sqr |
sl@0 | 66 |
} {7} |
sl@0 | 67 |
} |
sl@0 | 68 |
do_test mutex2-2.6 { |
sl@0 | 69 |
sqlite3_reset_auto_extension |
sl@0 | 70 |
} {} |
sl@0 | 71 |
do_test mutex2-2.7 { |
sl@0 | 72 |
sqlite3_malloc 10000 |
sl@0 | 73 |
} {0} |
sl@0 | 74 |
do_test mutex2-2.8 { |
sl@0 | 75 |
sqlite3_realloc 0 10000 |
sl@0 | 76 |
} {0} |
sl@0 | 77 |
ifcapable threadsafe { |
sl@0 | 78 |
do_test mutex2-2.9 { |
sl@0 | 79 |
alloc_dealloc_mutex |
sl@0 | 80 |
} {0} |
sl@0 | 81 |
} |
sl@0 | 82 |
do_test mutex2-2.10 { |
sl@0 | 83 |
vfs_initfail_test |
sl@0 | 84 |
} {} |
sl@0 | 85 |
|
sl@0 | 86 |
# Restore the system to a functional state |
sl@0 | 87 |
# |
sl@0 | 88 |
install_mutex_counters 0 |
sl@0 | 89 |
set disable_mutex_init 0 |
sl@0 | 90 |
autoinstall_test_functions |
sl@0 | 91 |
|
sl@0 | 92 |
# Mutex allocation works now. |
sl@0 | 93 |
# |
sl@0 | 94 |
|
sl@0 | 95 |
do_test mutex2-3.1 { |
sl@0 | 96 |
set ptr [alloc_dealloc_mutex] |
sl@0 | 97 |
expr {$ptr!=0} |
sl@0 | 98 |
} {1} |
sl@0 | 99 |
|
sl@0 | 100 |
|
sl@0 | 101 |
finish_test |