1 // 2 // Copyright © 2017 Arm Ltd. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include <test/RuntimeTests.hpp> 7 8 #include <LeakChecking.hpp> 9 10 #include <backendsCommon/test/RuntimeTestImpl.hpp> 11 12 #include <doctest/doctest.h> 13 14 15 #ifdef ARMNN_LEAK_CHECKING_ENABLED 16 TEST_SUITE("RefRuntime") 17 { 18 TEST_CASE("RuntimeMemoryLeaksCpuRef") 19 { 20 CHECK(ARMNN_LEAK_CHECKER_IS_ACTIVE()); 21 22 armnn::IRuntime::CreationOptions options; 23 armnn::RuntimeImpl runtime(options); 24 armnn::RuntimeLoadedNetworksReserve(&runtime); 25 26 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef}; 27 { 28 // Do a warmup of this so we make sure that all one-time 29 // initialization happens before we do the leak checking. 30 CreateAndDropDummyNetwork(backends, runtime); 31 } 32 33 { 34 ARMNN_SCOPED_LEAK_CHECKER("LoadAndUnloadNetworkCpuRef"); 35 CHECK(ARMNN_NO_LEAKS_IN_SCOPE()); 36 // In the second run we check for all remaining memory 37 // in use after the network was unloaded. If there is any 38 // then it will be treated as a memory leak. 39 CreateAndDropDummyNetwork(backends, runtime); 40 CHECK(ARMNN_NO_LEAKS_IN_SCOPE()); 41 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 0); 42 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 0); 43 } 44 } 45 } 46 #endif 47 48