Skip to contentSkip to conversation

selftests: harness: Mark test fixture objects __maybe_unused

PATCH Superseded David Matlack 2 participants 3 messages Jul 6

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

Mark global test fixture object pointers __maybe_unused since they may not ever be read (e.g. if fixture variants are used instead).

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.

Fixes 24cf65a62266 ("selftests/harness: Share _metadata between forked processes")

---
v2:
- Update commit message about the change to clang (Nathan)
- Correct the Fixes: tag (Nathan)

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.

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
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.rc2.803.g1fd1e6609c-goog
#1 lore raw
Quoted 9 lines · David Matlack

Mark global test fixture object pointers __maybe_unused since they may not ever be read (e.g. if fixture variants are used instead).

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.

Quoted 8 lines

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.

Fixes 24cf65a62266 ("selftests/harness: Share _metadata between forked processes")

Sorry I forgot to apply Alex's Reviewed-by tag from v1:

https://lore.kernel.org/linux-kselftest/[email protected]/

Reviewed-by on v2 1/1
#2 lore raw
In reply to David Matlack
Quoted 3 lines · David Matlack

Mark global test fixture object pointers __maybe_unused since they may not ever be read (e.g. if fixture variants are used instead).

Not very accurate; using fixtures w/ XFAIL_ADD() does not trigger the warning.

Quoted 6 lines

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.

Quoted 8 lines

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.

Fixes 24cf65a62266 ("selftests/harness: Share _metadata between forked processes")

Not sure why Shuah didn't pick my patch though :/
https://lore.kernel.org/all/[email protected]/