]> xenbits.xensource.com Git - people/pauldu/qemu.git/commitdiff
Fix unit test now we have perms checks xenfv3
authorPaul Durrant <pdurrant@amazon.com>
Tue, 24 Jan 2023 13:51:55 +0000 (13:51 +0000)
committerPaul Durrant <pdurrant@amazon.com>
Tue, 24 Jan 2023 13:53:54 +0000 (13:53 +0000)
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
tests/unit/test-xs-node.c

index 879adebc2964117334c1284210552748c7b3bfeb..1cab111b7a3a07e3961647e9b9eca52bb7b6716f 100644 (file)
@@ -17,6 +17,7 @@ static GList *xs_node_list;
 #define XS_NODE_UNIT_TEST
 #include "hw/i386/kvm/xenstore_impl.c"
 
+#define DOMID_QEMU 0
 #define DOMID_GUEST 1
 
 /* This doesn't happen in qemu but we want to make valgrind happy */
@@ -59,9 +60,46 @@ static void watch_cb(void *_str, const char *path, const char *token)
     g_string_append(str, token);
 }
 
+static XenstoreImplState *setup(void)
+{
+   XenstoreImplState *s = xs_impl_create(DOMID_GUEST);
+   char *abspath;
+   GList *perms;
+   int err;
+
+   abspath = g_strdup_printf("/local/domain/%u", DOMID_GUEST);
+
+   err = write_str(s, DOMID_QEMU, XBT_NULL, abspath, "");
+   g_assert(!err);
+
+   perms = g_list_append(NULL, g_strdup_printf("n%u", DOMID_QEMU));
+   perms = g_list_append(perms, g_strdup_printf("r%u", DOMID_GUEST));
+
+   err = xs_impl_set_perms(s, DOMID_QEMU, XBT_NULL, abspath, perms);
+   g_assert(!err);
+
+   g_list_free_full(perms, g_free);
+   g_free(abspath);
+
+   abspath = g_strdup_printf("/local/domain/%u/some", DOMID_GUEST);
+
+   err = write_str(s, DOMID_QEMU, XBT_NULL, abspath, "");
+   g_assert(!err);
+
+   perms = g_list_append(NULL, g_strdup_printf("n%u", DOMID_GUEST));
+
+   err = xs_impl_set_perms(s, DOMID_QEMU, XBT_NULL, abspath, perms);
+   g_assert(!err);
+
+   g_list_free_full(perms, g_free);
+   g_free(abspath);
+
+   return s;
+}
+
 static void test_xs_node_simple(void)
 {
-    XenstoreImplState *s = xs_impl_create(DOMID_GUEST);
+    XenstoreImplState *s = setup();
     GString *guest_watches = g_string_new(NULL);
     GString *qemu_watches = g_string_new(NULL);
     GList *items = NULL;
@@ -222,7 +260,7 @@ static void test_xs_node_simple(void)
 
 static void do_test_xs_node_tx(bool fail, bool commit)
 {
-    XenstoreImplState *s = xs_impl_create(DOMID_GUEST);
+    XenstoreImplState *s = setup();
     GString *watches = g_string_new(NULL);
     GByteArray *data = g_byte_array_new();
     unsigned int tx_id = XBT_NULL;
@@ -322,7 +360,7 @@ static void test_xs_node_tx_succeed(void)
 
 static void test_xs_node_tx_rm(void)
 {
-    XenstoreImplState *s = xs_impl_create(DOMID_GUEST);
+    XenstoreImplState *s = setup();
     GString *watches = g_string_new(NULL);
     GByteArray *data = g_byte_array_new();
     unsigned int tx_id = XBT_NULL;
@@ -385,7 +423,7 @@ static void test_xs_node_tx_rm(void)
 
 static void test_xs_node_tx_resurrect(void)
 {
-    XenstoreImplState *s = xs_impl_create(DOMID_GUEST);
+    XenstoreImplState *s = setup();
     GString *watches = g_string_new(NULL);
     GByteArray *data = g_byte_array_new();
     unsigned int tx_id = XBT_NULL;