1*c5c4113dSnw141292 2*c5c4113dSnw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*c5c4113dSnw141292 4*c5c4113dSnw141292# 2001 September 15 5*c5c4113dSnw141292# 6*c5c4113dSnw141292# The author disclaims copyright to this source code. In place of 7*c5c4113dSnw141292# a legal notice, here is a blessing: 8*c5c4113dSnw141292# 9*c5c4113dSnw141292# May you do good and not evil. 10*c5c4113dSnw141292# May you find forgiveness for yourself and forgive others. 11*c5c4113dSnw141292# May you share freely, never taking more than you give. 12*c5c4113dSnw141292# 13*c5c4113dSnw141292#*********************************************************************** 14*c5c4113dSnw141292# This file runs all tests. 15*c5c4113dSnw141292# 16*c5c4113dSnw141292# $Id: memleak.test,v 1.3 2004/02/12 18:46:39 drh Exp $ 17*c5c4113dSnw141292 18*c5c4113dSnw141292set testdir [file dirname $argv0] 19*c5c4113dSnw141292source $testdir/tester.tcl 20*c5c4113dSnw141292rename finish_test really_finish_test 21*c5c4113dSnw141292proc finish_test {} { 22*c5c4113dSnw141292 catch {db close} 23*c5c4113dSnw141292 memleak_check 24*c5c4113dSnw141292} 25*c5c4113dSnw141292 26*c5c4113dSnw141292if {[file exists ./sqlite_test_count]} { 27*c5c4113dSnw141292 set COUNT [exec cat ./sqlite_test_count] 28*c5c4113dSnw141292} else { 29*c5c4113dSnw141292 set COUNT 3 30*c5c4113dSnw141292} 31*c5c4113dSnw141292 32*c5c4113dSnw141292# LeakList will hold a list of the number of unfreed mallocs after 33*c5c4113dSnw141292# each round of the test. This number should be constant. If it 34*c5c4113dSnw141292# grows, it may mean there is a memory leak in the library. 35*c5c4113dSnw141292# 36*c5c4113dSnw141292set LeakList {} 37*c5c4113dSnw141292 38*c5c4113dSnw141292set EXCLUDE { 39*c5c4113dSnw141292 all.test 40*c5c4113dSnw141292 quick.test 41*c5c4113dSnw141292 malloc.test 42*c5c4113dSnw141292 misuse.test 43*c5c4113dSnw141292 memleak.test 44*c5c4113dSnw141292 btree2.test 45*c5c4113dSnw141292 trans.test 46*c5c4113dSnw141292} 47*c5c4113dSnw141292if {[sqlite -has-codec]} { 48*c5c4113dSnw141292 lappend EXCLUDE \ 49*c5c4113dSnw141292 attach.test \ 50*c5c4113dSnw141292 attach2.test \ 51*c5c4113dSnw141292 auth.test \ 52*c5c4113dSnw141292 format3.test \ 53*c5c4113dSnw141292 version.test 54*c5c4113dSnw141292} 55*c5c4113dSnw141292if {[llength $argv]>0} { 56*c5c4113dSnw141292 set FILELIST $argv 57*c5c4113dSnw141292 set argv {} 58*c5c4113dSnw141292} else { 59*c5c4113dSnw141292 set FILELIST [lsort -dictionary [glob $testdir/*.test]] 60*c5c4113dSnw141292} 61*c5c4113dSnw141292 62*c5c4113dSnw141292foreach testfile $FILELIST { 63*c5c4113dSnw141292 set tail [file tail $testfile] 64*c5c4113dSnw141292 if {[lsearch -exact $EXCLUDE $tail]>=0} continue 65*c5c4113dSnw141292 set LeakList {} 66*c5c4113dSnw141292 for {set COUNTER 0} {$COUNTER<$COUNT} {incr COUNTER} { 67*c5c4113dSnw141292 source $testfile 68*c5c4113dSnw141292 if {[info exists Leak]} { 69*c5c4113dSnw141292 lappend LeakList $Leak 70*c5c4113dSnw141292 } 71*c5c4113dSnw141292 } 72*c5c4113dSnw141292 if {$LeakList!=""} { 73*c5c4113dSnw141292 puts -nonewline memory-leak-test-$tail... 74*c5c4113dSnw141292 incr ::nTest 75*c5c4113dSnw141292 foreach x $LeakList { 76*c5c4113dSnw141292 if {$x!=[lindex $LeakList 0]} { 77*c5c4113dSnw141292 puts " failed! ($LeakList)" 78*c5c4113dSnw141292 incr ::nErr 79*c5c4113dSnw141292 lappend ::failList memory-leak-test-$tail 80*c5c4113dSnw141292 break 81*c5c4113dSnw141292 } 82*c5c4113dSnw141292 } 83*c5c4113dSnw141292 puts " Ok" 84*c5c4113dSnw141292 } 85*c5c4113dSnw141292} 86*c5c4113dSnw141292really_finish_test 87*c5c4113dSnw141292 88*c5c4113dSnw141292# Run the malloc tests and the misuse test after memory leak detection. 89*c5c4113dSnw141292# Both tests leak memory. 90*c5c4113dSnw141292# 91*c5c4113dSnw141292#catch {source $testdir/misuse.test} 92*c5c4113dSnw141292#catch {source $testdir/malloc.test} 93*c5c4113dSnw141292 94*c5c4113dSnw141292really_finish_test 95