From: Ben Pfaff Date: Wed, 4 Mar 2009 21:20:47 +0000 (-0800) Subject: classifier: Test classifier_for_each_match(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8150d6c4b13921bbe49c11e6ce75dd0730b6e2b1;p=openvswitch classifier: Test classifier_for_each_match(). --- diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 5c5fe90c..c4d7f57c 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -217,6 +217,25 @@ tcls_lookup(const struct tcls *cls, const flow_t *flow, int include) } return NULL; } + +static void +tcls_delete_matches(struct tcls *cls, + const struct cls_rule *target, + int include) +{ + size_t i; + + for (i = 0; i < cls->n_rules; ) { + struct test_rule *pos = cls->rules[i]; + uint32_t wildcards = pos->cls_rule.wc.wildcards; + if (include & (wildcards ? CLS_INC_WILD : CLS_INC_EXACT) + && match(target, &pos->cls_rule.flow)) { + tcls_remove(cls, pos); + } else { + i++; + } + } +} #ifdef WORDS_BIGENDIAN #define HTONL(VALUE) ((uint32_t) (VALUE)) @@ -923,6 +942,21 @@ test_many_rules_in_different_tables(void) compare_classifiers(&cls, &tcls); } + while (!classifier_is_empty(&cls)) { + struct test_rule *rule = xmemdup(tcls.rules[rand() % tcls.n_rules], + sizeof(struct test_rule)); + int include = rand() % 2 ? CLS_INC_WILD : CLS_INC_EXACT; + include |= (rule->cls_rule.wc.wildcards + ? CLS_INC_WILD : CLS_INC_EXACT); + classifier_for_each_match(&cls, &rule->cls_rule, include, + free_rule, &cls); + tcls_delete_matches(&tcls, &rule->cls_rule, include); + compare_classifiers(&cls, &tcls); + free(rule); + } + putchar('.'); + fflush(stdout); + destroy_classifier(&cls); tcls_destroy(&tcls); }