IVGCVSW-6077 Add Custom Allocator tests

 * Add test for invalid backend and nullptr
 * Small refactor
 * Throw exception on nullptr allocator instead of assert

Signed-off-by: Francis Murtagh <francis.murtagh@arm.com>
Change-Id: I94ce4f61d7cb3123831f1acd98165ae14c40033a
diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp
index 5a52888..824a2b0 100644
--- a/src/armnn/Runtime.cpp
+++ b/src/armnn/Runtime.cpp
@@ -286,6 +286,11 @@
             ARMNN_ASSERT(backend.get() != nullptr);
 
             auto customAllocatorMapIterator = options.m_CustomAllocatorMap.find(id);
+            if (customAllocatorMapIterator != options.m_CustomAllocatorMap.end() &&
+                customAllocatorMapIterator->second == nullptr)
+            {
+                throw armnn::Exception("Allocator associated with id " + id.Get() + " is null");
+            }
 
             // If the runtime is created in protected mode only add backends that support this mode
             if (options.m_ProtectedMode)
@@ -307,8 +312,6 @@
                 if (customAllocatorMapIterator != options.m_CustomAllocatorMap.end())
                 {
                     std::string err;
-                    // Check we have actually been given an allocator.
-                    ARMNN_ASSERT(customAllocatorMapIterator->second != nullptr);
                     if (customAllocatorMapIterator->second->GetMemorySourceType()
                         == armnn::MemorySource::DmaBufProtected)
                     {