* [PATCH] tests/unit/test-image-locking: Fix handling of temporary files
@ 2022-10-12 8:59 Thomas Huth
2022-10-12 9:21 ` Marc-André Lureau
2022-10-12 12:59 ` Bin Meng
0 siblings, 2 replies; 4+ messages in thread
From: Thomas Huth @ 2022-10-12 8:59 UTC (permalink / raw)
To: Fam Zheng, qemu-devel; +Cc: qemu-block
test-image-locking leaves some temporary files around - clean
them up. While we're at it, test-image-locking is a unit test,
so it should not use "qtest.*" for temporary file names. Give
them better names instead, so that it clear where the temporary
files come from.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/unit/test-image-locking.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tests/unit/test-image-locking.c b/tests/unit/test-image-locking.c
index a47299c247..2624cec6a0 100644
--- a/tests/unit/test-image-locking.c
+++ b/tests/unit/test-image-locking.c
@@ -79,7 +79,7 @@ static void test_image_locking_basic(void)
g_autofree char *img_path = NULL;
uint64_t perm, shared_perm;
- int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL);
+ int fd = g_file_open_tmp("qemu-tst-img-lock.XXXXXX", &img_path, NULL);
assert(fd >= 0);
perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;
@@ -120,7 +120,7 @@ static void test_set_perm_abort(void)
g_autofree char *img_path = NULL;
uint64_t perm, shared_perm;
int r;
- int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL);
+ int fd = g_file_open_tmp("qemu-tst-img-lock.XXXXXX", &img_path, NULL);
assert(fd >= 0);
perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;
@@ -140,6 +140,8 @@ static void test_set_perm_abort(void)
check_locked_bytes(fd, perm, ~shared_perm);
blk_unref(blk1);
blk_unref(blk2);
+ close(fd);
+ unlink(img_path);
}
int main(int argc, char **argv)
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tests/unit/test-image-locking: Fix handling of temporary files
2022-10-12 8:59 [PATCH] tests/unit/test-image-locking: Fix handling of temporary files Thomas Huth
@ 2022-10-12 9:21 ` Marc-André Lureau
2022-10-12 9:46 ` Thomas Huth
2022-10-12 12:59 ` Bin Meng
1 sibling, 1 reply; 4+ messages in thread
From: Marc-André Lureau @ 2022-10-12 9:21 UTC (permalink / raw)
To: Thomas Huth, Bin Meng; +Cc: Fam Zheng, qemu-devel, qemu-block
[-- Attachment #1: Type: text/plain, Size: 1914 bytes --]
Hi
On Wed, Oct 12, 2022 at 1:03 PM Thomas Huth <thuth@redhat.com> wrote:
> test-image-locking leaves some temporary files around - clean
> them up. While we're at it, test-image-locking is a unit test,
> so it should not use "qtest.*" for temporary file names. Give
> them better names instead, so that it clear where the temporary
> files come from.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> tests/unit/test-image-locking.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tests/unit/test-image-locking.c
> b/tests/unit/test-image-locking.c
> index a47299c247..2624cec6a0 100644
> --- a/tests/unit/test-image-locking.c
> +++ b/tests/unit/test-image-locking.c
> @@ -79,7 +79,7 @@ static void test_image_locking_basic(void)
> g_autofree char *img_path = NULL;
> uint64_t perm, shared_perm;
>
> - int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL);
> + int fd = g_file_open_tmp("qemu-tst-img-lock.XXXXXX", &img_path, NULL);
> assert(fd >= 0);
>
> perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;
> @@ -120,7 +120,7 @@ static void test_set_perm_abort(void)
> g_autofree char *img_path = NULL;
> uint64_t perm, shared_perm;
> int r;
> - int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL);
> + int fd = g_file_open_tmp("qemu-tst-img-lock.XXXXXX", &img_path, NULL);
> assert(fd >= 0);
>
> perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;
> @@ -140,6 +140,8 @@ static void test_set_perm_abort(void)
> check_locked_bytes(fd, perm, ~shared_perm);
> blk_unref(blk1);
> blk_unref(blk2);
> + close(fd);
> + unlink(img_path);
>
Perhaps we should use g_unlink() instead for better portability? although
this is pre-existing.
otherwise, lgtm
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
--
Marc-André Lureau
[-- Attachment #2: Type: text/html, Size: 2638 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tests/unit/test-image-locking: Fix handling of temporary files
2022-10-12 9:21 ` Marc-André Lureau
@ 2022-10-12 9:46 ` Thomas Huth
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2022-10-12 9:46 UTC (permalink / raw)
To: Marc-André Lureau, Bin Meng; +Cc: Fam Zheng, qemu-devel, qemu-block
On 12/10/2022 11.21, Marc-André Lureau wrote:
> Hi
>
> On Wed, Oct 12, 2022 at 1:03 PM Thomas Huth <thuth@redhat.com
> <mailto:thuth@redhat.com>> wrote:
>
> test-image-locking leaves some temporary files around - clean
> them up. While we're at it, test-image-locking is a unit test,
> so it should not use "qtest.*" for temporary file names. Give
> them better names instead, so that it clear where the temporary
> files come from.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com <mailto:thuth@redhat.com>>
> ---
[...]
> @@ -140,6 +140,8 @@ static void test_set_perm_abort(void)
> check_locked_bytes(fd, perm, ~shared_perm);
> blk_unref(blk1);
> blk_unref(blk2);
> + close(fd);
> + unlink(img_path);
>
>
> Perhaps we should use g_unlink() instead for better portability? although
> this is pre-existing.
I thought about that, too, but apparently you have to include an additional
header file (gstdio.h) to get the prototype - so it seems to be more effort
for no real gain (unless you want to use non-ASCII characters in the
filename - which we are not doing here).
Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tests/unit/test-image-locking: Fix handling of temporary files
2022-10-12 8:59 [PATCH] tests/unit/test-image-locking: Fix handling of temporary files Thomas Huth
2022-10-12 9:21 ` Marc-André Lureau
@ 2022-10-12 12:59 ` Bin Meng
1 sibling, 0 replies; 4+ messages in thread
From: Bin Meng @ 2022-10-12 12:59 UTC (permalink / raw)
To: Thomas Huth; +Cc: Fam Zheng, qemu-devel, qemu-block
On Wed, Oct 12, 2022 at 4:59 PM Thomas Huth <thuth@redhat.com> wrote:
>
> test-image-locking leaves some temporary files around - clean
> them up. While we're at it, test-image-locking is a unit test,
> so it should not use "qtest.*" for temporary file names. Give
> them better names instead, so that it clear where the temporary
> files come from.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> tests/unit/test-image-locking.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
Fixes: aef96d7d4f0b ("tests: Add unit tests for image locking")
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-12 13:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 8:59 [PATCH] tests/unit/test-image-locking: Fix handling of temporary files Thomas Huth
2022-10-12 9:21 ` Marc-André Lureau
2022-10-12 9:46 ` Thomas Huth
2022-10-12 12:59 ` Bin Meng
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.