[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 33/37] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp
From: |
Thomas Huth |
Subject: |
[PULL 33/37] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp |
Date: |
Wed, 28 Sep 2022 09:18:39 +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>
Message-Id: <20220927110632.1973965-16-bmeng.cn@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/pflash-cfi02-test.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
index 7fce614b64..0b52c2ca5c 100644
--- a/tests/qtest/pflash-cfi02-test.c
+++ b/tests/qtest/pflash-cfi02-test.c
@@ -56,7 +56,7 @@ typedef struct {
QTestState *qtest;
} FlashConfig;
-static char image_path[] = "/tmp/qtest.XXXXXX";
+static char *image_path;
/*
* The pflash implementation allows some parameters to be unspecified. We want
@@ -608,6 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
static void cleanup(void *opaque)
{
unlink(image_path);
+ g_free(image_path);
}
/*
@@ -635,16 +636,14 @@ static const FlashConfig configuration[] = {
int main(int argc, char **argv)
{
- int fd = mkstemp(image_path);
- if (fd == -1) {
- g_printerr("Failed to create temporary file %s: %s\n", image_path,
- strerror(errno));
- exit(EXIT_FAILURE);
- }
+ GError *err = NULL;
+ int fd = g_file_open_tmp("qtest.XXXXXX", &image_path, &err);
+ g_assert_no_error(err);
+
if (ftruncate(fd, UNIFORM_FLASH_SIZE) < 0) {
int error_code = errno;
close(fd);
- unlink(image_path);
+ cleanup(NULL);
g_printerr("Failed to truncate file %s to %u MB: %s\n", image_path,
UNIFORM_FLASH_SIZE, strerror(error_code));
exit(EXIT_FAILURE);
--
2.31.1
- [PULL 21/37] tests/qtest: libqtest: Exclude the *_fds APIs for win32, (continued)
- [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
- [PULL 20/37] tests/qtest: libqtest: Adapt global_qtest declaration for win32, Thomas Huth, 2022/09/28
- [PULL 24/37] tests/qtest: migration-test: Disable IO redirection for win32, Thomas Huth, 2022/09/28
- [PULL 27/37] tests/qtest: microbit-test: Fix socket access for win32, Thomas Huth, 2022/09/28
- [PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket with closesocket(), Thomas Huth, 2022/09/28
- [PULL 30/37] .gitlab-ci.d/windows.yml: Display meson test logs, Thomas Huth, 2022/09/28
- [PULL 32/37] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 34/37] tests/qtest: qmp-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 33/37] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp,
Thomas Huth <=
- [PULL 35/37] tests/qtest: vhost-user-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU, Thomas Huth, 2022/09/28
- [PULL 09/37] tests/qtest: ide-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 12/37] tests/qtest: virtio-scsi-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 16/37] tests: vhost-user-bridge: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 17/37] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32, Thomas Huth, 2022/09/28
- [PULL 23/37] tests/qtest: bios-tables-test: Adapt the case for win32, Thomas Huth, 2022/09/28
- [PULL 25/37] tests/qtest: ide-test: Open file in binary mode, Thomas Huth, 2022/09/28
- [PULL 29/37] tests/qtest: migration-test: Skip running some TLS cases for win32, Thomas Huth, 2022/09/28
- [PULL 08/37] tests/qtest: virtio_blk_fuzz: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28