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