diff mbox

[libvirt,1/3] tests: sheepdog: Drop use of virtTestResult

Message ID d7246c4dfc0d5654fac58e678ae25ed803ad5c00.1443570876.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson Sept. 29, 2015, 11:56 p.m. UTC
Instead use the same pattern that most other test files use.
---
 tests/storagebackendsheepdogtest.c | 63 ++++++++++++++++++++++++++++----------
 1 file changed, 47 insertions(+), 16 deletions(-)

Comments

Martin Kletzander Sept. 30, 2015, 5:39 a.m. UTC | #1
On Tue, Sep 29, 2015 at 07:56:45PM -0400, Cole Robinson wrote:
>Instead use the same pattern that most other test files use.
>---
> tests/storagebackendsheepdogtest.c | 63 ++++++++++++++++++++++++++++----------
> 1 file changed, 47 insertions(+), 16 deletions(-)
>

ACK
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox

Patch

diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
index 7744119..2b0f4db 100644
--- a/tests/storagebackendsheepdogtest.c
+++ b/tests/storagebackendsheepdogtest.c
@@ -44,15 +44,28 @@  typedef struct {
     uint64_t expected_allocation;
 } collie_test;
 
+struct testNodeInfoParserData {
+    collie_test data;
+    const char *poolxml;
+};
+
+struct testVDIListParserData {
+    collie_test data;
+    const char *poolxml;
+    const char *volxml;
+};
+
 
 static int
-test_node_info_parser(collie_test test, char *poolxml)
+test_node_info_parser(const void *opaque)
 {
+    const struct testNodeInfoParserData *data = opaque;
+    collie_test test = data->data;
     int ret = -1;
     char *output = NULL;
     virStoragePoolDefPtr pool = NULL;
 
-    if (!(pool = virStoragePoolDefParseFile(poolxml)))
+    if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
         goto cleanup;
 
     if (VIR_STRDUP(output, test.output) < 0)
@@ -78,17 +91,19 @@  test_node_info_parser(collie_test test, char *poolxml)
 }
 
 static int
-test_vdi_list_parser(collie_test test, char *poolxml, char *volxml)
+test_vdi_list_parser(const void *opaque)
 {
+    const struct testVDIListParserData *data = opaque;
+    collie_test test = data->data;
     int ret = -1;
     char *output = NULL;
     virStoragePoolDefPtr pool = NULL;
     virStorageVolDefPtr vol = NULL;
 
-    if (!(pool = virStoragePoolDefParseFile(poolxml)))
+    if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
         goto cleanup;
 
-    if (!(vol = virStorageVolDefParseFile(pool, volxml, 0)))
+    if (!(vol = virStorageVolDefParseFile(pool, data->volxml, 0)))
         goto cleanup;
 
     if (VIR_STRDUP(output, test.output) < 0)
@@ -118,7 +133,7 @@  test_vdi_list_parser(collie_test test, char *poolxml, char *volxml)
 static int
 mymain(void)
 {
-    int ret = -1;
+    int ret = 0;
     char *poolxml = NULL;
     char *volxml = NULL;
 
@@ -170,26 +185,42 @@  mymain(void)
                     abs_srcdir) < 0)
         goto cleanup;
 
+#define DO_TEST_NODE(collie)                                            \
+    do {                                                                \
+        struct testNodeInfoParserData data = {                          \
+            .data = collie,                                             \
+            .poolxml = poolxml,                                         \
+        };                                                              \
+        if (virtTestRun("node_info_parser", test_node_info_parser,      \
+                        &data) < 0)                                     \
+            ret = -1;                                                   \
+    } while (0)
+
     while (test->output != NULL) {
-        ret = test_node_info_parser(*test, poolxml);
-        virtTestResult("node_info_parser", ret, NULL);
+        DO_TEST_NODE(*test);
         ++test;
-        if (ret < 0)
-            return EXIT_FAILURE;
     }
 
+
+#define DO_TEST_VDI(collie)                                             \
+    do {                                                                \
+        struct testVDIListParserData data = {                           \
+            .data = collie,                                             \
+            .poolxml = poolxml,                                         \
+            .volxml = volxml,                                           \
+        };                                                              \
+        if (virtTestRun("vdi_list_parser", test_vdi_list_parser,        \
+                        &data) < 0)                                     \
+            ret = -1;                                                   \
+    } while (0)
+
     test = vdi_list_tests;
 
     while (test->output != NULL) {
-        ret = test_vdi_list_parser(*test, poolxml, volxml);
-        virtTestResult("vdi_list_parser", ret, NULL);
+        DO_TEST_VDI(*test);
         ++test;
-        if (ret < 0)
-            return EXIT_FAILURE;
     }
 
-    ret = 0;
-
  cleanup:
     VIR_FREE(poolxml);
     VIR_FREE(volxml);