thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-i440fx-test-give-each-GTest-case-its-own-qtest.patch

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