From 0024592541b514a476e72e613e70b5d0b9fcd7d6 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 7 Sep 2024 17:16:48 +0100 Subject: [PATCH] tests/color-management: Use the inherited temporary XDG_DATA_HOME Previously these tests tried to write to /usr when run as an installed-test, which happens to work on Gitlab-CI because we're running as root inside a container, but will not work when running in a more realistic scenario as an unprivileged user (which is how Debian's autopkgtest framework runs this test suite). This also avoids leaving non-package-manager-managed detritus in /usr. In color-management-tests, we can just delete the code that sets XDG_DATA_HOME. In color-management-profile-conflict-test, we also need to copy the conflicting vx239-calibrated.icc into the temporary XDG_DATA_HOME to get onto the code path that this test is intended to exercise. Resolves: https://gitlab.gnome.org/GNOME/mutter/-/issues/3658 Signed-off-by: Simon McVittie Part-of: --- .../color-management-profile-conflict-test.c | 24 ++++++++++++++----- src/tests/color-management-tests.c | 8 ------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/tests/color-management-profile-conflict-test.c b/src/tests/color-management-profile-conflict-test.c index 7f39b891d..b3b7e2dbe 100644 --- a/src/tests/color-management-profile-conflict-test.c +++ b/src/tests/color-management-profile-conflict-test.c @@ -107,9 +107,14 @@ init_tests (void) int main (int argc, char **argv) { + g_autoptr (GError) error = NULL; + g_autoptr (GFile) source_file = NULL; + g_autoptr (GFile) dest_file = NULL; g_autoptr (MetaContext) context = NULL; g_autofree char *system_profile_path = NULL; - g_autofree char *data_home_path = NULL; + g_autofree char *dest_dir = NULL; + g_autofree char *dest_path = NULL; + const char *data_home_path = NULL; context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS, META_CONTEXT_TEST_FLAG_NONE); @@ -123,11 +128,18 @@ main (int argc, char **argv) NULL); add_colord_system_profile (VX239_ICC_PROFILE_ID, system_profile_path); - data_home_path = g_test_build_filename (G_TEST_DIST, - "tests", - "share", - NULL); - g_setenv ("XDG_DATA_HOME", data_home_path, TRUE); + data_home_path = g_getenv ("XDG_DATA_HOME"); + g_assert_nonnull (data_home_path); + + dest_dir = g_build_filename (data_home_path, + "icc", + NULL); + g_assert_no_errno (g_mkdir_with_parents (dest_dir, 0755)); + dest_path = g_build_filename (dest_dir, "vx239-calibrated.icc", NULL); + source_file = g_file_new_for_path (system_profile_path); + dest_file = g_file_new_for_path (dest_path); + g_file_copy (source_file, dest_file, G_FILE_COPY_NONE, NULL, NULL, NULL, &error); + g_assert_no_error (error); test_context = context; diff --git a/src/tests/color-management-tests.c b/src/tests/color-management-tests.c index 1039ec8ba..24bab4b71 100644 --- a/src/tests/color-management-tests.c +++ b/src/tests/color-management-tests.c @@ -1428,20 +1428,12 @@ int main (int argc, char **argv) { g_autoptr (MetaContext) context = NULL; - char *path; context = meta_create_test_context (META_CONTEXT_TEST_TYPE_TEST, META_CONTEXT_TEST_FLAG_NONE); g_assert (meta_context_configure (context, &argc, &argv, NULL)); - path = g_test_build_filename (G_TEST_BUILT, - "tests", - "share", - NULL); - g_setenv ("XDG_DATA_HOME", path, TRUE); - g_free (path); - test_context = context; init_tests ();