2008-06-18 13:45:56 +04:00
|
|
|
# 2008 June 17
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
2009-04-23 18:58:39 +04:00
|
|
|
# $Id: mutex1.test,v 1.20 2009/04/23 14:58:40 danielk1977 Exp $
|
2008-06-18 13:45:56 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2008-07-12 19:55:54 +04:00
|
|
|
|
2008-10-07 19:25:48 +04:00
|
|
|
ifcapable !mutex {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
2008-07-12 19:55:54 +04:00
|
|
|
if {[info exists tester_do_binarylog]} {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2008-06-19 21:54:33 +04:00
|
|
|
sqlite3_reset_auto_extension
|
2009-01-09 17:29:35 +03:00
|
|
|
clear_mutex_counters
|
2008-06-18 13:45:56 +04:00
|
|
|
|
|
|
|
proc mutex_counters {varname} {
|
|
|
|
upvar $varname var
|
|
|
|
set var(total) 0
|
|
|
|
foreach {name value} [read_mutex_counters] {
|
|
|
|
set var($name) $value
|
|
|
|
incr var(total) $value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# Tests mutex1-1.* test that sqlite3_config() returns SQLITE_MISUSE if
|
2015-07-04 02:11:36 +03:00
|
|
|
# is called at the wrong time. And that the first time sqlite3_initialize
|
2020-06-19 16:33:53 +03:00
|
|
|
# is called it obtains the 'static_main' mutex 3 times and a recursive
|
2015-07-04 02:11:36 +03:00
|
|
|
# mutex (sqlite3Config.pInitMutex) twice. Subsequent calls are no-ops
|
2008-06-26 12:29:34 +04:00
|
|
|
# that do not require any mutexes.
|
2008-06-18 13:45:56 +04:00
|
|
|
#
|
|
|
|
do_test mutex1-1.0 {
|
|
|
|
install_mutex_counters 1
|
|
|
|
} {SQLITE_MISUSE}
|
|
|
|
|
|
|
|
do_test mutex1-1.1 {
|
|
|
|
db close
|
|
|
|
install_mutex_counters 1
|
|
|
|
} {SQLITE_MISUSE}
|
|
|
|
|
|
|
|
do_test mutex1-1.2 {
|
|
|
|
sqlite3_shutdown
|
|
|
|
install_mutex_counters 1
|
|
|
|
} {SQLITE_OK}
|
|
|
|
|
|
|
|
do_test mutex1-1.3 {
|
|
|
|
install_mutex_counters 0
|
|
|
|
} {SQLITE_OK}
|
|
|
|
|
|
|
|
do_test mutex1-1.4 {
|
|
|
|
install_mutex_counters 1
|
|
|
|
} {SQLITE_OK}
|
|
|
|
|
|
|
|
do_test mutex1-1.5 {
|
|
|
|
mutex_counters counters
|
|
|
|
set counters(total)
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
do_test mutex1-1.6 {
|
|
|
|
sqlite3_initialize
|
|
|
|
} {SQLITE_OK}
|
|
|
|
|
|
|
|
do_test mutex1-1.7 {
|
|
|
|
mutex_counters counters
|
2020-06-19 16:33:53 +03:00
|
|
|
# list $counters(total) $counters(static_main)
|
2008-06-28 15:23:00 +04:00
|
|
|
expr {$counters(total)>0}
|
|
|
|
} {1}
|
2008-06-18 13:45:56 +04:00
|
|
|
|
|
|
|
do_test mutex1-1.8 {
|
|
|
|
clear_mutex_counters
|
|
|
|
sqlite3_initialize
|
|
|
|
} {SQLITE_OK}
|
|
|
|
|
|
|
|
do_test mutex1-1.9 {
|
|
|
|
mutex_counters counters
|
2020-06-19 16:33:53 +03:00
|
|
|
list $counters(total) $counters(static_main)
|
2008-06-18 13:45:56 +04:00
|
|
|
} {0 0}
|
|
|
|
|
2008-06-18 21:09:10 +04:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# Tests mutex1-2.* test the three thread-safety related modes that
|
|
|
|
# can be selected using sqlite3_config:
|
|
|
|
#
|
|
|
|
# * Serialized mode,
|
|
|
|
# * Multi-threaded mode,
|
|
|
|
# * Single-threaded mode.
|
|
|
|
#
|
2016-03-18 03:19:48 +03:00
|
|
|
ifcapable threadsafe1&&shared_cache {
|
2009-04-23 18:58:39 +04:00
|
|
|
set enable_shared_cache [sqlite3_enable_shared_cache 1]
|
2008-06-18 21:59:03 +04:00
|
|
|
foreach {mode mutexes} {
|
|
|
|
singlethread {}
|
2011-01-26 10:25:32 +03:00
|
|
|
multithread {
|
2015-07-04 02:11:36 +03:00
|
|
|
fast static_app1 static_app2 static_app3
|
2020-06-19 16:33:53 +03:00
|
|
|
static_lru static_main static_mem static_open
|
2015-07-04 02:11:36 +03:00
|
|
|
static_prng static_pmem static_vfs1 static_vfs2
|
|
|
|
static_vfs3
|
2011-01-26 10:25:32 +03:00
|
|
|
}
|
|
|
|
serialized {
|
2015-07-04 02:11:36 +03:00
|
|
|
fast recursive static_app1 static_app2
|
2020-06-19 16:33:53 +03:00
|
|
|
static_app3 static_lru static_main static_mem
|
2015-07-04 02:11:36 +03:00
|
|
|
static_open static_prng static_pmem static_vfs1
|
|
|
|
static_vfs2 static_vfs3
|
2011-01-26 10:25:32 +03:00
|
|
|
}
|
2008-06-18 21:59:03 +04:00
|
|
|
} {
|
2008-07-08 06:12:37 +04:00
|
|
|
|
2008-06-18 21:59:03 +04:00
|
|
|
do_test mutex1.2.$mode.1 {
|
|
|
|
catch {db close}
|
|
|
|
sqlite3_shutdown
|
|
|
|
sqlite3_config $mode
|
|
|
|
} SQLITE_OK
|
2008-06-26 12:29:34 +04:00
|
|
|
|
2008-06-18 21:59:03 +04:00
|
|
|
do_test mutex1.2.$mode.2 {
|
2008-06-26 12:29:34 +04:00
|
|
|
sqlite3_initialize
|
2008-06-18 21:59:03 +04:00
|
|
|
clear_mutex_counters
|
2009-03-24 18:08:09 +03:00
|
|
|
sqlite3 db test.db -nomutex 0 -fullmutex 0
|
2008-06-18 21:59:03 +04:00
|
|
|
catchsql { CREATE TABLE abc(a, b, c) }
|
|
|
|
db eval {
|
|
|
|
INSERT INTO abc VALUES(1, 2, 3);
|
2008-06-18 21:09:10 +04:00
|
|
|
}
|
2008-06-18 21:59:03 +04:00
|
|
|
} {}
|
2011-01-18 19:13:27 +03:00
|
|
|
ifcapable !memorymanage {
|
|
|
|
regsub { static_lru} $mutexes {} mutexes
|
|
|
|
}
|
2015-07-04 02:11:36 +03:00
|
|
|
if {$mode ne "singlethread"} {
|
|
|
|
do_test mutex1.2.$mode.3 {
|
|
|
|
#
|
|
|
|
# NOTE: Make sure all the app and vfs mutexes get used.
|
|
|
|
#
|
|
|
|
enter_static_mutex static_app1
|
|
|
|
leave_static_mutex static_app1
|
|
|
|
enter_static_mutex static_app2
|
|
|
|
leave_static_mutex static_app2
|
|
|
|
enter_static_mutex static_app3
|
|
|
|
leave_static_mutex static_app3
|
|
|
|
enter_static_mutex static_vfs1
|
|
|
|
leave_static_mutex static_vfs1
|
|
|
|
enter_static_mutex static_vfs2
|
|
|
|
leave_static_mutex static_vfs2
|
|
|
|
enter_static_mutex static_vfs3
|
|
|
|
leave_static_mutex static_vfs3
|
|
|
|
} {}
|
|
|
|
}
|
|
|
|
do_test mutex1.2.$mode.4 {
|
2008-06-18 21:59:03 +04:00
|
|
|
mutex_counters counters
|
2015-07-04 02:11:36 +03:00
|
|
|
|
2008-06-18 21:59:03 +04:00
|
|
|
set res [list]
|
|
|
|
foreach {key value} [array get counters] {
|
|
|
|
if {$key ne "total" && $value > 0} {
|
|
|
|
lappend res $key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lsort $res
|
2008-07-08 06:12:37 +04:00
|
|
|
} [lsort $mutexes]
|
2008-06-18 21:59:03 +04:00
|
|
|
}
|
2009-04-23 18:58:39 +04:00
|
|
|
sqlite3_enable_shared_cache $enable_shared_cache
|
2008-06-18 13:45:56 +04:00
|
|
|
|
2009-04-23 18:58:39 +04:00
|
|
|
# Open and use a connection in "nomutex" mode. Test that no recursive
|
|
|
|
# mutexes are obtained.
|
2008-07-15 04:27:34 +04:00
|
|
|
do_test mutex1.3.1 {
|
|
|
|
catch {db close}
|
|
|
|
clear_mutex_counters
|
|
|
|
sqlite3 db test.db -nomutex 1
|
|
|
|
execsql { SELECT * FROM abc }
|
|
|
|
} {1 2 3 1 2 3 1 2 3}
|
|
|
|
do_test mutex1.3.2 {
|
|
|
|
mutex_counters counters
|
|
|
|
set counters(recursive)
|
|
|
|
} {0}
|
|
|
|
}
|
2008-07-10 21:52:49 +04:00
|
|
|
|
2008-11-04 17:55:47 +03:00
|
|
|
# Test the sqlite3_db_mutex() function.
|
|
|
|
#
|
|
|
|
do_test mutex1.4.1 {
|
|
|
|
catch {db close}
|
|
|
|
sqlite3 db test.db
|
|
|
|
enter_db_mutex db
|
|
|
|
db eval {SELECT 1, 2, 3}
|
|
|
|
} {1 2 3}
|
|
|
|
do_test mutex1.4.2 {
|
|
|
|
leave_db_mutex db
|
|
|
|
db eval {SELECT 1, 2, 3}
|
|
|
|
} {1 2 3}
|
|
|
|
do_test mutex1.4.3 {
|
|
|
|
catch {db close}
|
|
|
|
sqlite3 db test.db -nomutex 1
|
|
|
|
enter_db_mutex db
|
|
|
|
db eval {SELECT 1, 2, 3}
|
|
|
|
} {1 2 3}
|
|
|
|
do_test mutex1.4.4 {
|
|
|
|
leave_db_mutex db
|
|
|
|
db eval {SELECT 1, 2, 3}
|
|
|
|
} {1 2 3}
|
|
|
|
|
2008-06-18 13:45:56 +04:00
|
|
|
do_test mutex1-X {
|
2008-06-18 21:59:03 +04:00
|
|
|
catch {db close}
|
2008-06-18 13:45:56 +04:00
|
|
|
sqlite3_shutdown
|
|
|
|
clear_mutex_counters
|
|
|
|
install_mutex_counters 0
|
2008-06-18 21:59:03 +04:00
|
|
|
sqlite3_initialize
|
2008-06-18 13:45:56 +04:00
|
|
|
} {SQLITE_OK}
|
|
|
|
|
2008-06-19 21:54:33 +04:00
|
|
|
autoinstall_test_functions
|
2008-06-18 13:45:56 +04:00
|
|
|
finish_test
|