danielk1977 | 49e439d | 2007-09-10 07:35:47 +0000 | [diff] [blame^] | 1 | # 2007 September 10 |
| 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: thread_common.tcl,v 1.1 2007/09/10 07:35:47 danielk1977 Exp $ |
| 13 | |
| 14 | set testdir [file dirname $argv0] |
| 15 | source $testdir/tester.tcl |
| 16 | |
| 17 | if {[info commands sqlthread] eq ""} { |
| 18 | puts -nonewline "Skipping thread-safety tests - " |
| 19 | puts " not running a threadsafe sqlite/tcl build" |
| 20 | puts -nonewline "Both SQLITE_THREADSAFE and TCL_THREADS must be defined when" |
| 21 | puts " building testfixture" |
| 22 | finish_test |
| 23 | return |
| 24 | } |
| 25 | |
| 26 | set ::NTHREAD 10 |
| 27 | |
| 28 | # The following script is sourced by every thread spawned using |
| 29 | # [sqlthread spawn]: |
| 30 | set thread_procs { |
| 31 | |
| 32 | # Execute the supplied SQL using database handle $::DB. |
| 33 | # |
| 34 | proc execsql {sql} { |
| 35 | |
| 36 | set rc SQLITE_LOCKED |
| 37 | while {$rc eq "SQLITE_LOCKED"} { |
| 38 | set res [list] |
| 39 | set ::STMT [sqlite3_prepare $::DB $sql -1 dummy_tail] |
| 40 | while {[set rc [sqlite3_step $::STMT]] eq "SQLITE_ROW"} { |
| 41 | for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} { |
| 42 | lappend res [sqlite3_column_text $::STMT 0] |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | set rc [sqlite3_finalize $::STMT] |
| 47 | if {$rc eq "SQLITE_LOCKED"} { |
| 48 | after 20 |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | if {$rc ne "SQLITE_OK"} { |
| 53 | error "$rc - [sqlite3_errmsg $::DB]" |
| 54 | } |
| 55 | set res |
| 56 | } |
| 57 | |
| 58 | proc do_test {name script result} { |
| 59 | set res [eval $script] |
| 60 | if {$res ne $result} { |
| 61 | error "$name failed: expected \"$result\" got \"$res\"" |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | proc thread_spawn {varname args} { |
| 67 | sqlthread spawn $varname [join $args ;] |
| 68 | } |
| 69 | |
| 70 | return 0 |