When disconnecting from the 'swarmvtab' extension, close each database prior to invok...
[sqlite.git] / test / mutex2.test
blob9dfb03e0dea1b9dd6c2a294c46735b134d656000
1 # 2008 July 7
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # Test scripts for deliberate failures of mutex routines.
14 # $Id: mutex2.test,v 1.9 2008/10/07 15:25:49 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 ifcapable !mutex {
19   finish_test
20   return
23 # deinitialize
25 catch {db close}
26 sqlite3_reset_auto_extension
27 sqlite3_shutdown
28 install_mutex_counters 1
30 # Fix the mutex subsystem so that it will not initialize.  In other words,
31 # make it so that sqlite3_initialize() always fails.  
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}
42 proc utf16 {str} {
43   set r [encoding convertto unicode $str]
44   append r "\x00\x00"
45   return $r
48 # Now that sqlite3_initialize() is failing, try to run various APIs that
49 # require that SQLite be initialized.  Verify that they fail.
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
55 } {1 {}}
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}
64 do_test mutex2-2.4 {
65   sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3
66 } {}
67 ifcapable load_ext {
68   do_test mutex2-2.5 {
69     sqlite3_auto_extension_sqr
70   } {7}
72 do_test mutex2-2.6 {
73   sqlite3_reset_auto_extension
74 } {}
75 do_test mutex2-2.7 {
76   sqlite3_malloc 10000
77 } {0}
78 do_test mutex2-2.8 {
79   sqlite3_realloc 0 10000
80 } {0}
81 ifcapable threadsafe {
82   do_test mutex2-2.9 {
83     alloc_dealloc_mutex
84   } {0}
86 do_test mutex2-2.10 {
87   vfs_initfail_test
88 } {}
90 # Restore the system to a functional state
92 install_mutex_counters 0
93 set disable_mutex_init 0
94 autoinstall_test_functions
96 # Mutex allocation works now.
99 do_test mutex2-3.1 {
100   set ptr [alloc_dealloc_mutex]
101   expr {$ptr!=0}
102 } {1}
105 finish_test