3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests the ability of the library to open
14 # many different databases at the same time without leaking memory.
16 # $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
22 # if we're using proxy locks, we use 5 filedescriptors for a db
23 # that is open and in the middle of writing changes, normally
24 # sqlite uses 3 (proxy locking adds the conch and the local lock)
26 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
29 set num_fd_per_openwrite_db 3
31 set num_fd_per_openwrite_db 5
34 # First test how many file descriptors are available for use. To open a
35 # database for writing SQLite requires 3 file descriptors (the database, the
36 # journal and the directory).
39 for {set i 0} {$i<($N * 3)} {incr i} {
40 lappend filehandles [open testfile.1 w]
43 foreach fd $filehandles {
47 forcedelete testfile.1
49 set N [expr $i / $num_fd_per_openwrite_db]
51 # Create a bunch of random database names
53 unset -nocomplain dbname
54 unset -nocomplain used
55 for {set i 0} {$i<$N} {incr i} {
57 set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db
58 if {[info exists used($name)]} continue
65 # Create a bunch of databases
67 for {set i 0} {$i<$N} {incr i} {
69 sqlite3 db$i $dbname($i)
73 INSERT INTO t1 VALUES(1,2);
78 # Finish the transactions
80 for {set i 0} {$i<$N} {incr i} {
90 # Close the databases and erase the files.
92 for {set i 0} {$i<$N} {incr i} {
95 forcedelete $dbname($i)