Commit 3759770f authored by Nils Goroll's avatar Nils Goroll

fix and improve dcs_test

- when missing to hit the tested entry and the returned entry
  contains negative matches, add these to the test string

- improve output
parent 7ab410e6
......@@ -61,16 +61,21 @@ main (int argc, char *argv[]) {
static void
test_p_diff (const char *label, const int i, const char *testkey, const int r) {
if (testkey && *testkey && testkey != dcs_entry[i].key)
printf("%s\tteststring\t\t\t%s\n", label, testkey);
else
printf("%s", label);
if (dcs_entry[i].type != dcs_entry[r].type) {
printf("%s\ti: %8d %s %s\ntype diff\tr: %8d %s %s\n",
label,
dcs_entry[i].id, testkey, dcs_type[dcs_entry[i].type],
dcs_entry[r].id, dcs_entry[r].key, dcs_type[dcs_entry[r].type]);
printf("\ti: %8d (id %8d)\t%s\t%s\n"
"type\tr: %8d (id %8d)\t%s\t%s\n",
i, dcs_entry[i].id, dcs_entry[i].key, dcs_type[dcs_entry[i].type],
r, dcs_entry[r].id, dcs_entry[r].key, dcs_type[dcs_entry[r].type]);
} else {
printf("%s\ti: %8d %s\n\t\tr: %8d %s\n",
label,
dcs_entry[i].id, testkey,
dcs_entry[r].id, dcs_entry[r].key);
printf("\ti: %8d (id %8d)\t%s\n"
"\tr: %8d (id %8d)\t%s\n",
i, dcs_entry[i].id, dcs_entry[i].key,
r, dcs_entry[r].id, dcs_entry[r].key);
}
}
......@@ -94,6 +99,8 @@ fixup_out (FILE *f_remove, FILE *f_reorder, const int i, const int r) {
}
}
#define KEYLIM 256
int
test (const char *fixup_remove_name, const char *fixup_reorder_name) {
char mem[DCS_MATCH_MEM_SZ];
......@@ -118,15 +125,75 @@ test (const char *fixup_remove_name, const char *fixup_reorder_name) {
}
for (i = NB_E_SPECIAL_LIMIT; i < DCS_ENTRY_COUNT; i++) {
if (dcs_entry[i].active == 0)
continue;
if (dcs_matchstate_init.matchmask[i] == 0) {
/* only positive matches */
char nkey[KEYLIM];
int pr = -1;
const char *prk = NULL;
nkey[0] = '\0';
r = dcs_match(dcs_entry[i].key, mem, DCS_MATCH_MEM_SZ);
if (i != r) {
test_p_diff("miss\t", i, dcs_entry[i].key, r);
fixup_out(f_remove, f_reorder, i, r);
errcount++;
while (i != r) {
const char *ntok, *ntoke, *p;
/*
* check if the entry we have hit contains
* negative tokens and, if yes, retry with all
* of them (in succession)
*/
ntok = NULL;
/*
* end the recursion when we get an earlier
* match than previous
*/
if (pr != -1 && r < pr) {
test_p_diff("miss r", i, NULL, r);
fixup_out(f_remove, f_reorder, i, r);
errcount++;
break;
}
if (pr != r) {
pr = r;
prk = dcs_entry[r].key;
if (prk[0] == '!')
ntok = prk++;
}
if (ntok == NULL &&
(ntok = strstr(prk++, "*!")) != NULL)
ntok += 1;
if (ntok == NULL) {
test_p_diff("miss", i, NULL, r);
fixup_out(f_remove, f_reorder, i, r);
errcount++;
break;
}
assert(strlen(dcs_entry[r].key) < KEYLIM);
/* append the negative token from entry r to entry i */
if (nkey[0] == '\0')
strcpy(nkey, dcs_entry[i].key);
if ((ntoke = strchr(ntok, '*')) != NULL) {
assert((strlen(nkey) + (ntoke - ntok)) < KEYLIM);
strncat(nkey, ntok, (ntoke - ntok));
} else {
assert((strlen(nkey) + strlen(ntok)) < KEYLIM);
strcat(nkey, ntok);
}
r = dcs_match(nkey, mem, DCS_MATCH_MEM_SZ);
}
} else {
#define KEYLIM 256
const char *poskey = dcs_entry[i].key;
const char *negkey = dcs_entry[i].key;
char p1[KEYLIM], p2[KEYLIM];
......@@ -176,14 +243,14 @@ test (const char *fixup_remove_name, const char *fixup_reorder_name) {
r = dcs_match(poskey, mem, DCS_MATCH_MEM_SZ);
if (i != r) {
test_p_diff("miss n-p", i, poskey, r);
test_p_diff("miss np", i, poskey, r);
fixup_out(f_remove, f_reorder, i, r);
errcount++;
}
r = dcs_match(negkey, mem, DCS_MATCH_MEM_SZ);
if (r == i) {
test_p_diff("miss n-n", i, negkey, r);
test_p_diff("miss nn", i, negkey, r);
fixup_out(f_remove, f_reorder, i, r);
errcount++;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment