From c08dc25004398c575f57e6f5dad400c6f878826d Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Fri, 31 Jan 2025 11:48:35 +0000
Subject: [PATCH] tests: Ensure we have better coverage if built with --werror

Release builds are not done with --werror, so we will gracefully skip
various parts of the build if we are running on a particularly strange
platform (where /dev/pts isn't a directory, /dev/stderr isn't a symlink,
or we are unable to expand `${LIB}` and `${PLATFORM}`). But for our
official CI and individual developers' builds, we expect the build to
be done on a platform that makes sense, so we can be more strict.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 config.h.in                            |  1 +
 meson.build                            |  7 +++++++
 tests/pressure-vessel/adverb-preload.c |  7 +++++++
 tests/pressure-vessel/adverb-sdl.c     |  7 +++++++
 tests/utils.c                          | 10 ++++++++++
 5 files changed, 32 insertions(+)

diff --git a/config.h.in b/config.h.in
index 27b06c306..016f10f0b 100644
--- a/config.h.in
+++ b/config.h.in
@@ -7,6 +7,7 @@
 #define _SRT_SONAME "libsteam-runtime-tools-@api_major@.so.@abi_major"
 #define _GNU_SOURCE 1
 #mesondefine _SRT_MULTIARCH
+#mesondefine _SRT_TESTS_STRICT
 #mesondefine VERSION
 
 /* Allow using stuff from Flatpak with minimal modifications */
diff --git a/meson.build b/meson.build
index fcf4b0e60..346cc565f 100644
--- a/meson.build
+++ b/meson.build
@@ -262,10 +262,17 @@ elif host_machine.cpu_family() == 'x86'
   multiarch = 'i386-linux-gnu'
 elif host_machine.cpu_family() == 'aarch64' and host_machine.endian() == 'little'
   multiarch = 'aarch64-linux-gnu'
+elif get_option('werror')
+  # Some of our test coverage is skipped if we don't know the multiarch tuple
+  error('-Dmultiarch_tuple is required when building with --werror on an unknown CPU')
 else
   multiarch = ''
 endif
 
+if get_option('werror')
+  conf_data.set('_SRT_TESTS_STRICT', true)
+endif
+
 if multiarch != ''
   conf_data.set_quoted('_SRT_MULTIARCH', multiarch)
 endif
diff --git a/tests/pressure-vessel/adverb-preload.c b/tests/pressure-vessel/adverb-preload.c
index fbe595a5d..6078455a0 100644
--- a/tests/pressure-vessel/adverb-preload.c
+++ b/tests/pressure-vessel/adverb-preload.c
@@ -46,6 +46,13 @@ setup (Fixture *f,
   if (config->can_discover_platform)
     {
       f->lib_temp_dirs = pv_per_arch_dirs_new (&local_error);
+#ifdef _SRT_TESTS_STRICT
+      /* We allow this to fail because it might fail on particularly strange
+       * OS configurations, but for platforms we actively support,
+       * we expect it to work */
+      g_assert_no_error (local_error);
+      g_assert_nonnull (f->lib_temp_dirs);
+#endif
 
       if (f->lib_temp_dirs == NULL)
         {
diff --git a/tests/pressure-vessel/adverb-sdl.c b/tests/pressure-vessel/adverb-sdl.c
index d6fde6ef8..207f3c4b8 100644
--- a/tests/pressure-vessel/adverb-sdl.c
+++ b/tests/pressure-vessel/adverb-sdl.c
@@ -43,6 +43,13 @@ setup (Fixture *f,
   f->old_fds = tests_check_fd_leaks_enter ();
   f->bwrap = flatpak_bwrap_new (flatpak_bwrap_empty_env);
   f->lib_temp_dirs = pv_per_arch_dirs_new (&f->lib_temp_dirs_error);
+#ifdef _SRT_TESTS_STRICT
+  /* We allow this to fail because it might fail on particularly strange
+   * OS configurations, but for platforms we actively support,
+   * we expect it to work */
+  g_assert_no_error (f->lib_temp_dirs_error);
+  g_assert_nonnull (f->lib_temp_dirs);
+#endif
 
   if (f->lib_temp_dirs != NULL)
     {
diff --git a/tests/utils.c b/tests/utils.c
index 270daf4fc..8fbb2e913 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -1434,6 +1434,11 @@ test_recursive_list (Fixture *f,
         }
       else
         {
+#ifdef _SRT_TESTS_STRICT
+          /* We expect this to exist in our official CI,
+           * so make the test fail if it doesn't. */
+          g_warning ("/dev/pts doesn't exist or isn't a directory");
+#endif
           /* This could conceivably be false in some containers.
            * Mark the test as skipped but intentionally don't early-return
            * here: we can still check for /dev/stderr. */
@@ -1450,6 +1455,11 @@ test_recursive_list (Fixture *f,
         }
       else
         {
+#ifdef _SRT_TESTS_STRICT
+          /* We expect this to exist in our official CI,
+           * so make the test fail if it doesn't. */
+          g_warning ("/dev/stderr isn't a symlink");
+#endif
           /* This could conceivably be false in some containers.
            * Again, intentionally not early-returning here. */
           g_test_skip ("/dev/stderr isn't a symlink");
-- 
GitLab