Skip to contentSkip to conversation

selftests: harness: Mark test fixture objects __maybe_unused

PATCH Superseded David Matlack 3 participants 4 messages Jun 30 – Jul 6

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: harness: Mark test fixture objects __maybe_unused

Mark test fixture objects __maybe_unused since they will not be used when there are fixture variants (the variants will be used instead).

This fixes the VFIO selftest build with clang and -Werror:

vfio_dma_mapping_mmio_test.c:106:1: error: variable '_vfio_dma_mapping_mmio_test_map_full_bar_object' set but not used [-Werror,-Wunused-but-set-global]
106 | TEST_F(vfio_dma_mapping_mmio_test, map_full_bar)

      | ^
./../kselftest_harness.h:398:2: note: expanded from macro 'TEST_F'
  398 |         __TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT)
      |         ^
./../kselftest_harness.h:470:33: note: expanded from macro '__TEST_F_IMPL'
  470 |         static struct __test_metadata *_##fixture_name##_##test_name##_object; \
      |
Fixes ff556bd98348 ("vfio: selftests: Add -Wall and -Werror to the Makefile")
---
 tools/testing/selftests/kselftest_harness.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
index 261e4df94d9d..29a19bc87084 100644
@@ -467,7 +467,7 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
 				!__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \
 			fixture_name##_teardown(_metadata, self, variant); \
 	} \
-	static struct __test_metadata *_##fixture_name##_##test_name##_object; \
+	static struct __test_metadata *_##fixture_name##_##test_name##_object __maybe_unused; \
 	static void __attribute__((constructor(KSELFTEST_PRIO_TEST))) \
 			_register_##fixture_name##_##test_name(void) \
 	{ \

base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482

Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 36 lines · On Tue, 30 Jun 2026 21:33:41 +0000 David Matlack <[email protected]> wrote:

Mark test fixture objects __maybe_unused since they will not be used when there are fixture variants (the variants will be used instead).

This fixes the VFIO selftest build with clang and -Werror:

vfio_dma_mapping_mmio_test.c:106:1: error: variable '_vfio_dma_mapping_mmio_test_map_full_bar_object' set but not used [-Werror,-Wunused-but-set-global]
106 | TEST_F(vfio_dma_mapping_mmio_test, map_full_bar)

      | ^
./../kselftest_harness.h:398:2: note: expanded from macro 'TEST_F'
  398 |         __TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT)
      |         ^
./../kselftest_harness.h:470:33: note: expanded from macro '__TEST_F_IMPL'
  470 |         static struct __test_metadata *_##fixture_name##_##test_name##_object; \
      |
Fixes ff556bd98348 ("vfio: selftests: Add -Wall and -Werror to the Makefile")
---
 tools/testing/selftests/kselftest_harness.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
index 261e4df94d9d..29a19bc87084 100644
@@ -467,7 +467,7 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
 				!__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \
 			fixture_name##_teardown(_metadata, self, variant); \
 	} \
-	static struct __test_metadata *_##fixture_name##_##test_name##_object; \
+	static struct __test_metadata *_##fixture_name##_##test_name##_object __maybe_unused; \
 	static void __attribute__((constructor(KSELFTEST_PRIO_TEST))) \
 			_register_##fixture_name##_##test_name(void) \
 	{ \
Quoted 1 line

base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482

Kees/Shuah, I can take this through the vfio tree if you prefer, it fixes a commit that entered through vfio selftests. Thanks,

Alex

#2 lore raw
Quoted 39 lines · Alex Williamson
Quoted 36 lines · On Tue, 30 Jun 2026 21:33:41 +0000 David Matlack <[email protected]> wrote:

Mark test fixture objects __maybe_unused since they will not be used when there are fixture variants (the variants will be used instead).

This fixes the VFIO selftest build with clang and -Werror:

vfio_dma_mapping_mmio_test.c:106:1: error: variable '_vfio_dma_mapping_mmio_test_map_full_bar_object' set but not used [-Werror,-Wunused-but-set-global]
106 | TEST_F(vfio_dma_mapping_mmio_test, map_full_bar)

      | ^
./../kselftest_harness.h:398:2: note: expanded from macro 'TEST_F'
  398 |         __TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT)
      |         ^
./../kselftest_harness.h:470:33: note: expanded from macro '__TEST_F_IMPL'
  470 |         static struct __test_metadata *_##fixture_name##_##test_name##_object; \
      |
Fixes ff556bd98348 ("vfio: selftests: Add -Wall and -Werror to the Makefile")
---
 tools/testing/selftests/kselftest_harness.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
index 261e4df94d9d..29a19bc87084 100644
@@ -467,7 +467,7 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
 				!__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \
 			fixture_name##_teardown(_metadata, self, variant); \
 	} \
-	static struct __test_metadata *_##fixture_name##_##test_name##_object; \
+	static struct __test_metadata *_##fixture_name##_##test_name##_object __maybe_unused; \
 	static void __attribute__((constructor(KSELFTEST_PRIO_TEST))) \
 			_register_##fixture_name##_##test_name(void) \
 	{ \
Quoted 6 lines
Quoted 1 line

base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482

Kees/Shuah, I can take this through the vfio tree if you prefer, it fixes a commit that entered through vfio selftests. Thanks,

Not that it is a big deal or matters all too much but I do not think this fixes tag is entirely accurate. The blamed commit may have introduced the build warning/error in the VFIO code but that same warning could occur in any selftest code, as evidenced by the exact same patch submitted a month ago:

https://lore.kernel.org/[email protected]/

clang made a change to -Wunused-but-set-variable (split out into its own subwarning, -Wunused-but-set-global) that exposes this. Personally, I find that change explains the problem better but this one makes it clear that it can become fatal with -Werror.

Signature · 2 lines
Cheers,
Nathan
#3 lore raw
Quoted 54 lines · Nathan Chancellor
Quoted 39 lines · Alex Williamson
Quoted 36 lines · On Tue, 30 Jun 2026 21:33:41 +0000 David Matlack <[email protected]> wrote:

Mark test fixture objects __maybe_unused since they will not be used when there are fixture variants (the variants will be used instead).

This fixes the VFIO selftest build with clang and -Werror:

vfio_dma_mapping_mmio_test.c:106:1: error: variable '_vfio_dma_mapping_mmio_test_map_full_bar_object' set but not used [-Werror,-Wunused-but-set-global]
106 | TEST_F(vfio_dma_mapping_mmio_test, map_full_bar)

      | ^
./../kselftest_harness.h:398:2: note: expanded from macro 'TEST_F'
  398 |         __TEST_F_IMPL(fixture_name, test_name, -1, TEST_TIMEOUT_DEFAULT)
      |         ^
./../kselftest_harness.h:470:33: note: expanded from macro '__TEST_F_IMPL'
  470 |         static struct __test_metadata *_##fixture_name##_##test_name##_object; \
      |
Fixes ff556bd98348 ("vfio: selftests: Add -Wall and -Werror to the Makefile")
---
 tools/testing/selftests/kselftest_harness.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
index 261e4df94d9d..29a19bc87084 100644
@@ -467,7 +467,7 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
                            !__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \
                    fixture_name##_teardown(_metadata, self, variant); \
    } \
-   static struct __test_metadata *_##fixture_name##_##test_name##_object; \
+   static struct __test_metadata *_##fixture_name##_##test_name##_object __maybe_unused; \
    static void __attribute__((constructor(KSELFTEST_PRIO_TEST))) \
                    _register_##fixture_name##_##test_name(void) \
    { \
Quoted 6 lines
Quoted 1 line

base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482

Kees/Shuah, I can take this through the vfio tree if you prefer, it fixes a commit that entered through vfio selftests. Thanks,

Not that it is a big deal or matters all too much but I do not think this fixes tag is entirely accurate. The blamed commit may have introduced the build warning/error in the VFIO code but that same warning could occur in any selftest code, as evidenced by the exact same patch submitted a month ago:

Quoted 6 lines

https://lore.kernel.org/[email protected]/

clang made a change to -Wunused-but-set-variable (split out into its own subwarning, -Wunused-but-set-global) that exposes this. Personally, I find that change explains the problem better but this one makes it clear that it can become fatal with -Werror.

Thanks for the additional context Nathan. I can send out a quick v2 today with an updated commit message to capture these details and a better fixes tag.