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