aboutsummaryrefslogtreecommitdiff
path: root/include/malloc.h
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-06 20:27:00 -0600
committerTom Rini <trini@konsulko.com>2022-09-29 16:07:58 -0400
commit62d638386c17d17b929ad10956c7f60825335a4e (patch)
tree9f0e6f82f9bdc3fac8a8c64e2850c14002cd6a2a /include/malloc.h
parent7c14dc7f77705f79ba49e7f0b2879986fea70fea (diff)
downloadu-boot-62d638386c17d17b929ad10956c7f60825335a4e.zip
u-boot-62d638386c17d17b929ad10956c7f60825335a4e.tar.gz
u-boot-62d638386c17d17b929ad10956c7f60825335a4e.tar.bz2
test: Support testing malloc() failures
It is helpful to test that out-of-memory checks work correctly in code that calls malloc(). Add a simple way to force failure after a given number of malloc() calls. Fix a header guard to avoid a build error on sandbox_vpl. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Sean Anderson <seanga2@gmail.com>
Diffstat (limited to 'include/malloc.h')
-rw-r--r--include/malloc.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/malloc.h b/include/malloc.h
index e8c8b25..161ccbd 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -883,6 +883,18 @@ extern Void_t* sbrk();
void malloc_simple_info(void);
+/**
+ * malloc_enable_testing() - Put malloc() into test mode
+ *
+ * This only works if UNIT_TESTING is enabled
+ *
+ * @max_allocs: return -ENOMEM after max_allocs calls to malloc()
+ */
+void malloc_enable_testing(int max_allocs);
+
+/** malloc_disable_testing() - Put malloc() into normal mode */
+void malloc_disable_testing(void);
+
#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
#define malloc malloc_simple
#define realloc realloc_simple