[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/37] tests/qtest: ahci-test: Avoid using hardcoded /tmp
From: |
Thomas Huth |
Subject: |
[PULL 02/37] tests/qtest: ahci-test: Avoid using hardcoded /tmp |
Date: |
Wed, 28 Sep 2022 09:18:08 +0200 |
From: Bin Meng <bin.meng@windriver.com>
This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220925113032.1949844-6-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/ahci-test.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index f1e510b0ac..1d5929d8c3 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -44,9 +44,9 @@
#define TEST_IMAGE_SIZE_MB_SMALL 64
/*** Globals ***/
-static char tmp_path[] = "/tmp/qtest.XXXXXX";
-static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
-static char mig_socket[] = "/tmp/qtest-migration.XXXXXX";
+static char *tmp_path;
+static char *debug_path;
+static char *mig_socket;
static bool ahci_pedantic;
static const char *imgfmt;
static unsigned test_image_size_mb;
@@ -1437,10 +1437,10 @@ static void test_ncq_simple(void)
static int prepare_iso(size_t size, unsigned char **buf, char **name)
{
- char cdrom_path[] = "/tmp/qtest.iso.XXXXXX";
+ g_autofree char *cdrom_path = NULL;
unsigned char *patt;
ssize_t ret;
- int fd = mkstemp(cdrom_path);
+ int fd = g_file_open_tmp("qtest.iso.XXXXXX", &cdrom_path, NULL);
g_assert(fd != -1);
g_assert(buf);
@@ -1872,7 +1872,7 @@ int main(int argc, char **argv)
}
/* Create a temporary image */
- fd = mkstemp(tmp_path);
+ fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
g_assert(fd >= 0);
if (have_qemu_img()) {
imgfmt = "qcow2";
@@ -1889,12 +1889,12 @@ int main(int argc, char **argv)
close(fd);
/* Create temporary blkdebug instructions */
- fd = mkstemp(debug_path);
+ fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
g_assert(fd >= 0);
close(fd);
/* Reserve a hollow file to use as a socket for migration tests */
- fd = mkstemp(mig_socket);
+ fd = g_file_open_tmp("qtest-migration.XXXXXX", &mig_socket, NULL);
g_assert(fd >= 0);
close(fd);
@@ -1947,8 +1947,11 @@ int main(int argc, char **argv)
/* Cleanup */
unlink(tmp_path);
+ g_free(tmp_path);
unlink(debug_path);
+ g_free(debug_path);
unlink(mig_socket);
+ g_free(mig_socket);
return ret;
}
--
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 <=
- [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, 2022/09/28
- [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