#include <darwintest.h>
#include <stdlib.h>
#include <malloc/malloc.h>
T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
T_DECL(malloc_zone_batch, "malloc_zone_batch_malloc and malloc_zone_batch_free")
{
const unsigned count = 10;
void **results;
unsigned number;
results = calloc(count, sizeof(void *));
number = malloc_zone_batch_malloc(malloc_default_zone(), 32, results, count);
T_ASSERT_EQ(number, count, "allocated from tiny zone");
for (int i = 0; i < count; i++) {
T_QUIET; T_ASSERT_NOTNULL(results[i], "pointer %d is NULL", i);
}
malloc_zone_batch_free(malloc_default_zone(), results, count);
free(results);
results = calloc(count, sizeof(void *));
number = malloc_zone_batch_malloc(malloc_default_zone(), 2048, results, count);
T_ASSERT_EQ(0, number, "could not allocat from small zone");
for (int i = 0; i < count; i++) {
T_QUIET; T_ASSERT_NULL(results[i], "pointer %d is not NULL", i);
}
malloc_zone_batch_free(malloc_default_zone(), results, count);
free(results);
}