[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 15/54] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /
From: |
Bin Meng |
Subject: |
[PATCH v4 15/54] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp |
Date: |
Tue, 27 Sep 2022 19:05:53 +0800 |
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>
---
Changes in v4:
- Replace the whole block with a g_assert_no_error()
Changes in v3:
- Split to a separate patch
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.34.1
- Re: [PATCH v4 12/54] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp, (continued)
- [PATCH v4 14/54] tests/qtest: migration-test: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 21/54] tests/qtest: libqtest: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 19/54] tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 20/54] tests/qtest: virtio-scsi-test: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 22/54] tests/unit: test-image-locking: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 25/54] block/vvfat: Unify the mkdir() call, Bin Meng, 2022/09/27
- [PATCH v4 24/54] tests: vhost-user-bridge: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 15/54] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp,
Bin Meng <=
- [PATCH v4 16/54] tests/qtest: qmp-test: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 11/54] tests/qtest: virtio_blk_fuzz: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 23/54] tests/unit: test-qga: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 18/54] tests/qtest: vhost-user-test: Avoid using hardcoded /tmp, Bin Meng, 2022/09/27
- [PATCH v4 27/54] hw/usb: dev-mtp: Use g_mkdir(), Bin Meng, 2022/09/27
- [PATCH v4 29/54] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only, Bin Meng, 2022/09/27