diff options
author | dan miller | 2007-10-20 02:49:29 +0000 |
---|---|---|
committer | dan miller | 2007-10-20 02:49:29 +0000 |
commit | e36d23a85ebff914d74bb541558c2b6082b78edb (patch) | |
tree | 54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/test/mallocC.test | |
parent | * Fixed an issue whereby avatar chat distances were being calculated against ... (diff) | |
download | opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2 opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz |
sqlite source (unix build) added to libraries
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/mallocC.test')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/test/mallocC.test | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/mallocC.test b/libraries/sqlite/unix/sqlite-3.5.1/test/mallocC.test new file mode 100644 index 0000000..54e4c5f --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/test/mallocC.test | |||
@@ -0,0 +1,134 @@ | |||
1 | # 2007 Aug 13 | ||
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 | # This file tests aspects of the malloc failure while parsing | ||
13 | # CREATE TABLE statements in auto_vacuum mode. | ||
14 | # | ||
15 | # $Id: mallocC.test,v 1.7 2007/10/03 08:46:45 danielk1977 Exp $ | ||
16 | |||
17 | set testdir [file dirname $argv0] | ||
18 | source $testdir/tester.tcl | ||
19 | |||
20 | # Only run these tests if memory debugging is turned on. | ||
21 | # | ||
22 | ifcapable !memdebug||!compound { | ||
23 | puts "Skipping mallocC tests: not compiled with -DSQLITE_MEMDEBUG..." | ||
24 | finish_test | ||
25 | return | ||
26 | } | ||
27 | |||
28 | # Generate a checksum based on the contents of the database. If the | ||
29 | # checksum of two databases is the same, and the integrity-check passes | ||
30 | # for both, the two databases are identical. | ||
31 | # | ||
32 | proc cksum {db} { | ||
33 | set ret [list] | ||
34 | ifcapable tempdb { | ||
35 | set sql { | ||
36 | SELECT name FROM sqlite_master WHERE type = 'table' UNION | ||
37 | SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION | ||
38 | SELECT 'sqlite_master' UNION | ||
39 | SELECT 'sqlite_temp_master' | ||
40 | } | ||
41 | } else { | ||
42 | set sql { | ||
43 | SELECT name FROM sqlite_master WHERE type = 'table' UNION | ||
44 | SELECT 'sqlite_master' | ||
45 | } | ||
46 | } | ||
47 | set tbllist [$db eval $sql] | ||
48 | set txt {} | ||
49 | foreach tbl $tbllist { | ||
50 | append txt [$db eval "SELECT * FROM $tbl"] | ||
51 | } | ||
52 | # puts txt=$txt | ||
53 | return [md5 $txt] | ||
54 | } | ||
55 | |||
56 | proc do_mallocC_test {tn args} { | ||
57 | array set ::mallocopts $args | ||
58 | set sum [cksum db] | ||
59 | |||
60 | for {set ::n 1} {true} {incr ::n} { | ||
61 | |||
62 | # Run the SQL. Malloc number $::n is set to fail. A malloc() failure | ||
63 | # may or may not be reported. | ||
64 | sqlite3_memdebug_fail $::n -repeat 1 | ||
65 | do_test mallocC-$tn.$::n.1 { | ||
66 | set res [catchsql [string trim $::mallocopts(-sql)]] | ||
67 | set rc [expr { | ||
68 | 0==[string compare $res {1 {out of memory}}] || | ||
69 | [db errorcode] == 3082 || | ||
70 | 0==[lindex $res 0] | ||
71 | }] | ||
72 | if {$rc!=1} { | ||
73 | puts "Error: $res" | ||
74 | } | ||
75 | set rc | ||
76 | } {1} | ||
77 | |||
78 | # If $::n is greater than the number of malloc() calls required to | ||
79 | # execute the SQL, then this test is finished. Break out of the loop. | ||
80 | set nFail [sqlite3_memdebug_fail -1] | ||
81 | if {$nFail==0} { | ||
82 | break | ||
83 | } | ||
84 | |||
85 | # Recover from the malloc failure. | ||
86 | # | ||
87 | # Update: The new malloc() failure handling means that a transaction may | ||
88 | # still be active even if a malloc() has failed. But when these tests were | ||
89 | # written this was not the case. So do a manual ROLLBACK here so that the | ||
90 | # tests pass. | ||
91 | do_test mallocC-$tn.$::n.2 { | ||
92 | catch { | ||
93 | execsql { | ||
94 | ROLLBACK; | ||
95 | } | ||
96 | } | ||
97 | expr 0 | ||
98 | } {0} | ||
99 | |||
100 | # Checksum the database. | ||
101 | #do_test mallocC-$tn.$::n.3 { | ||
102 | # cksum db | ||
103 | #} $sum | ||
104 | |||
105 | #integrity_check mallocC-$tn.$::n.4 | ||
106 | if {$::nErr>1} return | ||
107 | } | ||
108 | unset ::mallocopts | ||
109 | } | ||
110 | |||
111 | sqlite3_extended_result_codes db 1 | ||
112 | |||
113 | execsql { | ||
114 | PRAGMA auto_vacuum=1; | ||
115 | CREATE TABLE t0(a, b, c); | ||
116 | } | ||
117 | do_mallocC_test 1 -sql { | ||
118 | BEGIN; | ||
119 | -- Allocate 32 new root pages. This will exercise the 'extract specific | ||
120 | -- page from the freelist' code when in auto-vacuum mode (see the | ||
121 | -- allocatePage() routine in btree.c). | ||
122 | CREATE TABLE t1(a UNIQUE, b UNIQUE, c UNIQUE); | ||
123 | CREATE TABLE t2(a UNIQUE, b UNIQUE, c UNIQUE); | ||
124 | CREATE TABLE t3(a UNIQUE, b UNIQUE, c UNIQUE); | ||
125 | CREATE TABLE t4(a UNIQUE, b UNIQUE, c UNIQUE); | ||
126 | CREATE TABLE t5(a UNIQUE, b UNIQUE, c UNIQUE); | ||
127 | CREATE TABLE t6(a UNIQUE, b UNIQUE, c UNIQUE); | ||
128 | CREATE TABLE t7(a UNIQUE, b UNIQUE, c UNIQUE); | ||
129 | CREATE TABLE t8(a UNIQUE, b UNIQUE, c UNIQUE); | ||
130 | |||
131 | ROLLBACK; | ||
132 | } | ||
133 | |||
134 | finish_test | ||