blob: 9dfb03e0dea1b9dd6c2a294c46735b134d656000 [file] [log] [blame]
drhc8d75672008-07-08 02:12:37 +00001# 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#
drh18472fa2008-10-07 15:25:48 +000014# $Id: mutex2.test,v 1.9 2008/10/07 15:25:49 drh Exp $
drhc8d75672008-07-08 02:12:37 +000015
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
drh18472fa2008-10-07 15:25:48 +000018ifcapable !mutex {
19 finish_test
20 return
21}
drhc8d75672008-07-08 02:12:37 +000022
23# deinitialize
24#
25catch {db close}
26sqlite3_reset_auto_extension
27sqlite3_shutdown
28install_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#
33do_test mutex2-1.1 {
34 set ::disable_mutex_init 10
35 sqlite3_initialize
36} {SQLITE_IOERR}
37do_test mutex2-1.1 {
38 set ::disable_mutex_init 7
39 sqlite3_initialize
40} {SQLITE_NOMEM}
41
42proc 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#
51do_test mutex2-2.1 {
52 set ::disable_mutex_init 7
53 set rc [catch {sqlite db test.db} msg]
54 lappend rc $msg
drhff1590e2008-07-14 12:52:53 +000055} {1 {}}
drhc8d75672008-07-08 02:12:37 +000056ifcapable 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}
64do_test mutex2-2.4 {
65 sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3
drhff1590e2008-07-14 12:52:53 +000066} {}
drh7830cd42008-07-16 12:25:32 +000067ifcapable load_ext {
68 do_test mutex2-2.5 {
69 sqlite3_auto_extension_sqr
70 } {7}
71}
drhc8d75672008-07-08 02:12:37 +000072do_test mutex2-2.6 {
73 sqlite3_reset_auto_extension
74} {}
75do_test mutex2-2.7 {
76 sqlite3_malloc 10000
drh8278ce72008-07-11 13:53:54 +000077} {0}
drhc8d75672008-07-08 02:12:37 +000078do_test mutex2-2.8 {
79 sqlite3_realloc 0 10000
drh8278ce72008-07-11 13:53:54 +000080} {0}
danielk1977b27475b2008-07-19 13:43:23 +000081ifcapable threadsafe {
82 do_test mutex2-2.9 {
83 alloc_dealloc_mutex
84 } {0}
85}
drhc8d75672008-07-08 02:12:37 +000086do_test mutex2-2.10 {
87 vfs_initfail_test
88} {}
89
90# Restore the system to a functional state
91#
92install_mutex_counters 0
93set disable_mutex_init 0
94autoinstall_test_functions
drh8a42cbd2008-07-10 18:13:42 +000095
96# Mutex allocation works now.
97#
98
99do_test mutex2-3.1 {
100 set ptr [alloc_dealloc_mutex]
101 expr {$ptr!=0}
102} {1}
103
104
drhc8d75672008-07-08 02:12:37 +0000105finish_test