/ Check-in [cb5f5ebc]
Login

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

Overview
Comment:Fix a case in test_fuzzer.c causing transformations from the wrong ruleset to be applied in some cases.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:cb5f5ebc563b8d3e47bc30b6dbb374bb91efd3ef
User & Date: dan 2012-02-20 19:36:09
Context
2012-02-20
20:03
Change the way the fuzzer (test_fuzzer.c) works so that it loads its configuration from a database table. check-in: 90b7b957 user: dan tags: trunk
19:36
Fix a case in test_fuzzer.c causing transformations from the wrong ruleset to be applied in some cases. check-in: cb5f5ebc user: dan tags: trunk
2012-02-14
18:56
Increase the maximum ruleset id in the fuzzer from 50 to 2^31-1. check-in: 760e009a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_fuzzer.c.

   476    476   ** Advance a fuzzer_stem to its next value.   Return 0 if there are
   477    477   ** no more values that can be generated by this fuzzer_stem.  Return
   478    478   ** -1 on a memory allocation failure.
   479    479   */
   480    480   static int fuzzerAdvance(fuzzer_cursor *pCur, fuzzer_stem *pStem){
   481    481     const fuzzer_rule *pRule;
   482    482     while( (pRule = pStem->pRule)!=0 ){
          483  +    assert( pRule==&pCur->nullRule || pRule->iRuleset==pCur->iRuleset );
   483    484       while( pStem->n < pStem->nBasis - pRule->nFrom ){
   484    485         pStem->n++;
   485    486         if( pRule->nFrom==0
   486    487          || memcmp(&pStem->zBasis[pStem->n], pRule->zFrom, pRule->nFrom)==0
   487    488         ){
   488    489           /* Found a rewrite case.  Make sure it is not a duplicate */
   489    490           int rc = fuzzerSeen(pCur, pStem);
................................................................................
   622    623     pNew = sqlite3_malloc( sizeof(*pNew) + strlen(zWord) + 1 );
   623    624     if( pNew==0 ) return 0;
   624    625     memset(pNew, 0, sizeof(*pNew));
   625    626     pNew->zBasis = (char*)&pNew[1];
   626    627     pNew->nBasis = strlen(zWord);
   627    628     memcpy(pNew->zBasis, zWord, pNew->nBasis+1);
   628    629     pNew->pRule = pCur->pVtab->pRule;
          630  +  while( pNew->pRule && pNew->pRule->iRuleset!=pCur->iRuleset ){
          631  +    pNew->pRule = pNew->pRule->pNext;
          632  +  }
   629    633     pNew->n = -1;
   630    634     pNew->rBaseCost = pNew->rCostX = rBaseCost;
   631    635     h = fuzzerHash(pNew->zBasis);
   632    636     pNew->pHash = pCur->apHash[h];
   633    637     pCur->apHash[h] = pNew;
   634    638     pCur->nStem++;
   635    639     return pNew;

Changes to test/fuzzer1.test.

    60     60       SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=0
    61     61     }
    62     62   } {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100 ebcdo 110 obcde 110 obcda 111 obcdo 210}
    63     63   do_test fuzzer1-1.7 {
    64     64     db eval {
    65     65       SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=1
    66     66     }
    67         -} {abcde 0 axcde 1 axcda 2 abcye 10 abcya 11 axcye 11 axcya 12 abcze 110 abcza 111 axcze 111 axcza 112}
           67  +} {abcde 0 axcde 1 abcye 10 axcye 11 abcze 110 axcze 111}
    68     68   do_test fuzzer1-1.8 {
    69     69     db eval {
    70     70       SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<100
    71     71     }
    72     72   } {abcde 0 abcda 1 ebcde 10 ebcda 11}
    73     73   do_test fuzzer1-1.9 {
    74     74     db eval {
................................................................................
    86     86       SELECT word, distance FROM f1
    87     87       WHERE word MATCH 'abcde' AND distance<=100 AND ruleset=0
    88     88     }
    89     89   } {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100}
    90     90   do_test fuzzer1-1.12 {
    91     91     db eval {
    92     92       SELECT word, distance FROM f1
    93         -     WHERE word MATCH 'abcde' AND distance<12 AND ruleset=1
           93  +     WHERE word MATCH 'abcde' AND distance<11 AND ruleset=1
    94     94     }
    95         -} {abcde 0 axcde 1 axcda 2 abcye 10 abcya 11 axcye 11}
           95  +} {abcde 0 axcde 1 abcye 10}
    96     96   do_test fuzzer1-1.13 {
    97     97     db eval {
    98     98       SELECT word, distance FROM f1
    99         -    WHERE word MATCH 'abcde' AND distance<=12 AND ruleset=1
           99  +    WHERE word MATCH 'abcde' AND distance<=11 AND ruleset=1
   100    100     }
   101         -} {abcde 0 axcde 1 axcda 2 abcye 10 abcya 11 axcye 11 axcya 12}
   102         -
          101  +} {abcde 0 axcde 1 abcye 10 axcye 11}
   103    102   
   104    103   do_test fuzzer1-2.0 {
   105    104     execsql {
   106    105       CREATE VIRTUAL TABLE temp.f2 USING fuzzer;
   107    106       -- costs based on English letter frequencies
   108    107       INSERT INTO f2(cFrom,cTo,cost) VALUES('a','e',24);
   109    108       INSERT INTO f2(cFrom,cTo,cost) VALUES('a','o',47);
................................................................................
  1432   1431       SELECT DISTINCT streetname.n FROM f2, streetname
  1433   1432        WHERE f2.word MATCH 'tayle'
  1434   1433          AND f2.distance<=200
  1435   1434          AND streetname.n>=f2.word AND streetname.n<=(f2.word || x'F7BFBFBF')
  1436   1435     }
  1437   1436   } {{tyler finley} trailer taymouth steelewood tallia tallu talwyn thelema}
  1438   1437   
         1438  +
         1439  +do_execsql_test fuzzer1-3.1 {
         1440  +  CREATE VIRTUAL TABLE temp.f3 USING fuzzer;
         1441  +  CREATE TABLE f3(ruleset, cfrom, cto, cost);
         1442  +  INSERT INTO f3(ruleset, cfrom, cto, cost) VALUES(0, 'x','y', 10);
         1443  +  INSERT INTO f3(ruleset, cfrom, cto, cost) VALUES(1, 'a','b', 10);
         1444  +  SELECT word FROM f3 WHERE word MATCH 'ax'
         1445  +} {ax ay}
  1439   1446   
  1440   1447   finish_test