drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 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 | # |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 14 | # $Id: mutex2.test,v 1.9 2008/10/07 15:25:49 drh Exp $ |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 18 | ifcapable !mutex { |
| 19 | finish_test |
| 20 | return |
| 21 | } |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 22 | |
| 23 | # deinitialize |
| 24 | # |
| 25 | catch {db close} |
| 26 | sqlite3_reset_auto_extension |
| 27 | sqlite3_shutdown |
| 28 | install_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 | # |
| 33 | do_test mutex2-1.1 { |
| 34 | set ::disable_mutex_init 10 |
| 35 | sqlite3_initialize |
| 36 | } {SQLITE_IOERR} |
| 37 | do_test mutex2-1.1 { |
| 38 | set ::disable_mutex_init 7 |
| 39 | sqlite3_initialize |
| 40 | } {SQLITE_NOMEM} |
| 41 | |
| 42 | proc 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 | # |
| 51 | do_test mutex2-2.1 { |
| 52 | set ::disable_mutex_init 7 |
| 53 | set rc [catch {sqlite db test.db} msg] |
| 54 | lappend rc $msg |
drh | ff1590e | 2008-07-14 12:52:53 +0000 | [diff] [blame] | 55 | } {1 {}} |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 56 | ifcapable 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 | } |
| 64 | do_test mutex2-2.4 { |
| 65 | sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3 |
drh | ff1590e | 2008-07-14 12:52:53 +0000 | [diff] [blame] | 66 | } {} |
drh | 7830cd4 | 2008-07-16 12:25:32 +0000 | [diff] [blame] | 67 | ifcapable load_ext { |
| 68 | do_test mutex2-2.5 { |
| 69 | sqlite3_auto_extension_sqr |
| 70 | } {7} |
| 71 | } |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 72 | do_test mutex2-2.6 { |
| 73 | sqlite3_reset_auto_extension |
| 74 | } {} |
| 75 | do_test mutex2-2.7 { |
| 76 | sqlite3_malloc 10000 |
drh | 8278ce7 | 2008-07-11 13:53:54 +0000 | [diff] [blame] | 77 | } {0} |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 78 | do_test mutex2-2.8 { |
| 79 | sqlite3_realloc 0 10000 |
drh | 8278ce7 | 2008-07-11 13:53:54 +0000 | [diff] [blame] | 80 | } {0} |
danielk1977 | b27475b | 2008-07-19 13:43:23 +0000 | [diff] [blame] | 81 | ifcapable threadsafe { |
| 82 | do_test mutex2-2.9 { |
| 83 | alloc_dealloc_mutex |
| 84 | } {0} |
| 85 | } |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 86 | do_test mutex2-2.10 { |
| 87 | vfs_initfail_test |
| 88 | } {} |
| 89 | |
| 90 | # Restore the system to a functional state |
| 91 | # |
| 92 | install_mutex_counters 0 |
| 93 | set disable_mutex_init 0 |
| 94 | autoinstall_test_functions |
drh | 8a42cbd | 2008-07-10 18:13:42 +0000 | [diff] [blame] | 95 | |
| 96 | # Mutex allocation works now. |
| 97 | # |
| 98 | |
| 99 | do_test mutex2-3.1 { |
| 100 | set ptr [alloc_dealloc_mutex] |
| 101 | expr {$ptr!=0} |
| 102 | } {1} |
| 103 | |
| 104 | |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 105 | finish_test |