IVGCVSW-3670 Fix Vts Tests after adding Ref Import functionality
authorFerran Balaguer <ferran.balaguer@arm.com>
Thu, 22 Aug 2019 13:09:44 +0000 (14:09 +0100)
committerDerek Lamberti <derek.lamberti@arm.com>
Thu, 22 Aug 2019 17:04:34 +0000 (17:04 +0000)
Signed-off-by: Ferran Balaguer <ferran.balaguer@arm.com>
Change-Id: I87d003ae14575d7d7be67b2a7d00d69ef6201849

src/backends/reference/RefTensorHandle.cpp
src/backends/reference/test/RefTensorHandleTests.cpp

index 59ccec6..42ac7f0 100644 (file)
@@ -35,7 +35,10 @@ RefTensorHandle::~RefTensorHandle()
     if (!m_Pool)
     {
         // unmanaged
-        ::operator delete(m_UnmanagedMemory);
+        if (!m_Imported)
+        {
+            ::operator delete(m_UnmanagedMemory);
+        }
     }
 }
 
@@ -110,6 +113,12 @@ bool RefTensorHandle::Import(void* memory, MemorySource source)
             // Checks the 16 byte memory alignment.
             if (reinterpret_cast<uint64_t>(memory) % 16)
             {
+                if (m_Imported)
+                {
+                    m_Imported = false;
+                    m_UnmanagedMemory = nullptr;
+                }
+
                 return false;
             }
 
index 8de03cf..2c5d6d4 100644 (file)
@@ -54,7 +54,6 @@ BOOST_AUTO_TEST_CASE(CheckSourceType)
     TensorInfo info({1}, DataType::Float32);
     RefTensorHandle handle(info, memoryManager, static_cast<unsigned int>(MemorySource::Malloc));
 
-    // This pointer will be deleted in the handle destructor
     int* testPtr = new int(4);
 
     // Not supported
@@ -65,6 +64,8 @@ BOOST_AUTO_TEST_CASE(CheckSourceType)
 
     // Supported
     BOOST_CHECK(handle.Import(static_cast<void *>(testPtr), MemorySource::Malloc));
+
+    delete testPtr;
 }
 
 BOOST_AUTO_TEST_CASE(ReusePointer)
@@ -74,13 +75,14 @@ BOOST_AUTO_TEST_CASE(ReusePointer)
     TensorInfo info({1}, DataType::Float32);
     RefTensorHandle handle(info, memoryManager, static_cast<unsigned int>(MemorySource::Malloc));
 
-    // This pointer will be deleted in the handle destructor
     int* testPtr = new int(4);
 
     handle.Import(static_cast<void *>(testPtr), MemorySource::Malloc);
 
     // Reusing previously Imported pointer
     BOOST_CHECK(handle.Import(static_cast<void *>(testPtr), MemorySource::Malloc));
+
+    delete testPtr;
 }
 
 BOOST_AUTO_TEST_CASE(MisalignedPointer)