Merge branch 'prerelease' of github.com:sqlcipher/sqlcipher into prerelease
[sqlcipher.git] / tool / omittest.tcl
blob3351b96b32f3630bc648c8204d047d03e78c3ec2
2 set rcsid {$Id: omittest.tcl,v 1.8 2008/10/13 15:35:09 drh Exp $}
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:
11 <script> ?test-symbol? ?-makefile PATH-TO-MAKEFILE? ?-skip_run?
13 The default value for ::MAKEFILE is "../Makefile.linux.gcc".
15 If -skip_run option is given then only the compile part is attempted.
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.
24 Almost any SQLite makefile (except those generated by configure - see below)
25 should work. The following properties are required:
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.
32 More precisely, the following two invocations must be supported:
34 $::MAKEBIN -f $::MAKEFILE testfixture OPTS="-DSQLITE_OMIT_ALTERTABLE=1"
35 $::MAKEBIN -f $::MAKEFILE test
37 Makefiles generated by the sqlite configure program cannot be used as
38 they do not respect the OPTS variable.
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:
47 # run_quick_test /tmp/testdir {SQLITE_OMIT_TRIGGER SQLITE_OMIT_VIEW}
50 proc run_quick_test {dir omit_symbol_list} {
51 # Compile the value of the OPTS Makefile variable.
52 set opts ""
53 if {$::tcl_platform(platform)=="windows"} {
54 append opts "OPTS += -DSQLITE_OS_WIN=1\n"
55 set target "testfixture.exe"
56 } else {
57 append opts "OPTS += -DSQLITE_OS_UNIX=1\n"
59 foreach sym $omit_symbol_list {
60 append opts "OPTS += -D${sym}=1\n"
63 # Create the directory and do the build. If an error occurs return
64 # early without attempting to run the test suite.
65 file mkdir $dir
66 puts -nonewline "Building $dir..."
67 flush stdout
68 catch {
69 file copy -force ./config.h $dir
70 file copy -force ./libtool $dir
72 set fd [open $::MAKEFILE]
73 set mkfile [read $fd]
74 close $fd
75 regsub {\ninclude} $mkfile "\n$opts\ninclude" mkfile
76 set fd [open $dir/makefile w]
77 puts $fd $mkfile
78 close $fd
80 set rc [catch {
81 exec $::MAKEBIN -C $dir -f makefile clean $::TARGET >& $dir/build.log
83 if {$rc} {
84 puts "No good. See $dir/build.log."
85 return
86 } else {
87 puts "Ok"
90 # Create an empty file "$dir/sqlite3". This is to trick the makefile out
91 # of trying to build the sqlite shell. The sqlite shell won't build
92 # with some of the OMIT options (i.e OMIT_COMPLETE).
93 set sqlite3_dummy $dir/sqlite3
94 if {$::tcl_platform(platform)=="windows"} {
95 append sqlite3_dummy ".exe"
97 if {![file exists $sqlite3_dummy]} {
98 set wr [open $sqlite3_dummy w]
99 puts $wr "dummy"
100 close $wr
103 if {$::SKIP_RUN} {
104 puts "Skip testing $dir."
105 } else {
106 # Run the test suite.
107 puts -nonewline "Testing $dir..."
108 flush stdout
109 set rc [catch {
110 exec $::MAKEBIN -C $dir -f makefile test >& $dir/test.log
112 if {$rc} {
113 puts "No good. See $dir/test.log."
114 } else {
115 puts "Ok"
121 # This proc processes the command line options passed to this script.
122 # Currently the only option supported is "-makefile", default
123 # "../Makefile.linux-gcc". Set the ::MAKEFILE variable to the value of this
124 # option.
126 proc process_options {argv} {
127 set ::MAKEBIN make ;# Default value
128 if {$::tcl_platform(platform)=="windows"} {
129 set ::MAKEFILE ./Makefile ;# Default value on Windows
130 } else {
131 set ::MAKEFILE ./Makefile.linux-gcc ;# Default value
133 set ::SKIP_RUN 0 ;# Default to attempt test
134 set ::TARGET testfixture ;# Default thing to build
136 for {set i 0} {$i < [llength $argv]} {incr i} {
137 switch -- [lindex $argv $i] {
138 -makefile {
139 incr i
140 set ::MAKEFILE [lindex $argv $i]
143 -nmake {
144 set ::MAKEBIN nmake
145 set ::MAKEFILE ./Makefile.msc
148 -target {
149 incr i
150 set ::TARGET [lindex $argv $i]
153 -skip_run {
154 set ::SKIP_RUN 1
157 default {
158 if {[info exists ::SYMBOL]} {
159 puts stderr [string trim $::USAGE_MESSAGE]
160 exit -1
162 set ::SYMBOL [lindex $argv $i]
165 set ::MAKEFILE [file normalize $::MAKEFILE]
169 # Main routine.
172 proc main {argv} {
173 # List of SQLITE_OMIT_XXX symbols supported by SQLite.
174 set ::OMIT_SYMBOLS [list \
175 SQLITE_OMIT_ALTERTABLE \
176 SQLITE_OMIT_ANALYZE \
177 SQLITE_OMIT_ATTACH \
178 SQLITE_OMIT_AUTHORIZATION \
179 SQLITE_OMIT_AUTOINCREMENT \
180 SQLITE_OMIT_AUTOINIT \
181 SQLITE_OMIT_AUTOMATIC_INDEX \
182 SQLITE_OMIT_AUTORESET \
183 SQLITE_OMIT_AUTOVACUUM \
184 SQLITE_OMIT_BETWEEN_OPTIMIZATION \
185 SQLITE_OMIT_BLOB_LITERAL \
186 SQLITE_OMIT_BTREECOUNT \
187 SQLITE_OMIT_BUILTIN_TEST \
188 SQLITE_OMIT_CAST \
189 SQLITE_OMIT_CHECK \
190 SQLITE_OMIT_COMPILEOPTION_DIAGS \
191 SQLITE_OMIT_COMPLETE \
192 SQLITE_OMIT_COMPOUND_SELECT \
193 SQLITE_OMIT_DATETIME_FUNCS \
194 SQLITE_OMIT_DECLTYPE \
195 SQLITE_OMIT_DEPRECATED \
196 SQLITE_OMIT_EXPLAIN \
197 SQLITE_OMIT_FLAG_PRAGMAS \
198 SQLITE_OMIT_FLOATING_POINT \
199 SQLITE_OMIT_FOREIGN_KEY \
200 SQLITE_OMIT_GET_TABLE \
201 SQLITE_OMIT_INCRBLOB \
202 SQLITE_OMIT_INTEGRITY_CHECK \
203 SQLITE_OMIT_LIKE_OPTIMIZATION \
204 SQLITE_OMIT_LOAD_EXTENSION \
205 SQLITE_OMIT_LOCALTIME \
206 SQLITE_OMIT_LOOKASIDE \
207 SQLITE_OMIT_MEMORYDB \
208 SQLITE_OMIT_OR_OPTIMIZATION \
209 SQLITE_OMIT_PAGER_PRAGMAS \
210 SQLITE_OMIT_PRAGMA \
211 SQLITE_OMIT_PROGRESS_CALLBACK \
212 SQLITE_OMIT_QUICKBALANCE \
213 SQLITE_OMIT_REINDEX \
214 SQLITE_OMIT_SCHEMA_PRAGMAS \
215 SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS \
216 SQLITE_OMIT_SHARED_CACHE \
217 SQLITE_OMIT_SUBQUERY \
218 SQLITE_OMIT_TCL_VARIABLE \
219 SQLITE_OMIT_TEMPDB \
220 SQLITE_OMIT_TRACE \
221 SQLITE_OMIT_TRIGGER \
222 SQLITE_OMIT_TRUNCATE_OPTIMIZATION \
223 SQLITE_OMIT_UNIQUE_ENFORCEMENT \
224 SQLITE_OMIT_UTF16 \
225 SQLITE_OMIT_VACUUM \
226 SQLITE_OMIT_VIEW \
227 SQLITE_OMIT_VIRTUALTABLE \
228 SQLITE_OMIT_WAL \
229 SQLITE_OMIT_WSD \
230 SQLITE_OMIT_XFER_OPT \
233 set ::ENABLE_SYMBOLS [list \
234 SQLITE_DISABLE_DIRSYNC \
235 SQLITE_DISABLE_LFS \
236 SQLITE_ENABLE_ATOMIC_WRITE \
237 SQLITE_ENABLE_COLUMN_METADATA \
238 SQLITE_ENABLE_EXPENSIVE_ASSERT \
239 SQLITE_ENABLE_FTS3 \
240 SQLITE_ENABLE_FTS3_PARENTHESIS \
241 SQLITE_ENABLE_FTS4 \
242 SQLITE_ENABLE_IOTRACE \
243 SQLITE_ENABLE_LOAD_EXTENSION \
244 SQLITE_ENABLE_LOCKING_STYLE \
245 SQLITE_ENABLE_MEMORY_MANAGEMENT \
246 SQLITE_ENABLE_MEMSYS3 \
247 SQLITE_ENABLE_MEMSYS5 \
248 SQLITE_ENABLE_OVERSIZE_CELL_CHECK \
249 SQLITE_ENABLE_RTREE \
250 SQLITE_ENABLE_STAT3 \
251 SQLITE_ENABLE_UNLOCK_NOTIFY \
252 SQLITE_ENABLE_UPDATE_DELETE_LIMIT \
255 # Process any command line options.
256 process_options $argv
258 if {[info exists ::SYMBOL] } {
259 set sym $::SYMBOL
261 if {[lsearch $::OMIT_SYMBOLS $sym]<0 && [lsearch $::ENABLE_SYMBOLS $sym]<0} {
262 puts stderr "No such symbol: $sym"
263 exit -1
266 set dirname "test_[regsub -nocase {^x*SQLITE_} $sym {}]"
267 run_quick_test $dirname $sym
268 } else {
269 # First try a test with all OMIT symbols except SQLITE_OMIT_FLOATING_POINT
270 # and SQLITE_OMIT_PRAGMA defined. The former doesn't work (causes segfaults)
271 # and the latter is currently incompatible with the test suite (this should
272 # be fixed, but it will be a lot of work).
273 set allsyms [list]
274 foreach s $::OMIT_SYMBOLS {
275 if {$s!="SQLITE_OMIT_FLOATING_POINT" && $s!="SQLITE_OMIT_PRAGMA"} {
276 lappend allsyms $s
279 run_quick_test test_OMIT_EVERYTHING $allsyms
281 # Now try one quick.test with each of the OMIT symbols defined. Included
282 # are the OMIT_FLOATING_POINT and OMIT_PRAGMA symbols, even though we
283 # know they will fail. It's good to be reminded of this from time to time.
284 foreach sym $::OMIT_SYMBOLS {
285 set dirname "test_[regsub -nocase {^x*SQLITE_} $sym {}]"
286 run_quick_test $dirname $sym
289 # Try the ENABLE/DISABLE symbols one at a time.
290 # We don't do them all at once since some are conflicting.
291 foreach sym $::ENABLE_SYMBOLS {
292 set dirname "test_[regsub -nocase {^x*SQLITE_} $sym {}]"
293 run_quick_test $dirname $sym
298 main $argv