/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/test_fuzzer.c.

476
477
478
479
480
481
482

483
484
485
486
487
488
489
...
622
623
624
625
626
627
628



629
630
631
632
633
634
635
** Advance a fuzzer_stem to its next value.   Return 0 if there are
** no more values that can be generated by this fuzzer_stem.  Return
** -1 on a memory allocation failure.
*/
static int fuzzerAdvance(fuzzer_cursor *pCur, fuzzer_stem *pStem){
  const fuzzer_rule *pRule;
  while( (pRule = pStem->pRule)!=0 ){

    while( pStem->n < pStem->nBasis - pRule->nFrom ){
      pStem->n++;
      if( pRule->nFrom==0
       || memcmp(&pStem->zBasis[pStem->n], pRule->zFrom, pRule->nFrom)==0
      ){
        /* Found a rewrite case.  Make sure it is not a duplicate */
        int rc = fuzzerSeen(pCur, pStem);
................................................................................
  pNew = sqlite3_malloc( sizeof(*pNew) + strlen(zWord) + 1 );
  if( pNew==0 ) return 0;
  memset(pNew, 0, sizeof(*pNew));
  pNew->zBasis = (char*)&pNew[1];
  pNew->nBasis = strlen(zWord);
  memcpy(pNew->zBasis, zWord, pNew->nBasis+1);
  pNew->pRule = pCur->pVtab->pRule;



  pNew->n = -1;
  pNew->rBaseCost = pNew->rCostX = rBaseCost;
  h = fuzzerHash(pNew->zBasis);
  pNew->pHash = pCur->apHash[h];
  pCur->apHash[h] = pNew;
  pCur->nStem++;
  return pNew;







>







 







>
>
>







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

Changes to test/fuzzer1.test.

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
....
1432
1433
1434
1435
1436
1437
1438
1439








1440
    SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=0
  }
} {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100 ebcdo 110 obcde 110 obcda 111 obcdo 210}
do_test fuzzer1-1.7 {
  db eval {
    SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=1
  }
} {abcde 0 axcde 1 axcda 2 abcye 10 abcya 11 axcye 11 axcya 12 abcze 110 abcza 111 axcze 111 axcza 112}
do_test fuzzer1-1.8 {
  db eval {
    SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<100
  }
} {abcde 0 abcda 1 ebcde 10 ebcda 11}
do_test fuzzer1-1.9 {
  db eval {
................................................................................
    SELECT word, distance FROM f1
    WHERE word MATCH 'abcde' AND distance<=100 AND ruleset=0
  }
} {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100}
do_test fuzzer1-1.12 {
  db eval {
    SELECT word, distance FROM f1
     WHERE word MATCH 'abcde' AND distance<12 AND ruleset=1
  }
} {abcde 0 axcde 1 axcda 2 abcye 10 abcya 11 axcye 11}
do_test fuzzer1-1.13 {
  db eval {
    SELECT word, distance FROM f1
    WHERE word MATCH 'abcde' AND distance<=12 AND ruleset=1
  }
} {abcde 0 axcde 1 axcda 2 abcye 10 abcya 11 axcye 11 axcya 12}


do_test fuzzer1-2.0 {
  execsql {
    CREATE VIRTUAL TABLE temp.f2 USING fuzzer;
    -- costs based on English letter frequencies
    INSERT INTO f2(cFrom,cTo,cost) VALUES('a','e',24);
    INSERT INTO f2(cFrom,cTo,cost) VALUES('a','o',47);
................................................................................
    SELECT DISTINCT streetname.n FROM f2, streetname
     WHERE f2.word MATCH 'tayle'
       AND f2.distance<=200
       AND streetname.n>=f2.word AND streetname.n<=(f2.word || x'F7BFBFBF')
  }
} {{tyler finley} trailer taymouth steelewood tallia tallu talwyn thelema}










finish_test







|







 







|

|



|

|
<







 








>
>
>
>
>
>
>
>

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
....
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
    SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=0
  }
} {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100 ebcdo 110 obcde 110 obcda 111 obcdo 210}
do_test fuzzer1-1.7 {
  db eval {
    SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=1
  }
} {abcde 0 axcde 1 abcye 10 axcye 11 abcze 110 axcze 111}
do_test fuzzer1-1.8 {
  db eval {
    SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<100
  }
} {abcde 0 abcda 1 ebcde 10 ebcda 11}
do_test fuzzer1-1.9 {
  db eval {
................................................................................
    SELECT word, distance FROM f1
    WHERE word MATCH 'abcde' AND distance<=100 AND ruleset=0
  }
} {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100}
do_test fuzzer1-1.12 {
  db eval {
    SELECT word, distance FROM f1
     WHERE word MATCH 'abcde' AND distance<11 AND ruleset=1
  }
} {abcde 0 axcde 1 abcye 10}
do_test fuzzer1-1.13 {
  db eval {
    SELECT word, distance FROM f1
    WHERE word MATCH 'abcde' AND distance<=11 AND ruleset=1
  }
} {abcde 0 axcde 1 abcye 10 axcye 11}


do_test fuzzer1-2.0 {
  execsql {
    CREATE VIRTUAL TABLE temp.f2 USING fuzzer;
    -- costs based on English letter frequencies
    INSERT INTO f2(cFrom,cTo,cost) VALUES('a','e',24);
    INSERT INTO f2(cFrom,cTo,cost) VALUES('a','o',47);
................................................................................
    SELECT DISTINCT streetname.n FROM f2, streetname
     WHERE f2.word MATCH 'tayle'
       AND f2.distance<=200
       AND streetname.n>=f2.word AND streetname.n<=(f2.word || x'F7BFBFBF')
  }
} {{tyler finley} trailer taymouth steelewood tallia tallu talwyn thelema}


do_execsql_test fuzzer1-3.1 {
  CREATE VIRTUAL TABLE temp.f3 USING fuzzer;
  CREATE TABLE f3(ruleset, cfrom, cto, cost);
  INSERT INTO f3(ruleset, cfrom, cto, cost) VALUES(0, 'x','y', 10);
  INSERT INTO f3(ruleset, cfrom, cto, cost) VALUES(1, 'a','b', 10);
  SELECT word FROM f3 WHERE word MATCH 'ax'
} {ax ay}

finish_test