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 #***********************************************************************
12 # Unit testing of the Bitvec object.
14 # $Id: bitvec.test,v 1.4 2009/04/01 23:49:04 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # The built-in test logic must be operational in order for
22 ifcapable !builtin_test {
27 # Test that sqlite3BitvecBuiltinTest correctly reports errors
28 # that are deliberately introduced.
30 do_test bitvec-1.0.1 {
31 sqlite3BitvecBuiltinTest 400 {5 1 1 1 0}
33 do_test bitvec-1.0.2 {
34 sqlite3BitvecBuiltinTest 400 {5 1 234 1 0}
37 # Run test cases that set every bit in vectors of various sizes.
38 # for larger cases, this should cycle the bit vector representation
39 # from hashing into subbitmaps. The subbitmaps should start as
40 # hashes then change to either subbitmaps or linear maps, depending
44 sqlite3BitvecBuiltinTest 400 {1 400 1 1 0}
47 sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 0}
50 sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 0}
53 sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 0}
56 # By specifying a larger increments, we spread the load around.
59 sqlite3BitvecBuiltinTest 400 {1 400 1 7 0}
62 sqlite3BitvecBuiltinTest 4000 {1 4000 1 7 0}
65 sqlite3BitvecBuiltinTest 40000 {1 40000 1 7 0}
68 sqlite3BitvecBuiltinTest 400000 {1 400000 1 7 0}
71 # First fill up the bitmap with ones, then go through and
72 # clear all the bits. This will stress the clearing mechanism.
75 sqlite3BitvecBuiltinTest 400 {1 400 1 1 2 400 1 1 0}
78 sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 2 4000 1 1 0}
81 sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 2 40000 1 1 0}
84 sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 2 400000 1 1 0}
88 sqlite3BitvecBuiltinTest 400 {1 400 1 1 2 400 1 7 0}
91 sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 2 4000 1 7 0}
94 sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 2 40000 1 77 0}
97 sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 2 400000 1 777 0}
100 do_test bitvec-1.18 {
101 sqlite3BitvecBuiltinTest 400000 {1 5000 100000 1 2 400000 1 37 0}
104 # Attempt to induce hash collisions.
106 unset -nocomplain start
107 unset -nocomplain incr
108 foreach start {1 2 3 4 5 6 7 8} {
109 foreach incr {124 125} {
110 do_test bitvec-1.20.$start.$incr {
111 set prog [list 1 60 $::start $::incr 2 5000 1 1 0]
112 sqlite3BitvecBuiltinTest 5000 $prog
117 do_test bitvec-1.30.big_and_slow {
118 sqlite3BitvecBuiltinTest 17000000 {1 17000000 1 1 2 17000000 1 1 0}
122 # Test setting and clearing a random subset of bits.
125 sqlite3BitvecBuiltinTest 4000 {3 2000 4 2000 0}
128 sqlite3BitvecBuiltinTest 4000 {3 1000 4 1000 3 1000 4 1000 3 1000 4 1000
129 3 1000 4 1000 3 1000 4 1000 3 1000 4 1000 0}
132 sqlite3BitvecBuiltinTest 400000 {3 10 0}
135 sqlite3BitvecBuiltinTest 4000 {3 10 2 4000 1 1 0}
138 sqlite3BitvecBuiltinTest 5000 {3 20 2 5000 1 1 0}
141 sqlite3BitvecBuiltinTest 50000 {3 60 2 50000 1 1 0}
144 sqlite3BitvecBuiltinTest 5000 {
152 # This procedure runs sqlite3BitvecBuiltinTest with argments "n" and
153 # "program". But it also causes a malloc error to occur after the
154 # "failcnt"-th malloc. The result should be "0" if no malloc failure
155 # occurs or "-1" if there is a malloc failure.
157 proc bitvec_malloc_test {label failcnt n program} {
158 do_test $label [subst {
159 sqlite3_memdebug_fail $failcnt
160 set x \[sqlite3BitvecBuiltinTest $n [list $program]\]
161 set nFail \[sqlite3_memdebug_fail -1\]
170 # Make sure malloc failures are handled sanily.
176 for {set n 0} {$go} {incr n} {
178 bitvec_malloc_test bitvec-3.1.$n $n 5000 {
179 3 60 2 5000 1 1 3 60 2 5000 1 1 3 60 2 5000 1 1 0
183 for {set n 0} {$go} {incr n} {
185 bitvec_malloc_test bitvec-3.2.$n $n 5000 {
186 3 600 2 5000 1 1 3 600 2 5000 1 1 3 600 2 5000 1 1 0
190 for {set n 1} {$go} {incr n} {
191 bitvec_malloc_test bitvec-3.3.$n $n 50000 {1 50000 1 1 0}