diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/alter.test | 9 | ||||
-rw-r--r-- | test/analyze3.test | 30 | ||||
-rw-r--r-- | test/corruptC.test | 2 | ||||
-rw-r--r-- | test/count.test | 5 | ||||
-rw-r--r-- | test/e_reindex.test | 8 | ||||
-rw-r--r-- | test/expr.test | 8 | ||||
-rw-r--r-- | test/fkey1.test | 30 | ||||
-rw-r--r-- | test/fkey2.test | 19 | ||||
-rw-r--r-- | test/fts3aa.test | 22 | ||||
-rw-r--r-- | test/fts3expr5.test | 48 | ||||
-rw-r--r-- | test/fts4check.test | 30 | ||||
-rw-r--r-- | test/fuzzdata1.txt | bin | 0 -> 2966109 bytes | |||
-rw-r--r-- | test/index7.test | 4 | ||||
-rw-r--r-- | test/insert2.test | 20 | ||||
-rw-r--r-- | test/insert4.test | 5 | ||||
-rw-r--r-- | test/malloc.test | 21 | ||||
-rw-r--r-- | test/misc1.test | 40 | ||||
-rw-r--r-- | test/misc5.test | 18 | ||||
-rw-r--r-- | test/mkfuzzdata1.tcl | 112 | ||||
-rw-r--r-- | test/pragma.test | 18 | ||||
-rw-r--r-- | test/releasetest.tcl | 23 | ||||
-rw-r--r-- | test/resolver01.test | 10 | ||||
-rw-r--r-- | test/select1.test | 8 | ||||
-rw-r--r-- | test/select4.test | 23 | ||||
-rw-r--r-- | test/statfault.test | 45 | ||||
-rw-r--r-- | test/subquery.test | 10 | ||||
-rw-r--r-- | test/table.test | 19 | ||||
-rw-r--r-- | test/trace2.test | 2 | ||||
-rw-r--r-- | test/triggerC.test | 49 | ||||
-rw-r--r-- | test/vtab1.test | 37 | ||||
-rw-r--r-- | test/vtabA.test | 23 |
31 files changed, 684 insertions, 14 deletions
diff --git a/test/alter.test b/test/alter.test index ddf169882..ebfe97a76 100644 --- a/test/alter.test +++ b/test/alter.test @@ -912,5 +912,14 @@ do_execsql_test alter-17.9 { do_execsql_test alter-17.10 { SELECT sqlite_rename_parent(NULL,'abc','xyz'); } {{}} +do_execsql_test alter-17.11 { + SELECT sqlite_rename_parent('create references ''','abc','xyz'); +} {{create references '}} +do_execsql_test alter-17.12 { + SELECT sqlite_rename_parent('create references "abc"123" ','abc','xyz'); +} {{create references "xyz"123" }} +do_execsql_test alter-17.13 { + SELECT sqlite_rename_parent("references '''",'abc','xyz'); +} {{references '''}} finish_test diff --git a/test/analyze3.test b/test/analyze3.test index d22387dcc..d61d21a94 100644 --- a/test/analyze3.test +++ b/test/analyze3.test @@ -16,6 +16,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix analyze3 ifcapable !stat4&&!stat3 { finish_test @@ -46,6 +47,9 @@ ifcapable !stat4&&!stat3 { # # analyze3-6.*: Test that the problem fixed by commit [127a5b776d] is fixed. # +# analyze3-7.*: Test that some memory leaks discovered by fuzz testing +# have been fixed. +# proc getvar {varname} { uplevel #0 set $varname } db function var getvar @@ -662,4 +666,30 @@ do_eqp_test analyze3-6-2 { SELECT * FROM t1 WHERE a = 5 AND b > 'w' AND c = 13; } {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (c=?)}} +#----------------------------------------------------------------------------- +# 2015-04-20. +# Memory leak in sqlite3Stat4ProbeFree(). (Discovered while fuzzing.) +# +do_execsql_test analyze-7.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + INSERT INTO t1 VALUES(1,1,'0000'); + CREATE INDEX t0b ON t1(b); + ANALYZE; + SELECT c FROM t1 WHERE b=3 AND a BETWEEN 30 AND hex(1); +} {} + +# At one point duplicate stat1 entries were causing a memory leak. +# +reset_db +do_execsql_test 7.2 { + CREATE TABLE t1(a,b,c); + CREATE INDEX t1a ON t1(a); + ANALYZE; + SELECT * FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1a','12000'); + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1a','12000'); + ANALYZE sqlite_master; +} + finish_test diff --git a/test/corruptC.test b/test/corruptC.test index adf6f44c4..a7f93c46d 100644 --- a/test/corruptC.test +++ b/test/corruptC.test @@ -292,7 +292,7 @@ do_test corruptC-2.15 { hexio_write test.db 986 b9 sqlite3 db test.db catchsql {SELECT count(*) FROM sqlite_master;} -} {1 {malformed database schema (t1i1) - no such table: main.t1}} +} {1 {database disk image is malformed}} # # Now test for a series of quasi-random seeds. diff --git a/test/count.test b/test/count.test index 3461e49c1..862b62ab1 100644 --- a/test/count.test +++ b/test/count.test @@ -191,4 +191,9 @@ do_execsql_test count-5.1 { SELECT count(*) FROM t5; } {1} +do_catchsql_test count-6.1 { + CREATE TABLE t6(x); + SELECT count(DISTINCT) FROM t6 GROUP BY x; +} {1 {DISTINCT aggregates must have exactly one argument}} + finish_test diff --git a/test/e_reindex.test b/test/e_reindex.test index 4b86787a0..fa66aa7a1 100644 --- a/test/e_reindex.test +++ b/test/e_reindex.test @@ -48,8 +48,11 @@ do_execsql_test e_reindex-1.1 { INSERT INTO t1 VALUES(1, 2); INSERT INTO t1 VALUES(3, 4); INSERT INTO t1 VALUES(5, 6); + + CREATE TABLE saved(a,b,c,d,e); + INSERT INTO saved SELECT * FROM sqlite_master WHERE type = 'index'; PRAGMA writable_schema = 1; - UPDATE sqlite_master SET sql = '-- ' || sql WHERE type = 'index'; + DELETE FROM sqlite_master WHERE type = 'index'; } {} db close @@ -59,7 +62,8 @@ do_execsql_test e_reindex-1.2 { INSERT INTO t1 VALUES(7, 8); INSERT INTO t1 VALUES(9, 10); PRAGMA writable_schema = 1; - UPDATE sqlite_master SET sql = substr(sql, 4) WHERE type = 'index'; + INSERT INTO sqlite_master SELECT * FROM saved; + DROP TABLE saved; } {} db close diff --git a/test/expr.test b/test/expr.test index 8d913d2a1..7d7b8ce5a 100644 --- a/test/expr.test +++ b/test/expr.test @@ -943,5 +943,13 @@ do_realnum_test expr-13.7 { } } {9.22337203685478e+18} +do_execsql_test expr-13.8 { + SELECT "" <= ''; +} {1} +do_execsql_test expr-13.9 { + SELECT '' <= ""; +} {1} + + finish_test diff --git a/test/fkey1.test b/test/fkey1.test index 90a4c4440..0bd4939eb 100644 --- a/test/fkey1.test +++ b/test/fkey1.test @@ -121,4 +121,34 @@ do_test fkey1-3.5 { sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 } {0 0 0} +# Stress the dequoting logic. The first test is not so bad. +do_execsql_test fkey1-4.0 { + PRAGMA foreign_keys=ON; + CREATE TABLE "xx1"("xx2" TEXT PRIMARY KEY, "xx3" TEXT); + INSERT INTO "xx1"("xx2","xx3") VALUES('abc','def'); + CREATE TABLE "xx4"("xx5" TEXT REFERENCES "xx1" ON DELETE CASCADE); + INSERT INTO "xx4"("xx5") VALUES('abc'); + INSERT INTO "xx1"("xx2","xx3") VALUES('uvw','xyz'); + SELECT 1, "xx5" FROM "xx4"; + DELETE FROM "xx1"; + SELECT 2, "xx5" FROM "xx4"; +} {1 abc} + +# This case is identical to the previous except the "xx" in each name +# is changed to a single escaped double-quote character. +do_execsql_test fkey1-4.1 { + PRAGMA foreign_keys=ON; + CREATE TABLE """1"("""2" TEXT PRIMARY KEY, """3" TEXT); + INSERT INTO """1"("""2","""3") VALUES('abc','def'); + CREATE TABLE """4"("""5" TEXT REFERENCES """1" ON DELETE CASCADE); + INSERT INTO """4"("""5") VALUES('abc'); + INSERT INTO """1"("""2","""3") VALUES('uvw','xyz'); + SELECT 1, """5" FROM """4"; + DELETE FROM """1"; + SELECT 2, """5" FROM """4"; +} {1 abc} +do_execsql_test fkey1-4.2 { + PRAGMA table_info="""1"; +} {0 {"2} TEXT 0 {} 1 1 {"3} TEXT 0 {} 0} + finish_test diff --git a/test/fkey2.test b/test/fkey2.test index 8b2871e5a..aec75ed69 100644 --- a/test/fkey2.test +++ b/test/fkey2.test @@ -676,6 +676,11 @@ do_test fkey2-9.2.3 { SELECT * FROM cc; } } {{} A {} {} B {} 3 A 2 3 B 2} +do_execsql_test fkey2-9.3.0 { + CREATE TABLE t3(x PRIMARY KEY REFERENCES t3 ON DELETE SET NULL); + INSERT INTO t3(x) VALUES(12345); + DROP TABLE t3; +} {} #------------------------------------------------------------------------- # The following tests, fkey2-10.*, test "foreign key mismatch" and @@ -2014,4 +2019,18 @@ do_test fkey2-ce7c13.1.6 { } } {1 {FOREIGN KEY constraint failed}} +# 2015-04-16: Foreign key errors propagate back up to the parser. +# +do_test fkey2-20150416-100 { + db close + sqlite3 db :memory: + catchsql { + PRAGMA foreign_keys=1; + CREATE TABLE t1(x PRIMARY KEY); + CREATE TABLE t(y REFERENCES t0(x)ON DELETE SET DEFAULT); + CREATE TABLE t0(y REFERENCES t1 ON DELETE SET NULL); + REPLACE INTO t1 SELECT(0);CREATE TABLE t2(x);CREATE TABLE t3; + } +} {1 {foreign key mismatch - "t" referencing "t0"}} + finish_test diff --git a/test/fts3aa.test b/test/fts3aa.test index 6ff384a0d..08d825dd1 100644 --- a/test/fts3aa.test +++ b/test/fts3aa.test @@ -16,6 +16,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix fts3aa # If SQLITE_ENABLE_FTS3 is defined, omit this file. ifcapable !fts3 { @@ -221,5 +222,26 @@ do_catchsql_test fts3aa-7.5 { CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple); } {1 {unrecognized parameter: tokenize=simple}} +do_execsql_test 8.0 { + CREATE VIRTUAL TABLE t0 USING fts4(order=desc); + BEGIN; + INSERT INTO t0(rowid, content) VALUES(1, 'abc'); + UPDATE t0 SET docid=5 WHERE docid=1; + INSERT INTO t0(rowid, content) VALUES(6, 'abc'); +} +do_execsql_test 8.1 { + SELECT docid FROM t0 WHERE t0 MATCH 'abc'; +} {6 5} +do_execsql_test 8.2 { + SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; +} {} +do_execsql_test 8.3 { COMMIT } +do_execsql_test 8.4 { + SELECT docid FROM t0 WHERE t0 MATCH 'abc'; +} {6 5} +do_execsql_test 8.5 { + SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; +} {} + finish_test diff --git a/test/fts3expr5.test b/test/fts3expr5.test new file mode 100644 index 000000000..1e0985108 --- /dev/null +++ b/test/fts3expr5.test @@ -0,0 +1,48 @@ +# 2006 September 9 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3expr5 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#------------------------------------------------------------------------- +# Various forms of empty phrase expressions. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t0 USING fts3(x); + SELECT rowid FROM t0 WHERE x MATCH ''; +} {} +do_execsql_test 1.1 { + SELECT rowid FROM t0 WHERE x MATCH '""'; +} {} +do_execsql_test 1.2 { + SELECT rowid FROM t0 WHERE x MATCH '"" ""'; +} {} +do_execsql_test 1.3 { + SELECT rowid FROM t0 WHERE x MATCH '"" OR ""'; +} {} +do_execsql_test 1.4 { + SELECT rowid FROM t0 WHERE x MATCH '"" NOT ""'; +} {} +do_execsql_test 1.5 { + SELECT rowid FROM t0 WHERE x MATCH '""""'; +} {} + +finish_test diff --git a/test/fts4check.test b/test/fts4check.test index c98886ccc..4ded05387 100644 --- a/test/fts4check.test +++ b/test/fts4check.test @@ -179,5 +179,35 @@ do_test 4.2 { } {1 {database disk image is malformed}} reset_db +#-------------------------------------------------------------------------- +# Test case 5.* +# +# Test that the integrity-check works if there is uncommitted data. +# +do_execsql_test 5.0 { + BEGIN; + CREATE VIRTUAL TABLE t5 USING fts4(a, prefix="1,2,3"); + INSERT INTO t5 VALUES('And down by Kosiosko, where the reed-banks sweep'); + INSERT INTO t5 VALUES('and sway, and the rolling plains are wide, the'); + INSERT INTO t5 VALUES('man from snowy river is a household name today,'); + INSERT INTO t5 VALUES('and the stockmen tell the story of his ride'); +} + +do_execsql_test 5.1 { + INSERT INTO t5(t5) VALUES('integrity-check'); +} {} + +do_catchsql_test 5.2 { + INSERT INTO t5_content VALUES(5, 'his hardy mountain pony'); + INSERT INTO t5(t5) VALUES('integrity-check'); +} {1 {database disk image is malformed}} + +do_execsql_test 5.3 ROLLBACK + +do_execsql_test 5.4 { + CREATE VIRTUAL TABLE t5 USING fts4(a, prefix="1,2,3"); + INSERT INTO t5(t5) VALUES('integrity-check'); +} {} + finish_test diff --git a/test/fuzzdata1.txt b/test/fuzzdata1.txt Binary files differnew file mode 100644 index 000000000..6d3b20c13 --- /dev/null +++ b/test/fuzzdata1.txt diff --git a/test/index7.test b/test/index7.test index 9a2444a87..557fe2132 100644 --- a/test/index7.test +++ b/test/index7.test @@ -311,5 +311,9 @@ do_eqp_test index7-6.4 { } { 0 0 0 {SEARCH TABLE t4 USING INDEX i4 (c=?)} } +do_catchsql_test index7-6.5 { + CREATE INDEX t5a ON t5(a) WHERE a=#1; +} {1 {near "#1": syntax error}} + finish_test diff --git a/test/insert2.test b/test/insert2.test index 6876d538a..977fbc584 100644 --- a/test/insert2.test +++ b/test/insert2.test @@ -16,6 +16,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix insert2 # Create some tables with data that we can select against # @@ -275,4 +276,23 @@ ifcapable subquery { } {1 2 1 3 1 4} } +do_execsql_test 6.0 { + CREATE TABLE t5(a, b, c DEFAULT 'c', d); +} +do_execsql_test 6.1 { + INSERT INTO t5(a) SELECT 456 UNION ALL SELECT 123 ORDER BY 1; + SELECT * FROM t5 ORDER BY rowid; +} {123 {} c {} 456 {} c {}} + +ifcapable fts3 { + do_execsql_test 6.2 { + CREATE VIRTUAL TABLE t0 USING fts4(a); + } + do_execsql_test 6.3 { + INSERT INTO t0 SELECT 0 UNION SELECT 0 AS 'x' ORDER BY x; + SELECT * FROM t0; + } {0} +} + + finish_test diff --git a/test/insert4.test b/test/insert4.test index 889d5e780..3eece87e5 100644 --- a/test/insert4.test +++ b/test/insert4.test @@ -560,5 +560,10 @@ do_test insert4-8.25 { } } {1 3} +do_catchsql_test insert4-9.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(5 COLLATE xyzzy) UNION SELECT 0; +} {1 {no such collation sequence: xyzzy}} finish_test diff --git a/test/malloc.test b/test/malloc.test index 86145672a..dbf4699b2 100644 --- a/test/malloc.test +++ b/test/malloc.test @@ -923,6 +923,27 @@ do_faultsim_test 41.2 -faults oom* -body { faultsim_integrity_check } +reset_db +do_execsql_test 42.0 { + CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z); + CREATE TABLE t2(a, b); + CREATE VIEW a002 AS SELECT *, sum(b) AS m FROM t2 GROUP BY a; +} +faultsim_save_and_close +do_faultsim_test 42 -faults oom-tran* -prep { + faultsim_restore_and_reopen + execsql { SELECT * FROM sqlite_master } +} -body { + execsql { + SELECT t1.z, a002.m + FROM t1 JOIN a002 ON t1.y=a002.m + WHERE t1.x IN (1,2,3); + } +} -test { + faultsim_test_result {0 {}} +} + + # Ensure that no file descriptors were leaked. do_test malloc-99.X { catch {db close} diff --git a/test/misc1.test b/test/misc1.test index 1b98eafc6..7ae50e4fe 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -644,4 +644,44 @@ do_execsql_test misc1-22.1 { SELECT ""+3 FROM (SELECT ""+5); } {3} +# 2015-04-19: NULL pointer dereference on a corrupt schema +# +db close +sqlite3 db :memory: +do_execsql_test misc1-23.1 { + CREATE TABLE t1(x); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE table t(d CHECK(T(#0)'; + BEGIN; + CREATE TABLE t2(y); + ROLLBACK; + DROP TABLE IF EXISTS t3; +} {} + +# 2015-04-19: Faulty assert() statement +# +db close +database_may_be_corrupt +sqlite3 db :memory: +do_catchsql_test misc1-23.2 { + CREATE TABLE t1(x UNIQUE); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE TABLE IF not EXISTS t(c)'; + BEGIN; + CREATE TABLE t2(x); + ROLLBACK; + DROP TABLE F; +} {1 {no such table: F}} +db close +sqlite3 db :memory: +do_catchsql_test misc1-23.3 { + CREATE TABLE t1(x UNIQUE); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE table y(a TEXT, a TEXT)'; + BEGIN; + CREATE TABLE t2(y); + ROLLBACK; + DROP TABLE IF EXISTS t; +} {0 {}} + finish_test diff --git a/test/misc5.test b/test/misc5.test index 14ba44ead..30176b808 100644 --- a/test/misc5.test +++ b/test/misc5.test @@ -583,6 +583,24 @@ do_test misc5-7.1 { catchsql $sql } {1 {parser stack overflow}} +# Parser stack overflow is silently ignored when it occurs while parsing the +# schema and PRAGMA writable_schema is turned on. +# +do_test misc5-7.2 { + sqlite3 db2 :memory: + catchsql { + CREATE TABLE t1(x UNIQUE); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE table t(o CHECK(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((;VALUES(o)'; + BEGIN; + CREATE TABLE t2(y); + ROLLBACK; + DROP TABLE IF EXISTS D; + } db2 +} {0 {}} +db2 close + + # Ticket #1911 # ifcapable compound { diff --git a/test/mkfuzzdata1.tcl b/test/mkfuzzdata1.tcl new file mode 100644 index 000000000..766757b91 --- /dev/null +++ b/test/mkfuzzdata1.tcl @@ -0,0 +1,112 @@ +#!/usr/bin/tclsh +# +# Run this script in order to rebuild the fuzzdata1.txt file containing +# fuzzer data for the fuzzershell utility that is create by afl-fuzz. +# +# This script gathers all of the test cases identified by afl-fuzz and +# runs afl-cmin and afl-tmin over them all to try to generate a mimimum +# set of tests that cover all observed behavior. +# +# Options: +# +# --afl-bin DIR1 DIR1 contains the AFL binaries +# --fuzzershell PATH Full pathname of instrumented fuzzershell +# --afl-data DIR3 DIR3 is the "-o" directory from afl-fuzz +# -o FILE Write results into FILE +# +set AFLBIN {} +set FUZZERSHELL {} +set AFLDATA {} +set OUTFILE {} + +proc usage {} { + puts stderr "Usage: $::argv0 --afl-bin DIR --fuzzershell PATH\ + --afl-data DIR -o FILE" + exit 1 +} +proc cmdlineerr {msg} { + puts stderr $msg + usage +} + +for {set i 0} {$i<[llength $argv]} {incr i} { + set x [lindex $argv $i] + if {[string index $x 0]!="-"} {cmdlineerr "illegal argument: $x"} + set x [string trimleft $x -] + incr i + if {$i>=[llength $argv]} {cmdlineerr "no argument on --$x"} + set a [lindex $argv $i] + switch -- $x { + afl-bin {set AFLBIN $a} + afl-data {set AFLDATA $a} + fuzzershell {set FUZZERSHELL $a} + o {set OUTFILE $a} + default {cmdlineerr "unknown option: --$x"} + } +} +proc checkarg {varname option} { + set val [set ::$varname] + if {$val==""} {cmdlineerr "required option missing: --$option"} +} +checkarg AFLBIN afl-bin +checkarg AFLDATA afl-data +checkarg FUZZERSHELL fuzzershell +checkarg OUTFILE o +proc checkexec {x} { + if {![file exec $x]} {cmdlineerr "cannot find $x"} +} +checkexec $AFLBIN/afl-cmin +checkexec $AFLBIN/afl-tmin +checkexec $FUZZERSHELL +proc checkdir {x} { + if {![file isdir $x]} {cmdlineerr "no such directory: $x"} +} +checkdir $AFLDATA/queue + +proc progress {msg} { + puts "******** $msg" + flush stdout +} +progress "mkdir tmp1 tmp2" +file mkdir tmp1 tmp2 +progress "copying test cases from $AFLDATA into tmp1..." +set n 0 +foreach file [glob -nocomplain $AFLDATA/queue/id:*] { + incr n + file copy $file tmp1/$n +} +foreach file [glob -nocomplain $AFLDATA/crash*/id:*] { + incr n + file copy $file tmp1/$n +} +progress "total $n files copied." +progress "running: $AFLBIN/afl-cmin -i tmp1 -o tmp2 $FUZZERSHELL" +exec $AFLBIN/afl-cmin -i tmp1 -o tmp2 $FUZZERSHELL >&@ stdout +progress "afl-cmin complete." +# +# Experiments show that running afl-tmin is too slow for this application. +# And it doesn't really make the test cases that much smaller. So let's +# just skip it. +# +# foreach file [glob tmp2/*] { +# progress "$AFLBIN/afl-tmin -i $file -o tmp3/[file tail $file] $FUZZERSHELL" +# exec $AFLBIN/afl-tmin -i $file -o tmp3/[file tail $file] \ +# $FUZZERSHELL >&@ stdout +# } +progress "generating final output into $OUTFILE" +set out [open $OUTFILE wb] +puts $out "# Test data for use with fuzzershell. Automatically +# generated using $argv0. This file contains binary data +#" +set n 0 +foreach file [glob tmp2/*] { + incr n + puts -nonewline $out "/****<$n>****/" + set in [open $file rb] + puts -nonewline $out [read $in] + close $in +} +close $out +progress "done. $n test cases written to $OUTFILE" +progress "clean-up..." +file delete -force tmp1 tmp2 diff --git a/test/pragma.test b/test/pragma.test index e8a53f442..587a03c8a 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -219,6 +219,24 @@ do_test pragma-1.14 { PRAGMA synchronous; } } {2} +do_test pragma-1.14.1 { + execsql { + PRAGMA synchronous=4; + PRAGMA synchronous; + } +} {0} +do_test pragma-1.14.2 { + execsql { + PRAGMA synchronous=3; + PRAGMA synchronous; + } +} {0} +do_test pragma-1.14.3 { + execsql { + PRAGMA synchronous=10; + PRAGMA synchronous; + } +} {2} } ;# ifcapable pager_pragmas # Test turning "flag" pragmas on and off. diff --git a/test/releasetest.tcl b/test/releasetest.tcl index 95cacf590..a429d83ca 100644 --- a/test/releasetest.tcl +++ b/test/releasetest.tcl @@ -18,6 +18,7 @@ optional) are: --buildonly (Just build testfixture - do not run) --dryrun (Print what would have happened) --info (Show diagnostic info) + --with-tcl=DIR (Use TCL build at DIR) The default value for --srcdir is the parent of the directory holding this script. @@ -110,6 +111,13 @@ array set ::Configs [strip_comments { -DSQLITE_ENABLE_STAT4 -DSQLITE_MAX_ATTACHED=125 } + "Fast-One" { + -O6 + -DSQLITE_ENABLE_FTS4=1 + -DSQLITE_ENABLE_RTREE=1 + -DSQLITE_ENABLE_STAT4 + -DSQLITE_MAX_ATTACHED=125 + } "Device-One" { -O2 -DSQLITE_DEBUG=1 @@ -199,6 +207,8 @@ array set ::Configs [strip_comments { Fail2 {-O0} Fail3 {-O0} Fail4 {-O0} + FuzzFail1 {-O0} + FuzzFail2 {-O0} }] array set ::Platforms [strip_comments { @@ -214,6 +224,7 @@ array set ::Platforms [strip_comments { "No-lookaside" test "Devkit" test "Sanitize" {QUICKTEST_OMIT=func4.test,nan.test test} + "Fast-One" fuzzoomtest "Valgrind" valgrindtest "Default" "threadtest fulltest" "Device-One" fulltest @@ -255,6 +266,8 @@ array set ::Platforms [strip_comments { Fail2 "TEST_FAILURE=2 valgrindtest" Fail3 "TEST_FAILURE=3 valgrindtest" Fail4 "TEST_FAILURE=4 test" + FuzzFail1 "TEST_FAILURE=5 test" + FuzzFail2 "TEST_FAILURE=5 valgrindtest" } }] @@ -351,7 +364,7 @@ proc run_test_suite {name testtarget config} { set cflags [expr {$::MSVC ? "-Zi" : "-g"}] set opts "" set title ${name}($testtarget) - set configOpts "" + set configOpts $::WITHTCL regsub -all {#[^\n]*\n} $config \n config foreach arg $config { @@ -482,6 +495,7 @@ proc process_options {argv} { set ::DRYRUN 0 set ::EXEC exec set ::TRACE 0 + set ::WITHTCL {} set config {} set platform $::tcl_platform(os)-$::tcl_platform(machine) @@ -556,6 +570,10 @@ proc process_options {argv} { } } + -with-tcl=* { + set ::WITHTCL -$x + } + -D* - -O* - -enable-* - @@ -643,10 +661,11 @@ proc main {argv} { # it and run veryquick.test. If it did not include the SQLITE_DEBUG option # add it and run veryquick.test. if {$target!="checksymbols" && $target!="valgrindtest" - && !$::BUILDONLY && $::QUICK<2} { + && $target!="fuzzoomtest" && !$::BUILDONLY && $::QUICK<2} { set debug_idx [lsearch -glob $config_options -DSQLITE_DEBUG*] set xtarget $target regsub -all {fulltest[a-z]*} $xtarget test xtarget + regsub -all {fuzzoomtest} $xtarget fuzztest xtarget if {$debug_idx < 0} { incr NTEST append config_options " -DSQLITE_DEBUG=1" diff --git a/test/resolver01.test b/test/resolver01.test index 7d95a2132..59bb3c021 100644 --- a/test/resolver01.test +++ b/test/resolver01.test @@ -11,10 +11,12 @@ # # This file tests features of the name resolver (the component that # figures out what identifiers in the SQL statement refer to) that -# were fixed by ticket [2500cdb9be] +# were fixed by ticket [2500cdb9be]. # # See also tickets [1c69be2daf] and [f617ea3125] from 2013-08-14. # +# Also a fuzzer-discovered problem on 2015-04-23. +# set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -201,6 +203,12 @@ do_execsql_test resolver01-6.3 { GROUP BY lower(name); } {1 {} 1 {}} +do_execsql_test resolver01-7.1 { + SELECT 2 AS x WHERE (SELECT x AS y WHERE 3>y); +} {2} +do_execsql_test resolver01-7.2 { + SELECT 2 AS x WHERE (SELECT x AS y WHERE 1>y); +} {} diff --git a/test/select1.test b/test/select1.test index 875c87c84..4d6c07f2d 100644 --- a/test/select1.test +++ b/test/select1.test @@ -307,6 +307,9 @@ do_test select1-4.4 { set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1)}} msg] lappend v $msg } {1 {misuse of aggregate: min()}} +do_catchsql_test select1-4.5 { + INSERT INTO test1(f1) SELECT f1 FROM test1 ORDER BY min(f1); +} {1 {misuse of aggregate: min()}} # The restriction not allowing constants in the ORDER BY clause # has been removed. See ticket #1768 @@ -1072,5 +1075,10 @@ if {[db one {PRAGMA locking_mode}]=="normal"} { do_test select1-16.1 { catchsql {SELECT 1 FROM (SELECT *)} } {1 {no tables specified}} + +# 2015-04-17: assertion fix. +do_catchsql_test select1-16.2 { + SELECT 1 FROM sqlite_master LIMIT 1,#1; +} {1 {near "#1": syntax error}} finish_test diff --git a/test/select4.test b/test/select4.test index 2f3ddbe96..42c61d92a 100644 --- a/test/select4.test +++ b/test/select4.test @@ -118,6 +118,10 @@ do_test select4-1.3 { }} msg] lappend v $msg } {1 {ORDER BY clause should come after UNION ALL not before}} +do_catchsql_test select4-1.4 { + SELECT (VALUES(0) INTERSECT SELECT(0) UNION SELECT(0) ORDER BY 1 UNION + SELECT 0 UNION SELECT 0 ORDER BY 1); +} {1 {ORDER BY clause should come after UNION not before}} # Union operator # @@ -148,6 +152,12 @@ do_test select4-2.3 { }} msg] lappend v $msg } {1 {ORDER BY clause should come after UNION not before}} +do_test select4-2.4 { + set v [catch {execsql { + SELECT 0 ORDER BY (SELECT 0) UNION SELECT 0; + }} msg] + lappend v $msg +} {1 {ORDER BY clause should come after UNION not before}} # Except operator # @@ -874,6 +884,17 @@ do_execsql_test select4-14.10 { do_execsql_test select4-14.11 { SELECT (SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) } {1} - +do_execsql_test select4-14.12 { + VALUES(1) UNION VALUES(2); +} {1 2} +do_execsql_test select4-14.13 { + VALUES(1),(2),(3) EXCEPT VALUES(2); +} {1 3} +do_execsql_test select4-14.14 { + VALUES(1),(2),(3) EXCEPT VALUES(1),(3); +} {2} +do_execsql_test select4-14.15 { + SELECT * FROM (SELECT 123), (SELECT 456) ON likely(0 OR 1) OR 0; +} {123 456} finish_test diff --git a/test/statfault.test b/test/statfault.test new file mode 100644 index 000000000..ce79e328d --- /dev/null +++ b/test/statfault.test @@ -0,0 +1,45 @@ +# 2015 April 28 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set testprefix statfault + +ifcapable !vtab||!compound { + finish_test + return +} + +register_dbstat_vtab db +do_execsql_test statfault-1 { + CREATE TABLE t1(a, b UNIQUE); + INSERT INTO t1 VALUES(1, randomblob(500)); + INSERT INTO t1 VALUES(randomblob(500), 1); + INSERT INTO t1 VALUES(2, randomblob(250)); + INSERT INTO t1 VALUES(randomblob(250), 2); + CREATE VIRTUAL TABLE sss USING dbstat; +} {} +faultsim_save_and_close + +do_faultsim_test 1 -faults * -prep { + faultsim_restore_and_reopen + register_dbstat_vtab db + execsql { SELECT 1 FROM sqlite_master LIMIT 1 } +} -body { + execsql { SELECT count(*) FROM sss } +} -test { + faultsim_test_result {0 8} +} + + +finish_test diff --git a/test/subquery.test b/test/subquery.test index 93c3f28dd..06facbbae 100644 --- a/test/subquery.test +++ b/test/subquery.test @@ -584,4 +584,14 @@ do_test subquery-7.11 { } {30303} } ;############# Disabled +# 2015-04-21. +# Verify that a memory leak in the table column type and collation analysis +# is plugged. +# +do_execsql_test subquery-8.1 { + CREATE TABLE t8(a TEXT, b INT); + SELECT (SELECT 0 FROM (SELECT * FROM t1)) AS x WHERE x; + SELECT (SELECT 0 FROM (SELECT * FROM (SELECT 0))) AS x WHERE x; +} {} + finish_test diff --git a/test/table.test b/test/table.test index 69f105aa6..faa9712bf 100644 --- a/test/table.test +++ b/test/table.test @@ -272,6 +272,25 @@ do_test table-5.2.1 { } } {} +do_test table-5.2.2 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + CREATE TABLE t0(a,b); + CREATE INDEX t ON t0(a); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE TABLE a.b(a UNIQUE'; + BEGIN; + CREATE TABLE t1(x); + ROLLBACK; + DROP TABLE IF EXISTS t99; + } +} {} +db close +forcedelete test.db +sqlite3 db test.db + # Make sure an EXPLAIN does not really create a new table # do_test table-5.3 { diff --git a/test/trace2.test b/test/trace2.test index 562c70c53..a3f0aeb87 100644 --- a/test/trace2.test +++ b/test/trace2.test @@ -143,7 +143,7 @@ ifcapable fts3 { INSERT INTO x1(x1) VALUES('optimize'); } { "INSERT INTO x1(x1) VALUES('optimize');" - "-- SELECT DISTINCT level / (1024 * ?) FROM 'main'.'x1_segdir'" + "-- SELECT ? UNION SELECT level / (1024 * ?) FROM 'main'.'x1_segdir'" "-- SELECT idx, start_block, leaves_end_block, end_block, root FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?ORDER BY level DESC, idx ASC" "-- SELECT max(level) FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?" "-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)" diff --git a/test/triggerC.test b/test/triggerC.test index 14cc0f01d..3e47521fd 100644 --- a/test/triggerC.test +++ b/test/triggerC.test @@ -12,6 +12,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix triggerC ifcapable {!trigger} { finish_test return @@ -993,4 +994,52 @@ reset_db optimization_control db factor-constants 0 do_execsql_test triggerC-14.2 $SQL {1 2 3} +#------------------------------------------------------------------------- +# Check that table names used by trigger programs are dequoted exactly +# once. +# +do_execsql_test 15.1.1 { + PRAGMA recursive_triggers = 1; + CREATE TABLE node( + id int not null primary key, + pid int not null default 0 references node, + key varchar not null, + path varchar default '', + unique(pid, key) + ); + CREATE TRIGGER node_delete_referencing AFTER DELETE ON "node" + BEGIN + DELETE FROM "node" WHERE pid = old."id"; + END; +} +do_execsql_test 15.1.2 { + INSERT INTO node(id, pid, key) VALUES(9, 0, 'test'); + INSERT INTO node(id, pid, key) VALUES(90, 9, 'test1'); + INSERT INTO node(id, pid, key) VALUES(900, 90, 'test2'); + DELETE FROM node WHERE id=9; + SELECT * FROM node; +} + +do_execsql_test 15.2.1 { + CREATE TABLE x1 (x); + + CREATE TABLE x2 (a, b); + CREATE TABLE '"x2"'(a, b); + + INSERT INTO x2 VALUES(1, 2); + INSERT INTO x2 VALUES(3, 4); + INSERT INTO '"x2"' SELECT * FROM x2; + + CREATE TRIGGER x1ai AFTER INSERT ON x1 BEGIN + INSERT INTO """x2""" VALUES('x', 'y'); + DELETE FROM """x2""" WHERE a=1; + UPDATE """x2""" SET b = 11 WHERE a = 3; + END; + + INSERT INTO x1 VALUES('go!'); +} + +do_execsql_test 15.2.2 { SELECT * FROM x2; } {1 2 3 4} +do_execsql_test 15.2.3 { SELECT * FROM """x2"""; } {3 11 x y} + finish_test diff --git a/test/vtab1.test b/test/vtab1.test index dfc989a64..c0cf3e4e8 100644 --- a/test/vtab1.test +++ b/test/vtab1.test @@ -1491,4 +1491,41 @@ do_test 23.3.1 { } {1 {database table is locked}} do_execsql_test 23.3.2 { SELECT * FROM t1e } {1 2 3 4} +#------------------------------------------------------------------------- +# At one point SQL like this: +# +# SAVEPOINT xyz; -- Opens SQL transaction +# INSERT INTO vtab -- Write to virtual table +# ROLLBACK TO xyz; +# RELEASE xyz; +# +# was not invoking the xRollbackTo() callback for the ROLLBACK TO +# operation. Which meant that virtual tables like FTS3 would incorrectly +# commit the results of the INSERT as part of the "RELEASE xyz" command. +# +# The following tests check that this has been fixed. +# +ifcapable fts3 { + do_execsql_test 24.0 { + CREATE VIRTUAL TABLE t4 USING fts3(); + SAVEPOINT a; + INSERT INTO t4 VALUES('a b c'); + ROLLBACK TO a; + RELEASE a; + SELECT * FROM t4; + } {} + + do_execsql_test 24.1 { SELECT * FROM t4 WHERE t4 MATCH 'b' } {} + do_execsql_test 24.2 { INSERT INTO t4(t4) VALUES('integrity-check') } {} + + do_execsql_test 24.3 { + SAVEPOINT a; + CREATE VIRTUAL TABLE t5 USING fts3(); + SAVEPOINT b; + ROLLBACK TO a; + SAVEPOINT c; + RELEASE a; + } +} + finish_test diff --git a/test/vtabA.test b/test/vtabA.test index 928cc2b70..eddaa70d1 100644 --- a/test/vtabA.test +++ b/test/vtabA.test @@ -74,28 +74,39 @@ do_test vtabA-1.6 { SELECT * FROM t1e; } } {{value a} {value c}} +do_execsql_test vtabA-1.7 { + DELETE FROM t1e; + INSERT INTO t1e SELECT 'abc','def'; +} {} +do_execsql_test vtabA-1.8 { + INSERT INTO t1e VALUES('ghi','jkl'),('mno','pqr'),('stu','vwx'); +} {} +do_execsql_test vtabA-1.9 { + SELECT a,b,c, '|' FROM t1e ORDER BY 1; +} {abc {} def | ghi {} jkl | mno {} pqr | stu {} vwx |} + # Test that the expansion of a '*' expression in the result set of # a SELECT does not include the hidden column. # -do_test vtabA-1.7 { +do_test vtabA-1.20 { execsql { INSERT INTO t1e SELECT * FROM t1e; } } {} -do_test vtabA-1.8 { +do_test vtabA-1.21 { execsql { - SELECT * FROM t1e; + SELECT * FROM t1e ORDER BY 1; } -} {{value a} {value c} {value a} {value c}} +} {abc def abc def ghi jkl ghi jkl mno pqr mno pqr stu vwx stu vwx} # Test that the declaration type of the hidden column does not include # the token "HIDDEN". # -do_test vtabA-1.9 { +do_test vtabA-1.22 { get_decltype t1e b } {VARCHAR} -do_test vtabA-1.10 { +do_test vtabA-1.23 { get_collist t1e } {a c} |