Browse Source

tools: Provide a definition of WARN_ON

The definition of WARN_ON being used by the radix tree test suite was
deficient in two ways: it did not provide a return value, and it stopped
execution instead of continuing.  This version of WARN_ON tells you
which file & line the assertion was triggered in.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Matthew Wilcox 8 years ago
parent
commit
b246a9d267
2 changed files with 8 additions and 1 deletions
  1. 8 0
      tools/include/asm/bug.h
  2. 0 1
      tools/testing/radix-tree/linux/kernel.h

+ 8 - 0
tools/include/asm/bug.h

@@ -12,6 +12,14 @@
 	unlikely(__ret_warn_on);		\
 	unlikely(__ret_warn_on);		\
 })
 })
 
 
+#define WARN_ON(condition) ({					\
+	int __ret_warn_on = !!(condition);			\
+	if (unlikely(__ret_warn_on))				\
+		__WARN_printf("assertion failed at %s:%d\n",	\
+				__FILE__, __LINE__);		\
+	unlikely(__ret_warn_on);				\
+})
+
 #define WARN_ON_ONCE(condition) ({			\
 #define WARN_ON_ONCE(condition) ({			\
 	static int __warned;				\
 	static int __warned;				\
 	int __ret_warn_once = !!(condition);		\
 	int __ret_warn_once = !!(condition);		\

+ 0 - 1
tools/testing/radix-tree/linux/kernel.h

@@ -24,7 +24,6 @@
 #endif
 #endif
 
 
 #define BUG_ON(expr)	assert(!(expr))
 #define BUG_ON(expr)	assert(!(expr))
-#define WARN_ON(expr)	assert(!(expr))
 #define __init
 #define __init
 #define __must_check
 #define __must_check
 #define panic(expr)
 #define panic(expr)