diff options
author | Alex Wang <alexw@nicira.com> | 2014-10-16 13:27:32 -0700 |
---|---|---|
committer | Alex Wang <alexw@nicira.com> | 2014-10-28 18:43:11 -0700 |
commit | 451de37e7fe6a89a482771fbec5e653be6117380 (patch) | |
tree | b95caf67c9236afa85036aba47fd025aa8502357 /tests | |
parent | 56cad66697eba8ee9b7c52ac3051407210dadc70 (diff) | |
download | openvswitch-451de37e7fe6a89a482771fbec5e653be6117380.tar.gz |
command-line: Add function to print command usage.
This commit adds a new variable in 'struct command' for
recording the command usage. Also, a new function is
added to print the usage given the array of defined
commands.
Later patch will use the output in bash command-line
completion script.
Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ovstest.c | 5 | ||||
-rw-r--r-- | tests/test-bitmap.c | 6 | ||||
-rw-r--r-- | tests/test-classifier.c | 24 | ||||
-rw-r--r-- | tests/test-cmap.c | 6 | ||||
-rw-r--r-- | tests/test-heap.c | 15 | ||||
-rw-r--r-- | tests/test-jsonrpc.c | 10 | ||||
-rw-r--r-- | tests/test-ovsdb.c | 70 | ||||
-rw-r--r-- | tests/test-reconnect.c | 32 | ||||
-rw-r--r-- | tests/test-util.c | 32 | ||||
-rw-r--r-- | tests/test-vconn.c | 18 |
10 files changed, 110 insertions, 108 deletions
diff --git a/tests/ovstest.c b/tests/ovstest.c index dbb4555da..dc6d18f69 100644 --- a/tests/ovstest.c +++ b/tests/ovstest.c @@ -32,7 +32,7 @@ static size_t allocated_commands = 0; static void add_command(struct command *cmd) { - const struct command nil = {NULL, 0, 0, NULL}; + const struct command nil = {NULL, NULL, 0, 0, NULL}; while (n_commands + 1 >= allocated_commands) { commands = x2nrealloc(commands, &allocated_commands, @@ -85,7 +85,7 @@ help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) static void add_top_level_commands(void) { - struct command help_cmd = {"--help", 0, 0, help}; + struct command help_cmd = {"--help", NULL, 0, 0, help}; add_command(&help_cmd); } @@ -96,6 +96,7 @@ ovstest_register(const char *test_name, ovstest_func f) struct command test_cmd; test_cmd.name = test_name; + test_cmd.usage = NULL; test_cmd.min_args = 0; test_cmd.max_args = INT_MAX; test_cmd.handler = f; diff --git a/tests/test-bitmap.c b/tests/test-bitmap.c index 9e874b5ad..5008f5195 100644 --- a/tests/test-bitmap.c +++ b/tests/test-bitmap.c @@ -150,9 +150,9 @@ run_benchmarks(int argc OVS_UNUSED, char *argv[]) } static const struct command commands[] = { - {"check", 0, 0, run_tests}, - {"benchmark", 1, 1, run_benchmarks}, - {NULL, 0, 0, NULL}, + {"check", NULL, 0, 0, run_tests}, + {"benchmark", NULL, 1, 1, run_benchmarks}, + {NULL, NULL, 0, 0, NULL}, }; static void diff --git a/tests/test-classifier.c b/tests/test-classifier.c index f4e65bfdb..2f5a181e4 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -1403,21 +1403,21 @@ test_minimask_combine(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) static const struct command commands[] = { /* Classifier tests. */ - {"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}, - {"many-rules-in-one-list", 0, 0, test_many_rules_in_one_list}, - {"many-rules-in-one-table", 0, 0, test_many_rules_in_one_table}, - {"many-rules-in-two-tables", 0, 0, test_many_rules_in_two_tables}, - {"many-rules-in-five-tables", 0, 0, test_many_rules_in_five_tables}, + {"empty", NULL, 0, 0, test_empty}, + {"destroy-null", NULL, 0, 0, test_destroy_null}, + {"single-rule", NULL, 0, 0, test_single_rule}, + {"rule-replacement", NULL, 0, 0, test_rule_replacement}, + {"many-rules-in-one-list", NULL, 0, 0, test_many_rules_in_one_list}, + {"many-rules-in-one-table", NULL, 0, 0, test_many_rules_in_one_table}, + {"many-rules-in-two-tables", NULL, 0, 0, test_many_rules_in_two_tables}, + {"many-rules-in-five-tables", NULL, 0, 0, test_many_rules_in_five_tables}, /* Miniflow and minimask tests. */ - {"miniflow", 0, 0, test_miniflow}, - {"minimask_has_extra", 0, 0, test_minimask_has_extra}, - {"minimask_combine", 0, 0, test_minimask_combine}, + {"miniflow", NULL, 0, 0, test_miniflow}, + {"minimask_has_extra", NULL, 0, 0, test_minimask_has_extra}, + {"minimask_combine", NULL, 0, 0, test_minimask_combine}, - {NULL, 0, 0, NULL}, + {NULL, NULL, 0, 0, NULL}, }; static void diff --git a/tests/test-cmap.c b/tests/test-cmap.c index 2976d5f8f..8825e6f9a 100644 --- a/tests/test-cmap.c +++ b/tests/test-cmap.c @@ -638,9 +638,9 @@ benchmark_hmap(void) } static const struct command commands[] = { - {"check", 0, 1, run_tests}, - {"benchmark", 3, 4, run_benchmarks}, - {NULL, 0, 0, NULL}, + {"check", NULL, 0, 1, run_tests}, + {"benchmark", NULL, 3, 4, run_benchmarks}, + {NULL, NULL, 0, 0, NULL}, }; static void diff --git a/tests/test-heap.c b/tests/test-heap.c index 3a0afa5fa..fcb33ccea 100644 --- a/tests/test-heap.c +++ b/tests/test-heap.c @@ -465,16 +465,17 @@ test_heap_raw_delete(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) } static const struct command commands[] = { - { "insert-delete-same-order", 0, 0, test_heap_insert_delete_same_order, }, - { "insert-delete-reverse-order", 0, 0, + { "insert-delete-same-order", NULL, 0, 0, + test_heap_insert_delete_same_order, }, + { "insert-delete-reverse-order", NULL, 0, 0, test_heap_insert_delete_reverse_order, }, - { "insert-delete-every-order", 0, 0, + { "insert-delete-every-order", NULL, 0, 0, test_heap_insert_delete_every_order, }, - { "insert-delete-same-order-with-dups", 0, 0, + { "insert-delete-same-order-with-dups", NULL, 0, 0, test_heap_insert_delete_same_order_with_dups, }, - { "raw-insert", 0, 0, test_heap_raw_insert, }, - { "raw-delete", 0, 0, test_heap_raw_delete, }, - { NULL, 0, 0, NULL, }, + { "raw-insert", NULL, 0, 0, test_heap_raw_insert, }, + { "raw-delete", NULL, 0, 0, test_heap_raw_delete, }, + { NULL, NULL, 0, 0, NULL, }, }; static void diff --git a/tests/test-jsonrpc.c b/tests/test-jsonrpc.c index cf90c4434..1fd753f35 100644 --- a/tests/test-jsonrpc.c +++ b/tests/test-jsonrpc.c @@ -330,11 +330,11 @@ do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) } static struct command all_commands[] = { - { "listen", 1, 1, do_listen }, - { "request", 3, 3, do_request }, - { "notify", 3, 3, do_notify }, - { "help", 0, INT_MAX, do_help }, - { NULL, 0, 0, NULL }, + { "listen", NULL, 1, 1, do_listen }, + { "request", NULL, 3, 3, do_request }, + { "notify", NULL, 3, 3, do_notify }, + { "help", NULL, 0, INT_MAX, do_help }, + { NULL, NULL, 0, 0, NULL }, }; static struct command * diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index 4d73a0dd3..b95f1db06 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -1508,13 +1508,13 @@ static void do_transact(int argc, char *argv[]) { static const struct command do_transact_commands[] = { - { "commit", 0, 0, do_transact_commit }, - { "abort", 0, 0, do_transact_abort }, - { "insert", 2, 3, do_transact_insert }, - { "delete", 1, 1, do_transact_delete }, - { "modify", 2, 3, do_transact_modify }, - { "print", 0, 0, do_transact_print }, - { NULL, 0, 0, NULL }, + { "commit", NULL, 0, 0, do_transact_commit }, + { "abort", NULL, 0, 0, do_transact_abort }, + { "insert", NULL, 2, 3, do_transact_insert }, + { "delete", NULL, 1, 1, do_transact_delete }, + { "modify", NULL, 2, 3, do_transact_modify }, + { "print", NULL, 0, 0, do_transact_print }, + { NULL, NULL, 0, 0, NULL }, }; struct ovsdb_schema *schema; @@ -1963,34 +1963,34 @@ do_idl(int argc, char *argv[]) } static struct command all_commands[] = { - { "log-io", 2, INT_MAX, do_log_io }, - { "default-atoms", 0, 0, do_default_atoms }, - { "default-data", 0, 0, do_default_data }, - { "parse-atomic-type", 1, 1, do_parse_atomic_type }, - { "parse-base-type", 1, 1, do_parse_base_type }, - { "parse-type", 1, 1, do_parse_type }, - { "parse-atoms", 2, INT_MAX, do_parse_atoms }, - { "parse-atom-strings", 2, INT_MAX, do_parse_atom_strings }, - { "parse-data", 2, INT_MAX, do_parse_data }, - { "parse-data-strings", 2, INT_MAX, do_parse_data_strings }, - { "sort-atoms", 2, 2, do_sort_atoms }, - { "parse-column", 2, 2, do_parse_column }, - { "parse-table", 2, 3, do_parse_table }, - { "parse-rows", 2, INT_MAX, do_parse_rows }, - { "compare-rows", 2, INT_MAX, do_compare_rows }, - { "parse-conditions", 2, INT_MAX, do_parse_conditions }, - { "evaluate-conditions", 3, 3, do_evaluate_conditions }, - { "parse-mutations", 2, INT_MAX, do_parse_mutations }, - { "execute-mutations", 3, 3, do_execute_mutations }, - { "query", 3, 3, do_query }, - { "query-distinct", 4, 4, do_query_distinct }, - { "transact", 1, INT_MAX, do_transact }, - { "parse-schema", 1, 1, do_parse_schema }, - { "execute", 2, INT_MAX, do_execute }, - { "trigger", 2, INT_MAX, do_trigger }, - { "idl", 1, INT_MAX, do_idl }, - { "help", 0, INT_MAX, do_help }, - { NULL, 0, 0, NULL }, + { "log-io", NULL, 2, INT_MAX, do_log_io }, + { "default-atoms", NULL, 0, 0, do_default_atoms }, + { "default-data", NULL, 0, 0, do_default_data }, + { "parse-atomic-type", NULL, 1, 1, do_parse_atomic_type }, + { "parse-base-type", NULL, 1, 1, do_parse_base_type }, + { "parse-type", NULL, 1, 1, do_parse_type }, + { "parse-atoms", NULL, 2, INT_MAX, do_parse_atoms }, + { "parse-atom-strings", NULL, 2, INT_MAX, do_parse_atom_strings }, + { "parse-data", NULL, 2, INT_MAX, do_parse_data }, + { "parse-data-strings", NULL, 2, INT_MAX, do_parse_data_strings }, + { "sort-atoms", NULL, 2, 2, do_sort_atoms }, + { "parse-column", NULL, 2, 2, do_parse_column }, + { "parse-table", NULL, 2, 3, do_parse_table }, + { "parse-rows", NULL, 2, INT_MAX, do_parse_rows }, + { "compare-rows", NULL, 2, INT_MAX, do_compare_rows }, + { "parse-conditions", NULL, 2, INT_MAX, do_parse_conditions }, + { "evaluate-conditions", NULL, 3, 3, do_evaluate_conditions }, + { "parse-mutations", NULL, 2, INT_MAX, do_parse_mutations }, + { "execute-mutations", NULL, 3, 3, do_execute_mutations }, + { "query", NULL, 3, 3, do_query }, + { "query-distinct", NULL, 4, 4, do_query_distinct }, + { "transact", NULL, 1, INT_MAX, do_transact }, + { "parse-schema", NULL, 1, 1, do_parse_schema }, + { "execute", NULL, 2, INT_MAX, do_execute }, + { "trigger", NULL, 2, INT_MAX, do_trigger }, + { "idl", NULL, 1, INT_MAX, do_idl }, + { "help", NULL, 0, INT_MAX, do_help }, + { NULL, NULL, 0, 0, NULL }, }; static struct command * diff --git a/tests/test-reconnect.c b/tests/test-reconnect.c index 35d5f4175..a3e97b066 100644 --- a/tests/test-reconnect.c +++ b/tests/test-reconnect.c @@ -271,22 +271,22 @@ do_listen_error(int argc OVS_UNUSED, char *argv[]) } static const struct command all_commands[] = { - { "enable", 0, 0, do_enable }, - { "disable", 0, 0, do_disable }, - { "force-reconnect", 0, 0, do_force_reconnect }, - { "disconnected", 0, 1, do_disconnected }, - { "connecting", 0, 0, do_connecting }, - { "connect-failed", 0, 1, do_connect_failed }, - { "connected", 0, 0, do_connected }, - { "activity", 0, 0, do_activity }, - { "run", 0, 1, do_run }, - { "advance", 1, 1, do_advance }, - { "timeout", 0, 0, do_timeout }, - { "set-max-tries", 1, 1, do_set_max_tries }, - { "passive", 0, 0, do_set_passive }, - { "listening", 0, 0, do_listening }, - { "listen-error", 1, 1, do_listen_error }, - { NULL, 0, 0, NULL }, + { "enable", NULL, 0, 0, do_enable }, + { "disable", NULL, 0, 0, do_disable }, + { "force-reconnect", NULL, 0, 0, do_force_reconnect }, + { "disconnected", NULL, 0, 1, do_disconnected }, + { "connecting", NULL, 0, 0, do_connecting }, + { "connect-failed", NULL, 0, 1, do_connect_failed }, + { "connected", NULL, 0, 0, do_connected }, + { "activity", NULL, 0, 0, do_activity }, + { "run", NULL, 0, 1, do_run }, + { "advance", NULL, 1, 1, do_advance }, + { "timeout", NULL, 0, 0, do_timeout }, + { "set-max-tries", NULL, 1, 1, do_set_max_tries }, + { "passive", NULL, 0, 0, do_set_passive }, + { "listening", NULL, 0, 0, do_listening }, + { "listen-error", NULL, 1, 1, do_listen_error }, + { NULL, NULL, 0, 0, NULL }, }; static const struct command * diff --git a/tests/test-util.c b/tests/test-util.c index a8060b0c4..fd01fcb92 100644 --- a/tests/test-util.c +++ b/tests/test-util.c @@ -1053,24 +1053,24 @@ test_file_name(int argc, char *argv[]) #endif /* _WIN32 */ static const struct command commands[] = { - {"ctz", 0, 0, test_ctz}, - {"clz", 0, 0, test_clz}, - {"round_up_pow2", 0, 0, test_round_up_pow2}, - {"round_down_pow2", 0, 0, test_round_down_pow2}, - {"count_1bits", 0, 0, test_count_1bits}, - {"log_2_floor", 0, 0, test_log_2_floor}, - {"bitwise_copy", 0, 0, test_bitwise_copy}, - {"bitwise_zero", 0, 0, test_bitwise_zero}, - {"bitwise_one", 0, 0, test_bitwise_one}, - {"bitwise_is_all_zeros", 0, 0, test_bitwise_is_all_zeros}, - {"follow-symlinks", 1, INT_MAX, test_follow_symlinks}, - {"assert", 0, 0, test_assert}, - {"ovs_scan", 0, 0, test_ovs_scan}, - {"snprintf", 0, 0, test_snprintf}, + {"ctz", NULL, 0, 0, test_ctz}, + {"clz", NULL, 0, 0, test_clz}, + {"round_up_pow2", NULL, 0, 0, test_round_up_pow2}, + {"round_down_pow2", NULL, 0, 0, test_round_down_pow2}, + {"count_1bits", NULL, 0, 0, test_count_1bits}, + {"log_2_floor", NULL, 0, 0, test_log_2_floor}, + {"bitwise_copy", NULL, 0, 0, test_bitwise_copy}, + {"bitwise_zero", NULL, 0, 0, test_bitwise_zero}, + {"bitwise_one", NULL, 0, 0, test_bitwise_one}, + {"bitwise_is_all_zeros", NULL, 0, 0, test_bitwise_is_all_zeros}, + {"follow-symlinks", NULL, 1, INT_MAX, test_follow_symlinks}, + {"assert", NULL, 0, 0, test_assert}, + {"ovs_scan", NULL, 0, 0, test_ovs_scan}, + {"snprintf", NULL, 0, 0, test_snprintf}, #ifndef _WIN32 - {"file_name", 1, INT_MAX, test_file_name}, + {"file_name", NULL, 1, INT_MAX, test_file_name}, #endif - {NULL, 0, 0, NULL}, + {NULL, NULL, 0, 0, NULL}, }; static void diff --git a/tests/test-vconn.c b/tests/test-vconn.c index 266ad4e77..bcaa3da95 100644 --- a/tests/test-vconn.c +++ b/tests/test-vconn.c @@ -433,15 +433,15 @@ test_send_invalid_version_hello(int argc OVS_UNUSED, char *argv[]) } static const struct command commands[] = { - {"refuse-connection", 1, 1, test_refuse_connection}, - {"accept-then-close", 1, 1, test_accept_then_close}, - {"read-hello", 1, 1, test_read_hello}, - {"send-plain-hello", 1, 1, test_send_plain_hello}, - {"send-long-hello", 1, 1, test_send_long_hello}, - {"send-echo-hello", 1, 1, test_send_echo_hello}, - {"send-short-hello", 1, 1, test_send_short_hello}, - {"send-invalid-version-hello", 1, 1, test_send_invalid_version_hello}, - {NULL, 0, 0, NULL}, + {"refuse-connection", NULL, 1, 1, test_refuse_connection}, + {"accept-then-close", NULL, 1, 1, test_accept_then_close}, + {"read-hello", NULL, 1, 1, test_read_hello}, + {"send-plain-hello", NULL, 1, 1, test_send_plain_hello}, + {"send-long-hello", NULL, 1, 1, test_send_long_hello}, + {"send-echo-hello", NULL, 1, 1, test_send_echo_hello}, + {"send-short-hello", NULL, 1, 1, test_send_short_hello}, + {"send-invalid-version-hello", NULL, 1, 1, test_send_invalid_version_hello}, + {NULL, NULL, 0, 0, NULL}, }; static void |