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 # $Id: mutex1.test,v 1.20 2009/04/23 14:58:40 danielk1977 Exp $
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
21 if {[info exists tester_do_binarylog]} {
26 sqlite3_reset_auto_extension
29 proc mutex_counters {varname} {
32 foreach {name value} [read_mutex_counters] {
34 incr var(total) $value
38 #-------------------------------------------------------------------------
39 # Tests mutex1-1.* test that sqlite3_config() returns SQLITE_MISUSE if
40 # is called at the wrong time. And that the first time sqlite3_initialize
41 # is called it obtains the 'static_master' mutex 3 times and a recursive
42 # mutex (sqlite3Config.pInitMutex) twice. Subsequent calls are no-ops
43 # that do not require any mutexes.
46 install_mutex_counters 1
51 install_mutex_counters 1
56 install_mutex_counters 1
60 install_mutex_counters 0
64 install_mutex_counters 1
68 mutex_counters counters
77 mutex_counters counters
78 # list $counters(total) $counters(static_master)
79 expr {$counters(total)>0}
88 mutex_counters counters
89 list $counters(total) $counters(static_master)
92 #-------------------------------------------------------------------------
93 # Tests mutex1-2.* test the three thread-safety related modes that
94 # can be selected using sqlite3_config:
97 # * Multi-threaded mode,
98 # * Single-threaded mode.
100 ifcapable threadsafe&&shared_cache {
101 set enable_shared_cache [sqlite3_enable_shared_cache 1]
102 foreach {mode mutexes} {
105 fast static_lru static_master static_mem static_open static_prng
109 fast recursive static_lru static_master static_mem static_open
110 static_prng static_pmem
114 do_test mutex1.2.$mode.1 {
120 do_test mutex1.2.$mode.2 {
123 sqlite3 db test.db -nomutex 0 -fullmutex 0
124 catchsql { CREATE TABLE abc(a, b, c) }
126 INSERT INTO abc VALUES(1, 2, 3);
129 ifcapable !memorymanage {
130 regsub { static_lru} $mutexes {} mutexes
132 do_test mutex1.2.$mode.3 {
133 mutex_counters counters
136 foreach {key value} [array get counters] {
137 if {$key ne "total" && $value > 0} {
144 sqlite3_enable_shared_cache $enable_shared_cache
146 # Open and use a connection in "nomutex" mode. Test that no recursive
147 # mutexes are obtained.
151 sqlite3 db test.db -nomutex 1
152 execsql { SELECT * FROM abc }
153 } {1 2 3 1 2 3 1 2 3}
155 mutex_counters counters
156 set counters(recursive)
160 # Test the sqlite3_db_mutex() function.
166 db eval {SELECT 1, 2, 3}
170 db eval {SELECT 1, 2, 3}
174 sqlite3 db test.db -nomutex 1
176 db eval {SELECT 1, 2, 3}
180 db eval {SELECT 1, 2, 3}
187 install_mutex_counters 0
191 autoinstall_test_functions