]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Introduce and use xenstore_init()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 12 Feb 2018 11:33:42 +0000 (11:33 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 12 Feb 2018 14:38:52 +0000 (14:38 +0000)
This really should have been introduced along with xenstore_read(), but the
problem only becomes apparent when booting an XTF test as the initial domain.
The presence of xenstore must not be assumed.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
common/lib.c
common/xenbus.c
include/xtf/xenstore.h
tests/selftest/main.c

index 43142ce7cf7644a7111c2a7c5038507b930cd327..acf4da17d2894fbd97635cf341d9052950cbbbf0 100644 (file)
@@ -45,6 +45,11 @@ int xtf_probe_sysctl_interface_version(void)
 
 int xtf_get_domid(void)
 {
+    int rc = xenstore_init();
+
+    if ( rc )
+        return -1;
+
     const char *str = xenstore_read("domid");
     unsigned int domid = 0;
 
index 2888ab03c1a3592dcf9cf02e22182d576d7d4f7d..59159f29b7eb0208929b7e7ab24799b33ff324b9 100644 (file)
@@ -108,6 +108,12 @@ static void xenbus_read(void *data, size_t len)
     }
 }
 
+int xenstore_init(void)
+{
+    /* Nothing to initialise.  Report the presence of the xenbus ring. */
+    return xb_port ? 0 : -ENODEV;
+}
+
 const char *xenstore_read(const char *path)
 {
     struct xenstore_msg_hdr hdr = {
index 2c0778e609d6eca6418af6ac1c13766b97b3460d..857d82eccedf9aa9a533576202144d6761780633 100644 (file)
@@ -6,6 +6,12 @@
 #ifndef XTF_XENSTORE_H
 #define XTF_XENSTORE_H
 
+/**
+ * Initialise XTF ready for xenstore communication.  May fail if there is no
+ * xenbus ring found.
+ */
+int xenstore_init(void);
+
 /**
  * Issue a #XS_READ operation for @p key, waiting synchronously for the reply.
  *
index 1f57cb2bd7e5e9b7e2604c21373c64f2bc5f1a11..321b0824be82a80728837ad6757ad5dcf3e09b0a 100644 (file)
@@ -17,6 +17,7 @@
 #include <arch/segment.h>
 
 const char test_title[] = "XTF Selftests";
+bool has_xenstore = true;
 
 static void test_xenstore(void)
 {
@@ -317,6 +318,11 @@ static void test_driver_init(void)
             xtf_failure("Fail: apic_init() returned %d\n", rc);
     }
 
+    rc = xenstore_init();
+    has_xenstore = !rc;
+    if ( rc && rc != -ENODEV )
+        xtf_failure("Fail: xenstore_init() returned %d\n", rc);
+
     rc = xtf_init_grant_table(1);
     if ( rc )
         xtf_failure("Fail: xtf_init_grant_table(1) returned %d\n", rc);
@@ -345,7 +351,6 @@ void test_main(void)
             write_cr4(cr4);
     }
 
-    test_xenstore();
     test_extable();
     test_exlog();
     test_exec_user();
@@ -356,6 +361,9 @@ void test_main(void)
     test_custom_idte();
     test_driver_init();
 
+    if ( has_xenstore )
+        test_xenstore();
+
     xtf_success(NULL);
 }