Util Test: Add memory mapping tests
Jeffrey Pfau jeffrey@endrift.com
Sun, 23 Oct 2016 10:37:28 -0700
1 files changed,
42 insertions(+),
1 deletions(-)
jump to
M
src/util/test/vfs.c
→
src/util/test/vfs.c
@@ -107,6 +107,44 @@ assert_int_equal(vf->size(vf), 16);
vf->close(vf); } +M_TEST_DEFINE(mapMem) { + uint8_t bytes[32] = "Test Pattern"; + struct VFile* vf = VFileFromMemory(bytes, 32); + assert_non_null(vf); + void* mapped = vf->map(vf, 32, MAP_READ); + assert_non_null(mapped); + assert_ptr_equal(mapped, &bytes); + vf->unmap(vf, mapped, 32); + vf->close(vf); +} + +M_TEST_DEFINE(mapConstMem) { + uint8_t bytes[32] = "Test Pattern"; + struct VFile* vf = VFileFromConstMemory(bytes, 32); + assert_non_null(vf); + void* mapped = vf->map(vf, 32, MAP_READ); + assert_non_null(mapped); + assert_ptr_equal(mapped, &bytes); + vf->unmap(vf, mapped, 32); + vf->close(vf); +} + +M_TEST_DEFINE(mapMemChunk) { + uint8_t bytes[32] = "Test Pattern"; + struct VFile* vf = VFileMemChunk(bytes, 32); + assert_non_null(vf); + void* mapped = vf->map(vf, 32, MAP_READ); + assert_non_null(mapped); + assert_ptr_not_equal(mapped, &bytes); + assert_memory_equal(mapped, &bytes, 32); + vf->write(vf, bytes, sizeof(bytes)); + void* mapped2 = vf->map(vf, 32, MAP_READ); + assert_ptr_equal(mapped, mapped2); + vf->unmap(vf, mapped, 32); + vf->unmap(vf, mapped2, 32); + vf->close(vf); +} + M_TEST_SUITE_DEFINE(VFS, #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 cmocka_unit_test(openNullPathR),@@ -123,4 +161,7 @@ cmocka_unit_test(openNonNullMemChunk0),
cmocka_unit_test(openNullMemChunkNonzero), cmocka_unit_test(resizeMem), cmocka_unit_test(resizeConstMem), - cmocka_unit_test(resizeMemChunk)) + cmocka_unit_test(resizeMemChunk), + cmocka_unit_test(mapMem), + cmocka_unit_test(mapConstMem), + cmocka_unit_test(mapMemChunk))