From 000b8dc02d988e0021470782762852e6ae949269 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Wed, 27 Jan 2021 16:49:25 +0000
Subject: [PATCH] tests: Don't look at the real environment for
 driver_environment()

If one of the variables we are interested in happens to be set
already, and doesn't get overridden, then the test will fail.
For example, `DRI_PRIME=1 meson test -C _build` would fail.

This will become a lot more likely to happen when I start logging
ubiquitous environment variables like `DISPLAY`.

We can't just set envp = NULL initially, because g_environ_setenv()
in Ubuntu 12.04 won't accept NULL as a valid environment block (although
newer versions do).

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 tests/system-info.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/system-info.c b/tests/system-info.c
index 4967bfc71..7dcd72b1a 100644
--- a/tests/system-info.c
+++ b/tests/system-info.c
@@ -2195,6 +2195,7 @@ driver_environment (Fixture *f,
   gchar **envp;
   gchar **output;
   gsize i;
+  const gchar * const no_environment[] = { NULL };
   const gchar *environment[][2] = { {"LIBVA_DRIVER_NAME", "radeonsi"},
                                     {"MESA_LOADER_DRIVER_OVERRIDE", "i965"},
                                     {"VDPAU_DRIVER", "secret_2"},
@@ -2203,7 +2204,7 @@ driver_environment (Fixture *f,
                                     {"__GLX_VENDOR_LIBRARY_NAME", "my_custom_driver"},
                                     {NULL, NULL} };
 
-  envp = g_get_environ ();
+  envp = g_strdupv ((gchar **) no_environment);
 
   for (i = 0; environment[i][0] != NULL; i++)
     envp = g_environ_setenv (envp, environment[i][0], environment[i][1], TRUE);
-- 
GitLab