xref: /titanic_50/usr/src/lib/libsqlite/test/all.test (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
1*c5c4113dSnw141292
2*c5c4113dSnw141292#pragma ident	"%Z%%M%	%I%	%E% SMI"
3*c5c4113dSnw141292
4*c5c4113dSnw141292# 2001 September 15
5*c5c4113dSnw141292#
6*c5c4113dSnw141292# The author disclaims copyright to this source code.  In place of
7*c5c4113dSnw141292# a legal notice, here is a blessing:
8*c5c4113dSnw141292#
9*c5c4113dSnw141292#    May you do good and not evil.
10*c5c4113dSnw141292#    May you find forgiveness for yourself and forgive others.
11*c5c4113dSnw141292#    May you share freely, never taking more than you give.
12*c5c4113dSnw141292#
13*c5c4113dSnw141292#***********************************************************************
14*c5c4113dSnw141292# This file runs all tests.
15*c5c4113dSnw141292#
16*c5c4113dSnw141292# $Id: all.test,v 1.19 2003/02/16 22:21:33 drh Exp $
17*c5c4113dSnw141292
18*c5c4113dSnw141292set testdir [file dirname $argv0]
19*c5c4113dSnw141292source $testdir/tester.tcl
20*c5c4113dSnw141292rename finish_test really_finish_test
21*c5c4113dSnw141292proc finish_test {} {memleak_check}
22*c5c4113dSnw141292
23*c5c4113dSnw141292if {[file exists ./sqlite_test_count]} {
24*c5c4113dSnw141292  set COUNT [exec cat ./sqlite_test_count]
25*c5c4113dSnw141292} else {
26*c5c4113dSnw141292  set COUNT 4
27*c5c4113dSnw141292}
28*c5c4113dSnw141292
29*c5c4113dSnw141292if {[llength $argv]>0} {
30*c5c4113dSnw141292  foreach {name value} $argv {
31*c5c4113dSnw141292    switch -- $name {
32*c5c4113dSnw141292      -count {
33*c5c4113dSnw141292         set COUNT $value
34*c5c4113dSnw141292      }
35*c5c4113dSnw141292      -quick {
36*c5c4113dSnw141292         set ISQUICK $value
37*c5c4113dSnw141292      }
38*c5c4113dSnw141292      default {
39*c5c4113dSnw141292         puts stderr "Unknown option: $name"
40*c5c4113dSnw141292         exit
41*c5c4113dSnw141292      }
42*c5c4113dSnw141292    }
43*c5c4113dSnw141292  }
44*c5c4113dSnw141292}
45*c5c4113dSnw141292set argv {}
46*c5c4113dSnw141292
47*c5c4113dSnw141292# LeakList will hold a list of the number of unfreed mallocs after
48*c5c4113dSnw141292# each round of the test.  This number should be constant.  If it
49*c5c4113dSnw141292# grows, it may mean there is a memory leak in the library.
50*c5c4113dSnw141292#
51*c5c4113dSnw141292set LeakList {}
52*c5c4113dSnw141292
53*c5c4113dSnw141292set EXCLUDE {
54*c5c4113dSnw141292  all.test
55*c5c4113dSnw141292  quick.test
56*c5c4113dSnw141292  malloc.test
57*c5c4113dSnw141292  misuse.test
58*c5c4113dSnw141292  memleak.test
59*c5c4113dSnw141292}
60*c5c4113dSnw141292#  btree2.test
61*c5c4113dSnw141292
62*c5c4113dSnw141292for {set Counter 0} {$Counter<$COUNT && $nErr==0} {incr Counter} {
63*c5c4113dSnw141292  set btree_native_byte_order [expr {($Counter>>1)&0x1}]
64*c5c4113dSnw141292  if {$Counter%2} {
65*c5c4113dSnw141292    set ::SETUP_SQL {PRAGMA default_synchronous=off;}
66*c5c4113dSnw141292  } else {
67*c5c4113dSnw141292    catch {unset ::SETUP_SQL}
68*c5c4113dSnw141292  }
69*c5c4113dSnw141292  foreach testfile [lsort -dictionary [glob $testdir/*.test]] {
70*c5c4113dSnw141292    set tail [file tail $testfile]
71*c5c4113dSnw141292    if {[lsearch -exact $EXCLUDE $tail]>=0} continue
72*c5c4113dSnw141292    source $testfile
73*c5c4113dSnw141292    catch {db close}
74*c5c4113dSnw141292    if {$sqlite_open_file_count>0} {
75*c5c4113dSnw141292      puts "$tail did not close all files: $sqlite_open_file_count"
76*c5c4113dSnw141292      incr nErr
77*c5c4113dSnw141292      lappend ::failList $tail
78*c5c4113dSnw141292    }
79*c5c4113dSnw141292  }
80*c5c4113dSnw141292  if {[info exists Leak]} {
81*c5c4113dSnw141292    lappend LeakList $Leak
82*c5c4113dSnw141292  }
83*c5c4113dSnw141292}
84*c5c4113dSnw141292
85*c5c4113dSnw141292# Do one last test to look for a memory leak in the library.  This will
86*c5c4113dSnw141292# only work if SQLite is compiled with the -DMEMORY_DEBUG=1 flag.
87*c5c4113dSnw141292#
88*c5c4113dSnw141292if {$LeakList!=""} {
89*c5c4113dSnw141292  puts -nonewline memory-leak-test...
90*c5c4113dSnw141292  incr ::nTest
91*c5c4113dSnw141292  foreach x $LeakList {
92*c5c4113dSnw141292    if {$x!=[lindex $LeakList 0]} {
93*c5c4113dSnw141292       puts " failed!"
94*c5c4113dSnw141292       puts "Expected: all values to be the same"
95*c5c4113dSnw141292       puts "     Got: $LeakList"
96*c5c4113dSnw141292       incr ::nErr
97*c5c4113dSnw141292       lappend ::failList memory-leak-test
98*c5c4113dSnw141292       break
99*c5c4113dSnw141292    }
100*c5c4113dSnw141292  }
101*c5c4113dSnw141292  puts " Ok"
102*c5c4113dSnw141292}
103*c5c4113dSnw141292
104*c5c4113dSnw141292# Run the malloc tests and the misuse test after memory leak detection.
105*c5c4113dSnw141292# Both tests leak memory.
106*c5c4113dSnw141292#
107*c5c4113dSnw141292catch {source $testdir/misuse.test}
108*c5c4113dSnw141292catch {source $testdir/malloc.test}
109*c5c4113dSnw141292
110*c5c4113dSnw141292catch {db close}
111*c5c4113dSnw141292set sqlite_open_file_count 0
112*c5c4113dSnw141292really_finish_test
113