[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/19] i440fx-test: generate temporary firmware blob
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 06/19] i440fx-test: generate temporary firmware blob |
Date: |
Mon, 23 Dec 2013 18:11:45 +0200 |
From: Laszlo Ersek <address@hidden>
The blob is 64K in size and contains 0x00..0xFF repeatedly.
The client code added to main() wouldn't make much sense in the long term.
It helps with debugging and it silences gcc about create_blob_file() being
unused, and we'll replace it in the next patch anyway.
Signed-off-by: Laszlo Ersek <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
tests/i440fx-test.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c
index 3962bca..b6e0cd3 100644
--- a/tests/i440fx-test.c
+++ b/tests/i440fx-test.c
@@ -20,6 +20,11 @@
#include <glib.h>
#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <stdlib.h>
#define BROKEN 1
@@ -272,13 +277,68 @@ static void test_i440fx_pam(gconstpointer opaque)
qtest_end();
}
+#define BLOB_SIZE ((size_t)65536)
+
+/* Create a blob file, and return its absolute pathname as a dynamically
+ * allocated string.
+ * The file is closed before the function returns.
+ * In case of error, NULL is returned. The function prints the error message.
+ */
+static char *create_blob_file(void)
+{
+ int ret, fd;
+ char *pathname;
+ GError *error = NULL;
+
+ ret = -1;
+ fd = g_file_open_tmp("blob_XXXXXX", &pathname, &error);
+ if (fd == -1) {
+ fprintf(stderr, "unable to create blob file: %s\n", error->message);
+ g_error_free(error);
+ } else {
+ if (ftruncate(fd, BLOB_SIZE) == -1) {
+ fprintf(stderr, "ftruncate(\"%s\", %zu): %s\n", pathname,
+ BLOB_SIZE, strerror(errno));
+ } else {
+ void *buf;
+
+ buf = mmap(NULL, BLOB_SIZE, PROT_WRITE, MAP_SHARED, fd, 0);
+ if (buf == MAP_FAILED) {
+ fprintf(stderr, "mmap(\"%s\", %zu): %s\n", pathname, BLOB_SIZE,
+ strerror(errno));
+ } else {
+ size_t i;
+
+ for (i = 0; i < BLOB_SIZE; ++i) {
+ ((uint8_t *)buf)[i] = i;
+ }
+ munmap(buf, BLOB_SIZE);
+ ret = 0;
+ }
+ }
+ close(fd);
+ if (ret == -1) {
+ unlink(pathname);
+ g_free(pathname);
+ }
+ }
+
+ return ret == -1 ? NULL : pathname;
+}
+
int main(int argc, char **argv)
{
+ char *fw_pathname;
TestData data;
int ret;
g_test_init(&argc, &argv, NULL);
+ fw_pathname = create_blob_file();
+ g_assert(fw_pathname != NULL);
+ unlink(fw_pathname);
+ g_free(fw_pathname);
+
data.num_cpus = 1;
g_test_add_data_func("/i440fx/defaults", &data, test_i440fx_defaults);
--
MST
- [Qemu-devel] [PULL 00/19] acpi, pci, pc, fedora, virtio fixes and enhancements, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 01/19] piix: gigabyte alignment for ram, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 02/19] pc_piix: document gigabyte_align, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 03/19] hw/i386/pc_sysfw: support two flash drives, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 04/19] i440fx-test: qtest_start() should be paired with qtest_end(), Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 05/19] i440fx-test: give each GTest case its own qtest, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 06/19] i440fx-test: generate temporary firmware blob,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 07/19] i440fx-test: verify firmware under 4G and 1M, both -bios and -pflash, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 08/19] acpi: piix4: remove not needed GPE0 mask, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 09/19] acpi: factor out common pm_update_sci() into acpi core, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 10/19] acpi: ich9: allow guest to clear SCI rised by GPE, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 11/19] ACPI: Q35 DSDT: fix CPU hotplug GPE0.2 handler, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 12/19] ACPI/DSDT-CPU: cleanup bogus comment, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 13/19] pci: do not export pci_bus_reset, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 15/19] qdev: allow both pre- and post-order vists in qdev walking functions, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 14/19] pci: clean up resetting of IRQs, Michael S. Tsirkin, 2013/12/23
- [Qemu-devel] [PULL 17/19] piix: fix 32bit pci hole, Michael S. Tsirkin, 2013/12/23