lib: Fix netbsd compilation error.
[cascardo/ovs.git] / tests / test-heap.c
index ccb1484..6dab22b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012 Nicira, Inc.
+ * Copyright (c) 2012, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 /* A test for for functions and macros declared in heap.h. */
 
 #include <config.h>
+#undef NDEBUG
 #include "heap.h"
+#include <assert.h>
 #include <inttypes.h>
 #include <limits.h>
 #include <stdlib.h>
 #include "command-line.h"
+#include "ovstest.h"
 #include "random.h"
 #include "util.h"
 
-#undef NDEBUG
-#include <assert.h>
-
 /* Sample heap element. */
 struct element {
     uint32_t full_pri;
@@ -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 };
 
@@ -463,24 +459,31 @@ 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,
+static const struct ovs_cmdl_command commands[] = {
+    { "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, },
+    { "raw-insert", NULL, 0, 0, test_heap_raw_insert, },
+    { "raw-delete", NULL, 0, 0, test_heap_raw_delete, },
+    { NULL, NULL, 0, 0, NULL, },
 };
 
-int
-main(int argc, char *argv[])
+static void
+test_heap_main(int argc, char *argv[])
 {
-    set_program_name(argv[0]);
+    struct ovs_cmdl_context ctx = {
+        .argc = argc - 1,
+        .argv = argv + 1,
+    };
 
-    run_command(argc - 1, argv + 1, commands);
+    set_program_name(argv[0]);
 
-    return 0;
+    ovs_cmdl_run_command(&ctx, commands);
 }
+
+OVSTEST_REGISTER("test-heap", test_heap_main);