[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32
From: |
Bin Meng |
Subject: |
[PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32 |
Date: |
Wed, 24 Aug 2022 17:40:10 +0800 |
From: Bin Meng <bin.meng@windriver.com>
On Windows, the MinGW provided mkstemp() API opens the file with
exclusive access, denying other processes to read/write the file.
Such behavior prevents the QEMU executable from opening the file,
(e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
This can be fixed by closing the file and reopening it.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
tests/qtest/ahci-test.c | 14 ++++++++++++++
tests/qtest/boot-serial-test.c | 13 +++++++++++++
2 files changed, 27 insertions(+)
diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index f26cd6f86f..0e88cd0eef 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1443,6 +1443,20 @@ static int prepare_iso(size_t size, unsigned char **buf,
char **name)
int fd = mkstemp(cdrom_path);
g_assert(fd != -1);
+#ifdef _WIN32
+ /*
+ * On Windows, the MinGW provided mkstemp() API opens the file with
+ * exclusive access, denying other processes to read/write the file.
+ * Such behavior prevents the QEMU executable from opening the file,
+ * (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
+ *
+ * Close the file and reopen it.
+ */
+ close(fd);
+ fd = open(cdrom_path, O_WRONLY);
+ g_assert(fd != -1);
+#endif
+
g_assert(buf);
g_assert(name);
patt = g_malloc(size);
diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
index 404adcfa20..fb6c81bf35 100644
--- a/tests/qtest/boot-serial-test.c
+++ b/tests/qtest/boot-serial-test.c
@@ -235,6 +235,19 @@ static void test_machine(const void *data)
ser_fd = mkstemp(serialtmp);
g_assert(ser_fd != -1);
+#ifdef _WIN32
+ /*
+ * On Windows, the MinGW provided mkstemp() API opens the file with
+ * exclusive access, denying other processes to read/write the file.
+ * Such behavior prevents the QEMU executable from opening the file,
+ * (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
+ *
+ * Close the file and reopen it.
+ */
+ close(ser_fd);
+ ser_fd = open(serialtmp, O_RDONLY);
+ g_assert(ser_fd != -1);
+#endif
if (test->kernel) {
code = test->kernel;
--
2.34.1
- Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication, (continued)
[PATCH 28/51] tests/qtest: libqtest: Exclude the *_fds APIs for win32, Bin Meng, 2022/08/24
[PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal(), Bin Meng, 2022/08/24
[PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices', Bin Meng, 2022/08/24
[PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows, Bin Meng, 2022/08/24
[PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32,
Bin Meng <=
[PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32, Bin Meng, 2022/08/24
[PATCH 39/51] tests/qtest: virtio-net-failover: Disable migration tests for win32, Bin Meng, 2022/08/24
[PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32, Bin Meng, 2022/08/24
[PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files, Bin Meng, 2022/08/24
[PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode, Bin Meng, 2022/08/24