sl@0: # 2008 June 21
sl@0: #
sl@0: # The author disclaims copyright to this source code.  In place of
sl@0: # a legal notice, here is a blessing:
sl@0: #
sl@0: #    May you do good and not evil.
sl@0: #    May you find forgiveness for yourself and forgive others.
sl@0: #    May you share freely, never taking more than you give.
sl@0: #
sl@0: #***********************************************************************
sl@0: #
sl@0: # $Id: permutations.test,v 1.32 2008/09/29 14:27:41 danielk1977 Exp $
sl@0: 
sl@0: set testdir [file dirname $argv0]
sl@0: source $testdir/tester.tcl
sl@0: 
sl@0: # Argument processing.
sl@0: #
sl@0: #puts "PERM-DEBUG: argv=$argv"
sl@0: namespace eval ::perm {
sl@0:   variable testmode [lindex $::argv 0]
sl@0:   variable testfile [lindex $::argv 1]
sl@0: }
sl@0: set argv [lrange $argv 2 end]
sl@0: #puts "PERM-DEBUG: testmode=$::perm::testmode tstfile=$::perm::testfile"
sl@0: 
sl@0: set ::permutations_presql ""
sl@0: set ::permutations_test_prefix ""
sl@0: 
sl@0: if {$::perm::testmode eq "veryquick"} {
sl@0:   set ::perm::testmode [list persistent_journal no_journal]
sl@0:   set ISQUICK 1
sl@0: }
sl@0: if {$::perm::testmode eq "quick"} {
sl@0:   set ::perm::testmode [list persistent_journal no_journal autovacuum_ioerr]
sl@0:   set ISQUICK 1
sl@0: }
sl@0: if {$::perm::testmode eq "all" || $::perm::testmode eq ""} {
sl@0:   set ::perm::testmode {
sl@0:     memsubsys1 memsubsys2 singlethread multithread onefile utf16 exclusive
sl@0:     persistent_journal persistent_journal_error no_journal no_journal_error
sl@0:     autovacuum_ioerr no_mutex_try
sl@0:   }
sl@0: }
sl@0: if {$::perm::testmode eq "targets"} { 
sl@0:   puts ""
sl@0:   puts -nonewline "veryquick            "
sl@0:   puts "Same as persistent_journal and no_journal"
sl@0:   puts -nonewline "quick                "
sl@0:   puts "Same as persistent_journal, no_journal and autovacuum_ioerr"
sl@0:   puts -nonewline "all                  "
sl@0:   puts "Everything except autovacuum_crash"
sl@0: }
sl@0: #puts "PERM-DEBUG: testmode=$::perm::testmode"
sl@0: 
sl@0: set EXCLUDE {
sl@0:   all.test                  in2.test                  onefile.test
sl@0:   async2.test               incrvacuum_ioerr.test     permutations.test
sl@0:   async.test                jrnlmode2.test            quick.test
sl@0:   autovacuum_crash.test     jrnlmode3.test            shared_err.test
sl@0:   autovacuum_ioerr.test     jrnlmode4.test            soak.test
sl@0:   btree8.test               loadext.test              speed1p.test
sl@0:   corrupt.test              malloc2.test              speed1.test
sl@0:   crash2.test               malloc3.test              speed2.test
sl@0:   crash3.test               malloc4.test              speed3.test
sl@0:   crash4.test               mallocAll.test            speed4p.test
sl@0:   crash6.test               malloc.test               speed4.test
sl@0:   crash7.test               memleak.test              sqllimits1.test
sl@0:   crash.test                memsubsys1.test           thread001.test
sl@0:   exclusive3.test           memsubsys2.test           thread002.test
sl@0:   fts3.test                 misc7.test                utf16.test
sl@0:   fuzz_malloc.test          misuse.test               veryquick.test
sl@0:   fuzz.test                 mutex2.test               vtab_err.test
sl@0:   lookaside.test            fuzz3.test
sl@0: }
sl@0: set ALLTESTS [list]
sl@0: foreach filename [glob $testdir/*.test] {
sl@0:   set filename [file tail $filename]
sl@0:   if {[lsearch $EXCLUDE $filename] < 0} { lappend ALLTESTS $filename }
sl@0: }
sl@0: set ALLTESTS [lsort $ALLTESTS]
sl@0: 
sl@0: rename finish_test really_finish_test2
sl@0: proc finish_test {} {}
sl@0: 
sl@0: rename do_test really_do_test
sl@0: 
sl@0: proc do_test {name args} {
sl@0:   eval really_do_test [list "perm-$::permutations_test_prefix.$name"] $args
sl@0: }
sl@0: 
sl@0: # Overload the [sqlite3] command
sl@0: rename sqlite3 really_sqlite3
sl@0: proc sqlite3 {args} {
sl@0:   set r [eval really_sqlite3 $args]
sl@0:   if { [llength $args] == 2 && $::permutations_presql ne "" } {
sl@0:     [lindex $args 0] eval $::permutations_presql
sl@0:   }
sl@0:   set r
sl@0: }
sl@0: 
sl@0: # run_tests OPTIONS
sl@0: #
sl@0: # where available options are:  
sl@0: #
sl@0: #       -initialize  SCRIPT                 (default "")
sl@0: #       -shutdown    SCRIPT                 (default "")
sl@0: #       -include     LIST-OF-FILES          (default $::ALLTESTS)
sl@0: #       -exclude     LIST-OF-FILES          (default "")
sl@0: #       -presql      SQL                    (default "")
sl@0: #       -description TITLE                  (default "")
sl@0: #
sl@0: proc run_tests {name args} {
sl@0:   set ::permutations_test_prefix $name
sl@0:   set options(-shutdown) ""
sl@0:   set options(-initialize) ""
sl@0:   set options(-exclude) ""
sl@0:   set options(-include) $::ALLTESTS
sl@0:   set options(-presql) ""
sl@0:   set options(-description) "no description supplied (fixme)"
sl@0:   array set options $args
sl@0:   #puts "PERM-DEBUG: name=$name testfile=$::perm::testfile"
sl@0:   #puts "PERM-DEBUG: [array get options]"
sl@0: 
sl@0:   if {$::perm::testmode eq "targets"} {
sl@0:     puts [format "% -20s %s" $name [string trim $options(-description)]]
sl@0:     return
sl@0:   }
sl@0:   if {$::perm::testmode ne "" && [lsearch $::perm::testmode $name]<0} {
sl@0:     puts "skipping permutation test $name..."
sl@0:     return
sl@0:   }
sl@0: 
sl@0:   uplevel $options(-initialize)
sl@0:   set ::permutations_presql $options(-presql)
sl@0: 
sl@0:   foreach file [lsort $options(-include)] {
sl@0:     if {[lsearch $options(-exclude) $file] < 0 &&
sl@0:        ( $::perm::testfile eq "" ||
sl@0:          $::perm::testfile eq $file ||
sl@0:         "$::perm::testfile.test" eq $file )
sl@0:     } {
sl@0:       set ::perm::shared_cache_setting [shared_cache_setting]
sl@0:       uplevel source $::testdir/$file
sl@0:       if {$::perm::shared_cache_setting ne [shared_cache_setting]} {
sl@0:         error "File $::testdir/$file changed the shared cache setting from $::perm::shared_cache_setting to [shared_cache_setting]"
sl@0:       }
sl@0:     } else {
sl@0:       # puts "skipping file $file"
sl@0:     }
sl@0:   }
sl@0: 
sl@0:   uplevel $options(-shutdown)
sl@0: }
sl@0: 
sl@0: proc shared_cache_setting {} {
sl@0:   set ret 0
sl@0:   catch {
sl@0:     set ret [sqlite3_enable_shared_cache]
sl@0:   }
sl@0:   return $ret
sl@0: }
sl@0: 
sl@0: #############################################################################
sl@0: # Start of tests
sl@0: 
sl@0: # Run some tests using pre-allocated page and scratch blocks.
sl@0: #
sl@0: run_tests "memsubsys1" -description {
sl@0:   Tests using pre-allocated page and scratch blocks
sl@0: } -exclude {
sl@0:   ioerr5.test
sl@0:   malloc5.test
sl@0: } -initialize {
sl@0:   catch {db close}
sl@0:   sqlite3_shutdown
sl@0:   sqlite3_config_pagecache 4096 24
sl@0:   sqlite3_config_scratch 25000 1
sl@0:   sqlite3_initialize
sl@0: } -shutdown {
sl@0:   catch {db close}
sl@0:   sqlite3_shutdown
sl@0:   sqlite3_config_pagecache 0 0
sl@0:   sqlite3_config_scratch 0 0
sl@0:   sqlite3_initialize
sl@0: }
sl@0: 
sl@0: # Run some tests using pre-allocated page and scratch blocks. This time
sl@0: # the allocations are too small to use in most cases.
sl@0: #
sl@0: # Both ioerr5.test and malloc5.test are excluded because they test the
sl@0: # sqlite3_soft_heap_limit() and sqlite3_release_memory() functionality.
sl@0: # This functionality is disabled if a pre-allocated page block is provided.
sl@0: #
sl@0: run_tests "memsubsys2" -description {
sl@0:   Tests using small pre-allocated page and scratch blocks
sl@0: } -exclude {
sl@0:   ioerr5.test
sl@0:   malloc5.test
sl@0: } -initialize {
sl@0:   catch {db close}
sl@0:   sqlite3_shutdown
sl@0:   sqlite3_config_pagecache 512 5
sl@0:   sqlite3_config_scratch 1000 1
sl@0:   sqlite3_initialize
sl@0: } -shutdown {
sl@0:   catch {db close}
sl@0:   sqlite3_shutdown
sl@0:   sqlite3_config_pagecache 0 0
sl@0:   sqlite3_config_scratch 0 0
sl@0:   sqlite3_initialize
sl@0: }
sl@0: 
sl@0: # Run all tests with the lookaside allocator disabled.
sl@0: #
sl@0: run_tests "memsubsys3" -description {
sl@0:   OOM tests with lookaside disabled
sl@0: } -include {
sl@0:   malloc.test
sl@0:   malloc3.test
sl@0:   malloc4.test
sl@0:   malloc5.test
sl@0:   malloc6.test
sl@0:   malloc7.test
sl@0:   malloc8.test
sl@0:   malloc9.test
sl@0:   mallocA.test
sl@0:   mallocB.test
sl@0:   mallocC.test
sl@0:   mallocD.test
sl@0:   mallocE.test
sl@0:   mallocF.test
sl@0:   mallocG.test
sl@0: } -initialize {
sl@0:   catch {db close}
sl@0:   sqlite3_shutdown
sl@0:   sqlite3_config_lookaside 0 0
sl@0:   sqlite3_initialize
sl@0: } -shutdown {
sl@0:   catch {db close}
sl@0:   sqlite3_shutdown
sl@0:   sqlite3_config_lookaside 100 500
sl@0:   sqlite3_initialize
sl@0: }
sl@0: 
sl@0: # Run some tests in SQLITE_CONFIG_SINGLETHREAD mode.
sl@0: #
sl@0: run_tests "singlethread" -description {
sl@0:   Tests run in SQLITE_CONFIG_SINGLETHREAD mode
sl@0: } -initialize {
sl@0:   do_test mutex2-singlethread.0 {
sl@0:     catch {db close}
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config singlethread
sl@0:   } SQLITE_OK
sl@0: } -include {
sl@0:   delete.test   delete2.test  insert.test  rollback.test  select1.test
sl@0:   select2.test  trans.test    update.test  vacuum.test    types.test
sl@0:   types2.test   types3.test
sl@0: } -shutdown {
sl@0:   do_test mutex2-X {
sl@0:     catch {db close}
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config serialized
sl@0:   } SQLITE_OK
sl@0: }
sl@0: 
sl@0: run_tests "nomutex" -description {
sl@0:   Tests run with the SQLITE_OPEN_MULTITHREADED flag passed to sqlite3_open().
sl@0: } -initialize {
sl@0:   rename sqlite3 sqlite3_nomutex
sl@0:   proc sqlite3 {args} {
sl@0:     if {[string range [lindex $args 0] 0 0] ne "-"} {
sl@0:       lappend args -fullmutex 0 -nomutex 1
sl@0:     }
sl@0:     uplevel [concat sqlite3_nomutex $args]
sl@0:   }
sl@0: } -include {
sl@0:   delete.test   delete2.test  insert.test  rollback.test  select1.test
sl@0:   select2.test  trans.test    update.test  vacuum.test    types.test
sl@0:   types2.test   types3.test
sl@0: } -shutdown {
sl@0:   rename sqlite3 {}
sl@0:   rename sqlite3_nomutex sqlite3
sl@0: }
sl@0: 
sl@0: # Run some tests in SQLITE_CONFIG_MULTITHREAD mode.
sl@0: #
sl@0: run_tests "multithread" -description {
sl@0:   Tests run in SQLITE_CONFIG_MULTITHREAD mode
sl@0: } -initialize {
sl@0:   do_test mutex2-multithread.0 {
sl@0:     catch {db close}
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config multithread
sl@0:   } SQLITE_OK
sl@0: } -include {
sl@0:   delete.test   delete2.test  insert.test  rollback.test  select1.test
sl@0:   select2.test  trans.test    update.test  vacuum.test    types.test
sl@0:   types2.test   types3.test
sl@0: } -shutdown {
sl@0:   do_test mutex2-X {
sl@0:     catch {db close}
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config serialized
sl@0:   } SQLITE_OK
sl@0: }
sl@0: 
sl@0: # Run some tests in SQLITE_OPEN_FULLMUTEX mode.
sl@0: #
sl@0: run_tests "fullmutex" -description {
sl@0:   Tests run in SQLITE_OPEN_FULLMUTEX mode
sl@0: } -initialize {
sl@0:   rename sqlite3 sqlite3_fullmutex
sl@0:   proc sqlite3 {args} {
sl@0:     if {[string range [lindex $args 0] 0 0] ne "-"} {
sl@0:       lappend args -nomutex 0 -fullmutex 1
sl@0:     }
sl@0:     uplevel [concat sqlite3_fullmutex $args]
sl@0:   }
sl@0: } -include {
sl@0:   delete.test   delete2.test  insert.test  rollback.test  select1.test
sl@0:   select2.test  trans.test    update.test  vacuum.test    types.test
sl@0:   types2.test   types3.test
sl@0: } -shutdown {
sl@0:   rename sqlite3 {}
sl@0:   rename sqlite3_fullmutex sqlite3
sl@0: }
sl@0: 
sl@0: # Run some tests using the "onefile" demo.
sl@0: #
sl@0: run_tests "onefile" -description {
sl@0:   Run some tests using the "test_onefile.c" demo
sl@0: } -initialize {
sl@0:   rename sqlite3 sqlite3_onefile
sl@0:   proc sqlite3 {args} {
sl@0:     if {[string range [lindex $args 0] 0 0] ne "-"} {
sl@0:       lappend args -vfs fs
sl@0:     }
sl@0:     uplevel [concat sqlite3_onefile $args]
sl@0:   }
sl@0: } -include {
sl@0:   conflict.test  insert.test   insert2.test  insert3.test
sl@0:   rollback.test  select1.test  select2.test  select3.test
sl@0: } -shutdown {
sl@0:   rename sqlite3 {}
sl@0:   rename sqlite3_onefile sqlite3
sl@0: }
sl@0: 
sl@0: # Run some tests using UTF-16 databases.
sl@0: #
sl@0: run_tests "utf16" -description {
sl@0:   Run tests using UTF-16 databases
sl@0: } -presql {
sl@0:   pragma encoding = 'UTF-16'
sl@0: } -include {
sl@0:     alter.test alter3.test
sl@0:     auth.test bind.test blob.test capi2.test capi3.test collate1.test
sl@0:     collate2.test collate3.test collate4.test collate5.test collate6.test
sl@0:     conflict.test date.test delete.test expr.test fkey1.test func.test
sl@0:     hook.test index.test insert2.test insert.test interrupt.test in.test
sl@0:     intpkey.test ioerr.test join2.test join.test lastinsert.test
sl@0:     laststmtchanges.test limit.test lock2.test lock.test main.test 
sl@0:     memdb.test minmax.test misc1.test misc2.test misc3.test notnull.test
sl@0:     null.test progress.test quote.test rowid.test select1.test select2.test
sl@0:     select3.test select4.test select5.test select6.test sort.test 
sl@0:     subselect.test tableapi.test table.test temptable.test
sl@0:     trace.test trigger1.test trigger2.test trigger3.test
sl@0:     trigger4.test types2.test types.test unique.test update.test
sl@0:     vacuum.test view.test where.test
sl@0: }
sl@0: 
sl@0: # Run some tests in exclusive locking mode.
sl@0: #
sl@0: run_tests "exclusive" -description {
sl@0:   Run tests in exclusive locking mode.
sl@0: } -presql {
sl@0:   pragma locking_mode = 'exclusive'
sl@0: } -include {
sl@0:   rollback.test select1.test select2.test 
sl@0:   malloc.test ioerr.test
sl@0: } 
sl@0: 
sl@0: # Run some tests in exclusive locking mode with truncated journals.
sl@0: #
sl@0: run_tests "exclusive-truncate" -description {
sl@0:   Run tests in exclusive locking mode and truncate journal mode.
sl@0: } -presql {
sl@0:   pragma locking_mode = 'exclusive';
sl@0:   pragma journal_mode = TRUNCATE;
sl@0: } -include {
sl@0:   delete.test delete2.test insert.test rollback.test select1.test
sl@0:   select2.test update.test malloc.test ioerr.test
sl@0: } 
sl@0: 
sl@0: # Run some tests in persistent journal mode.
sl@0: #
sl@0: run_tests "persistent_journal" -description {
sl@0:   Run tests in persistent-journal mode.
sl@0: } -presql {
sl@0:   pragma journal_mode = persist
sl@0: } -include {
sl@0:   delete.test delete2.test insert.test rollback.test select1.test
sl@0:   select2.test trans.test update.test vacuum.test 
sl@0: }
sl@0: 
sl@0: # Run some tests in truncating journal mode.
sl@0: #
sl@0: run_tests "truncate_journal" -description {
sl@0:   Run tests in persistent-journal mode.
sl@0: } -presql {
sl@0:   pragma journal_mode = truncate
sl@0: } -include {
sl@0:   delete.test delete2.test insert.test rollback.test select1.test
sl@0:   select2.test trans.test update.test vacuum.test 
sl@0:   malloc.test ioerr.test
sl@0: }
sl@0: 
sl@0: # Run some error tests in persistent journal mode.
sl@0: #
sl@0: run_tests "persistent_journal_error" -description {
sl@0:   Run malloc.test and ioerr.test in persistent-journal mode.
sl@0: } -presql {
sl@0:   pragma journal_mode = persist
sl@0: } -include {
sl@0:   malloc.test ioerr.test
sl@0: }
sl@0: 
sl@0: # Run some tests in no journal mode.
sl@0: #
sl@0: run_tests "no_journal" -description {
sl@0:   Run tests in no-journal mode.
sl@0: } -presql {
sl@0:   pragma journal_mode = persist
sl@0: } -include {
sl@0:   delete.test delete2.test insert.test rollback.test select1.test
sl@0:   select2.test trans.test update.test vacuum.test 
sl@0: }
sl@0: 
sl@0: # Run some error tests in no journal mode.
sl@0: #
sl@0: run_tests "no_journal_error" -description {
sl@0:   Run malloc.test and ioerr.test in no-journal mode.
sl@0: } -presql {
sl@0:   pragma journal_mode = persist
sl@0: } -include {
sl@0:   malloc.test ioerr.test
sl@0: }
sl@0: 
sl@0: # Run some crash-tests in autovacuum mode.
sl@0: #
sl@0: run_tests "autovacuum_crash" -description {
sl@0:   Run crash.test in autovacuum mode.
sl@0: } -presql {
sl@0:   pragma auto_vacuum = 1
sl@0: } -include crash.test
sl@0: 
sl@0: # Run some ioerr-tests in autovacuum mode.
sl@0: #
sl@0: run_tests "autovacuum_ioerr" -description {
sl@0:   Run ioerr.test in autovacuum mode.
sl@0: } -presql {
sl@0:   pragma auto_vacuum = 1
sl@0: } -include ioerr.test
sl@0: 
sl@0: ifcapable mem3 {
sl@0:   run_tests "memsys3" -description {
sl@0:     Run tests using the allocator in mem3.c.
sl@0:   } -exclude {
sl@0:     autovacuum.test           delete3.test              manydb.test
sl@0:     bigrow.test               incrblob2.test            memdb.test
sl@0:     bitvec.test               index2.test               memsubsys1.test
sl@0:     capi3c.test               ioerr.test                memsubsys2.test
sl@0:     capi3.test                join3.test                pagesize.test
sl@0:     collate5.test             limit.test
sl@0:   } -initialize {
sl@0:     catch {db close}
sl@0:     sqlite3_reset_auto_extension
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config_heap 25000000 0
sl@0:     sqlite3_config_lookaside 0 0
sl@0:     install_malloc_faultsim 1 
sl@0:     sqlite3_initialize
sl@0:     autoinstall_test_functions
sl@0:   } -shutdown {
sl@0:     catch {db close}
sl@0:     sqlite3_reset_auto_extension
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config_heap 0 0
sl@0:     sqlite3_config_lookaside 100 500
sl@0:     install_malloc_faultsim 1 
sl@0:     sqlite3_initialize
sl@0:   }
sl@0: }
sl@0: 
sl@0: ifcapable mem5 {
sl@0:   run_tests "memsys5" -description {
sl@0:     Run tests using the allocator in mem5.c.
sl@0:   } -exclude {
sl@0:     autovacuum.test           delete3.test              manydb.test
sl@0:     bigrow.test               incrblob2.test            memdb.test
sl@0:     bitvec.test               index2.test               memsubsys1.test
sl@0:     capi3c.test               ioerr.test                memsubsys2.test
sl@0:     capi3.test                join3.test                pagesize.test
sl@0:     collate5.test             limit.test
sl@0:   } -initialize {
sl@0:     catch {db close}
sl@0:     sqlite3_reset_auto_extension
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config_heap 25000000 64
sl@0:     sqlite3_config_lookaside 0 0
sl@0:     install_malloc_faultsim 1 
sl@0:     sqlite3_initialize
sl@0:     autoinstall_test_functions
sl@0:   } -shutdown {
sl@0:     catch {db close}
sl@0:     sqlite3_reset_auto_extension
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config_heap 0 0
sl@0:     sqlite3_config_lookaside 100 500
sl@0:     install_malloc_faultsim 1 
sl@0:     sqlite3_initialize
sl@0:   }
sl@0: 
sl@0:   run_tests "memsys5-2" -description {
sl@0:     Run tests using the allocator in mem5.c in a different configuration.
sl@0:   } -include {
sl@0:     select1.test 
sl@0:   } -initialize {
sl@0:     catch {db close}
sl@0:     sqlite3_reset_auto_extension
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config_heap 40000000 16
sl@0:     sqlite3_config_lookaside 0 0
sl@0:     install_malloc_faultsim 1 
sl@0:     sqlite3_initialize
sl@0:     autoinstall_test_functions
sl@0:   } -shutdown {
sl@0:     catch {db close}
sl@0:     sqlite3_reset_auto_extension
sl@0:     sqlite3_shutdown
sl@0:     sqlite3_config_heap 0 0
sl@0:     sqlite3_config_lookaside 100 500
sl@0:     install_malloc_faultsim 1 
sl@0:     sqlite3_initialize
sl@0:   }
sl@0: }
sl@0: 
sl@0: ifcapable threadsafe {
sl@0:   run_tests "no_mutex_try" -description {
sl@0:      The sqlite3_mutex_try() interface always fails
sl@0:   } -exclude [concat $EXCLUDE mutex1.test mutex2.test] \
sl@0:   -initialize {
sl@0:     catch {db close}
sl@0:     sqlite3_shutdown
sl@0:     install_mutex_counters 1
sl@0:     set ::disable_mutex_try 1
sl@0:   } -shutdown {
sl@0:     catch {db close}
sl@0:     sqlite3_shutdown
sl@0:     install_mutex_counters 0
sl@0:   }
sl@0: }
sl@0: 
sl@0: run_tests "memsys6" -description {
sl@0:   Run tests using the allocator in mem6.c.
sl@0: } -exclude {
sl@0:   capi3.test capi3c.test 
sl@0: } -initialize {
sl@0:   catch {db close}
sl@0:   sqlite3_reset_auto_extension
sl@0:   sqlite3_shutdown
sl@0:   sqlite3_config_chunkalloc 0
sl@0:   install_malloc_faultsim 1 
sl@0:   sqlite3_initialize
sl@0:   autoinstall_test_functions
sl@0: } -shutdown {
sl@0:   catch {db close}
sl@0:   sqlite3_reset_auto_extension
sl@0:   sqlite3_shutdown
sl@0:   sqlite3_config_heap 0 0
sl@0:   install_malloc_faultsim 1 
sl@0:   sqlite3_initialize
sl@0: }
sl@0: 
sl@0: # run_tests "crash_safe_append" -description {
sl@0: #   Run crash.test with persistent journals on a SAFE_APPEND file-system.
sl@0: # } -initialize {
sl@0: #   rename crashsql sa_crashsql
sl@0: #   proc crashsql {args} {
sl@0: #     set options [lrange $args 0 [expr {[llength $args]-2}]]
sl@0: #     lappend options -char safe_append
sl@0: #     set sql [lindex $args end]
sl@0: #     lappend options "
sl@0: #       PRAGMA journal_mode=persistent;
sl@0: #       $sql
sl@0: #     "
sl@0: #     set fd [open test.db-journal w]
sl@0: #     puts $fd [string repeat 1234567890 100000]
sl@0: #     close $fd
sl@0: #     eval sa_crashsql $options
sl@0: #   }
sl@0: # } -shutdown {
sl@0: #   rename crashsql {}
sl@0: #   rename sa_crashsql crashsql
sl@0: # } -include crash.test
sl@0: 
sl@0: run_tests "safe_append" -description {
sl@0:   Run some tests on a SAFE_APPEND file-system.
sl@0: } -initialize {
sl@0:   rename sqlite3 sqlite3_safeappend
sl@0:   proc sqlite3 {args} {
sl@0:     if {[string range [lindex $args 0] 0 0] ne "-"} {
sl@0:       lappend args -vfs devsym
sl@0:     }
sl@0:     uplevel [concat sqlite3_safeappend $args]
sl@0:   }
sl@0:   sqlite3_simulate_device -char safe_append
sl@0: } -shutdown {
sl@0:   rename sqlite3 {}
sl@0:   rename sqlite3_shutdown sqlite3
sl@0: } -include [lsort [concat shared_err.test $ALLTESTS]] \
sl@0:   -exclude async3.test
sl@0: 
sl@0: 
sl@0: # End of tests
sl@0: #############################################################################
sl@0: 
sl@0: if {$::perm::testmode eq "targets"} { puts "" ; exit }
sl@0: 
sl@0: # Restore the [sqlite3] command.
sl@0: #
sl@0: rename sqlite3 {}
sl@0: rename really_sqlite3 sqlite3
sl@0: 
sl@0: # Restore the [finish_test] command.
sl@0: #
sl@0: rename finish_test ""
sl@0: rename really_finish_test2 finish_test
sl@0: 
sl@0: # Restore the [do_test] command.
sl@0: #
sl@0: rename do_test ""
sl@0: rename really_do_test do_test
sl@0: 
sl@0: finish_test