From 6d2e62156d660c0e29439e9d8f480f8171f24ef2 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Thu, 26 Mar 2020 15:22:48 +0000
Subject: [PATCH] tests: Factor out the directory containing mock sysroots

Signed-off-by: Simon McVittie <smcv@collabora.com>
Co-authored-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
---
 tests/graphics.c    | 20 ++++++++++++--------
 tests/system-info.c | 24 ++++++++++++++----------
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/tests/graphics.c b/tests/graphics.c
index a693b8586..8fac26974 100644
--- a/tests/graphics.c
+++ b/tests/graphics.c
@@ -44,6 +44,7 @@ typedef struct
 {
   gchar *srcdir;
   gchar *builddir;
+  gchar *sysroots;
   gchar *sysroot;
   gchar **fake_icds_envp;
 } Fixture;
@@ -76,6 +77,8 @@ setup (Fixture *f,
   if (f->builddir == NULL)
     f->builddir = g_path_get_dirname (argv0);
 
+  f->sysroots = g_build_filename (f->srcdir, "sysroots", NULL);
+
   if (g_chdir (f->srcdir) != 0)
     g_error ("chdir %s: %s", f->srcdir, g_strerror (errno));
 
@@ -185,6 +188,7 @@ teardown (Fixture *f,
   g_free (f->srcdir);
   g_free (f->builddir);
   g_free (f->sysroot);
+  g_free (f->sysroots);
   g_strfreev (f->fake_icds_envp);
 }
 
@@ -1910,7 +1914,7 @@ test_dri_debian10 (Fixture *f,
                                            "/lib/x86_64-linux-gnu/dri/radeonsi_drv_video.so",
                                            NULL};
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "debian10", NULL);
+  sysroot = g_build_filename (f->sysroots, "debian10", NULL);
   envp = g_get_environ ();
   envp = g_environ_setenv (envp, "SRT_TEST_SYSROOT", sysroot, TRUE);
   envp = g_environ_unsetenv (envp, "LIBGL_DRIVERS_PATH");
@@ -1996,7 +2000,7 @@ test_dri_fedora (Fixture *f,
                                        "/usr/lib64/dri/radeonsi_drv_video.so",
                                        NULL};
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "fedora", NULL);
+  sysroot = g_build_filename (f->sysroots, "fedora", NULL);
   envp = g_get_environ ();
   envp = g_environ_setenv (envp, "SRT_TEST_SYSROOT", sysroot, TRUE);
   envp = g_environ_unsetenv (envp, "LIBGL_DRIVERS_PATH");
@@ -2046,7 +2050,7 @@ test_dri_ubuntu16 (Fixture *f,
   const gchar *va_api_suffixes[] = {"/lib/mock-ubuntu-64-bit/dri/radeonsi_drv_video.so",
                                     NULL};
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "ubuntu16", NULL);
+  sysroot = g_build_filename (f->sysroots, "ubuntu16", NULL);
   envp = g_get_environ ();
   envp = g_environ_setenv (envp, "SRT_TEST_SYSROOT", sysroot, TRUE);
   envp = g_environ_setenv (envp, "SRT_TEST_FORCE_ELF", "64", TRUE);
@@ -2123,7 +2127,7 @@ test_dri_with_env (Fixture *f,
       return;
     }
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "no-os-release", NULL);
+  sysroot = g_build_filename (f->sysroots, "no-os-release", NULL);
 
   libgl = g_build_filename (sysroot, "custom_path32", "dri", NULL);
   libva = g_build_filename (sysroot, "custom_path32", "va", NULL);
@@ -2232,7 +2236,7 @@ test_dri_flatpak (Fixture *f,
                                     "/usr/lib/mock-abi/GL/lib/dri/r600_drv_video.so",
                                     NULL};
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "flatpak-example", NULL);
+  sysroot = g_build_filename (f->sysroots, "flatpak-example", NULL);
   envp = g_get_environ ();
   envp = g_environ_setenv (envp, "SRT_TEST_SYSROOT", sysroot, TRUE);
   envp = g_environ_unsetenv (envp, "LIBGL_DRIVERS_PATH");
@@ -2401,7 +2405,7 @@ test_vdpau (Fixture *f,
 
       g_test_message ("%s: %s", test->sysroot, test->description);
 
-      sysroot = g_build_filename (f->srcdir, "sysroots", test->sysroot, NULL);
+      sysroot = g_build_filename (f->sysroots, test->sysroot, NULL);
       envp = g_get_environ ();
       envp = g_environ_setenv (envp, "SRT_TEST_SYSROOT", sysroot, TRUE);
       if (test->vdpau_path_env == NULL)
@@ -2486,7 +2490,7 @@ test_glx_debian (Fixture *f,
   const gchar *glx_paths_x86_64[] = {"/lib/x86_64-linux-gnu/libGLX_mesa.so.0",
                                      NULL};
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "debian10", NULL);
+  sysroot = g_build_filename (f->sysroots, "debian10", NULL);
   envp = g_get_environ ();
   envp = g_environ_setenv (envp, "SRT_TEST_SYSROOT", sysroot, TRUE);
 
@@ -2536,7 +2540,7 @@ test_glx_container (Fixture *f,
                                      "/lib/x86_64-linux-gnu/libGLX_mesa.so.0",
                                      NULL};
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "steamrt", NULL);
+  sysroot = g_build_filename (f->sysroots, "steamrt", NULL);
   envp = g_get_environ ();
   envp = g_environ_setenv (envp, "SRT_TEST_SYSROOT", sysroot, TRUE);
 
diff --git a/tests/system-info.c b/tests/system-info.c
index cd0ed8108..fad588f67 100644
--- a/tests/system-info.c
+++ b/tests/system-info.c
@@ -48,6 +48,7 @@ typedef struct
 {
   gchar *srcdir;
   gchar *builddir;
+  gchar *sysroots;
 } Fixture;
 
 typedef struct
@@ -69,6 +70,8 @@ setup (Fixture *f,
 
   if (f->builddir == NULL)
     f->builddir = g_path_get_dirname (argv0);
+
+  f->sysroots = g_build_filename (f->srcdir, "sysroots", NULL);
 }
 
 static void
@@ -79,6 +82,7 @@ teardown (Fixture *f,
 
   g_free (f->srcdir);
   g_free (f->builddir);
+  g_free (f->sysroots);
 
   /* We expect that fake_home already cleaned this up, but just to be sure we
    * do it too */
@@ -1278,7 +1282,7 @@ os_debian10 (Fixture *f,
   gchar *sysroot;
   gchar *s;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "debian10", NULL);
+  sysroot = g_build_filename (f->sysroots, "debian10", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -1338,7 +1342,7 @@ os_debian_unstable (Fixture *f,
   gchar *sysroot;
   gchar *s;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "debian-unstable", NULL);
+  sysroot = g_build_filename (f->sysroots, "debian-unstable", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -1399,7 +1403,7 @@ os_steamrt (Fixture *f,
   gchar *s;
   SrtRuntimeIssues runtime_issues;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "steamrt", NULL);
+  sysroot = g_build_filename (f->sysroots, "steamrt", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -1477,7 +1481,7 @@ os_steamrt_unofficial (Fixture *f,
   gchar *s;
   SrtRuntimeIssues runtime_issues;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "steamrt-unofficial", NULL);
+  sysroot = g_build_filename (f->sysroots, "steamrt-unofficial", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -1558,7 +1562,7 @@ os_invalid_os_release (Fixture *f,
   gchar *s;
   SrtRuntimeIssues runtime_issues;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "invalid-os-release", NULL);
+  sysroot = g_build_filename (f->sysroots, "invalid-os-release", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -1632,7 +1636,7 @@ os_no_os_release (Fixture *f,
   gchar *sysroot;
   gchar *s;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "no-os-release", NULL);
+  sysroot = g_build_filename (f->sysroots, "no-os-release", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -1693,7 +1697,7 @@ overrides (Fixture *f,
   gsize i;
   gboolean seen_link;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "steamrt", NULL);
+  sysroot = g_build_filename (f->sysroots, "steamrt", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -1759,7 +1763,7 @@ overrides_issues (Fixture *f,
   gsize i;
   gboolean seen_link;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "steamrt-overrides-issues", NULL);
+  sysroot = g_build_filename (f->sysroots, "steamrt-overrides-issues", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -1819,7 +1823,7 @@ overrides_not_available (Fixture *f,
   gchar **issues;
   gchar *sysroot;
 
-  sysroot = g_build_filename (f->srcdir, "sysroots", "debian10", NULL);
+  sysroot = g_build_filename (f->sysroots, "debian10", NULL);
 
   info = srt_system_info_new (NULL);
   srt_system_info_set_sysroot (info, sysroot);
@@ -2238,7 +2242,7 @@ test_containers (Fixture *f,
 
       g_test_message ("%s: %s", test->sysroot, test->description);
 
-      sysroot = g_build_filename (f->srcdir, "sysroots", test->sysroot, NULL);
+      sysroot = g_build_filename (f->sysroots, test->sysroot, NULL);
 
       info = srt_system_info_new (NULL);
       g_assert_nonnull (info);
-- 
GitLab