From: Bin Meng <bin.m...@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.m...@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