/ Check-in [8b77d395]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Further fuzzer test cases. Fix a case in the fuzzer where an error code was being dropped.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8b77d3953f082e6fa42e42fe903ea9eddf99dd91
User & Date: dan 2012-02-21 14:11:12
Context
2012-02-21
18:00
Prevent the fuzzer from ever returning a string longer than 100 bytes. check-in: 969095ca user: dan tags: trunk
14:11
Further fuzzer test cases. Fix a case in the fuzzer where an error code was being dropped. check-in: 8b77d395 user: dan tags: trunk
10:36
Add further test cases and minor fixes for the fuzzer. check-in: 583dde93 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_fuzzer.c.

   528    528           rc = SQLITE_NOMEM;
   529    529         }else{
   530    530           rc = fuzzerLoadRules(db, pNew, zDb, zTab, pzErr);
   531    531           sqlite3_free(zTab);
   532    532         }
   533    533   
   534    534         if( rc==SQLITE_OK ){
   535         -        sqlite3_declare_vtab(db, "CREATE TABLE x(word, distance, ruleset)");
   536         -      }else{
          535  +        rc = sqlite3_declare_vtab(db, "CREATE TABLE x(word,distance,ruleset)");
          536  +      }
          537  +      if( rc!=SQLITE_OK ){
   537    538           fuzzerDisconnect((sqlite3_vtab *)pNew);
   538    539           pNew = 0;
   539    540         }
   540    541       }
   541    542     }
   542    543   
   543    544     *ppVtab = (sqlite3_vtab *)pNew;

Changes to test/fuzzer1.test.

  1691   1691     SELECT word FROM x1 WHERE word MATCH 'xx' LIMIT 10;
  1692   1692   } {xx hw hx hy hz ia ib ic id ie}
  1693   1693   do_execsql_test 6.2.2 {
  1694   1694     SELECT cTo FROM x1_rules WHERE cFrom='xx' 
  1695   1695     ORDER BY cost asc, rowid asc LIMIT 9;
  1696   1696   } {hw hx hy hz ia ib ic id ie}
  1697   1697   
  1698         -
  1699   1698   #-------------------------------------------------------------------------
  1700   1699   # Test using different types of quotes with CREATE VIRTUAL TABLE 
  1701   1700   # arguments.
  1702   1701   #
  1703   1702   do_execsql_test 7.1 {
  1704   1703     CREATE TABLE [x2 "rules] (a, b, c, d);
  1705   1704     INSERT INTO [x2 "rules] VALUES(0, 'a', 'b', 5);
................................................................................
  1712   1711   } {
  1713   1712     do_execsql_test 7.2.$tn.1 { DROP TABLE IF EXISTS x2 }
  1714   1713     do_execsql_test 7.2.$tn.2 $sql
  1715   1714     do_execsql_test 7.2.$tn.3 { 
  1716   1715       SELECT word FROM x2 WHERE word MATCH 'aaa' 
  1717   1716     } {aaa baa aba aab bab abb bba bbb}
  1718   1717   }
         1718  +
         1719  +#-------------------------------------------------------------------------
         1720  +# Test using a fuzzer table in different contexts.
         1721  +#
         1722  +do_execsql_test 8.1 {
         1723  +  CREATE TABLE x3_rules(rule_set, cFrom, cTo, cost);
         1724  +  INSERT INTO x3_rules VALUES(2, 'a', 'x', 10);
         1725  +  INSERT INTO x3_rules VALUES(2, 'a', 'y',  9);
         1726  +  INSERT INTO x3_rules VALUES(2, 'a', 'z',  8);
         1727  +  CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules);
         1728  +}
         1729  +
         1730  +do_execsql_test 8.2.1 {
         1731  +  SELECT cFrom, cTo, word 
         1732  +    FROM x3_rules CROSS JOIN x3 
         1733  +    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
         1734  +} {a x x a y y a z z}
         1735  +
         1736  +do_execsql_test 8.2.2 {
         1737  +  SELECT cFrom, cTo, word 
         1738  +    FROM x3 CROSS JOIN x3_rules
         1739  +    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
         1740  +} {a z z a y y a x x}
         1741  +
         1742  +do_execsql_test 8.2.3 {
         1743  +  SELECT cFrom, cTo, word 
         1744  +    FROM x3_rules, x3 
         1745  +    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
         1746  +} {a z z a y y a x x}
         1747  +
         1748  +do_execsql_test 8.2.4 {
         1749  +  SELECT cFrom, cTo, word 
         1750  +    FROM x3, x3_rules
         1751  +    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
         1752  +} {a z z a y y a x x}
         1753  +
         1754  +do_execsql_test 8.2.5 {
         1755  +  CREATE INDEX i1 ON x3_rules(cost);
         1756  +  SELECT cFrom, cTo, word 
         1757  +    FROM x3_rules, x3 
         1758  +    WHERE word MATCH 'a' AND cost=distance AND ruleset=2;
         1759  +} {a z z a y y a x x}
         1760  +
         1761  +do_execsql_test 8.2.5 {
         1762  +  SELECT word FROM x3_rules, x3 WHERE word MATCH x3_rules.cFrom AND ruleset=2;
         1763  +} {a z y x a z y x a z y x}
         1764  +
         1765  +do_execsql_test 8.2.6 {
         1766  +  SELECT word FROM x3_rules, x3 
         1767  +  WHERE word MATCH x3_rules.cFrom 
         1768  +    AND ruleset=2 
         1769  +    AND x3_rules.cost=8;
         1770  +} {a z y x}
         1771  +
         1772  +do_execsql_test 8.2.7 {
         1773  +  CREATE TABLE t1(a, b);
         1774  +  CREATE INDEX i2 ON t1(b);
         1775  +  SELECT word, distance FROM x3, t1 
         1776  +    WHERE x3.word MATCH t1.a AND ruleset=2 AND distance=t1.b;
         1777  +} {}
         1778  +
         1779  +do_execsql_test 8.2.8 {
         1780  +  INSERT INTO x3_rules VALUES(1, 'a', 't',  5);
         1781  +  INSERT INTO x3_rules VALUES(1, 'a', 'u',  4);
         1782  +  INSERT INTO x3_rules VALUES(1, 'a', 'v',  3);
         1783  +  DROP TABLE x3;
         1784  +  CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules);
         1785  +  SELECT * FROM x3_rules;
         1786  +} {
         1787  +  2 a x 10 
         1788  +  2 a y 9 
         1789  +  2 a z 8 
         1790  +  1 a t 5 
         1791  +  1 a u 4 
         1792  +  1 a v 3
         1793  +}
         1794  +
         1795  +do_catchsql_test 8.2.9 {
         1796  +  SELECT word FROM x3 WHERE ruleset=2 AND word MATCH 'a' AND WORD MATCH 'b';
         1797  +} {1 {unable to use function MATCH in the requested context}}
         1798  +
         1799  +do_execsql_test 8.2.10 {
         1800  +  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a'
         1801  +} {a v u t}
         1802  +
         1803  +# The term "ruleset<=1" is not handled by the fuzzer module. Instead, it
         1804  +# is handled by SQLite, which assumes that all rows have a NULL value in
         1805  +# the ruleset column. Since NULL<=1 is never true, this query returns
         1806  +# no rows.
         1807  +do_execsql_test 8.2.11 {
         1808  +  SELECT word FROM x3 WHERE ruleset<=1 AND word MATCH 'a'
         1809  +} {}
         1810  +
         1811  +do_execsql_test 8.2.12 {
         1812  +  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance ASC;
         1813  +} {a v u t}
         1814  +
         1815  +do_execsql_test 8.2.13 {
         1816  +  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance DESC;
         1817  +} {t u v a}
         1818  +
         1819  +do_execsql_test 8.2.13 {
         1820  +  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word ASC;
         1821  +} {a t u v}
         1822  +
         1823  +do_execsql_test 8.2.14 {
         1824  +  SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word DESC;
         1825  +} {v u t a}
         1826  +
  1719   1827   
  1720   1828   finish_test
  1721   1829   

Added test/fuzzerfault.test.

            1  +# 2012 February 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  +# This file implements regression tests for TCL interface to the
           12  +# SQLite library. 
           13  +#
           14  +
           15  +set testdir [file dirname $argv0]
           16  +source $testdir/tester.tcl
           17  +ifcapable !vtab { finish_test ; return }
           18  +set ::testprefix fuzzerfault
           19  +
           20  +register_fuzzer_module db
           21  +
           22  +do_test 1-pre1 {
           23  +  execsql {
           24  +    CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost);
           25  +    INSERT INTO x1_rules VALUES(0, 'a', 'b', 1);
           26  +    INSERT INTO x1_rules VALUES(0, 'a', 'c', 2);
           27  +    INSERT INTO x1_rules VALUES(0, 'a', 'd', 3);
           28  +  }
           29  +  faultsim_save_and_close
           30  +} {}
           31  +
           32  +do_faultsim_test 1 -faults oom-t* -prep {
           33  +  faultsim_restore_and_reopen
           34  +  register_fuzzer_module db
           35  +} -body {
           36  +  execsql { 
           37  +    CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules);
           38  +    SELECT word FROM x1 WHERE word MATCH 'xax';
           39  +  }
           40  +} -test {
           41  +  faultsim_test_result {0 {xax xbx xcx xdx}}               \
           42  +                       {1 {vtable constructor failed: x1}}
           43  +}
           44  +
           45  +
           46  +
           47  +finish_test