]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: extend DEBUG_STRESS to ease testing and turn on extra checks
authorWilly Tarreau <w@1wt.eu>
Fri, 14 Nov 2025 14:58:06 +0000 (15:58 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Nov 2025 15:38:04 +0000 (16:38 +0100)
DEBUG_STRESS is currently used only to expose "stress-level". With this
patch, we go a bit further, by automatically forcing DEBUG_STRICT and
DEBUG_STRICT_ACTION to their highest values in order to enable all
BUG_ON levels, and make all of them result in a crash. In addition,
care is taken to always only have 0 or 1 in the macro, so that it can be
tested using "#if DEBUG_STRESS > 0" as well as "if (DEBUG_STRESS) { }"
everywhere.

The goal will be to ease insertion of extra tests for builds dedicated
to stress-testing that enable possibly expensive extra checks on certain
code paths that cannot reasonably be compiled in for production code
right now.

include/haproxy/bug.h
include/haproxy/stress.h

index ffe701af37768ed1e1008afa40bc26942c12d084..8b110711f85b375fdea4f8e12f996c4f1c82ac0e 100644 (file)
 #define DPRINTF(x...)
 #endif
 
+/* Let's make DEBUG_STRESS equal to zero if not set or not valid, or to
+ * 1 if set. This way it is always set and should be easy to use in "if ()"
+ * statements without requiring ifdefs, while remaining compatible with
+ * "#if DEBUG_STRESS > 0". We also force DEBUG_STRICT and DEBUG_STRICT_ACTION
+ * when stressed.
+ */
+#if !defined(DEBUG_STRESS)
+# define DEBUG_STRESS 0
+#elif DEBUG_STRESS != 0
+# undef DEBUG_STRESS
+# define DEBUG_STRESS 1        // make sure comparison >0 always works
+# undef DEBUG_STRICT
+# define DEBUG_STRICT 2        // enable BUG_ON
+# undef DEBUG_STRICT_ACTION
+# define DEBUG_STRICT_ACTION 3 // enable crash on match
+#endif
+
 #define DUMP_TRACE() do { extern void ha_backtrace_to_stderr(void); ha_backtrace_to_stderr(); } while (0)
 
 /* First, let's try to handle some arch-specific crashing methods. We prefer
index a6c616354e0935c5ea52cf7274b3fff03bc3d00c..2555c173d77fc3646bcfa2d11e5de24e4586a299 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _HAPROXY_STRESS_H
 #define _HAPROXY_STRESS_H
 
-#ifdef DEBUG_STRESS
+#if defined(DEBUG_STRESS) && (DEBUG_STRESS > 0)
 enum { mode_stress = 1 };
 #else
 enum { mode_stress = 0 };