selftests: harness: Mark test fixture objects __maybe_unused
Subsystems (2)
PATCH v3 1/1 selftests: harness: Mark test fixture objects __maybe_unused
Mark _##fixture_name##_##test_name##_object __maybe_unused since it may not ever be read. This pointer is only read in XFAIL_ADD(), which tests are not required to use.
clang made a change to -Wunused-but-set-variable (split out into its own subwarning, -Wunused-but-set-global) that causes this warning to be emitted for various selftests and can be upgraded to an error in selftest that set -Werror.
VFIO selftests have been broken since commit ff556bd98348 ("vfio:
selftests: Add -Wall and -Werror to the Makefile"), and the net selftests builds have been noisy due to -Wall.
---
v3:
- Pick up Kuniyuki's Reviewed-by tag.
- Pick up Alex's Reviewed-by tag from v1.
- Fix commit description accuracy (Kuniyuki)
v2: https://lore.kernel.org/linux-kselftest/[email protected]/
v1: https://lore.kernel.org/linux-kselftest/[email protected]/
Note: The fixes tag is commit 24cf65a62266 ("selftests/harness: Share _metadata between forked processes"), which refactored TEST_F to share test metadata across processes using mmap and convereted the test fixture object from a static struct to a static pointer. Prior to commit 24cf65a62266 the static struct was always used once (the address of it was taken and passed to __register_test()), but after the static pointer was always assigned but potentially never read.
tools/testing/selftests/kselftest_harness.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
@@ -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.rc2.803.g1fd1e6609c-goog
Quoted 13 lines · David Matlack
Mark _##fixture_name##_##test_name##_object
__maybe_unusedsince it may not ever be read. This pointer is only read inXFAIL_ADD(), which tests are not required to use.clang made a change to -Wunused-but-set-variable (split out into its own subwarning, -Wunused-but-set-global) that causes this warning to be emitted for various selftests and can be upgraded to an error in selftest that set -Werror.
VFIO selftests have been broken since commit
ff556bd98348("vfio:
selftests: Add -Wall and -Werror to theMakefile"), and the net selftests builds have been noisy due to -Wall.
Quoted 6 lines
Fixes 24cf65a62266 ("selftests/harness: Share _metadata between forked processes")Reported-by Kuniyuki Iwashima <[email protected]>Reported-by Aaron Lewis <[email protected]>Reviewed-by Alex Williamson <[email protected]>Reviewed-by Kuniyuki Iwashima <[email protected]>Signed-off-by David Matlack <[email protected]>
Quoted 41 lines
---
v3:
- Pick up Kuniyuki's Reviewed-by tag.
- Pick up Alex's Reviewed-by tag from v1.
- Fix commit description accuracy (Kuniyuki)v2: https://lore.kernel.org/linux-kselftest/[email protected]/
v1: https://lore.kernel.org/linux-kselftest/[email protected]/
Note: The fixes tag is commit
24cf65a62266("selftests/harness: Share_metadatabetween forked processes"), which refactoredTEST_Fto share test metadata across processes using mmap and convereted the test fixture object from a static struct to a static pointer. Prior to commit24cf65a62266the static struct was always used once (the address of it was taken and passed to__register_test()), but after the static pointer was always assigned but potentially never read.Cc Nathan Chancellor <[email protected]>tools/testing/selftests/kselftest_harness.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/kselftest_harness.h +1
-1@@ -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:
dc59e4fea9d83f03bad6bddf3fa2e52491777482Signature · 1 line
2.55.0.rc2.803.g1fd1e6609c-goog
Signature · 2 lines
Cheers, Nathan
Quoted 14 lines · David Matlack
Mark _##fixture_name##_##test_name##_object
__maybe_unusedsince it may not ever be read. This pointer is only read inXFAIL_ADD(), which tests are not required to use.clang made a change to -Wunused-but-set-variable (split out into its own subwarning, -Wunused-but-set-global) that causes this warning to be emitted for various selftests and can be upgraded to an error in selftest that set -Werror.
VFIO selftests have been broken since commit
ff556bd98348("vfio:
selftests: Add -Wall and -Werror to theMakefile"), and the net selftests builds have been noisy due to -Wall.
Quoted 6 lines
Fixes 24cf65a62266 ("selftests/harness: Share _metadata between forked processes")Reported-by Kuniyuki Iwashima <[email protected]>Reported-by Aaron Lewis <[email protected]>Reviewed-by Alex Williamson <[email protected]>Reviewed-by Kuniyuki Iwashima <[email protected]>Signed-off-by David Matlack <[email protected]>
Kees and Shuah, is it ok if Alex takes this through the VFIO tree? [1] This fixes a bug exposed by recent VFIO selftests commit ff556bd98348 ("vfio: selftests: Add -Wall and -Werror to the Makefile").
[1] https://lore.kernel.org/linux-kselftest/[email protected]/
Kees Cook
maintainerQuoted 22 lines · David Matlack
Quoted 14 lines · David Matlack
Mark _##fixture_name##_##test_name##_object
__maybe_unusedsince it may not ever be read. This pointer is only read inXFAIL_ADD(), which tests are not required to use.clang made a change to -Wunused-but-set-variable (split out into its own subwarning, -Wunused-but-set-global) that causes this warning to be emitted for various selftests and can be upgraded to an error in selftest that set -Werror.
VFIO selftests have been broken since commit
ff556bd98348("vfio:
selftests: Add -Wall and -Werror to theMakefile"), and the net selftests builds have been noisy due to -Wall.Quoted 6 lines
Fixes 24cf65a62266 ("selftests/harness: Share _metadata between forked processes")Reported-by Kuniyuki Iwashima <[email protected]>Reported-by Aaron Lewis <[email protected]>Reviewed-by Alex Williamson <[email protected]>Reviewed-by Kuniyuki Iwashima <[email protected]>Signed-off-by David Matlack <[email protected]>
Quoted 5 lines
Kees and Shuah, is it ok if Alex takes this through the VFIO tree? [1] This fixes a bug exposed by recent VFIO selftests commit
ff556bd98348("vfio: selftests: Add -Wall and -Werror to theMakefile").[1] https://lore.kernel.org/linux-kselftest/[email protected]/
Yeah, please do. This has ample review. :)
Signature · 1 line
Kees Cook
Quoted 24 lines · Kees Cook
Quoted 22 lines · David Matlack
Quoted 20 lines · David Matlack
Mark _##fixture_name##_##test_name##_object
__maybe_unusedsince it may not ever be read. This pointer is only read inXFAIL_ADD(), which tests are not required to use.clang made a change to -Wunused-but-set-variable (split out into its own subwarning, -Wunused-but-set-global) that causes this warning to be emitted for various selftests and can be upgraded to an error in selftest that set -Werror.
VFIO selftests have been broken since commit
ff556bd98348("vfio:
selftests: Add -Wall and -Werror to theMakefile"), and the net selftests builds have been noisy due to -Wall.Fixes 24cf65a62266 ("selftests/harness: Share _metadata between forked processes")Reported-by Kuniyuki Iwashima <[email protected]>Reported-by Aaron Lewis <[email protected]>Reviewed-by Alex Williamson <[email protected]>Reviewed-by Kuniyuki Iwashima <[email protected]>Signed-off-by David Matlack <[email protected]>
Quoted 7 lines
Quoted 5 lines
Kees and Shuah, is it ok if Alex takes this through the VFIO tree? [1] This fixes a bug exposed by recent VFIO selftests commit
ff556bd98348("vfio: selftests: Add -Wall and -Werror to theMakefile").[1] https://lore.kernel.org/linux-kselftest/[email protected]/
Yeah, please do. This has ample review. :)
Thanks. Alex, can you pick this one up for 7.2 if there's still time, or for 7.3 otherwise?
Quoted 29 lines · On Tue, 11 Aug 2026 13:21:37 -0700 David Matlack <[email protected]> wrote:
Quoted 28 lines · Kees Cook
Quoted 26 lines · David Matlack
Quoted 14 lines · David Matlack
Mark _##fixture_name##_##test_name##_object
__maybe_unusedsince it may not ever be read. This pointer is only read inXFAIL_ADD(), which tests are not required to use.clang made a change to -Wunused-but-set-variable (split out into its own subwarning, -Wunused-but-set-global) that causes this warning to be emitted for various selftests and can be upgraded to an error in selftest that set -Werror.
VFIO selftests have been broken since commit
ff556bd98348("vfio:
selftests: Add -Wall and -Werror to theMakefile"), and the net selftests builds have been noisy due to -Wall.Quoted 6 lines
Fixes 24cf65a62266 ("selftests/harness: Share _metadata between forked processes")Reported-by Kuniyuki Iwashima <[email protected]>Reported-by Aaron Lewis <[email protected]>Reviewed-by Alex Williamson <[email protected]>Reviewed-by Kuniyuki Iwashima <[email protected]>Signed-off-by David Matlack <[email protected]>Kees and Shuah, is it ok if Alex takes this through the VFIO tree? [1] This fixes a bug exposed by recent VFIO selftests commit
ff556bd98348("vfio: selftests: Add -Wall and -Werror to theMakefile").
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
[1] https://lore.kernel.org/linux-kselftest/[email protected]/
Yeah, please do. This has ample review. :)
Thanks. Alex, can you pick this one up for 7.2 if there's still time, or for 7.3 otherwise?
Thanks for the reminder, applied to vfio next branch for v7.3. Thanks,
Alex