1# 2001 September 15 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 runs all tests. 12# 13# $Id: all.test,v 1.30 2005/01/17 07:53:44 danielk1977 Exp $ 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17rename finish_test really_finish_test 18proc finish_test {} {memleak_check} 19 20if {[file exists ./sqlite_test_count]} { 21 set COUNT [exec cat ./sqlite_test_count] 22} else { 23 set COUNT 3 24} 25 26if {[llength $argv]>0} { 27 foreach {name value} $argv { 28 switch -- $name { 29 -count { 30 set COUNT $value 31 } 32 -quick { 33 set ISQUICK $value 34 } 35 default { 36 puts stderr "Unknown option: $name" 37 exit 38 } 39 } 40 } 41} 42set argv {} 43 44# LeakList will hold a list of the number of unfreed mallocs after 45# each round of the test. This number should be constant. If it 46# grows, it may mean there is a memory leak in the library. 47# 48set LeakList {} 49 50set EXCLUDE { 51 all.test 52 crash.test 53 autovacuum_crash.test 54 quick.test 55 malloc.test 56 misuse.test 57 memleak.test 58} 59 60# Test files btree2.test and btree4.test don't work if the 61# SQLITE_DEFAULT_AUTOVACUUM macro is defined to true (because they depend 62# on tables being allocated starting at page 2). 63# 64ifcapable default_autovacuum { 65 lappend EXCLUDE btree2.test 66 lappend EXCLUDE btree4.test 67} 68 69for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} { 70 if {$Counter%2} { 71 set ::SETUP_SQL {PRAGMA default_synchronous=off;} 72 } else { 73 catch {unset ::SETUP_SQL} 74 } 75 foreach testfile [lsort -dictionary [glob $testdir/*.test]] { 76 set tail [file tail $testfile] 77 if {[lsearch -exact $EXCLUDE $tail]>=0} continue 78 source $testfile 79 catch {db close} 80 if {$sqlite_open_file_count>0} { 81 puts "$tail did not close all files: $sqlite_open_file_count" 82 incr nErr 83 lappend ::failList $tail 84 } 85 } 86 if {[info exists Leak]} { 87 lappend LeakList $Leak 88 } 89} 90 91# Do one last test to look for a memory leak in the library. This will 92# only work if SQLite is compiled with the -DSQLITE_DEBUG=1 flag. 93# 94if {$LeakList!=""} { 95 puts -nonewline memory-leak-test... 96 incr ::nTest 97 foreach x $LeakList { 98 if {$x!=[lindex $LeakList 0]} { 99 puts " failed!" 100 puts "Expected: all values to be the same" 101 puts " Got: $LeakList" 102 incr ::nErr 103 lappend ::failList memory-leak-test 104 break 105 } 106 } 107 puts " Ok" 108} 109 110# Run the crashtest only on unix and only once. If the library does not 111# always create auto-vacuum databases, also run autovacuum_crash.test. 112# 113if {$::tcl_platform(platform)=="unix"} { 114 source $testdir/crash.test 115 ifcapable !default_autovacuum { 116 source $testdir/autovacuum_crash.test 117 } 118} 119 120# Run the malloc tests and the misuse test after memory leak detection. 121# Both tests leak memory. Currently, misuse.test also leaks a handful of 122# file descriptors. This is not considered a problem, but can cause tests 123# in malloc.test to fail. So set the open-file count to zero before running 124# malloc.test to get around this. 125# 126catch {source $testdir/misuse.test} 127set sqlite_open_file_count 0 128catch {source $testdir/malloc.test} 129 130catch {db close} 131set sqlite_open_file_count 0 132really_finish_test 133