From: Willy Tarreau Date: Fri, 14 Nov 2025 14:58:06 +0000 (+0100) Subject: DEBUG: extend DEBUG_STRESS to ease testing and turn on extra checks X-Git-Tag: v3.3-dev13~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3d441e78e50f6de953c5656a5c8e443b7bc2f16e;p=thirdparty%2Fhaproxy.git DEBUG: extend DEBUG_STRESS to ease testing and turn on extra checks 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. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index ffe701af3..8b110711f 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -40,6 +40,23 @@ #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 diff --git a/include/haproxy/stress.h b/include/haproxy/stress.h index a6c616354..2555c173d 100644 --- a/include/haproxy/stress.h +++ b/include/haproxy/stress.h @@ -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 };