xref: /illumos-gate/usr/src/lib/libsqlite/test/all.test (revision 7dbbfe7762f9eabac3999ee1a8b38311d428f7a8)
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: all.test,v 1.19 2003/02/16 22:21:33 drh Exp $
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18rename finish_test really_finish_test
19proc finish_test {} {memleak_check}
20
21if {[file exists ./sqlite_test_count]} {
22  set COUNT [exec cat ./sqlite_test_count]
23} else {
24  set COUNT 4
25}
26
27if {[llength $argv]>0} {
28  foreach {name value} $argv {
29    switch -- $name {
30      -count {
31         set COUNT $value
32      }
33      -quick {
34         set ISQUICK $value
35      }
36      default {
37         puts stderr "Unknown option: $name"
38         exit
39      }
40    }
41  }
42}
43set argv {}
44
45# LeakList will hold a list of the number of unfreed mallocs after
46# each round of the test.  This number should be constant.  If it
47# grows, it may mean there is a memory leak in the library.
48#
49set LeakList {}
50
51set EXCLUDE {
52  all.test
53  quick.test
54  malloc.test
55  misuse.test
56  memleak.test
57}
58#  btree2.test
59
60for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
61  set btree_native_byte_order [expr {($Counter>>1)&0x1}]
62  if {$Counter%2} {
63    set ::SETUP_SQL {PRAGMA default_synchronous=off;}
64  } else {
65    catch {unset ::SETUP_SQL}
66  }
67  foreach testfile [lsort -dictionary [glob $testdir/*.test]] {
68    set tail [file tail $testfile]
69    if {[lsearch -exact $EXCLUDE $tail]>=0} continue
70    source $testfile
71    catch {db close}
72    if {$sqlite_open_file_count>0} {
73      puts "$tail did not close all files: $sqlite_open_file_count"
74      incr nErr
75      lappend ::failList $tail
76    }
77  }
78  if {[info exists Leak]} {
79    lappend LeakList $Leak
80  }
81}
82
83# Do one last test to look for a memory leak in the library.  This will
84# only work if SQLite is compiled with the -DMEMORY_DEBUG=1 flag.
85#
86if {$LeakList!=""} {
87  puts -nonewline memory-leak-test...
88  incr ::nTest
89  foreach x $LeakList {
90    if {$x!=[lindex $LeakList 0]} {
91       puts " failed!"
92       puts "Expected: all values to be the same"
93       puts "     Got: $LeakList"
94       incr ::nErr
95       lappend ::failList memory-leak-test
96       break
97    }
98  }
99  puts " Ok"
100}
101
102# Run the malloc tests and the misuse test after memory leak detection.
103# Both tests leak memory.
104#
105catch {source $testdir/misuse.test}
106catch {source $testdir/malloc.test}
107
108catch {db close}
109set sqlite_open_file_count 0
110really_finish_test
111