~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to third_party/sqlite_google/test/mutex1.test

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# 2008 June 17
 
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
# $Id: mutex1.test,v 1.10 2008/07/15 00:27:35 drh Exp $
 
13
 
 
14
set testdir [file dirname $argv0]
 
15
source $testdir/tester.tcl
 
16
 
 
17
if {[info exists tester_do_binarylog]} {
 
18
  finish_test
 
19
  return
 
20
}
 
21
 
 
22
sqlite3_reset_auto_extension
 
23
 
 
24
proc mutex_counters {varname} {
 
25
  upvar $varname var
 
26
  set var(total) 0
 
27
  foreach {name value} [read_mutex_counters] {
 
28
    set var($name) $value
 
29
    incr var(total) $value
 
30
  }
 
31
}
 
32
 
 
33
#-------------------------------------------------------------------------
 
34
# Tests mutex1-1.* test that sqlite3_config() returns SQLITE_MISUSE if
 
35
# is called at the wrong time. And that the first time sqlite3_initialize 
 
36
# is called it obtains the 'static_master' mutex 3 times and a recursive
 
37
# mutex (sqlite3Config.pInitMutex) twice. Subsequent calls are no-ops 
 
38
# that do not require any mutexes.
 
39
#
 
40
do_test mutex1-1.0 {
 
41
  install_mutex_counters 1
 
42
} {SQLITE_MISUSE}
 
43
 
 
44
do_test mutex1-1.1 {
 
45
  db close
 
46
  install_mutex_counters 1
 
47
} {SQLITE_MISUSE}
 
48
 
 
49
do_test mutex1-1.2 {
 
50
  sqlite3_shutdown
 
51
  install_mutex_counters 1
 
52
} {SQLITE_OK}
 
53
 
 
54
do_test mutex1-1.3 {
 
55
  install_mutex_counters 0
 
56
} {SQLITE_OK}
 
57
 
 
58
do_test mutex1-1.4 {
 
59
  install_mutex_counters 1
 
60
} {SQLITE_OK}
 
61
 
 
62
do_test mutex1-1.5 {
 
63
  mutex_counters counters
 
64
  set counters(total)
 
65
} {0}
 
66
 
 
67
do_test mutex1-1.6 {
 
68
  sqlite3_initialize
 
69
} {SQLITE_OK}
 
70
 
 
71
do_test mutex1-1.7 {
 
72
  mutex_counters counters
 
73
  # list $counters(total) $counters(static_master)
 
74
  expr {$counters(total)>0}
 
75
} {1}
 
76
 
 
77
do_test mutex1-1.8 {
 
78
  clear_mutex_counters
 
79
  sqlite3_initialize
 
80
} {SQLITE_OK}
 
81
 
 
82
do_test mutex1-1.9 {
 
83
  mutex_counters counters
 
84
  list $counters(total) $counters(static_master)
 
85
} {0 0}
 
86
 
 
87
#-------------------------------------------------------------------------
 
88
# Tests mutex1-2.* test the three thread-safety related modes that
 
89
# can be selected using sqlite3_config:
 
90
#
 
91
#   * Serialized mode,
 
92
#   * Multi-threaded mode,
 
93
#   * Single-threaded mode.
 
94
#
 
95
set enable_shared_cache [sqlite3_enable_shared_cache 1]
 
96
ifcapable threadsafe {
 
97
  foreach {mode mutexes} {
 
98
    singlethread {}
 
99
    multithread  {fast static_master static_mem static_prng}
 
100
    serialized   {fast recursive static_master static_mem static_prng}
 
101
  } {
 
102
    ifcapable memorymanage {
 
103
      if {$mode ne "singlethread"} {
 
104
        lappend mutexes static_lru static_lru2 static_mem2
 
105
      }
 
106
    }
 
107
 
 
108
    do_test mutex1.2.$mode.1 {
 
109
      catch {db close}
 
110
      sqlite3_shutdown
 
111
      sqlite3_config $mode
 
112
    } SQLITE_OK
 
113
 
 
114
    do_test mutex1.2.$mode.2 {
 
115
      sqlite3_initialize
 
116
      clear_mutex_counters
 
117
      sqlite3 db test.db
 
118
      catchsql { CREATE TABLE abc(a, b, c) }
 
119
      db eval {
 
120
        INSERT INTO abc VALUES(1, 2, 3);
 
121
      }
 
122
    } {}
 
123
  
 
124
    do_test mutex1.2.$mode.3 {
 
125
      mutex_counters counters
 
126
  
 
127
      set res [list]
 
128
      foreach {key value} [array get counters] {
 
129
        if {$key ne "total" && $value > 0} {
 
130
          lappend res $key
 
131
        }
 
132
      }
 
133
      lsort $res
 
134
    } [lsort $mutexes]
 
135
  }
 
136
}
 
137
sqlite3_enable_shared_cache $enable_shared_cache
 
138
 
 
139
# Open and use a connection in "nomutex" mode. Test that no recursive
 
140
# mutexes are obtained.
 
141
ifcapable threadsafe {
 
142
  do_test mutex1.3.1 {
 
143
    catch {db close}
 
144
    clear_mutex_counters
 
145
    sqlite3 db test.db -nomutex 1
 
146
    execsql { SELECT * FROM abc }
 
147
  } {1 2 3 1 2 3 1 2 3}
 
148
  do_test mutex1.3.2 {
 
149
    mutex_counters counters
 
150
    set counters(recursive)
 
151
  } {0}
 
152
}
 
153
 
 
154
do_test mutex1-X {
 
155
  catch {db close}
 
156
  sqlite3_shutdown
 
157
  clear_mutex_counters
 
158
  install_mutex_counters 0
 
159
  sqlite3_initialize
 
160
} {SQLITE_OK}
 
161
 
 
162
autoinstall_test_functions
 
163
finish_test