<member name="MALLOC_DEBUG" displayname="Keep Track of Memory Allocations">
<support_level>core</support_level>
</member>
+ <member name="DEBUG_CHAOS" displayname="Randomly FAIL memory allocations or other operations">
+ <conflict>MALLOC_DEBUG</conflict>
+ <support_level>core</support_level>
+ </member>
<member name="BUSYDETECT_TONEONLY" displayname="Enable additional comparision of only the tone duration not the silence part">
<conflict>BUSYDETECT_COMPARE_TONE_AND_SILENCE</conflict>
<defaultenabled>no</defaultenabled>
*/
#define ast_random_double() (((double)ast_random()) / RAND_MAX)
+/*!
+ * \brief DEBUG_CHAOS returns failure randomly
+ *
+ * DEBUG_CHAOS_RETURN(failure); can be used to fake
+ * failure of functions such as memory allocation,
+ * for the purposes of testing failure handling.
+ */
+#ifdef DEBUG_CHAOS
+#ifndef DEBUG_CHAOS_ALLOC_CHANCE
+#define DEBUG_CHAOS_ALLOC_CHANCE 100000
+#endif
+/* Could #define DEBUG_CHAOS_ENABLE ast_fully_booted */
+#ifndef DEBUG_CHAOS_ENABLE
+#define DEBUG_CHAOS_ENABLE 1
+#endif
+#define DEBUG_CHAOS_RETURN(CHANCE, FAILURE) \
+ do { \
+ if ((DEBUG_CHAOS_ENABLE) && (ast_random() % CHANCE == 0)) { \
+ return FAILURE; \
+ } \
+ } while (0)
+#else
+#define DEBUG_CHAOS_RETURN(c,f)
+#endif
+
+
#ifndef __AST_DEBUG_MALLOC
#define ast_std_malloc malloc
#define ast_std_calloc calloc
{
void *p;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (!(p = malloc(len))) {
MALLOC_FAILURE_MSG;
}
{
void *p;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (!(p = calloc(num, len))) {
MALLOC_FAILURE_MSG;
}
{
void *newp;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (!(newp = realloc(p, len))) {
MALLOC_FAILURE_MSG;
}
{
char *newstr = NULL;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (str) {
if (!(newstr = strdup(str))) {
MALLOC_FAILURE_MSG;
{
char *newstr = NULL;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (str) {
if (!(newstr = strndup(str, len))) {
MALLOC_FAILURE_MSG;
{
int res;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
+
if ((res = vasprintf(ret, fmt, ap)) == -1) {
MALLOC_FAILURE_MSG;
}