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