feat(unittests): add support for dynamic test harnesses

This patch adds support to the unittest framework to support
dynamic reconfiguration of test harnesses at run time, adding
flexibility to the tests.

It also replaces the build-time-linked test harnesses used
by the existing unit tests by dynamic ones and includes
some refactor on the slot buffer and the host test helpers to
ease the tests.

Signed-off-by: Javier Almansa Sobrino <javier.almansasobrino@arm.com>
Change-Id: Iabe9d0982d4fb6e78424fcd24a916324c7675697
diff --git a/lib/realm/src/buffer.c b/lib/realm/src/buffer.c
index 7fcaa48..687d86f 100644
--- a/lib/realm/src/buffer.c
+++ b/lib/realm/src/buffer.c
@@ -235,11 +235,9 @@
 	return buffer_arch_map(slot, addr);
 }
 
-static void ns_buffer_unmap(enum buffer_slot slot)
+static inline void ns_buffer_unmap(void *buf)
 {
-	assert(is_ns_slot(slot));
-
-	buffer_arch_unmap((void *)slot_to_va(slot));
+	buffer_arch_unmap(buf);
 }
 
 /*
@@ -297,9 +295,9 @@
 	offset &= ~GRANULE_MASK;
 	assert(offset + size <= GRANULE_SIZE);
 
-	src = (uintptr_t)ns_granule_map(slot, ns_gr) + offset;
-	retval = memcpy_ns_read(dest, (void *)src, size);
-	ns_buffer_unmap(slot);
+	src = (uintptr_t)ns_granule_map(slot, ns_gr);
+	retval = memcpy_ns_read(dest, (void *)(src + offset), size);
+	ns_buffer_unmap((void *)src);
 
 	return retval;
 }
@@ -336,9 +334,9 @@
 	offset &= ~GRANULE_MASK;
 	assert(offset + size <= GRANULE_SIZE);
 
-	dest = (uintptr_t)ns_granule_map(slot, ns_gr) + offset;
-	retval = memcpy_ns_write((void *)dest, src, size);
-	ns_buffer_unmap(slot);
+	dest = (uintptr_t)ns_granule_map(slot, ns_gr);
+	retval = memcpy_ns_write((void *)(dest + offset), src, size);
+	ns_buffer_unmap((void *)dest);
 
 	return retval;
 }