Skip to contentSkip to conversation

selftests: harness: Add __maybe_unused to _##fixture_name##_##test_name##_object.

PATCH In review Kuniyuki Iwashima 2 participants 2 messages May 30 – Jun 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: harness: Add __maybe_unused to _##fixture_name##_##test_name##_object.

tools/testing/selftests/net/Makefile adds -Wall to CFLAGS.

With clang supporting -Wunused-but-set-global, building kselftest gets too noisy:

bind_timewait.c:76:1: warning: variable '_bind_timewait_1_object' set but not used [-Wunused-but-set-global]

     76 | TEST_F(bind_timewait, 1)
        | ^
  ../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; \
        |                                        ^
  <scratch space>:155:1: note: expanded from here
    155 | _bind_timewait_1_object
        | ^

The global variable _##fixture_name##_##test_name##_object is not used if a test does not use XFAIL_ADD().

Let's add __maybe_unused to it.

---
 tools/testing/selftests/kselftest_harness.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
index cfdce9cd252e..a2e104f7fb52 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) \
 	{ \
Signature · 1 line
2.54.0.823.g6e5bcc1fc9-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Kuniyuki Iwashima

tools/testing/selftests/net/Makefile adds -Wall to CFLAGS.

With clang supporting -Wunused-but-set-global, building kselftest gets too noisy:

bind_timewait.c:76:1: warning: variable '_bind_timewait_1_object' set but not used [-Wunused-but-set-global]

     76 | TEST_F(bind_timewait, 1)
        | ^
  ../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; \
        |                                        ^
  <scratch space>:155:1: note: expanded from here
    155 | _bind_timewait_1_object
        | ^
Quoted 7 lines

The global variable _##fixture_name##_##test_name##_object is not used if a test does not use XFAIL_ADD().

Let's add __maybe_unused to it.

Seems reasonable.

Quoted 20 lines
---
 tools/testing/selftests/kselftest_harness.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
index cfdce9cd252e..a2e104f7fb52 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) \
 	{ \
Signature · 1 line
2.54.0.823.g6e5bcc1fc9-goog
Signature · 2 lines
Cheers,
Nathan