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