[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be
From: |
Thomas Huth |
Subject: |
[PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable |
Date: |
Wed, 28 Sep 2022 09:18:07 +0200 |
From: Bin Meng <bin.meng@windriver.com>
Previously request_{bios, pflash} cases were skipped on win32, mainly
due to create_blob_file() calling mmap() which does not exist on win32.
This rewirtes create_blob_file() to be portable, so that we can enable
these cases on Windows.
Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220925113032.1949844-2-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/i440fx-test.c | 54 ++++++++++-----------------------------
1 file changed, 14 insertions(+), 40 deletions(-)
diff --git a/tests/qtest/i440fx-test.c b/tests/qtest/i440fx-test.c
index 3890f1237c..795fd85343 100644
--- a/tests/qtest/i440fx-test.c
+++ b/tests/qtest/i440fx-test.c
@@ -278,56 +278,34 @@ static void test_i440fx_pam(gconstpointer opaque)
qtest_end();
}
-#ifndef _WIN32
-
#define BLOB_SIZE ((size_t)65536)
#define ISA_BIOS_MAXSZ ((size_t)(128 * 1024))
-/* Create a blob file, and return its absolute pathname as a dynamically
+/*
+ * 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.
+ * In case of error, the function aborts and prints the error message.
*/
static char *create_blob_file(void)
{
- int ret, fd;
+ int i, fd;
char *pathname;
GError *error = NULL;
+ g_autofree uint8_t *buf = g_malloc(BLOB_SIZE);
- 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);
- }
+ g_assert_no_error(error);
+ close(fd);
+
+ for (i = 0; i < BLOB_SIZE; i++) {
+ buf[i] = i;
}
- return ret == -1 ? NULL : pathname;
+ g_file_set_contents(pathname, (char *)buf, BLOB_SIZE, &error);
+ g_assert_no_error(error);
+
+ return pathname;
}
static void test_i440fx_firmware(FirmwareTestFixture *fixture,
@@ -398,8 +376,6 @@ static void request_pflash(FirmwareTestFixture *fixture,
fixture->is_bios = false;
}
-#endif /* _WIN32 */
-
int main(int argc, char **argv)
{
TestData data;
@@ -410,10 +386,8 @@ int main(int argc, char **argv)
qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults);
qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam);
-#ifndef _WIN32
add_firmware_test("i440fx/firmware/bios", request_bios);
add_firmware_test("i440fx/firmware/pflash", request_pflash);
-#endif
return g_test_run();
}
--
2.31.1
- [PULL 00/37] qtests fixes, Thomas Huth, 2022/09/28
- [PULL 02/37] tests/qtest: ahci-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 03/37] tests/qtest: aspeed_smc-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable,
Thomas Huth <=
- [PULL 06/37] tests/qtest: fdc-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 04/37] tests/qtest: boot-serial-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 07/37] tests/qtest: generic_fuzz: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 15/37] tests/unit: test-qga: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 13/37] tests/qtest: libqtest: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 05/37] tests/qtest: cxl-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 10/37] tests/qtest: vhost-user-blk-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 21/37] tests/qtest: libqtest: Exclude the *_fds APIs for win32, Thomas Huth, 2022/09/28
- [PULL 22/37] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32, Thomas Huth, 2022/09/28
- [PULL 11/37] tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28