X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Ftest-classifier.c;h=e0a3e96351688d52d760544edc3de7bbfe03b178;hb=06036898849;hp=c831559ba674b3cae08845b079c787609d34b472;hpb=659586efcf6f9539282da9447007897907c41112;p=openvswitch diff --git a/tests/test-classifier.c b/tests/test-classifier.c index c831559b..e0a3e963 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -26,12 +26,11 @@ */ #include -#include #include "classifier.h" #include #include +#include "command-line.h" #include "flow.h" -#include #include "packets.h" #undef NDEBUG @@ -156,7 +155,7 @@ read_uint32(const void *p) } static bool -match(const struct cls_rule *wild, const flow_t *fixed) +match(const struct cls_rule *wild, const struct flow *fixed) { int f_idx; @@ -188,7 +187,7 @@ match(const struct cls_rule *wild, const flow_t *fixed) } static struct cls_rule * -tcls_lookup(const struct tcls *cls, const flow_t *flow, int include) +tcls_lookup(const struct tcls *cls, const struct flow *flow, int include) { size_t i; @@ -336,7 +335,7 @@ get_value(unsigned int *x, unsigned n_values) static struct cls_rule * lookup_with_include_bits(const struct classifier *cls, - const flow_t *flow, int include) + const struct flow *flow, int include) { switch (include) { case CLS_INC_WILD: @@ -353,17 +352,18 @@ lookup_with_include_bits(const struct classifier *cls, static void compare_classifiers(struct classifier *cls, struct tcls *tcls) { + static const int confidence = 500; unsigned int i; assert(classifier_count(cls) == tcls->n_rules); assert(classifier_count_exact(cls) == tcls_count_exact(tcls)); - for (i = 0; i < N_FLOW_VALUES; i++) { + for (i = 0; i < confidence; i++) { struct cls_rule *cr0, *cr1; - flow_t flow; + struct flow flow; unsigned int x; int include; - x = i; + x = rand () % N_FLOW_VALUES; flow.nw_src = nw_src_values[get_value(&x, N_NW_SRC_VALUES)]; flow.nw_dst = nw_dst_values[get_value(&x, N_NW_DST_VALUES)]; flow.tun_id = tun_id_values[get_value(&x, N_TUN_ID_VALUES)]; @@ -380,7 +380,6 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls) ETH_ADDR_LEN); flow.nw_proto = nw_proto_values[get_value(&x, N_NW_PROTO_VALUES)]; flow.nw_tos = nw_tos_values[get_value(&x, N_NW_TOS_VALUES)]; - memset(flow.reserved, 0, sizeof flow.reserved); for (include = 1; include <= 3; include++) { cr0 = lookup_with_include_bits(cls, &flow, include); @@ -430,7 +429,7 @@ check_tables(const struct classifier *cls, if (!hmap_is_empty(&cls->tables[i])) { found_tables++; } - HMAP_FOR_EACH (bucket, struct cls_bucket, hmap_node, &cls->tables[i]) { + HMAP_FOR_EACH (bucket, hmap_node, &cls->tables[i]) { found_buckets++; assert(!list_is_empty(&bucket->rules)); found_rules += list_size(&bucket->rules); @@ -454,7 +453,7 @@ make_rule(int wc_fields, unsigned int priority, int value_pat) const struct cls_field *f; struct test_rule *rule; uint32_t wildcards; - flow_t flow; + struct flow flow; wildcards = 0; memset(&flow, 0, sizeof flow); @@ -487,7 +486,7 @@ shuffle(unsigned int *p, size_t n) /* Tests an empty classifier. */ static void -test_empty(void) +test_empty(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { struct classifier cls; struct tcls tcls; @@ -503,14 +502,14 @@ test_empty(void) /* Destroys a null classifier. */ static void -test_destroy_null(void) +test_destroy_null(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { classifier_destroy(NULL); } /* Tests classification with one rule at a time. */ static void -test_single_rule(void) +test_single_rule(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { unsigned int wc_fields; /* Hilarious. */ @@ -548,7 +547,7 @@ test_single_rule(void) /* Tests replacing one rule by another. */ static void -test_rule_replacement(void) +test_rule_replacement(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { unsigned int wc_fields; @@ -599,7 +598,7 @@ random_wcf_in_table(int table, int seed) /* Tests classification with two rules at a time that fall into the same * bucket. */ static void -test_two_rules_in_one_bucket(void) +test_two_rules_in_one_bucket(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { int table, rel_pri, wcf_pat, value_pat; @@ -688,7 +687,7 @@ test_two_rules_in_one_bucket(void) /* Tests classification with two rules at a time that fall into the same * table but different buckets. */ static void -test_two_rules_in_one_table(void) +test_two_rules_in_one_table(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { int table, rel_pri, wcf_pat; @@ -764,7 +763,8 @@ test_two_rules_in_one_table(void) /* Tests classification with two rules at a time that fall into different * tables. */ static void -test_two_rules_in_different_tables(void) +test_two_rules_in_different_tables(int argc OVS_UNUSED, + char *argv[] OVS_UNUSED) { int table1, table2, rel_pri, wcf_pat; @@ -833,7 +833,7 @@ test_two_rules_in_different_tables(void) /* Tests classification with many rules at a time that fall into the same * bucket but have unique priorities (and various wildcards). */ static void -test_many_rules_in_one_bucket(void) +test_many_rules_in_one_bucket(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { enum { MAX_RULES = 50 }; int iteration, table; @@ -877,7 +877,7 @@ test_many_rules_in_one_bucket(void) /* Tests classification with many rules at a time that fall into the same * table but random buckets. */ static void -test_many_rules_in_one_table(void) +test_many_rules_in_one_table(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { enum { MAX_RULES = 50 }; int iteration, table; @@ -920,7 +920,8 @@ test_many_rules_in_one_table(void) /* Tests classification with many rules at a time that fall into random buckets * in random tables. */ static void -test_many_rules_in_different_tables(void) +test_many_rules_in_different_tables(int argc OVS_UNUSED, + char *argv[] OVS_UNUSED) { enum { MAX_RULES = 50 }; int iteration; @@ -965,36 +966,32 @@ test_many_rules_in_different_tables(void) compare_classifiers(&cls, &tcls); free(rule); } - putchar('.'); - fflush(stdout); destroy_classifier(&cls); tcls_destroy(&tcls); } } -static void -run_test(void (*function)(void)) -{ - function(); - putchar('.'); - fflush(stdout); -} +static const struct command commands[] = { + {"empty", 0, 0, test_empty}, + {"destroy-null", 0, 0, test_destroy_null}, + {"single-rule", 0, 0, test_single_rule}, + {"rule-replacement", 0, 0, test_rule_replacement}, + {"two-rules-in-one-bucket", 0, 0, test_two_rules_in_one_bucket}, + {"two-rules-in-one-table", 0, 0, test_two_rules_in_one_table}, + {"two-rules-in-different-tables", 0, 0, + test_two_rules_in_different_tables}, + {"many-rules-in-one-bucket", 0, 0, test_many_rules_in_one_bucket}, + {"many-rules-in-one-table", 0, 0, test_many_rules_in_one_table}, + {"many-rules-in-different-tables", 0, 0, + test_many_rules_in_different_tables}, + {NULL, 0, 0, NULL}, +}; int -main(void) +main(int argc, char *argv[]) { init_values(); - run_test(test_empty); - run_test(test_destroy_null); - run_test(test_single_rule); - run_test(test_rule_replacement); - run_test(test_two_rules_in_one_bucket); - run_test(test_two_rules_in_one_table); - run_test(test_two_rules_in_different_tables); - run_test(test_many_rules_in_one_bucket); - run_test(test_many_rules_in_one_table); - run_test(test_many_rules_in_different_tables); - putchar('\n'); + run_command(argc - 1, argv + 1, commands); return 0; }