From: Thomas Huth <thuth@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Bin Meng <bin.meng@windriver.com>
Subject: [PULL 32/37] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp
Date: Wed, 28 Sep 2022 09:18:38 +0200 [thread overview]
Message-ID: <20220928071843.1468323-33-thuth@redhat.com> (raw)
In-Reply-To: <20220928071843.1468323-1-thuth@redhat.com>
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>
Message-Id: <20220927110632.1973965-13-bmeng.cn@gmail.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/hd-geo-test.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index 413cf964c0..ba772f4d7a 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -27,16 +27,16 @@
static char *create_test_img(int secs)
{
- char *template = strdup("/tmp/qtest.XXXXXX");
+ char *template;
int fd, ret;
- fd = mkstemp(template);
+ fd = g_file_open_tmp("qtest.XXXXXX", &template, NULL);
g_assert(fd >= 0);
ret = ftruncate(fd, (off_t)secs * 512);
close(fd);
if (ret) {
- free(template);
+ g_free(template);
template = NULL;
}
@@ -422,9 +422,8 @@ static MBRpartitions empty_mbr = { {false, 0, 0, 0, 0, 0, 0, 0, 0},
static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
{
- const char *template = "/tmp/qtest.XXXXXX";
- char *raw_path = strdup(template);
- char *qcow2_path = strdup(template);
+ g_autofree char *raw_path = NULL;
+ char *qcow2_path;
char cmd[100 + 2 * PATH_MAX];
uint8_t buf[512] = {};
int i, ret, fd, offset;
@@ -468,7 +467,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
offset += 0x10;
}
- fd = mkstemp(raw_path);
+ fd = g_file_open_tmp("qtest.XXXXXX", &raw_path, NULL);
g_assert(fd >= 0);
close(fd);
@@ -478,7 +477,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
g_assert(ret == sizeof(buf));
close(fd);
- fd = mkstemp(qcow2_path);
+ fd = g_file_open_tmp("qtest.XXXXXX", &qcow2_path, NULL);
g_assert(fd >= 0);
close(fd);
@@ -506,7 +505,6 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
free(qemu_img_abs_path);
unlink(raw_path);
- free(raw_path);
return qcow2_path;
}
@@ -714,7 +712,7 @@ static void test_override(TestArgs *args, CHSResult expected[])
for (i = 0; i < args->n_drives; i++) {
unlink(args->drives[i]);
- free(args->drives[i]);
+ g_free(args->drives[i]);
}
g_free(args->drives);
g_strfreev(args->argv);
@@ -867,7 +865,7 @@ static void test_override_scsi_hot_unplug(void)
for (i = 0; i < args->n_drives; i++) {
unlink(args->drives[i]);
- free(args->drives[i]);
+ g_free(args->drives[i]);
}
g_free(args->drives);
g_strfreev(args->argv);
@@ -927,7 +925,7 @@ static void test_override_virtio_hot_unplug(void)
for (i = 0; i < args->n_drives; i++) {
unlink(args->drives[i]);
- free(args->drives[i]);
+ g_free(args->drives[i]);
}
g_free(args->drives);
g_strfreev(args->argv);
@@ -987,7 +985,7 @@ test_add_done:
for (i = 0; i < backend_last; i++) {
if (img_file_name[i]) {
unlink(img_file_name[i]);
- free(img_file_name[i]);
+ g_free(img_file_name[i]);
}
}
--
2.31.1
next prev parent reply other threads:[~2022-09-28 9:16 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 7:18 [PULL 00/37] qtests fixes Thomas Huth
2022-09-28 7:18 ` [PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Thomas Huth
2022-09-28 7:18 ` [PULL 02/37] tests/qtest: ahci-test: Avoid using hardcoded /tmp Thomas Huth
2022-09-28 7:18 ` [PULL 03/37] tests/qtest: aspeed_smc-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 04/37] tests/qtest: boot-serial-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 05/37] tests/qtest: cxl-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 06/37] tests/qtest: fdc-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 07/37] tests/qtest: generic_fuzz: " Thomas Huth
2022-09-28 7:18 ` [PULL 08/37] tests/qtest: virtio_blk_fuzz: " Thomas Huth
2022-09-28 7:18 ` [PULL 09/37] tests/qtest: ide-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 10/37] tests/qtest: vhost-user-blk-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 11/37] tests/qtest: virtio-blk-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 12/37] tests/qtest: virtio-scsi-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 13/37] tests/qtest: libqtest: " Thomas Huth
2022-09-28 7:18 ` [PULL 14/37] tests/unit: test-image-locking: " Thomas Huth
2022-09-28 7:18 ` [PULL 15/37] tests/unit: test-qga: " Thomas Huth
2022-09-28 7:18 ` [PULL 16/37] tests: vhost-user-bridge: " Thomas Huth
2022-09-28 7:18 ` [PULL 17/37] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Thomas Huth
2022-09-28 7:18 ` [PULL 18/37] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Thomas Huth
2022-09-28 7:18 ` [PULL 19/37] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Thomas Huth
2022-09-28 7:18 ` [PULL 20/37] tests/qtest: libqtest: Adapt global_qtest declaration " Thomas Huth
2022-09-28 7:18 ` [PULL 21/37] tests/qtest: libqtest: Exclude the *_fds APIs " Thomas Huth
2022-09-28 7:18 ` [PULL 22/37] tests/qtest: {ahci, ide}-test: Use relative path for temporary files " Thomas Huth
2022-09-28 7:18 ` [PULL 23/37] tests/qtest: bios-tables-test: Adapt the case " Thomas Huth
2022-09-28 7:18 ` [PULL 24/37] tests/qtest: migration-test: Disable IO redirection " Thomas Huth
2022-09-28 7:18 ` [PULL 25/37] tests/qtest: ide-test: Open file in binary mode Thomas Huth
2022-09-28 7:18 ` [PULL 26/37] tests/qtest: virtio-net-failover: Disable migration tests for win32 Thomas Huth
2022-09-28 7:18 ` [PULL 27/37] tests/qtest: microbit-test: Fix socket access " Thomas Huth
2022-09-28 7:18 ` [PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Thomas Huth
2022-09-28 7:18 ` [PULL 29/37] tests/qtest: migration-test: Skip running some TLS cases for win32 Thomas Huth
2022-09-28 7:18 ` [PULL 30/37] .gitlab-ci.d/windows.yml: Display meson test logs Thomas Huth
2022-09-28 7:18 ` [PULL 31/37] tests/x86: Move common code to function in device-plug-test Thomas Huth
2022-09-28 7:18 ` Thomas Huth [this message]
2022-09-28 7:18 ` [PULL 33/37] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp Thomas Huth
2022-09-28 7:18 ` [PULL 34/37] tests/qtest: qmp-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 35/37] tests/qtest: vhost-user-test: " Thomas Huth
2022-09-28 7:18 ` [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU Thomas Huth
2022-09-28 7:18 ` [PULL 37/37] docs/devel: testing: Document writing portable test cases Thomas Huth
2022-09-29 14:49 ` [PULL 00/37] qtests fixes Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220928071843.1468323-33-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=bin.meng@windriver.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).