[asterisk-commits] sgriepentrog: branch 13 r433060 - in /branches/13: build_tools/ include/aster...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 17 16:57:28 CDT 2015
Author: sgriepentrog
Date: Tue Mar 17 16:57:26 2015
New Revision: 433060
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433060
Log:
core: Introduce chaos into memory allocations
Locate potential crashes by exercising seldom
used code paths. This patch introduces a new
define DEBUG_CHAOS, and mechanism to randomly
return an error condition from functions that
will seldom do so. Functions that handle the
allocation of memory get the first treatment.
Review: https://reviewboard.asterisk.org/r/4463/
Modified:
branches/13/build_tools/cflags.xml
branches/13/include/asterisk/utils.h
Modified: branches/13/build_tools/cflags.xml
URL: http://svnview.digium.com/svn/asterisk/branches/13/build_tools/cflags.xml?view=diff&rev=433060&r1=433059&r2=433060
==============================================================================
--- branches/13/build_tools/cflags.xml (original)
+++ branches/13/build_tools/cflags.xml Tue Mar 17 16:57:26 2015
@@ -79,6 +79,10 @@
<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>
Modified: branches/13/include/asterisk/utils.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/include/asterisk/utils.h?view=diff&rev=433060&r1=433059&r2=433060
==============================================================================
--- branches/13/include/asterisk/utils.h (original)
+++ branches/13/include/asterisk/utils.h Tue Mar 17 16:57:26 2015
@@ -485,6 +485,32 @@
*/
#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
@@ -537,6 +563,8 @@
{
void *p;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (!(p = malloc(len))) {
MALLOC_FAILURE_MSG;
}
@@ -561,6 +589,8 @@
{
void *p;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (!(p = calloc(num, len))) {
MALLOC_FAILURE_MSG;
}
@@ -598,6 +628,8 @@
{
void *newp;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (!(newp = realloc(p, len))) {
MALLOC_FAILURE_MSG;
}
@@ -625,6 +657,8 @@
char * attribute_malloc _ast_strdup(const char *str, const char *file, int lineno, const char *func),
{
char *newstr = NULL;
+
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
if (str) {
if (!(newstr = strdup(str))) {
@@ -656,6 +690,8 @@
{
char *newstr = NULL;
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
if (str) {
if (!(newstr = strndup(str, len))) {
MALLOC_FAILURE_MSG;
@@ -696,6 +732,8 @@
int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, va_list ap),
{
int res;
+
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
if ((res = vasprintf(ret, fmt, ap)) == -1) {
MALLOC_FAILURE_MSG;
More information about the asterisk-commits
mailing list