Adedd load/unload warm-up before the memory lek test to put the runtime into a
authorMatteo Martincigh <matteo.martincigh@arm.com>
Thu, 15 Nov 2018 10:54:54 +0000 (10:54 +0000)
committerAron Virginas-Tar <aron.virginas-tar@arm.com>
Thu, 15 Nov 2018 12:52:36 +0000 (12:52 +0000)
stable test (memory-wise)
This prevents false-positives when running the tests on Master

Change-Id: I4348378f3689cb3ec98686a93315d2b88bb7bcc7

src/armnn/test/RuntimeTests.cpp

index 08e3190..998808c 100644 (file)
@@ -126,27 +126,27 @@ BOOST_AUTO_TEST_CASE(RuntimeMemoryLeak)
     armnn::Runtime runtime(options);
     armnn::RuntimeLoadedNetworksReserve(&runtime);
 
-    // Checks for leaks before we load the network and record them so that we can see the delta after unloading.
-    VALGRIND_DO_QUICK_LEAK_CHECK;
-    VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed);
-
-    // Builds a mock-network and load it into the runtime.
     {
-        unsigned int inputShape[] = {1, 7, 1, 1};
-        armnn::TensorInfo inputTensorInfo(4, inputShape, armnn::DataType::Float32);
+        std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
 
         std::unique_ptr<armnn::Network> mockNetwork1 = std::make_unique<armnn::Network>();
         mockNetwork1->AddInputLayer(0, "test layer");
 
-
-        std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
+        // Warm-up load/unload pair to put the runtime in a stable state (memory-wise).
         runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
-    }
+        runtime.UnloadNetwork(networkIdentifier1);
+
+        // Checks for leaks before we load the network and record them so that we can see the delta after unloading.
+        VALGRIND_DO_QUICK_LEAK_CHECK;
+        VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed);
 
-    runtime.UnloadNetwork(networkIdentifier1);
+        // The actual test.
+        runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
+        runtime.UnloadNetwork(networkIdentifier1);
 
-    VALGRIND_DO_ADDED_LEAK_CHECK;
-    VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
+        VALGRIND_DO_ADDED_LEAK_CHECK;
+        VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
+    }
 
     // If we're not running under Valgrind, these vars will have been initialised to 0, so this will always pass.
     BOOST_TEST(leakedBefore    == leakedAfter);