tests/qtest: fdc-test: Avoid using hardcoded /tmp

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: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220925113032.1949844-10-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Bin Meng 2022-09-25 19:29:47 +08:00 committed by Thomas Huth
parent 39180d4e94
commit 394bcc5bc5

View File

@ -68,7 +68,7 @@ enum {
DSKCHG = 0x80,
};
static char test_image[] = "/tmp/qtest.XXXXXX";
static char *test_image;
#define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
#define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
@ -608,7 +608,7 @@ int main(int argc, char **argv)
int ret;
/* Create a temporary raw image */
fd = mkstemp(test_image);
fd = g_file_open_tmp("qtest.XXXXXX", &test_image, NULL);
g_assert(fd >= 0);
ret = ftruncate(fd, TEST_IMAGE_SIZE);
g_assert(ret == 0);
@ -640,6 +640,7 @@ int main(int argc, char **argv)
/* Cleanup */
qtest_end();
unlink(test_image);
g_free(test_image);
return ret;
}