Skip to contentSkip to conversation

tests/unit/test-image-locking: Fix handling of temporary files

PATCH In review Thomas Huth 3 participants 4 messages Oct 12, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/unit/test-image-locking: Fix handling of temporary files

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.

---
 tests/unit/test-image-locking.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tests/unit/test-image-locking.c +4 -2
index a47299c247..2624cec6a0 100644
@@ -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)
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 35 lines · Thomas Huth

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.

---
 tests/unit/test-image-locking.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tests/unit/test-image-locking.c +2 -2
index a47299c247..2624cec6a0 100644
@@ -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;

tests/unit/test-image-locking.c static void test_set_perm_abort(void) · line 145

Quoted 6 lines
tests/unit/test-image-locking.c +2 -0
@@ -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

Signature · 1 line
Marc-André Lureau
#2 lore raw
Quoted 12 lines · Marc-André Lureau

Hi

On Wed, Oct 12, 2022 at 1:03 PM Thomas Huth <[email protected] <mailto:[email protected]>> 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 <[email protected] <mailto:[email protected]>>

---

[...]

Quoted 9 lines
    @@ -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

Reviewed-by on v1 1/1
#3 lore raw
In reply to Thomas Huth
Quoted 7 lines · Thomas Huth

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.

Quoted 5 lines
---
 tests/unit/test-image-locking.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Fixes aef96d7d4f0b ("tests: Add unit tests for image locking")