os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/bitvec.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2008 February 18
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
#
sl@0
    12
# Unit testing of the Bitvec object.
sl@0
    13
#
sl@0
    14
# $Id: bitvec.test,v 1.2 2008/03/21 16:45:48 drh Exp $
sl@0
    15
#
sl@0
    16
sl@0
    17
set testdir [file dirname $argv0]
sl@0
    18
source $testdir/tester.tcl
sl@0
    19
sl@0
    20
# The built-in test logic must be operational in order for
sl@0
    21
# this test to work.
sl@0
    22
ifcapable !builtin_test {
sl@0
    23
  finish_test
sl@0
    24
  return
sl@0
    25
}
sl@0
    26
sl@0
    27
# Test that sqlite3BitvecBuiltinTest correctly reports errors
sl@0
    28
# that are deliberately introduced.
sl@0
    29
#
sl@0
    30
do_test bitvec-1.0.1 {
sl@0
    31
  sqlite3BitvecBuiltinTest 400 {5 1 1 1 0}
sl@0
    32
} 1
sl@0
    33
do_test bitvec-1.0.2 {
sl@0
    34
  sqlite3BitvecBuiltinTest 400 {5 1 234 1 0}
sl@0
    35
} 234
sl@0
    36
sl@0
    37
# Run test cases that set every bit in vectors of various sizes.
sl@0
    38
# for larger cases, this should cycle the bit vector representation
sl@0
    39
# from hashing into subbitmaps.  The subbitmaps should start as
sl@0
    40
# hashes then change to either subbitmaps or linear maps, depending
sl@0
    41
# on their size.
sl@0
    42
#
sl@0
    43
do_test bitvec-1.1 {
sl@0
    44
  sqlite3BitvecBuiltinTest 400 {1 400 1 1 0}
sl@0
    45
} 0
sl@0
    46
do_test bitvec-1.2 {
sl@0
    47
  sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 0}
sl@0
    48
} 0
sl@0
    49
do_test bitvec-1.3 {
sl@0
    50
  sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 0}
sl@0
    51
} 0
sl@0
    52
do_test bitvec-1.4 {
sl@0
    53
  sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 0}
sl@0
    54
} 0
sl@0
    55
sl@0
    56
# By specifying a larger increments, we spread the load around.
sl@0
    57
#
sl@0
    58
do_test bitvec-1.5 {
sl@0
    59
  sqlite3BitvecBuiltinTest 400 {1 400 1 7 0}
sl@0
    60
} 0
sl@0
    61
do_test bitvec-1.6 {
sl@0
    62
  sqlite3BitvecBuiltinTest 4000 {1 4000 1 7 0}
sl@0
    63
} 0
sl@0
    64
do_test bitvec-1.7 {
sl@0
    65
  sqlite3BitvecBuiltinTest 40000 {1 40000 1 7 0}
sl@0
    66
} 0
sl@0
    67
do_test bitvec-1.8 {
sl@0
    68
  sqlite3BitvecBuiltinTest 400000 {1 400000 1 7 0}
sl@0
    69
} 0
sl@0
    70
sl@0
    71
# First fill up the bitmap with ones,  then go through and
sl@0
    72
# clear all the bits.  This will stress the clearing mechanism.
sl@0
    73
#
sl@0
    74
do_test bitvec-1.9 {
sl@0
    75
  sqlite3BitvecBuiltinTest 400 {1 400 1 1 2 400 1 1 0}
sl@0
    76
} 0
sl@0
    77
do_test bitvec-1.10 {
sl@0
    78
  sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 2 4000 1 1 0}
sl@0
    79
} 0
sl@0
    80
do_test bitvec-1.11 {
sl@0
    81
  sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 2 40000 1 1 0}
sl@0
    82
} 0
sl@0
    83
do_test bitvec-1.12 {
sl@0
    84
  sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 2 400000 1 1 0}
sl@0
    85
} 0
sl@0
    86
sl@0
    87
do_test bitvec-1.13 {
sl@0
    88
  sqlite3BitvecBuiltinTest 400 {1 400 1 1 2 400 1 7 0}
sl@0
    89
} 0
sl@0
    90
do_test bitvec-1.15 {
sl@0
    91
  sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 2 4000 1 7 0}
sl@0
    92
} 0
sl@0
    93
do_test bitvec-1.16 {
sl@0
    94
  sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 2 40000 1 77 0}
sl@0
    95
} 0
sl@0
    96
do_test bitvec-1.17 {
sl@0
    97
  sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 2 400000 1 777 0}
sl@0
    98
} 0
sl@0
    99
sl@0
   100
do_test bitvec-1.18 {
sl@0
   101
  sqlite3BitvecBuiltinTest 400000 {1 5000 100000 1 2 400000 1 37 0}
sl@0
   102
} 0
sl@0
   103
sl@0
   104
# Attempt to induce hash collisions.  
sl@0
   105
#
sl@0
   106
unset -nocomplain start
sl@0
   107
unset -nocomplain incr
sl@0
   108
foreach start {1 2 3 4 5 6 7 8} {
sl@0
   109
  foreach incr {124 125} {
sl@0
   110
    do_test bitvec-1.20.$start.$incr {
sl@0
   111
      set prog [list 1 60 $::start $::incr 2 5000 1 1 0]
sl@0
   112
      sqlite3BitvecBuiltinTest 5000 $prog
sl@0
   113
    } 0
sl@0
   114
  }
sl@0
   115
}
sl@0
   116
sl@0
   117
do_test bitvec-1.30.big_and_slow {
sl@0
   118
  sqlite3BitvecBuiltinTest 17000000 {1 17000000 1 1 2 17000000 1 1 0}
sl@0
   119
} 0
sl@0
   120
sl@0
   121
sl@0
   122
# Test setting and clearing a random subset of bits.
sl@0
   123
#
sl@0
   124
do_test bitvec-2.1 {
sl@0
   125
  sqlite3BitvecBuiltinTest 4000 {3 2000 4 2000 0}
sl@0
   126
} 0
sl@0
   127
do_test bitvec-2.2 {
sl@0
   128
  sqlite3BitvecBuiltinTest 4000 {3 1000 4 1000 3 1000 4 1000 3 1000 4 1000
sl@0
   129
                                 3 1000 4 1000 3 1000 4 1000 3 1000 4 1000 0}
sl@0
   130
} 0
sl@0
   131
do_test bitvec-2.3 {
sl@0
   132
  sqlite3BitvecBuiltinTest 400000 {3 10 0}
sl@0
   133
} 0
sl@0
   134
do_test bitvec-2.4 {
sl@0
   135
  sqlite3BitvecBuiltinTest 4000 {3 10 2 4000 1 1 0}
sl@0
   136
} 0
sl@0
   137
do_test bitvec-2.5 {
sl@0
   138
  sqlite3BitvecBuiltinTest 5000 {3 20 2 5000 1 1 0}
sl@0
   139
} 0
sl@0
   140
do_test bitvec-2.6 {
sl@0
   141
  sqlite3BitvecBuiltinTest 50000 {3 60 2 50000 1 1 0}
sl@0
   142
} 0
sl@0
   143
sl@0
   144
# This procedure runs sqlite3BitvecBuiltinTest with argments "n" and
sl@0
   145
# "program".  But it also causes a malloc error to occur after the
sl@0
   146
# "failcnt"-th malloc.  The result should be "0" if no malloc failure
sl@0
   147
# occurs or "-1" if there is a malloc failure.
sl@0
   148
#
sl@0
   149
proc bitvec_malloc_test {label failcnt n program} {
sl@0
   150
  do_test $label [subst {
sl@0
   151
    sqlite3_memdebug_fail $failcnt
sl@0
   152
    set x \[sqlite3BitvecBuiltinTest $n [list $program]\]
sl@0
   153
    set nFail \[sqlite3_memdebug_fail -1\]
sl@0
   154
    if {\$nFail==0} {
sl@0
   155
      set ::go 0
sl@0
   156
      set x -1
sl@0
   157
    }
sl@0
   158
    set x
sl@0
   159
  }] -1
sl@0
   160
}
sl@0
   161
sl@0
   162
# Make sure malloc failures are handled sanily.
sl@0
   163
#
sl@0
   164
unset -nocomplain n
sl@0
   165
unset -nocomplain go
sl@0
   166
set go 1
sl@0
   167
save_prng_state
sl@0
   168
for {set n 0} {$go} {incr n} {
sl@0
   169
  restore_prng_state
sl@0
   170
  bitvec_malloc_test bitvec-3.1.$n $n 5000 {
sl@0
   171
      3 60 2 5000 1 1 3 60 2 5000 1 1 3 60 2 5000 1 1 0
sl@0
   172
  }
sl@0
   173
}
sl@0
   174
set go 1
sl@0
   175
for {set n 0} {$go} {incr n} {
sl@0
   176
  restore_prng_state
sl@0
   177
  bitvec_malloc_test bitvec-3.2.$n $n 5000 {
sl@0
   178
      3 600 2 5000 1 1 3 600 2 5000 1 1 3 600 2 5000 1 1 0
sl@0
   179
  }
sl@0
   180
}
sl@0
   181
set go 1
sl@0
   182
for {set n 1} {$go} {incr n} {
sl@0
   183
  bitvec_malloc_test bitvec-3.3.$n $n 50000 {1 50000 1 1 0}
sl@0
   184
}
sl@0
   185
sl@0
   186
finish_test
sl@0
   187
return
sl@0
   188
sl@0
   189
sl@0
   190
sl@0
   191
finish_test