Whamcloud - gitweb
LU-12923 utils: Use BUILD_BUG_ON() for wirehdr.c & wirecheck.c 11/36711/4
authorArshad Hussain <arshad.super@gmail.com>
Tue, 29 Oct 2019 12:55:04 +0000 (18:25 +0530)
committerOleg Drokin <green@whamcloud.com>
Fri, 20 Dec 2019 03:27:15 +0000 (03:27 +0000)
This patch replaces all CLASSERT() with user defined
BUILD_BUG_ON() for file lustre/utils/wirehdr.c and
lustre/utils/wirecheck.c

Test-Parameters: trivial
Signed-off-by: Arshad Hussain <arshad.super@gmail.com>
Change-Id: If46603158a9ad311762fe51839000c39a0b15307
Reviewed-on: https://review.whamcloud.com/36711
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Shaun Tancheff <stancheff@cray.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Petros Koutoupis <pkoutoupis@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/wirecheck.c
lustre/utils/wirehdr.c

index e252ecd..f6c9bad 100644 (file)
@@ -56,13 +56,13 @@ do {                                                                \
 #define STRINGIFY(a) #a
 
 #define CHECK_CDEFINE(a)                                       \
-       printf("        CLASSERT("#a" == "STRINGIFY(a) ");\n")
+       printf("        BUILD_BUG_ON("#a" != "STRINGIFY(a) ");\n")
 
 #define CHECK_CVALUE(a)                                         \
-       printf("        CLASSERT("#a" == %lld);\n", (long long)a)
+       printf("        BUILD_BUG_ON("#a" != %lld);\n", (long long)a)
 
 #define CHECK_CVALUE_X(a)                                      \
-       printf("        CLASSERT("#a" == 0x%.8x);\n", a)
+       printf("        BUILD_BUG_ON("#a" != 0x%.8x);\n", a)
 
 #define CHECK_DEFINE(a)                                                \
 do {                                                           \
index cb0aa1b..f9f33d9 100644 (file)
 #define LASSERT(cond) if (!(cond)) { printf("failed " #cond "\n"); ret = 1; }
 #define LASSERTF(cond, fmt, ...) if (!(cond)) { printf("failed '" #cond "'" fmt, ## __VA_ARGS__);ret = 1;}
 /*
- * Compile-time LASSERT, which verifies correctness at compile-time rather
- * than runtime. If "cond" is true, then there are two different cases
- * ("(non-zero)" and "0"). If "cond" is false, then there are two identical
- * cases ("0" and "0"), which is an error that causes the compiler to complain.
+ * BUILD_BUG_ON() is Compile-time check which verifies correctness at
+ * compile-time rather than runtime.
  */
-#define CLASSERT(cond) do {switch (1) {case (cond): case 0: break; } } while (0)
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
 
 int ret;
 
@@ -65,10 +63,10 @@ void lustre_assert_wire_constants(void);
 
 int main()
 {
-        lustre_assert_wire_constants();
+       lustre_assert_wire_constants();
 
-        if (ret == 0)
-                printf("wire constants OK\n");
+       if (ret == 0)
+               printf("wire constants OK\n");
 
-        return ret;
+       return ret;
 }