-test_two_rules_in_one_table(void)
-{
- int table, rel_pri, wcf_pat;
-
- /* Skip tables 0 and CLS_F_IDX_EXACT because they have one bucket. */
- for (table = 1; table < CLS_N_FIELDS; table++) {
- for (rel_pri = -1; rel_pri <= +1; rel_pri++) {
- for (wcf_pat = 0; wcf_pat < 5; wcf_pat++) {
- struct test_rule *rule1, *tcls_rule1;
- struct test_rule *rule2, *tcls_rule2;
- struct classifier cls;
- struct tcls tcls;
- unsigned int pri1, pri2;
- int wcf1, wcf2;
- int value_mask, value_pat1, value_pat2;
- int i;
-
- /* We can use identical priorities in this test because the
- * classifier always chooses the rule added later for
- * equal-priority rules that fall into the same table. */
- pri1 = table * 257 + 50;
- pri2 = pri1 + rel_pri;
-
- if (wcf_pat & 4) {
- wcf1 = wcf2 = random_wcf_in_table(table, pri1);
- } else {
- wcf1 = (wcf_pat & 1
- ? random_wcf_in_table(table, pri1)
- : 1u << table);
- wcf2 = (wcf_pat & 2
- ? random_wcf_in_table(table, pri2)
- : 1u << table);
- }
-
- /* Generate value patterns that will put the two rules into
- * different buckets. */
- value_mask = ((1u << table) - 1);
- value_pat1 = hash_int(pri1, 1) & value_mask;
- i = 0;
- do {
- value_pat2 = (hash_int(pri2, i++) & value_mask);
- } while (value_pat1 == value_pat2);
- rule1 = make_rule(wcf1, pri1, value_pat1);
- rule2 = make_rule(wcf2, pri2, value_pat2);
-
- classifier_init(&cls);
- tcls_init(&tcls);
-
- tcls_rule1 = tcls_insert(&tcls, rule1);
- tcls_rule2 = tcls_insert(&tcls, rule2);
- assert(!classifier_insert(&cls, &rule1->cls_rule));
- assert(!classifier_insert(&cls, &rule2->cls_rule));
- check_tables(&cls, 1, 2, 2);
- compare_classifiers(&cls, &tcls);