diff mbox series

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

Message ID 20211111223825.1757021-4-hzhou@ovn.org
State Accepted
Headers show
Series uuid-based conjunction id generation. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_ovn-kubernetes success github build: passed

Commit Message

Han Zhou Nov. 11, 2021, 10:38 p.m. UTC
Signed-off-by: Han Zhou <hzhou@ovn.org>
---
 tests/test-utils.c | 22 ++++++++++++++++++----
 tests/test-utils.h |  2 ++
 2 files changed, 20 insertions(+), 4 deletions(-)
diff mbox series

Patch

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);