qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC v4 03/11] linux-user: Implement envlist_appendenv and add tests


From: Richard Henderson
Subject: Re: [RFC v4 03/11] linux-user: Implement envlist_appendenv and add tests for envlist
Date: Wed, 9 Aug 2023 08:44:00 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0

On 8/8/23 07:17, Yeqi Fu wrote:
Signed-off-by: Yeqi Fu <fufuyqqqqqq@gmail.com>
---
  include/qemu/envlist.h    | 13 ++++++
  tests/unit/meson.build    |  1 +
  tests/unit/test-envlist.c | 94 +++++++++++++++++++++++++++++++++++++++
  util/envlist.c            | 71 ++++++++++++++++++++++++-----
  4 files changed, 169 insertions(+), 10 deletions(-)
  create mode 100644 tests/unit/test-envlist.c

diff --git a/include/qemu/envlist.h b/include/qemu/envlist.h
index 6006dfae44..9eb1459e79 100644
--- a/include/qemu/envlist.h
+++ b/include/qemu/envlist.h
@@ -1,12 +1,25 @@
  #ifndef ENVLIST_H
  #define ENVLIST_H
+#include "qemu/queue.h"
+
+struct envlist_entry {
+    const char *ev_var;            /* actual env value */
+    QLIST_ENTRY(envlist_entry) ev_link;
+};
+
+struct envlist {
+    QLIST_HEAD(, envlist_entry) el_entries; /* actual entries */
+    size_t el_count;                        /* number of entries */
+};
+

Why are you exposing the structures?

+static void envlist_parse_set_unset_test(void)
+{
+    envlist_t *testenvlist;
+    const char *env = "TEST1=123,TEST2=456";
+
+    testenvlist = envlist_create();
+    g_assert(envlist_parse_set(testenvlist, env) == 0);
+    g_assert(testenvlist->el_count == 2);
+    g_assert(envlist_parse_unset(testenvlist, "TEST1,TEST2") == 0);
+    g_assert(testenvlist->el_count == 0);

If it's just for the count, then add an envlist_length() function.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]