Skip to content

Commit

Permalink
vmh test: extend test for spanning
Browse files Browse the repository at this point in the history
Test both cases - when spanning multiple blocks is allowed and when
it isn't.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
  • Loading branch information
lyakh committed Jul 27, 2023
1 parent 17cba40 commit 5a11244
Showing 1 changed file with 62 additions and 8 deletions.
70 changes: 62 additions & 8 deletions zephyr/test/vmh.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,78 @@
#include <sof/boot_test.h>
#include <sof/lib/regions_mm.h>

static int vmh_test(void)
LOG_MODULE_REGISTER(vmhtest, CONFIG_SOF_LOG_LEVEL);

#define ALLOC_SIZE1 1616
#define ALLOC_SIZE2 26

static int vmh_test_single(bool span)
{
struct vmh_heap *h = vmh_init_heap(NULL, MEM_REG_ATTR_CORE_HEAP, 0, false);
struct vmh_heap *h = vmh_init_heap(NULL, MEM_REG_ATTR_CORE_HEAP, 0, span);

if (!h)
return -EINVAL;

char *buf = vmh_alloc(h, 1616);
char *buf = vmh_alloc(h, ALLOC_SIZE1);
int ret1;

if (buf) {
buf[0] = 0;
buf[ALLOC_SIZE1 - 1] = 15;

if (!buf)
return -ENOMEM;
ret1 = vmh_free(h, buf);
if (ret1 < 0)
goto out;
} else if (span) {
ret1 = -ENOMEM;
LOG_ERR("Failed to allocate %u in contiguous mode", ALLOC_SIZE1);
goto out;
} else {
LOG_WRN("Ignoring failure to allocate %u in non-contiguous mode",
ALLOC_SIZE1);
}

buf = vmh_alloc(h, ALLOC_SIZE2);

if (!buf) {
ret1 = -ENOMEM;
LOG_ERR("Failed to allocate %u", ALLOC_SIZE2);
goto out;
}

buf[0] = 0;
buf[1615] = 15;
buf[ALLOC_SIZE2 - 1] = 15;

ret1 = vmh_free(h, buf);
if (ret1 < 0)
LOG_ERR("Free error %d", ret1);

out:
int ret2 = vmh_free_heap(h);

if (ret2 < 0)
LOG_ERR("Free heap error %d", ret2);

if (!ret1)
ret1 = ret2;

return ret1;
}

static int vmh_test(void)
{
int ret = vmh_test_single(false);

if (ret < 0) {
LOG_ERR("Non-contiguous test error %d", ret);
return ret;
}

vmh_free(h, buf);
ret = vmh_test_single(true);
if (ret < 0)
LOG_ERR("Contiguous test error %d", ret);

return vmh_free_heap(h);
return ret;
}

SOF_BOOT_TEST(vmh_test);

0 comments on commit 5a11244

Please sign in to comment.