Home | History | Annotate | Download | only in tool
      1 
      2 set rcsid {$Id: omittest.tcl,v 1.8 2008/10/13 15:35:09 drh Exp $}
      3 
      4 # Documentation for this script. This may be output to stderr
      5 # if the script is invoked incorrectly.
      6 set ::USAGE_MESSAGE {
      7 This Tcl script is used to test the various compile time options
      8 available for omitting code (the SQLITE_OMIT_xxx options). It
      9 should be invoked as follows:
     10 
     11     <script> ?test-symbol? ?-makefile PATH-TO-MAKEFILE? ?-skip_run?
     12 
     13 The default value for ::MAKEFILE is "../Makefile.linux.gcc".
     14 
     15 If -skip_run option is given then only the compile part is attempted.
     16 
     17 This script builds the testfixture program and runs the SQLite test suite
     18 once with each SQLITE_OMIT_ option defined and then once with all options
     19 defined together. Each run is performed in a seperate directory created
     20 as a sub-directory of the current directory by the script. The output
     21 of the build is saved in <sub-directory>/build.log. The output of the
     22 test-suite is saved in <sub-directory>/test.log.
     23 
     24 Almost any SQLite makefile (except those generated by configure - see below)
     25 should work. The following properties are required:
     26 
     27   * The makefile should support the "testfixture" target.
     28   * The makefile should support the "test" target.
     29   * The makefile should support the variable "OPTS" as a way to pass
     30     options from the make command line to lemon and the C compiler.
     31 
     32 More precisely, the following two invocations must be supported:
     33 
     34   make -f $::MAKEFILE testfixture OPTS="-DSQLITE_OMIT_ALTERTABLE=1"
     35   make -f $::MAKEFILE test
     36 
     37 Makefiles generated by the sqlite configure program cannot be used as
     38 they do not respect the OPTS variable.
     39 }
     40 
     41 
     42 # Build a testfixture executable and run quick.test using it. The first
     43 # parameter is the name of the directory to create and use to run the
     44 # test in. The second parameter is a list of OMIT symbols to define
     45 # when doing so. For example:
     46 #
     47 #     run_quick_test /tmp/testdir {SQLITE_OMIT_TRIGGER SQLITE_OMIT_VIEW}
     48 #
     49 #
     50 proc run_quick_test {dir omit_symbol_list} {
     51   set target "testfixture"
     52   # Compile the value of the OPTS Makefile variable.
     53   set opts "-DSQLITE_MEMDEBUG -DSQLITE_DEBUG -DSQLITE_NO_SYNC"
     54   if {$::tcl_platform(platform)=="windows"} {
     55     append opts " -DSQLITE_OS_WIN=1"
     56     set target "testfixture.exe"
     57   } elseif {$::tcl_platform(platform)=="os2"} {
     58     append opts " -DSQLITE_OS_OS2=1"
     59   } else {
     60     append opts " -DSQLITE_OS_UNIX=1"
     61   }
     62   foreach sym $omit_symbol_list {
     63     append opts " -D${sym}=1"
     64   }
     65 
     66   # Create the directory and do the build. If an error occurs return
     67   # early without attempting to run the test suite.
     68   file mkdir $dir
     69   puts -nonewline "Building $dir..."
     70   flush stdout
     71 catch {
     72   file copy -force ./config.h $dir
     73   file copy -force ./libtool $dir
     74 }
     75   set rc [catch {
     76     exec make -C $dir -f $::MAKEFILE $target OPTS=$opts >& $dir/build.log
     77   }]
     78   if {$rc} {
     79     puts "No good. See $dir/build.log."
     80     return
     81   } else {
     82     puts "Ok"
     83   }
     84 
     85   # Create an empty file "$dir/sqlite3". This is to trick the makefile out
     86   # of trying to build the sqlite shell. The sqlite shell won't build
     87   # with some of the OMIT options (i.e OMIT_COMPLETE).
     88   set sqlite3_dummy $dir/sqlite3
     89   if {$::tcl_platform(platform)=="windows" || $::tcl_platform(platform)=="os2"} {
     90     append sqlite3_dummy ".exe"
     91   }
     92   if {![file exists $sqlite3_dummy]} {
     93     set wr [open $sqlite3_dummy w]
     94     puts $wr "dummy"
     95     close $wr
     96   }
     97 
     98   if {$::SKIP_RUN} {
     99       puts "Skip testing $dir."
    100   } else {
    101     # Run the test suite.
    102     puts -nonewline "Testing $dir..."
    103     flush stdout
    104     set rc [catch {
    105       exec make -C $dir -f $::MAKEFILE test OPTS=$opts >& $dir/test.log
    106     }]
    107     if {$rc} {
    108       puts "No good. See $dir/test.log."
    109     } else {
    110       puts "Ok"
    111     }
    112   }
    113 }
    114 
    115 
    116 # This proc processes the command line options passed to this script.
    117 # Currently the only option supported is "-makefile", default
    118 # "../Makefile.linux-gcc". Set the ::MAKEFILE variable to the value of this
    119 # option.
    120 #
    121 proc process_options {argv} {
    122   if {$::tcl_platform(platform)=="windows" || $::tcl_platform(platform)=="os2"} {
    123     set ::MAKEFILE ./Makefile               ;# Default value
    124   } else {
    125     set ::MAKEFILE ./Makefile.linux-gcc     ;# Default value
    126   }
    127   set ::SKIP_RUN 0                          ;# Default to attempt test
    128 
    129   for {set i 0} {$i < [llength $argv]} {incr i} {
    130     switch -- [lindex $argv $i] {
    131       -makefile {
    132         incr i
    133         set ::MAKEFILE [lindex $argv $i]
    134       }
    135 
    136       -skip_run {
    137         set ::SKIP_RUN 1
    138       }
    139 
    140       default {
    141         if {[info exists ::SYMBOL]} {
    142           puts stderr [string trim $::USAGE_MESSAGE]
    143           exit -1
    144         }
    145         set ::SYMBOL [lindex $argv $i]
    146       }
    147     }
    148     set ::MAKEFILE [file normalize $::MAKEFILE]
    149   }
    150 }
    151 
    152 # Main routine.
    153 #
    154 
    155 proc main {argv} {
    156   # List of SQLITE_OMIT_XXX symbols supported by SQLite.
    157   set ::OMIT_SYMBOLS [list \
    158     SQLITE_OMIT_ALTERTABLE \
    159     SQLITE_OMIT_ANALYZE \
    160     SQLITE_OMIT_ATTACH \
    161     SQLITE_OMIT_AUTHORIZATION \
    162     SQLITE_OMIT_AUTOINCREMENT \
    163     SQLITE_OMIT_AUTOINIT \
    164     SQLITE_OMIT_AUTOMATIC_INDEX \
    165     SQLITE_OMIT_AUTORESET \
    166     SQLITE_OMIT_AUTOVACUUM \
    167     SQLITE_OMIT_BETWEEN_OPTIMIZATION \
    168     SQLITE_OMIT_BLOB_LITERAL \
    169     SQLITE_OMIT_BTREECOUNT \
    170     SQLITE_OMIT_BUILTIN_TEST \
    171     SQLITE_OMIT_CAST \
    172     SQLITE_OMIT_CHECK \
    173     SQLITE_OMIT_COMPILEOPTION_DIAGS \
    174     SQLITE_OMIT_COMPLETE \
    175     SQLITE_OMIT_COMPOUND_SELECT \
    176     SQLITE_OMIT_DATETIME_FUNCS \
    177     SQLITE_OMIT_DECLTYPE \
    178     SQLITE_OMIT_DEPRECATED \
    179     xxxSQLITE_OMIT_DISKIO \
    180     SQLITE_OMIT_EXPLAIN \
    181     SQLITE_OMIT_FLAG_PRAGMAS \
    182     SQLITE_OMIT_FLOATING_POINT \
    183     SQLITE_OMIT_FOREIGN_KEY \
    184     SQLITE_OMIT_GET_TABLE \
    185     SQLITE_OMIT_INCRBLOB \
    186     SQLITE_OMIT_INTEGRITY_CHECK \
    187     SQLITE_OMIT_LIKE_OPTIMIZATION \
    188     SQLITE_OMIT_LOAD_EXTENSION \
    189     SQLITE_OMIT_LOCALTIME \
    190     SQLITE_OMIT_LOOKASIDE \
    191     SQLITE_OMIT_MEMORYDB \
    192     SQLITE_OMIT_OR_OPTIMIZATION \
    193     SQLITE_OMIT_PAGER_PRAGMAS \
    194     SQLITE_OMIT_PRAGMA \
    195     SQLITE_OMIT_PROGRESS_CALLBACK \
    196     SQLITE_OMIT_QUICKBALANCE \
    197     SQLITE_OMIT_REINDEX \
    198     SQLITE_OMIT_SCHEMA_PRAGMAS \
    199     SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS \
    200     SQLITE_OMIT_SHARED_CACHE \
    201     SQLITE_OMIT_SUBQUERY \
    202     SQLITE_OMIT_TCL_VARIABLE \
    203     SQLITE_OMIT_TEMPDB \
    204     SQLITE_OMIT_TRACE \
    205     SQLITE_OMIT_TRIGGER \
    206     SQLITE_OMIT_TRUNCATE_OPTIMIZATION \
    207     SQLITE_OMIT_UNIQUE_ENFORCEMENT \
    208     SQLITE_OMIT_UTF16 \
    209     SQLITE_OMIT_VACUUM \
    210     SQLITE_OMIT_VIEW \
    211     SQLITE_OMIT_VIRTUALTABLE \
    212     SQLITE_OMIT_WAL \
    213     SQLITE_OMIT_WSD \
    214     SQLITE_OMIT_XFER_OPT \
    215   ]
    216 
    217   set ::ENABLE_SYMBOLS [list \
    218     SQLITE_DISABLE_DIRSYNC \
    219     SQLITE_DISABLE_LFS \
    220     SQLITE_ENABLE_ATOMIC_WRITE \
    221     xxxSQLITE_ENABLE_CEROD \
    222     SQLITE_ENABLE_COLUMN_METADATA \
    223     SQLITE_ENABLE_EXPENSIVE_ASSERT \
    224     xxxSQLITE_ENABLE_FTS1 \
    225     xxxSQLITE_ENABLE_FTS2 \
    226     SQLITE_ENABLE_FTS3 \
    227     SQLITE_ENABLE_FTS3_PARENTHESIS \
    228     SQLITE_ENABLE_FTS4 \
    229     xxxSQLITE_ENABLE_ICU \
    230     SQLITE_ENABLE_IOTRACE \
    231     SQLITE_ENABLE_LOAD_EXTENSION \
    232     SQLITE_ENABLE_LOCKING_STYLE \
    233     SQLITE_ENABLE_MEMORY_MANAGEMENT \
    234     SQLITE_ENABLE_MEMSYS3 \
    235     SQLITE_ENABLE_MEMSYS5 \
    236     SQLITE_ENABLE_OVERSIZE_CELL_CHECK \
    237     SQLITE_ENABLE_RTREE \
    238     SQLITE_ENABLE_STAT2 \
    239     SQLITE_ENABLE_UNLOCK_NOTIFY \
    240     SQLITE_ENABLE_UPDATE_DELETE_LIMIT \
    241   ]
    242 
    243   # Process any command line options.
    244   process_options $argv
    245 
    246   if {[info exists ::SYMBOL] } {
    247     set sym $::SYMBOL
    248 
    249     if {[lsearch $::OMIT_SYMBOLS $sym]<0 && [lsearch $::ENABLE_SYMBOLS $sym]<0} {
    250       puts stderr "No such symbol: $sym"
    251       exit -1
    252     }
    253 
    254     set dirname "test_[string range $sym 7 end]"
    255     run_quick_test $dirname $sym
    256   } else {
    257     # First try a test with all OMIT symbols except SQLITE_OMIT_FLOATING_POINT
    258     # and SQLITE_OMIT_PRAGMA defined. The former doesn't work (causes segfaults)
    259     # and the latter is currently incompatible with the test suite (this should
    260     # be fixed, but it will be a lot of work).
    261     set allsyms [list]
    262     foreach s $::OMIT_SYMBOLS {
    263       if {$s!="SQLITE_OMIT_FLOATING_POINT" && $s!="SQLITE_OMIT_PRAGMA"} {
    264         lappend allsyms $s
    265       }
    266     }
    267     run_quick_test test_OMIT_EVERYTHING $allsyms
    268 
    269     # Now try one quick.test with each of the OMIT symbols defined. Included
    270     # are the OMIT_FLOATING_POINT and OMIT_PRAGMA symbols, even though we
    271     # know they will fail. It's good to be reminded of this from time to time.
    272     foreach sym $::OMIT_SYMBOLS {
    273       set dirname "test_[string range $sym 7 end]"
    274       run_quick_test $dirname $sym
    275     }
    276 
    277     # Try the ENABLE/DISABLE symbols one at a time.
    278     # We don't do them all at once since some are conflicting.
    279     foreach sym $::ENABLE_SYMBOLS {
    280       set dirname "test_[string range $sym 7 end]"
    281       run_quick_test $dirname $sym
    282     }
    283   }
    284 }
    285 
    286 main $argv
    287