1# 2006 January 14 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# This file implements regression tests for SQLite library. The 12# focus of this script is multithreading behavior 13# 14# $Id: thread2.test,v 1.3 2008/10/07 15:25:49 drh Exp $ 15 16 17set testdir [file dirname $argv0] 18source $testdir/tester.tcl 19 20ifcapable !mutex { 21 finish_test 22 return 23} 24 25 26# Skip this whole file if the thread testing code is not enabled 27# 28if {[llength [info command thread_step]]==0 || [sqlite3 -has-codec]} { 29 finish_test 30 return 31} 32 33# Create some data to work with 34# 35do_test thread1-1.1 { 36 execsql { 37 CREATE TABLE t1(a,b); 38 INSERT INTO t1 VALUES(1,'abcdefgh'); 39 INSERT INTO t1 SELECT a+1, b||b FROM t1; 40 INSERT INTO t1 SELECT a+2, b||b FROM t1; 41 INSERT INTO t1 SELECT a+4, b||b FROM t1; 42 SELECT count(*), max(length(b)) FROM t1; 43 } 44} {8 64} 45 46# Use the thread_swap command to move the database connections between 47# threads, then verify that they still work. 48# 49do_test thread2-1.2 { 50 db close 51 thread_create A test.db 52 thread_create B test.db 53 thread_swap A B 54 thread_compile A {SELECT a FROM t1 LIMIT 1} 55 thread_result A 56} {SQLITE_OK} 57do_test thread2-1.3 { 58 thread_step A 59 thread_result A 60} {SQLITE_ROW} 61do_test thread2-1.4 { 62 thread_argv A 0 63} {1} 64do_test thread2-1.5 { 65 thread_finalize A 66 thread_result A 67} {SQLITE_OK} 68do_test thread2-1.6 { 69 thread_compile B {SELECT a FROM t1 LIMIT 1} 70 thread_result B 71} {SQLITE_OK} 72do_test thread2-1.7 { 73 thread_step B 74 thread_result B 75} {SQLITE_ROW} 76do_test thread2-1.8 { 77 thread_argv B 0 78} {1} 79do_test thread2-1.9 { 80 thread_finalize B 81 thread_result B 82} {SQLITE_OK} 83 84# Swap them again. 85# 86do_test thread2-2.2 { 87 thread_swap A B 88 thread_compile A {SELECT a FROM t1 LIMIT 1} 89 thread_result A 90} {SQLITE_OK} 91do_test thread2-2.3 { 92 thread_step A 93 thread_result A 94} {SQLITE_ROW} 95do_test thread2-2.4 { 96 thread_argv A 0 97} {1} 98do_test thread2-2.5 { 99 thread_finalize A 100 thread_result A 101} {SQLITE_OK} 102do_test thread2-2.6 { 103 thread_compile B {SELECT a FROM t1 LIMIT 1} 104 thread_result B 105} {SQLITE_OK} 106do_test thread2-2.7 { 107 thread_step B 108 thread_result B 109} {SQLITE_ROW} 110do_test thread2-2.8 { 111 thread_argv B 0 112} {1} 113do_test thread2-2.9 { 114 thread_finalize B 115 thread_result B 116} {SQLITE_OK} 117thread_halt A 118thread_halt B 119 120# Also important to halt the worker threads, which are using spin 121# locks and eating away CPU cycles. 122# 123thread_halt * 124finish_test 125