[ovs-dev] [PATCH ovn v3 3/4] test-utils: Add test_read_uint_hex_value helper.

Han Zhou hzhou at ovn.org
Thu Nov 11 22:38:24 UTC 2021


Signed-off-by: Han Zhou <hzhou at ovn.org>
---
 tests/test-utils.c | 22 ++++++++++++++++++----
 tests/test-utils.h |  2 ++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/tests/test-utils.c b/tests/test-utils.c
index 6a3b198ae..78e63acb7 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -19,9 +19,9 @@
 
 #include "util.h"
 
-bool
-test_read_uint_value(struct ovs_cmdl_context *ctx, unsigned int index,
-                     const char *descr, unsigned int *result)
+static bool
+test_read_uint_value_base(struct ovs_cmdl_context *ctx, unsigned int index,
+                          const char *descr, int base, unsigned int *result)
 {
     if (index >= ctx->argc) {
         fprintf(stderr, "Missing %s argument\n", descr);
@@ -29,13 +29,27 @@ test_read_uint_value(struct ovs_cmdl_context *ctx, unsigned int index,
     }
 
     const char *arg = ctx->argv[index];
-    if (!str_to_uint(arg, 10, result)) {
+    if (!str_to_uint(arg, base, result)) {
         fprintf(stderr, "Invalid %s: %s\n", descr, arg);
         return false;
     }
     return true;
 }
 
+bool
+test_read_uint_value(struct ovs_cmdl_context *ctx, unsigned int index,
+                     const char *descr, unsigned int *result)
+{
+    return test_read_uint_value_base(ctx, index, descr, 10, result);
+}
+
+bool
+test_read_uint_hex_value(struct ovs_cmdl_context *ctx, unsigned int index,
+                         const char *descr, unsigned int *result)
+{
+    return test_read_uint_value_base(ctx, index, descr, 16, result);
+}
+
 const char *
 test_read_value(struct ovs_cmdl_context *ctx, unsigned int index,
                 const char *descr)
diff --git a/tests/test-utils.h b/tests/test-utils.h
index 721032f82..910358ea1 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -20,6 +20,8 @@
 
 bool test_read_uint_value(struct ovs_cmdl_context *ctx, unsigned int index,
                           const char *descr, unsigned int *result);
+bool test_read_uint_hex_value(struct ovs_cmdl_context *ctx, unsigned int index,
+                              const char *descr, unsigned int *result);
 const char *test_read_value(struct ovs_cmdl_context *ctx, unsigned int index,
                             const char *descr);
 
-- 
2.30.2



More information about the dev mailing list