cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-i440fx-test-verify-firmware-under-4G-and-1M-both-bio.patch

0a122b
From 473a279de264f7d56a41ac77aa9db4d783733f34 Mon Sep 17 00:00:00 2001
0a122b
From: Laszlo Ersek <lersek@redhat.com>
0a122b
Date: Sat, 11 Jan 2014 18:00:07 +0100
0a122b
Subject: [PATCH 17/22] i440fx-test: verify firmware under 4G and 1M, both -bios and -pflash
0a122b
0a122b
RH-Author: Laszlo Ersek <lersek@redhat.com>
0a122b
Message-id: <1389463208-6278-18-git-send-email-lersek@redhat.com>
0a122b
Patchwork-id: 56631
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH 17/18] i440fx-test: verify firmware under 4G and 1M, both -bios and -pflash
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
Check whether the firmware is not hidden by other memory regions.
0a122b
0a122b
Qemu is started in paused mode: it shouldn't try to interpret generated
0a122b
garbage.
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 3bcc77ae9935c8c3d10f63492af81f1d7d99d492)
0a122b
---
0a122b
 tests/i440fx-test.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++----
0a122b
 1 file changed, 75 insertions(+), 6 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 tests/i440fx-test.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++----
0a122b
 1 files changed, 75 insertions(+), 6 deletions(-)
0a122b
0a122b
diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c
0a122b
index b6e0cd3..fa3e3d6 100644
0a122b
--- a/tests/i440fx-test.c
0a122b
+++ b/tests/i440fx-test.c
0a122b
@@ -35,6 +35,11 @@ typedef struct TestData
0a122b
     int num_cpus;
0a122b
 } TestData;
0a122b
 
0a122b
+typedef struct FirmwareTestFixture {
0a122b
+    /* decides whether we're testing -bios or -pflash */
0a122b
+    bool is_bios;
0a122b
+} FirmwareTestFixture;
0a122b
+
0a122b
 static QPCIBus *test_start_get_bus(const TestData *s)
0a122b
 {
0a122b
     char *cmdline;
0a122b
@@ -278,6 +283,7 @@ static void test_i440fx_pam(gconstpointer opaque)
0a122b
 }
0a122b
 
0a122b
 #define BLOB_SIZE ((size_t)65536)
0a122b
+#define ISA_BIOS_MAXSZ ((size_t)(128 * 1024))
0a122b
 
0a122b
 /* Create a blob file, and return its absolute pathname as a dynamically
0a122b
  * allocated string.
0a122b
@@ -326,23 +332,86 @@ static char *create_blob_file(void)
0a122b
     return ret == -1 ? NULL : pathname;
0a122b
 }
0a122b
 
0a122b
-int main(int argc, char **argv)
0a122b
+static void test_i440fx_firmware(FirmwareTestFixture *fixture,
0a122b
+                                 gconstpointer user_data)
0a122b
 {
0a122b
-    char *fw_pathname;
0a122b
-    TestData data;
0a122b
-    int ret;
0a122b
-
0a122b
-    g_test_init(&argc, &argv, NULL);
0a122b
+    char *fw_pathname, *cmdline;
0a122b
+    uint8_t *buf;
0a122b
+    size_t i, isa_bios_size;
0a122b
 
0a122b
     fw_pathname = create_blob_file();
0a122b
     g_assert(fw_pathname != NULL);
0a122b
+
0a122b
+    /* Better hope the user didn't put metacharacters in TMPDIR and co. */
0a122b
+    cmdline = g_strdup_printf("-S %s %s",
0a122b
+                              fixture->is_bios ? "-bios" : "-pflash",
0a122b
+                              fw_pathname);
0a122b
+    g_test_message("qemu cmdline: %s", cmdline);
0a122b
+    qtest_start(cmdline);
0a122b
+    g_free(cmdline);
0a122b
+
0a122b
+    /* Qemu has loaded the firmware (because qtest_start() only returns after
0a122b
+     * the QMP handshake completes). We must unlink the firmware blob right
0a122b
+     * here, because any assertion firing below would leak it in the
0a122b
+     * filesystem. This is also the reason why we recreate the blob every time
0a122b
+     * this function is invoked.
0a122b
+     */
0a122b
     unlink(fw_pathname);
0a122b
     g_free(fw_pathname);
0a122b
 
0a122b
+    /* check below 4G */
0a122b
+    buf = g_malloc0(BLOB_SIZE);
0a122b
+    memread(0x100000000ULL - BLOB_SIZE, buf, BLOB_SIZE);
0a122b
+    for (i = 0; i < BLOB_SIZE; ++i) {
0a122b
+        g_assert_cmphex(buf[i], ==, (uint8_t)i);
0a122b
+    }
0a122b
+
0a122b
+    /* check in ISA space too */
0a122b
+    memset(buf, 0, BLOB_SIZE);
0a122b
+    isa_bios_size = ISA_BIOS_MAXSZ < BLOB_SIZE ? ISA_BIOS_MAXSZ : BLOB_SIZE;
0a122b
+    memread(0x100000 - isa_bios_size, buf, isa_bios_size);
0a122b
+    for (i = 0; i < isa_bios_size; ++i) {
0a122b
+        g_assert_cmphex(buf[i], ==,
0a122b
+                        (uint8_t)((BLOB_SIZE - isa_bios_size) + i));
0a122b
+    }
0a122b
+
0a122b
+    g_free(buf);
0a122b
+    qtest_end();
0a122b
+}
0a122b
+
0a122b
+static void add_firmware_test(const char *testpath,
0a122b
+                              void (*setup_fixture)(FirmwareTestFixture *f,
0a122b
+                                                    gconstpointer test_data))
0a122b
+{
0a122b
+    g_test_add(testpath, FirmwareTestFixture, NULL, setup_fixture,
0a122b
+               test_i440fx_firmware, NULL);
0a122b
+}
0a122b
+
0a122b
+static void request_bios(FirmwareTestFixture *fixture,
0a122b
+                         gconstpointer user_data)
0a122b
+{
0a122b
+    fixture->is_bios = true;
0a122b
+}
0a122b
+
0a122b
+static void request_pflash(FirmwareTestFixture *fixture,
0a122b
+                           gconstpointer user_data)
0a122b
+{
0a122b
+    fixture->is_bios = false;
0a122b
+}
0a122b
+
0a122b
+int main(int argc, char **argv)
0a122b
+{
0a122b
+    TestData data;
0a122b
+    int ret;
0a122b
+
0a122b
+    g_test_init(&argc, &argv, NULL);
0a122b
+
0a122b
     data.num_cpus = 1;
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
+    add_firmware_test("/i440fx/firmware/bios", request_bios);
0a122b
+    add_firmware_test("/i440fx/firmware/pflash", request_pflash);
0a122b
 
0a122b
     ret = g_test_run();
0a122b
     return ret;
0a122b
-- 
0a122b
1.7.1
0a122b