X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Ftest-classifier.c;h=57a1e2c2cc60d2817053df546fb23c217c9e589c;hb=d785193ad9989b429ea4c6931af9da7f4edf60ec;hp=c831559ba674b3cae08845b079c787609d34b472;hpb=659586efcf6f9539282da9447007897907c41112;p=openvswitch diff --git a/tests/test-classifier.c b/tests/test-classifier.c index c831559b..57a1e2c2 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 @@ -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; 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)]; @@ -487,7 +487,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 +503,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 +548,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 +599,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 +688,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 +764,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 +834,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 +878,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 +921,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 +967,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; }