From a040a2424316a7e727d07e69617b0eac5d18d7bc Mon Sep 17 00:00:00 2001 From: xinhui pan Date: Fri, 24 Aug 2018 11:57:04 +0800 Subject: [PATCH] kfdtest: Let BigBufferStressTest detect memory leak As it will alloc as much as small system memory to reach the allocation limit. We can try to alloc memory several times to see if any allocation in the previous step cause memory leak. Also we test if GPU can access these memory correctly or not. Change-Id: I309f9821b6bc99c212a6bfbc21fe3086ab589fd3 Signed-off-by: xinhui pan --- tests/kfdtest/src/KFDMemoryTest.cpp | 53 +++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/tests/kfdtest/src/KFDMemoryTest.cpp b/tests/kfdtest/src/KFDMemoryTest.cpp index 878c487afa..8617b0893c 100644 --- a/tests/kfdtest/src/KFDMemoryTest.cpp +++ b/tests/kfdtest/src/KFDMemoryTest.cpp @@ -819,33 +819,50 @@ TEST_F(KFDMemoryTest, BigBufferStressTest) { */ #define ARRAY_ENTRIES 2048 - int i = 0; + int i = 0, allocationCount = 0; unsigned int* pDb_array[ARRAY_ENTRIES]; HSAuint64 block_size_mb = 128; HSAuint64 block_size = block_size_mb * 1024 * 1024; + PM4Queue queue; + ASSERT_SUCCESS(queue.Create(defaultGPUNode)); - do { - ret = hsaKmtAllocMemory(0 /* system */, block_size, m_MemoryFlags, - reinterpret_cast(&pDb_array[i])); - if (ret) { - break; + /* Test 4 times to see if there is any memory leak.*/ + for (int repeat = 1; repeat < 5; repeat++) { + for (i = 0; i < ARRAY_ENTRIES; i++) { + ret = hsaKmtAllocMemory(0 /* system */, block_size, m_MemoryFlags, + reinterpret_cast(&pDb_array[i])); + if (ret) + break; + + ret = hsaKmtMapMemoryToGPUNodes(pDb_array[i], block_size, + &AlternateVAGPU, mapFlags, 1, reinterpret_cast(&defaultGPUNode)); + if (ret) { + EXPECT_SUCCESS(hsaKmtFreeMemory(pDb_array[i], block_size)); + break; + } } - ret = hsaKmtMapMemoryToGPUNodes(pDb_array[i], block_size, - &AlternateVAGPU, mapFlags, 1, reinterpret_cast(&defaultGPUNode)); - if (ret) { + LOG() << "Allocated system buffers time " << std::dec << repeat << ": " << i << "x" + << block_size_mb << "MB" << std::endl; + + if (allocationCount == 0) + allocationCount = i; + EXPECT_GE(i, allocationCount) << "There might be memory leak!" << std::endl; + + while (i--) { + /* To see if GPU can access the memory correctly*/ + unsigned int *begin = pDb_array[i]; + *begin = 0; + queue.PlaceAndSubmitPacket( + PM4WriteDataPacket(begin, 0xdeadbeaf)); + queue.Wait4PacketConsumption(); + EXPECT_TRUE(WaitOnValue(begin, 0xdeadbeaf)); + + EXPECT_SUCCESS(hsaKmtUnmapMemoryToGPU(pDb_array[i])); EXPECT_SUCCESS(hsaKmtFreeMemory(pDb_array[i], block_size)); - break; } - } while (++i < ARRAY_ENTRIES); - - LOG() << "Allocated system buffers: " << std::dec << i << "x" - << block_size_mb << "MB" << std::endl; - - while (i--) { - EXPECT_SUCCESS(hsaKmtUnmapMemoryToGPU(pDb_array[i])); - EXPECT_SUCCESS(hsaKmtFreeMemory(pDb_array[i], block_size)); } + EXPECT_SUCCESS(queue.Destroy()); TEST_END }