9ae3a8
From f57ff93bf55cfdf09995c441cbbf8ad886f1afcb Mon Sep 17 00:00:00 2001
9ae3a8
From: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Date: Sat, 11 Jan 2014 18:00:05 +0100
9ae3a8
Subject: [PATCH 15/22] i440fx-test: give each GTest case its own qtest
9ae3a8
9ae3a8
RH-Author: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Message-id: <1389463208-6278-16-git-send-email-lersek@redhat.com>
9ae3a8
Patchwork-id: 56628
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 15/18] i440fx-test: give each GTest case its own qtest
9ae3a8
Bugzilla: 1032346
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Amos Kong <akong@redhat.com>
9ae3a8
RH-Acked-by: Andrew Jones <drjones@redhat.com>
9ae3a8
9ae3a8
The current two GTest cases, /i440fx/defaults and /i440fx/pam can share a
9ae3a8
qemu process, but the next two cases will need dedicated instances. It is
9ae3a8
messy (and order-dependent) to dynamically configure GTest cases one by
9ae3a8
one to start, stop, or keep the current qtest (*); let's just have each
9ae3a8
GTest work with its own qtest. The performance difference should be
9ae3a8
negligible.
9ae3a8
9ae3a8
(*) As g_test_run() can be invoked at most once per process startup, and
9ae3a8
it runs GTest cases in sequence, we'd need clumsy data structures to
9ae3a8
control each GTest case to start/stop/keep the qemu instance. Or, we'd
9ae3a8
have to code the same information into the test methods themselves, which
9ae3a8
would make them even more order-dependent.
9ae3a8
9ae3a8
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
(cherry picked from commit c37805b6724e5d4c3ad41653630b72b43619474e)
9ae3a8
---
9ae3a8
 tests/i440fx-test.c | 32 +++++++++++++++++++-------------
9ae3a8
 1 file changed, 19 insertions(+), 13 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 tests/i440fx-test.c |   32 +++++++++++++++++++-------------
9ae3a8
 1 files changed, 19 insertions(+), 13 deletions(-)
9ae3a8
9ae3a8
diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c
9ae3a8
index 6ac46bf..3962bca 100644
9ae3a8
--- a/tests/i440fx-test.c
9ae3a8
+++ b/tests/i440fx-test.c
9ae3a8
@@ -28,16 +28,27 @@
9ae3a8
 typedef struct TestData
9ae3a8
 {
9ae3a8
     int num_cpus;
9ae3a8
-    QPCIBus *bus;
9ae3a8
 } TestData;
9ae3a8
 
9ae3a8
+static QPCIBus *test_start_get_bus(const TestData *s)
9ae3a8
+{
9ae3a8
+    char *cmdline;
9ae3a8
+
9ae3a8
+    cmdline = g_strdup_printf("-smp %d", s->num_cpus);
9ae3a8
+    qtest_start(cmdline);
9ae3a8
+    g_free(cmdline);
9ae3a8
+    return qpci_init_pc();
9ae3a8
+}
9ae3a8
+
9ae3a8
 static void test_i440fx_defaults(gconstpointer opaque)
9ae3a8
 {
9ae3a8
     const TestData *s = opaque;
9ae3a8
+    QPCIBus *bus;
9ae3a8
     QPCIDevice *dev;
9ae3a8
     uint32_t value;
9ae3a8
 
9ae3a8
-    dev = qpci_device_find(s->bus, QPCI_DEVFN(0, 0));
9ae3a8
+    bus = test_start_get_bus(s);
9ae3a8
+    dev = qpci_device_find(bus, QPCI_DEVFN(0, 0));
9ae3a8
     g_assert(dev != NULL);
9ae3a8
 
9ae3a8
     /* 3.2.2 */
9ae3a8
@@ -121,6 +132,8 @@ static void test_i440fx_defaults(gconstpointer opaque)
9ae3a8
     g_assert_cmpint(qpci_config_readb(dev, 0x91), ==, 0x00); /* ERRSTS */
9ae3a8
     /* 3.2.26 */
9ae3a8
     g_assert_cmpint(qpci_config_readb(dev, 0x93), ==, 0x00); /* TRC */
9ae3a8
+
9ae3a8
+    qtest_end();
9ae3a8
 }
9ae3a8
 
9ae3a8
 #define PAM_RE 1
9ae3a8
@@ -179,6 +192,7 @@ static void write_area(uint32_t start, uint32_t end, uint8_t value)
9ae3a8
 static void test_i440fx_pam(gconstpointer opaque)
9ae3a8
 {
9ae3a8
     const TestData *s = opaque;
9ae3a8
+    QPCIBus *bus;
9ae3a8
     QPCIDevice *dev;
9ae3a8
     int i;
9ae3a8
     static struct {
9ae3a8
@@ -201,7 +215,8 @@ static void test_i440fx_pam(gconstpointer opaque)
9ae3a8
         { 0xEC000, 0xEFFFF }, /* BIOS Extension */
9ae3a8
     };
9ae3a8
 
9ae3a8
-    dev = qpci_device_find(s->bus, QPCI_DEVFN(0, 0));
9ae3a8
+    bus = test_start_get_bus(s);
9ae3a8
+    dev = qpci_device_find(bus, QPCI_DEVFN(0, 0));
9ae3a8
     g_assert(dev != NULL);
9ae3a8
 
9ae3a8
     for (i = 0; i < ARRAY_SIZE(pam_area); i++) {
9ae3a8
@@ -254,30 +269,21 @@ static void test_i440fx_pam(gconstpointer opaque)
9ae3a8
         /* Verify the area is not our new mask */
9ae3a8
         g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x82));
9ae3a8
     }
9ae3a8
+    qtest_end();
9ae3a8
 }
9ae3a8
 
9ae3a8
 int main(int argc, char **argv)
9ae3a8
 {
9ae3a8
     TestData data;
9ae3a8
-    char *cmdline;
9ae3a8
     int ret;
9ae3a8
 
9ae3a8
     g_test_init(&argc, &argv, NULL);
9ae3a8
 
9ae3a8
     data.num_cpus = 1;
9ae3a8
 
9ae3a8
-    cmdline = g_strdup_printf("-smp %d", data.num_cpus);
9ae3a8
-    qtest_start(cmdline);
9ae3a8
-    g_free(cmdline);
9ae3a8
-
9ae3a8
-    data.bus = qpci_init_pc();
9ae3a8
-
9ae3a8
     g_test_add_data_func("/i440fx/defaults", &data, test_i440fx_defaults);
9ae3a8
     g_test_add_data_func("/i440fx/pam", &data, test_i440fx_pam);
9ae3a8
 
9ae3a8
     ret = g_test_run();
9ae3a8
-
9ae3a8
-    qtest_end();
9ae3a8
-
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8