diff options
author | Russell Bryant <rbryant@redhat.com> | 2015-03-17 10:35:26 -0400 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2015-03-17 08:15:57 -0700 |
commit | 1636c76112b63c50bb586186eb0c3aa16f9541c7 (patch) | |
tree | e04c48041d41a19ab7ffa3dc66137a3ec7db52e3 /tests/test-heap.c | |
parent | 1774d762da192d26f0f1a6176d20358adfe57dd5 (diff) | |
download | openvswitch-1636c76112b63c50bb586186eb0c3aa16f9541c7.tar.gz |
command-line: add ovs_cmdl_context
I started working on a new command line utility that used this shared
code. I wanted the ability to pass some data from common
initialization code to all of the commands. You can find a similar
pattern in ovs-vsctl.
This patch updates the command handler to take a new struct,
ovs_cmdl_context, instead of argc and argv directly. It includes argc
and argv, but also includes an opaque type (void *), where the user of
this API can attach its custom data it wants passed along to command
handlers.
This patch affected the ovstest sub-programs, as well. The patch
includes a bit of an odd hack to OVSTEST_REGISTER() to avoid making
the main() function of the sub-programs take a ovs_cmdl_context.
The test main() functions still receive argc and argv directly, as
that seems more natural. The test-subprograms themselves are able to
make use of a context internally, though.
Signed-off-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'tests/test-heap.c')
-rw-r--r-- | tests/test-heap.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/tests/test-heap.c b/tests/test-heap.c index 5340860c7..6dab22b51 100644 --- a/tests/test-heap.c +++ b/tests/test-heap.c @@ -273,8 +273,7 @@ test_insert_delete_raw__(struct element *elements, } static void -test_heap_insert_delete_same_order(int argc OVS_UNUSED, - char *argv[] OVS_UNUSED) +test_heap_insert_delete_same_order(struct ovs_cmdl_context *ctx OVS_UNUSED) { enum { N_ELEMS = 7 }; @@ -297,8 +296,7 @@ test_heap_insert_delete_same_order(int argc OVS_UNUSED, } static void -test_heap_insert_delete_reverse_order(int argc OVS_UNUSED, - char *argv[] OVS_UNUSED) +test_heap_insert_delete_reverse_order(struct ovs_cmdl_context *ctx OVS_UNUSED) { enum { N_ELEMS = 7 }; @@ -327,8 +325,7 @@ test_heap_insert_delete_reverse_order(int argc OVS_UNUSED, } static void -test_heap_insert_delete_every_order(int argc OVS_UNUSED, - char *argv[] OVS_UNUSED) +test_heap_insert_delete_every_order(struct ovs_cmdl_context *ctx OVS_UNUSED) { enum { N_ELEMS = 5 }; @@ -363,8 +360,7 @@ test_heap_insert_delete_every_order(int argc OVS_UNUSED, } static void -test_heap_insert_delete_same_order_with_dups(int argc OVS_UNUSED, - char *argv[] OVS_UNUSED) +test_heap_insert_delete_same_order_with_dups(struct ovs_cmdl_context *ctx OVS_UNUSED) { enum { N_ELEMS = 7 }; @@ -410,7 +406,7 @@ test_heap_insert_delete_same_order_with_dups(int argc OVS_UNUSED, } static void -test_heap_raw_insert(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) +test_heap_raw_insert(struct ovs_cmdl_context *ctx OVS_UNUSED) { enum { N_ELEMS = 7 }; @@ -436,7 +432,7 @@ test_heap_raw_insert(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) } static void -test_heap_raw_delete(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) +test_heap_raw_delete(struct ovs_cmdl_context *ctx OVS_UNUSED) { enum { N_ELEMS = 16 }; @@ -480,9 +476,14 @@ static const struct ovs_cmdl_command commands[] = { static void test_heap_main(int argc, char *argv[]) { + struct ovs_cmdl_context ctx = { + .argc = argc - 1, + .argv = argv + 1, + }; + set_program_name(argv[0]); - ovs_cmdl_run_command(argc - 1, argv + 1, commands); + ovs_cmdl_run_command(&ctx, commands); } OVSTEST_REGISTER("test-heap", test_heap_main); |