tools: fix ARRAY_SIZE defines in tools and selftests hdrs
authorShuah Khan <skhan@linuxfoundation.org>
Wed, 8 Dec 2021 17:47:42 +0000 (10:47 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Sat, 11 Dec 2021 00:50:17 +0000 (17:50 -0700)
tools/include/linux/kernel.h and kselftest_harness.h are missing
ifndef guard around ARRAY_SIZE define. Fix them to avoid duplicate
define errors during compile when another file defines it. This
problem was found when compiling selftests that include a header
with ARRAY_SIZE define.

ARRAY_SIZE is defined in several selftests. There are about 25+
duplicate defines in various selftests source and header files.
Add ARRAY_SIZE to kselftest.h in preparation for removing duplicate
ARRAY_SIZE defines from individual test files.

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/include/linux/kernel.h
tools/testing/selftests/kselftest.h
tools/testing/selftests/kselftest_harness.h

index 3e8df500cfbd41d4139906348dfb259fb4641fab..9701e8307db02731b40e1ff886df4ac6bf93c002 100644 (file)
@@ -92,7 +92,9 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int scnprintf(char * buf, size_t size, const char * fmt, ...);
 int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
 
+#ifndef ARRAY_SIZE
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+#endif
 
 #define current_gfp_context(k) 0
 #define synchronize_rcu()
index 8d50483fe204a71d50fe3df82399b1da2635ecc6..f1180987492c9a3c79185bdfeef3abad7509084c 100644 (file)
 #include <stdarg.h>
 #include <stdio.h>
 
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
 /* define kselftest exit codes */
 #define KSFT_PASS  0
 #define KSFT_FAIL  1
index 79a182cfa43ad6825a043cebd4d237aa01b984ee..471eaa7b3a3f20150bcb385eded0c8155d9e05be 100644 (file)
 #define EXPECT_STRNE(expected, seen) \
        __EXPECT_STR(expected, seen, !=, 0)
 
+#ifndef ARRAY_SIZE
 #define ARRAY_SIZE(a)  (sizeof(a) / sizeof(a[0]))
+#endif
 
 /* Support an optional handler after and ASSERT_* or EXPECT_*.  The approach is
  * not thread-safe, but it should be fine in most sane test scenarios.