From 412b24137edbfd54669fe0094ea6a1be2b842567 Mon Sep 17 00:00:00 2001 From: Felix Kuehling Date: Thu, 14 Jul 2022 16:45:12 -0400 Subject: [PATCH] kfdtest: Full TearDown and SetUp in child process With the next patch, child processes need to fully reinitialize the topology in order to recreate the process apertures. Just calling hsaKmtOpenKFD is no longer sufficient. Tests based on KFDMultiProcessTest already did this correctly (KFDHWSTest, eviction tests). This patch fixes KFDExceptionTest and KFDIPCTest. Signed-off-by: Felix Kuehling Change-Id: Iaad24e88ddd29c1105bf791a77891cc55a6072ff --- tests/kfdtest/src/KFDExceptionTest.cpp | 30 +++++++++----------------- tests/kfdtest/src/KFDExceptionTest.hpp | 5 ++++- tests/kfdtest/src/KFDIPCTest.cpp | 9 +++++--- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/tests/kfdtest/src/KFDExceptionTest.cpp b/tests/kfdtest/src/KFDExceptionTest.cpp index ddcf8ceb16..67ccc68336 100644 --- a/tests/kfdtest/src/KFDExceptionTest.cpp +++ b/tests/kfdtest/src/KFDExceptionTest.cpp @@ -184,11 +184,8 @@ TEST_F(KFDExceptionTest, AddressFault) { m_ChildPid = fork(); if (m_ChildPid == 0) { - m_ChildStatus = hsaKmtOpenKFD(); - if (m_ChildStatus != HSAKMT_STATUS_SUCCESS) { - WARN() << "KFD open failed in child process" << std::endl; - return; - } + KFDBaseComponentTest::TearDown(); + KFDBaseComponentTest::SetUp(); HsaMemoryBuffer srcBuffer(PAGE_SIZE, defaultGPUNode, false); @@ -228,11 +225,8 @@ TEST_F(KFDExceptionTest, PermissionFault) { m_ChildPid = fork(); if (m_ChildPid == 0) { - m_ChildStatus = hsaKmtOpenKFD(); - if (m_ChildStatus != HSAKMT_STATUS_SUCCESS) { - WARN() << "KFD open failed in child process" << std::endl; - return; - } + KFDBaseComponentTest::TearDown(); + KFDBaseComponentTest::SetUp(); HsaMemoryBuffer readOnlyBuffer(PAGE_SIZE, defaultGPUNode, false /*zero*/, false /*isLocal*/, true /*isExec*/, @@ -278,11 +272,8 @@ TEST_F(KFDExceptionTest, FaultStorm) { m_ChildPid = fork(); if (m_ChildPid == 0) { - m_ChildStatus = hsaKmtOpenKFD(); - if (m_ChildStatus != HSAKMT_STATUS_SUCCESS) { - WARN() << "KFD open failed in child process" << std::endl; - return; - } + KFDBaseComponentTest::TearDown(); + KFDBaseComponentTest::SetUp(); TestMemoryException(defaultGPUNode, 0x12345678, 0x76543210, 1024, 1024, 1); } else { @@ -321,11 +312,10 @@ TEST_F(KFDExceptionTest, SdmaQueueException) { if (m_ChildPid == 0) { unsigned int* pDb = NULL; unsigned int *nullPtr = NULL; - m_ChildStatus = hsaKmtOpenKFD(); - if (m_ChildStatus != HSAKMT_STATUS_SUCCESS) { - WARN() << "KFD open failed in child process" << std::endl; - return; - } + + KFDBaseComponentTest::TearDown(); + KFDBaseComponentTest::SetUp(); + m_MemoryFlags.ui32.NonPaged = 1; ASSERT_SUCCESS(hsaKmtAllocMemory(defaultGPUNode, PAGE_SIZE, m_MemoryFlags, reinterpret_cast(&pDb))); diff --git a/tests/kfdtest/src/KFDExceptionTest.hpp b/tests/kfdtest/src/KFDExceptionTest.hpp index df57649e2c..f544d95100 100644 --- a/tests/kfdtest/src/KFDExceptionTest.hpp +++ b/tests/kfdtest/src/KFDExceptionTest.hpp @@ -42,8 +42,11 @@ class KFDExceptionTest : public KFDBaseComponentTest { * child process finishes, gtest assumes the test has finished and * starts the next test while the parent is still active. */ - if (m_ChildPid == 0) + if (m_ChildPid == 0) { + if (!m_ChildStatus && HasFatalFailure()) + m_ChildStatus = HSAKMT_STATUS_ERROR; exit(m_ChildStatus); + } } protected: diff --git a/tests/kfdtest/src/KFDIPCTest.cpp b/tests/kfdtest/src/KFDIPCTest.cpp index c18b471307..77a94b6eb7 100644 --- a/tests/kfdtest/src/KFDIPCTest.cpp +++ b/tests/kfdtest/src/KFDIPCTest.cpp @@ -70,8 +70,8 @@ void KFDIPCTest::BasicTestChildProcess(int defaultGPUNode, int *pipefd, HsaMemFl /* Open KFD device for child process. This needs to called before * any memory definitions */ - if (HSAKMT_STATUS_SUCCESS != hsaKmtOpenKFD()) - exit(1); + TearDown(); + SetUp(); SDMAQueue sdmaQueue; HsaSharedMemoryHandle sharedHandleLM; @@ -635,7 +635,10 @@ TEST_F(KFDIPCTest, CrossMemoryAttachTest) { /* Create a child process and share the above Local Memory with it */ m_ChildPid = fork(); - if (m_ChildPid == 0 && hsaKmtOpenKFD() == HSAKMT_STATUS_SUCCESS) { + if (m_ChildPid == 0) { + TearDown(); + SetUp(); + /* Child Process */ status = CrossMemoryAttachChildProcess(defaultGPUNode, pipeCtoP[1], pipePtoC[0], CMA_READ_TEST);