diff mbox series

[v3,14/54] tests/qtest: migration-test: Avoid using hardcoded /tmp

Message ID 20220925113032.1949844-15-bmeng.cn@gmail.com (mailing list archive)
State New, archived
Headers show
Series tests/qtest: Enable running qtest on Windows | expand

Commit Message

Bin Meng Sept. 25, 2022, 11:29 a.m. UTC
From: Bin Meng <bin.meng@windriver.com>

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_dir_make_tmp() for a portable implementation.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

Changes in v3:
- Split to a separate patch

 tests/qtest/migration-test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Marc-André Lureau Sept. 26, 2022, 1:15 p.m. UTC | #1
Hi

On Sun, Sep 25, 2022 at 3:52 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_dir_make_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/migration-test.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 4728d528bb..029c4f3a6a 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -2434,7 +2434,6 @@ static bool kvm_dirty_ring_supported(void)
>
>  int main(int argc, char **argv)
>  {
> -    char template[] = "/tmp/migration-test-XXXXXX";
>      const bool has_kvm = qtest_has_accel("kvm");
>      const bool has_uffd = ufd_version_check();
>      const char *arch = qtest_get_arch();
> @@ -2462,9 +2461,10 @@ int main(int argc, char **argv)
>          return g_test_run();
>      }
>
> -    tmpfs = g_mkdtemp(template);
> +    tmpfs = g_dir_make_tmp("migration-test-XXXXXX", NULL);
>      if (!tmpfs) {
> -        g_test_message("g_mkdtemp on path (%s): %s", template,
> strerror(errno));
> +        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
> +                       strerror(errno));
>

You need to update the error reporting by using the GError "error" argument
of g_dir_make_tmp().


>      }
>      g_assert(tmpfs);
>
> @@ -2589,6 +2589,7 @@ int main(int argc, char **argv)
>          g_test_message("unable to rmdir: path (%s): %s",
>                         tmpfs, strerror(errno));
>      }
> +    g_free((gpointer)tmpfs);
>

 argh, remove the const from tmpfs declaration!



>      return ret;
>  }
> --
> 2.34.1
>
>
>
diff mbox series

Patch

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 4728d528bb..029c4f3a6a 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2434,7 +2434,6 @@  static bool kvm_dirty_ring_supported(void)
 
 int main(int argc, char **argv)
 {
-    char template[] = "/tmp/migration-test-XXXXXX";
     const bool has_kvm = qtest_has_accel("kvm");
     const bool has_uffd = ufd_version_check();
     const char *arch = qtest_get_arch();
@@ -2462,9 +2461,10 @@  int main(int argc, char **argv)
         return g_test_run();
     }
 
-    tmpfs = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("migration-test-XXXXXX", NULL);
     if (!tmpfs) {
-        g_test_message("g_mkdtemp on path (%s): %s", template, strerror(errno));
+        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
+                       strerror(errno));
     }
     g_assert(tmpfs);
 
@@ -2589,6 +2589,7 @@  int main(int argc, char **argv)
         g_test_message("unable to rmdir: path (%s): %s",
                        tmpfs, strerror(errno));
     }
+    g_free((gpointer)tmpfs);
 
     return ret;
 }