os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/permutations.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 # 2008 June 21
     2 #
     3 # The author disclaims copyright to this source code.  In place of
     4 # a legal notice, here is a blessing:
     5 #
     6 #    May you do good and not evil.
     7 #    May you find forgiveness for yourself and forgive others.
     8 #    May you share freely, never taking more than you give.
     9 #
    10 #***********************************************************************
    11 #
    12 # $Id: permutations.test,v 1.32 2008/09/29 14:27:41 danielk1977 Exp $
    13 
    14 set testdir [file dirname $argv0]
    15 source $testdir/tester.tcl
    16 
    17 # Argument processing.
    18 #
    19 #puts "PERM-DEBUG: argv=$argv"
    20 namespace eval ::perm {
    21   variable testmode [lindex $::argv 0]
    22   variable testfile [lindex $::argv 1]
    23 }
    24 set argv [lrange $argv 2 end]
    25 #puts "PERM-DEBUG: testmode=$::perm::testmode tstfile=$::perm::testfile"
    26 
    27 set ::permutations_presql ""
    28 set ::permutations_test_prefix ""
    29 
    30 if {$::perm::testmode eq "veryquick"} {
    31   set ::perm::testmode [list persistent_journal no_journal]
    32   set ISQUICK 1
    33 }
    34 if {$::perm::testmode eq "quick"} {
    35   set ::perm::testmode [list persistent_journal no_journal autovacuum_ioerr]
    36   set ISQUICK 1
    37 }
    38 if {$::perm::testmode eq "all" || $::perm::testmode eq ""} {
    39   set ::perm::testmode {
    40     memsubsys1 memsubsys2 singlethread multithread onefile utf16 exclusive
    41     persistent_journal persistent_journal_error no_journal no_journal_error
    42     autovacuum_ioerr no_mutex_try
    43   }
    44 }
    45 if {$::perm::testmode eq "targets"} { 
    46   puts ""
    47   puts -nonewline "veryquick            "
    48   puts "Same as persistent_journal and no_journal"
    49   puts -nonewline "quick                "
    50   puts "Same as persistent_journal, no_journal and autovacuum_ioerr"
    51   puts -nonewline "all                  "
    52   puts "Everything except autovacuum_crash"
    53 }
    54 #puts "PERM-DEBUG: testmode=$::perm::testmode"
    55 
    56 set EXCLUDE {
    57   all.test                  in2.test                  onefile.test
    58   async2.test               incrvacuum_ioerr.test     permutations.test
    59   async.test                jrnlmode2.test            quick.test
    60   autovacuum_crash.test     jrnlmode3.test            shared_err.test
    61   autovacuum_ioerr.test     jrnlmode4.test            soak.test
    62   btree8.test               loadext.test              speed1p.test
    63   corrupt.test              malloc2.test              speed1.test
    64   crash2.test               malloc3.test              speed2.test
    65   crash3.test               malloc4.test              speed3.test
    66   crash4.test               mallocAll.test            speed4p.test
    67   crash6.test               malloc.test               speed4.test
    68   crash7.test               memleak.test              sqllimits1.test
    69   crash.test                memsubsys1.test           thread001.test
    70   exclusive3.test           memsubsys2.test           thread002.test
    71   fts3.test                 misc7.test                utf16.test
    72   fuzz_malloc.test          misuse.test               veryquick.test
    73   fuzz.test                 mutex2.test               vtab_err.test
    74   lookaside.test            fuzz3.test
    75 }
    76 set ALLTESTS [list]
    77 foreach filename [glob $testdir/*.test] {
    78   set filename [file tail $filename]
    79   if {[lsearch $EXCLUDE $filename] < 0} { lappend ALLTESTS $filename }
    80 }
    81 set ALLTESTS [lsort $ALLTESTS]
    82 
    83 rename finish_test really_finish_test2
    84 proc finish_test {} {}
    85 
    86 rename do_test really_do_test
    87 
    88 proc do_test {name args} {
    89   eval really_do_test [list "perm-$::permutations_test_prefix.$name"] $args
    90 }
    91 
    92 # Overload the [sqlite3] command
    93 rename sqlite3 really_sqlite3
    94 proc sqlite3 {args} {
    95   set r [eval really_sqlite3 $args]
    96   if { [llength $args] == 2 && $::permutations_presql ne "" } {
    97     [lindex $args 0] eval $::permutations_presql
    98   }
    99   set r
   100 }
   101 
   102 # run_tests OPTIONS
   103 #
   104 # where available options are:  
   105 #
   106 #       -initialize  SCRIPT                 (default "")
   107 #       -shutdown    SCRIPT                 (default "")
   108 #       -include     LIST-OF-FILES          (default $::ALLTESTS)
   109 #       -exclude     LIST-OF-FILES          (default "")
   110 #       -presql      SQL                    (default "")
   111 #       -description TITLE                  (default "")
   112 #
   113 proc run_tests {name args} {
   114   set ::permutations_test_prefix $name
   115   set options(-shutdown) ""
   116   set options(-initialize) ""
   117   set options(-exclude) ""
   118   set options(-include) $::ALLTESTS
   119   set options(-presql) ""
   120   set options(-description) "no description supplied (fixme)"
   121   array set options $args
   122   #puts "PERM-DEBUG: name=$name testfile=$::perm::testfile"
   123   #puts "PERM-DEBUG: [array get options]"
   124 
   125   if {$::perm::testmode eq "targets"} {
   126     puts [format "% -20s %s" $name [string trim $options(-description)]]
   127     return
   128   }
   129   if {$::perm::testmode ne "" && [lsearch $::perm::testmode $name]<0} {
   130     puts "skipping permutation test $name..."
   131     return
   132   }
   133 
   134   uplevel $options(-initialize)
   135   set ::permutations_presql $options(-presql)
   136 
   137   foreach file [lsort $options(-include)] {
   138     if {[lsearch $options(-exclude) $file] < 0 &&
   139        ( $::perm::testfile eq "" ||
   140          $::perm::testfile eq $file ||
   141         "$::perm::testfile.test" eq $file )
   142     } {
   143       set ::perm::shared_cache_setting [shared_cache_setting]
   144       uplevel source $::testdir/$file
   145       if {$::perm::shared_cache_setting ne [shared_cache_setting]} {
   146         error "File $::testdir/$file changed the shared cache setting from $::perm::shared_cache_setting to [shared_cache_setting]"
   147       }
   148     } else {
   149       # puts "skipping file $file"
   150     }
   151   }
   152 
   153   uplevel $options(-shutdown)
   154 }
   155 
   156 proc shared_cache_setting {} {
   157   set ret 0
   158   catch {
   159     set ret [sqlite3_enable_shared_cache]
   160   }
   161   return $ret
   162 }
   163 
   164 #############################################################################
   165 # Start of tests
   166 
   167 # Run some tests using pre-allocated page and scratch blocks.
   168 #
   169 run_tests "memsubsys1" -description {
   170   Tests using pre-allocated page and scratch blocks
   171 } -exclude {
   172   ioerr5.test
   173   malloc5.test
   174 } -initialize {
   175   catch {db close}
   176   sqlite3_shutdown
   177   sqlite3_config_pagecache 4096 24
   178   sqlite3_config_scratch 25000 1
   179   sqlite3_initialize
   180 } -shutdown {
   181   catch {db close}
   182   sqlite3_shutdown
   183   sqlite3_config_pagecache 0 0
   184   sqlite3_config_scratch 0 0
   185   sqlite3_initialize
   186 }
   187 
   188 # Run some tests using pre-allocated page and scratch blocks. This time
   189 # the allocations are too small to use in most cases.
   190 #
   191 # Both ioerr5.test and malloc5.test are excluded because they test the
   192 # sqlite3_soft_heap_limit() and sqlite3_release_memory() functionality.
   193 # This functionality is disabled if a pre-allocated page block is provided.
   194 #
   195 run_tests "memsubsys2" -description {
   196   Tests using small pre-allocated page and scratch blocks
   197 } -exclude {
   198   ioerr5.test
   199   malloc5.test
   200 } -initialize {
   201   catch {db close}
   202   sqlite3_shutdown
   203   sqlite3_config_pagecache 512 5
   204   sqlite3_config_scratch 1000 1
   205   sqlite3_initialize
   206 } -shutdown {
   207   catch {db close}
   208   sqlite3_shutdown
   209   sqlite3_config_pagecache 0 0
   210   sqlite3_config_scratch 0 0
   211   sqlite3_initialize
   212 }
   213 
   214 # Run all tests with the lookaside allocator disabled.
   215 #
   216 run_tests "memsubsys3" -description {
   217   OOM tests with lookaside disabled
   218 } -include {
   219   malloc.test
   220   malloc3.test
   221   malloc4.test
   222   malloc5.test
   223   malloc6.test
   224   malloc7.test
   225   malloc8.test
   226   malloc9.test
   227   mallocA.test
   228   mallocB.test
   229   mallocC.test
   230   mallocD.test
   231   mallocE.test
   232   mallocF.test
   233   mallocG.test
   234 } -initialize {
   235   catch {db close}
   236   sqlite3_shutdown
   237   sqlite3_config_lookaside 0 0
   238   sqlite3_initialize
   239 } -shutdown {
   240   catch {db close}
   241   sqlite3_shutdown
   242   sqlite3_config_lookaside 100 500
   243   sqlite3_initialize
   244 }
   245 
   246 # Run some tests in SQLITE_CONFIG_SINGLETHREAD mode.
   247 #
   248 run_tests "singlethread" -description {
   249   Tests run in SQLITE_CONFIG_SINGLETHREAD mode
   250 } -initialize {
   251   do_test mutex2-singlethread.0 {
   252     catch {db close}
   253     sqlite3_shutdown
   254     sqlite3_config singlethread
   255   } SQLITE_OK
   256 } -include {
   257   delete.test   delete2.test  insert.test  rollback.test  select1.test
   258   select2.test  trans.test    update.test  vacuum.test    types.test
   259   types2.test   types3.test
   260 } -shutdown {
   261   do_test mutex2-X {
   262     catch {db close}
   263     sqlite3_shutdown
   264     sqlite3_config serialized
   265   } SQLITE_OK
   266 }
   267 
   268 run_tests "nomutex" -description {
   269   Tests run with the SQLITE_OPEN_MULTITHREADED flag passed to sqlite3_open().
   270 } -initialize {
   271   rename sqlite3 sqlite3_nomutex
   272   proc sqlite3 {args} {
   273     if {[string range [lindex $args 0] 0 0] ne "-"} {
   274       lappend args -fullmutex 0 -nomutex 1
   275     }
   276     uplevel [concat sqlite3_nomutex $args]
   277   }
   278 } -include {
   279   delete.test   delete2.test  insert.test  rollback.test  select1.test
   280   select2.test  trans.test    update.test  vacuum.test    types.test
   281   types2.test   types3.test
   282 } -shutdown {
   283   rename sqlite3 {}
   284   rename sqlite3_nomutex sqlite3
   285 }
   286 
   287 # Run some tests in SQLITE_CONFIG_MULTITHREAD mode.
   288 #
   289 run_tests "multithread" -description {
   290   Tests run in SQLITE_CONFIG_MULTITHREAD mode
   291 } -initialize {
   292   do_test mutex2-multithread.0 {
   293     catch {db close}
   294     sqlite3_shutdown
   295     sqlite3_config multithread
   296   } SQLITE_OK
   297 } -include {
   298   delete.test   delete2.test  insert.test  rollback.test  select1.test
   299   select2.test  trans.test    update.test  vacuum.test    types.test
   300   types2.test   types3.test
   301 } -shutdown {
   302   do_test mutex2-X {
   303     catch {db close}
   304     sqlite3_shutdown
   305     sqlite3_config serialized
   306   } SQLITE_OK
   307 }
   308 
   309 # Run some tests in SQLITE_OPEN_FULLMUTEX mode.
   310 #
   311 run_tests "fullmutex" -description {
   312   Tests run in SQLITE_OPEN_FULLMUTEX mode
   313 } -initialize {
   314   rename sqlite3 sqlite3_fullmutex
   315   proc sqlite3 {args} {
   316     if {[string range [lindex $args 0] 0 0] ne "-"} {
   317       lappend args -nomutex 0 -fullmutex 1
   318     }
   319     uplevel [concat sqlite3_fullmutex $args]
   320   }
   321 } -include {
   322   delete.test   delete2.test  insert.test  rollback.test  select1.test
   323   select2.test  trans.test    update.test  vacuum.test    types.test
   324   types2.test   types3.test
   325 } -shutdown {
   326   rename sqlite3 {}
   327   rename sqlite3_fullmutex sqlite3
   328 }
   329 
   330 # Run some tests using the "onefile" demo.
   331 #
   332 run_tests "onefile" -description {
   333   Run some tests using the "test_onefile.c" demo
   334 } -initialize {
   335   rename sqlite3 sqlite3_onefile
   336   proc sqlite3 {args} {
   337     if {[string range [lindex $args 0] 0 0] ne "-"} {
   338       lappend args -vfs fs
   339     }
   340     uplevel [concat sqlite3_onefile $args]
   341   }
   342 } -include {
   343   conflict.test  insert.test   insert2.test  insert3.test
   344   rollback.test  select1.test  select2.test  select3.test
   345 } -shutdown {
   346   rename sqlite3 {}
   347   rename sqlite3_onefile sqlite3
   348 }
   349 
   350 # Run some tests using UTF-16 databases.
   351 #
   352 run_tests "utf16" -description {
   353   Run tests using UTF-16 databases
   354 } -presql {
   355   pragma encoding = 'UTF-16'
   356 } -include {
   357     alter.test alter3.test
   358     auth.test bind.test blob.test capi2.test capi3.test collate1.test
   359     collate2.test collate3.test collate4.test collate5.test collate6.test
   360     conflict.test date.test delete.test expr.test fkey1.test func.test
   361     hook.test index.test insert2.test insert.test interrupt.test in.test
   362     intpkey.test ioerr.test join2.test join.test lastinsert.test
   363     laststmtchanges.test limit.test lock2.test lock.test main.test 
   364     memdb.test minmax.test misc1.test misc2.test misc3.test notnull.test
   365     null.test progress.test quote.test rowid.test select1.test select2.test
   366     select3.test select4.test select5.test select6.test sort.test 
   367     subselect.test tableapi.test table.test temptable.test
   368     trace.test trigger1.test trigger2.test trigger3.test
   369     trigger4.test types2.test types.test unique.test update.test
   370     vacuum.test view.test where.test
   371 }
   372 
   373 # Run some tests in exclusive locking mode.
   374 #
   375 run_tests "exclusive" -description {
   376   Run tests in exclusive locking mode.
   377 } -presql {
   378   pragma locking_mode = 'exclusive'
   379 } -include {
   380   rollback.test select1.test select2.test 
   381   malloc.test ioerr.test
   382 } 
   383 
   384 # Run some tests in exclusive locking mode with truncated journals.
   385 #
   386 run_tests "exclusive-truncate" -description {
   387   Run tests in exclusive locking mode and truncate journal mode.
   388 } -presql {
   389   pragma locking_mode = 'exclusive';
   390   pragma journal_mode = TRUNCATE;
   391 } -include {
   392   delete.test delete2.test insert.test rollback.test select1.test
   393   select2.test update.test malloc.test ioerr.test
   394 } 
   395 
   396 # Run some tests in persistent journal mode.
   397 #
   398 run_tests "persistent_journal" -description {
   399   Run tests in persistent-journal mode.
   400 } -presql {
   401   pragma journal_mode = persist
   402 } -include {
   403   delete.test delete2.test insert.test rollback.test select1.test
   404   select2.test trans.test update.test vacuum.test 
   405 }
   406 
   407 # Run some tests in truncating journal mode.
   408 #
   409 run_tests "truncate_journal" -description {
   410   Run tests in persistent-journal mode.
   411 } -presql {
   412   pragma journal_mode = truncate
   413 } -include {
   414   delete.test delete2.test insert.test rollback.test select1.test
   415   select2.test trans.test update.test vacuum.test 
   416   malloc.test ioerr.test
   417 }
   418 
   419 # Run some error tests in persistent journal mode.
   420 #
   421 run_tests "persistent_journal_error" -description {
   422   Run malloc.test and ioerr.test in persistent-journal mode.
   423 } -presql {
   424   pragma journal_mode = persist
   425 } -include {
   426   malloc.test ioerr.test
   427 }
   428 
   429 # Run some tests in no journal mode.
   430 #
   431 run_tests "no_journal" -description {
   432   Run tests in no-journal mode.
   433 } -presql {
   434   pragma journal_mode = persist
   435 } -include {
   436   delete.test delete2.test insert.test rollback.test select1.test
   437   select2.test trans.test update.test vacuum.test 
   438 }
   439 
   440 # Run some error tests in no journal mode.
   441 #
   442 run_tests "no_journal_error" -description {
   443   Run malloc.test and ioerr.test in no-journal mode.
   444 } -presql {
   445   pragma journal_mode = persist
   446 } -include {
   447   malloc.test ioerr.test
   448 }
   449 
   450 # Run some crash-tests in autovacuum mode.
   451 #
   452 run_tests "autovacuum_crash" -description {
   453   Run crash.test in autovacuum mode.
   454 } -presql {
   455   pragma auto_vacuum = 1
   456 } -include crash.test
   457 
   458 # Run some ioerr-tests in autovacuum mode.
   459 #
   460 run_tests "autovacuum_ioerr" -description {
   461   Run ioerr.test in autovacuum mode.
   462 } -presql {
   463   pragma auto_vacuum = 1
   464 } -include ioerr.test
   465 
   466 ifcapable mem3 {
   467   run_tests "memsys3" -description {
   468     Run tests using the allocator in mem3.c.
   469   } -exclude {
   470     autovacuum.test           delete3.test              manydb.test
   471     bigrow.test               incrblob2.test            memdb.test
   472     bitvec.test               index2.test               memsubsys1.test
   473     capi3c.test               ioerr.test                memsubsys2.test
   474     capi3.test                join3.test                pagesize.test
   475     collate5.test             limit.test
   476   } -initialize {
   477     catch {db close}
   478     sqlite3_reset_auto_extension
   479     sqlite3_shutdown
   480     sqlite3_config_heap 25000000 0
   481     sqlite3_config_lookaside 0 0
   482     install_malloc_faultsim 1 
   483     sqlite3_initialize
   484     autoinstall_test_functions
   485   } -shutdown {
   486     catch {db close}
   487     sqlite3_reset_auto_extension
   488     sqlite3_shutdown
   489     sqlite3_config_heap 0 0
   490     sqlite3_config_lookaside 100 500
   491     install_malloc_faultsim 1 
   492     sqlite3_initialize
   493   }
   494 }
   495 
   496 ifcapable mem5 {
   497   run_tests "memsys5" -description {
   498     Run tests using the allocator in mem5.c.
   499   } -exclude {
   500     autovacuum.test           delete3.test              manydb.test
   501     bigrow.test               incrblob2.test            memdb.test
   502     bitvec.test               index2.test               memsubsys1.test
   503     capi3c.test               ioerr.test                memsubsys2.test
   504     capi3.test                join3.test                pagesize.test
   505     collate5.test             limit.test
   506   } -initialize {
   507     catch {db close}
   508     sqlite3_reset_auto_extension
   509     sqlite3_shutdown
   510     sqlite3_config_heap 25000000 64
   511     sqlite3_config_lookaside 0 0
   512     install_malloc_faultsim 1 
   513     sqlite3_initialize
   514     autoinstall_test_functions
   515   } -shutdown {
   516     catch {db close}
   517     sqlite3_reset_auto_extension
   518     sqlite3_shutdown
   519     sqlite3_config_heap 0 0
   520     sqlite3_config_lookaside 100 500
   521     install_malloc_faultsim 1 
   522     sqlite3_initialize
   523   }
   524 
   525   run_tests "memsys5-2" -description {
   526     Run tests using the allocator in mem5.c in a different configuration.
   527   } -include {
   528     select1.test 
   529   } -initialize {
   530     catch {db close}
   531     sqlite3_reset_auto_extension
   532     sqlite3_shutdown
   533     sqlite3_config_heap 40000000 16
   534     sqlite3_config_lookaside 0 0
   535     install_malloc_faultsim 1 
   536     sqlite3_initialize
   537     autoinstall_test_functions
   538   } -shutdown {
   539     catch {db close}
   540     sqlite3_reset_auto_extension
   541     sqlite3_shutdown
   542     sqlite3_config_heap 0 0
   543     sqlite3_config_lookaside 100 500
   544     install_malloc_faultsim 1 
   545     sqlite3_initialize
   546   }
   547 }
   548 
   549 ifcapable threadsafe {
   550   run_tests "no_mutex_try" -description {
   551      The sqlite3_mutex_try() interface always fails
   552   } -exclude [concat $EXCLUDE mutex1.test mutex2.test] \
   553   -initialize {
   554     catch {db close}
   555     sqlite3_shutdown
   556     install_mutex_counters 1
   557     set ::disable_mutex_try 1
   558   } -shutdown {
   559     catch {db close}
   560     sqlite3_shutdown
   561     install_mutex_counters 0
   562   }
   563 }
   564 
   565 run_tests "memsys6" -description {
   566   Run tests using the allocator in mem6.c.
   567 } -exclude {
   568   capi3.test capi3c.test 
   569 } -initialize {
   570   catch {db close}
   571   sqlite3_reset_auto_extension
   572   sqlite3_shutdown
   573   sqlite3_config_chunkalloc 0
   574   install_malloc_faultsim 1 
   575   sqlite3_initialize
   576   autoinstall_test_functions
   577 } -shutdown {
   578   catch {db close}
   579   sqlite3_reset_auto_extension
   580   sqlite3_shutdown
   581   sqlite3_config_heap 0 0
   582   install_malloc_faultsim 1 
   583   sqlite3_initialize
   584 }
   585 
   586 # run_tests "crash_safe_append" -description {
   587 #   Run crash.test with persistent journals on a SAFE_APPEND file-system.
   588 # } -initialize {
   589 #   rename crashsql sa_crashsql
   590 #   proc crashsql {args} {
   591 #     set options [lrange $args 0 [expr {[llength $args]-2}]]
   592 #     lappend options -char safe_append
   593 #     set sql [lindex $args end]
   594 #     lappend options "
   595 #       PRAGMA journal_mode=persistent;
   596 #       $sql
   597 #     "
   598 #     set fd [open test.db-journal w]
   599 #     puts $fd [string repeat 1234567890 100000]
   600 #     close $fd
   601 #     eval sa_crashsql $options
   602 #   }
   603 # } -shutdown {
   604 #   rename crashsql {}
   605 #   rename sa_crashsql crashsql
   606 # } -include crash.test
   607 
   608 run_tests "safe_append" -description {
   609   Run some tests on a SAFE_APPEND file-system.
   610 } -initialize {
   611   rename sqlite3 sqlite3_safeappend
   612   proc sqlite3 {args} {
   613     if {[string range [lindex $args 0] 0 0] ne "-"} {
   614       lappend args -vfs devsym
   615     }
   616     uplevel [concat sqlite3_safeappend $args]
   617   }
   618   sqlite3_simulate_device -char safe_append
   619 } -shutdown {
   620   rename sqlite3 {}
   621   rename sqlite3_shutdown sqlite3
   622 } -include [lsort [concat shared_err.test $ALLTESTS]] \
   623   -exclude async3.test
   624 
   625 
   626 # End of tests
   627 #############################################################################
   628 
   629 if {$::perm::testmode eq "targets"} { puts "" ; exit }
   630 
   631 # Restore the [sqlite3] command.
   632 #
   633 rename sqlite3 {}
   634 rename really_sqlite3 sqlite3
   635 
   636 # Restore the [finish_test] command.
   637 #
   638 rename finish_test ""
   639 rename really_finish_test2 finish_test
   640 
   641 # Restore the [do_test] command.
   642 #
   643 rename do_test ""
   644 rename really_do_test do_test
   645 
   646 finish_test