ulong mem_malloc_end = 0;
ulong mem_malloc_brk = 0;
+static bool malloc_testing; /* enable test mode */
+static int malloc_max_allocs; /* return NULL after this many calls to malloc() */
+
void *sbrk(ptrdiff_t increment)
{
ulong old = mem_malloc_brk;
return malloc_simple(bytes);
#endif
+ if (CONFIG_IS_ENABLED(UNIT_TEST) && malloc_testing) {
+ if (--malloc_max_allocs < 0)
+ return NULL;
+ }
+
/* check if mem_malloc_init() was run */
if ((mem_malloc_start == 0) && (mem_malloc_end == 0)) {
/* not initialized yet */
return 0;
}
+void malloc_enable_testing(int max_allocs)
+{
+ malloc_testing = true;
+ malloc_max_allocs = max_allocs;
+}
+
+void malloc_disable_testing(void)
+{
+ malloc_testing = false;
+}
+
/*
History:
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
uts->force_fail_alloc = false;
uts->skip_post_probe = false;
gd->dm_root = NULL;
+ malloc_disable_testing();
if (CONFIG_IS_ENABLED(UT_DM) && !CONFIG_IS_ENABLED(OF_PLATDATA))
memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
arch_reset_for_test();