X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-classifier.c;h=18dee86f927707251ecd201ecbef9dba9487c8c4;hb=a6ca7c672f6d5aaf24111d3414ea132ec36b40d6;hp=79ca29c45d078048af82d2f9c43a9d66e7ee7ca1;hpb=296e07ace0ff2d5819ce760d6018ba82d14aa2a8;p=sliver-openvswitch.git diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 79ca29c45..18dee86f9 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -95,6 +95,15 @@ test_rule_from_cls_rule(const struct cls_rule *rule) return rule ? CONTAINER_OF(rule, struct test_rule, cls_rule) : NULL; } +static void +test_rule_destroy(struct test_rule *rule) +{ + if (rule) { + cls_rule_destroy(&rule->cls_rule); + free(rule); + } +} + static struct test_rule *make_rule(int wc_fields, unsigned int priority, int value_pat); static void free_rule(struct test_rule *); @@ -122,7 +131,7 @@ tcls_destroy(struct tcls *tcls) size_t i; for (i = 0; i < tcls->n_rules; i++) { - free(tcls->rules[i]); + test_rule_destroy(tcls->rules[i]); } free(tcls->rules); } @@ -172,9 +181,11 @@ tcls_remove(struct tcls *cls, const struct test_rule *rule) for (i = 0; i < cls->n_rules; i++) { struct test_rule *pos = cls->rules[i]; if (pos == rule) { - free(pos); + test_rule_destroy(pos); + memmove(&cls->rules[i], &cls->rules[i + 1], sizeof *cls->rules * (cls->n_rules - i - 1)); + cls->n_rules--; return; } @@ -452,6 +463,8 @@ check_tables(const struct classifier *cls, HMAP_FOR_EACH (table, hmap_node, &cls->tables) { const struct cls_rule *head; + unsigned int max_priority = 0; + unsigned int max_count = 0; assert(!hmap_is_empty(&table->rules)); @@ -460,15 +473,26 @@ check_tables(const struct classifier *cls, unsigned int prev_priority = UINT_MAX; const struct cls_rule *rule; + if (head->priority > max_priority) { + max_priority = head->priority; + max_count = 1; + } else if (head->priority == max_priority) { + ++max_count; + } + found_rules++; LIST_FOR_EACH (rule, list, &head->list) { assert(rule->priority < prev_priority); + assert(rule->priority <= table->max_priority); + prev_priority = rule->priority; found_rules++; found_dups++; assert(classifier_find_rule_exactly(cls, rule) == rule); } } + assert(table->max_priority == max_priority); + assert(table->max_count == max_count); } assert(found_tables == hmap_count(&cls->tables)); @@ -1221,6 +1245,8 @@ test_minimask_has_extra(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) minimask_destroy(&minimask); } + + minimask_destroy(&minicatchall); } static void @@ -1260,6 +1286,8 @@ test_minimask_combine(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) minimask_destroy(&minimask); minimask_destroy(&minimask2); } + + minimask_destroy(&minicatchall); } static const struct command commands[] = {