Kfdtest: Change and move drm device function into KFDBaseComponentTest

It is for other test to reuse this function.

Change-Id: Ib0dbc1a267a5bbcd8078ab3265677b53531f86f3
Signed-off-by: Eric Huang <JinHuiEric.Huang@amd.com>
Esse commit está contido em:
Eric Huang
2018-08-01 14:18:40 -04:00
commit de JinHuiEric Huang
commit f8d19104aa
4 arquivos alterados com 79 adições e 117 exclusões
-94
Ver Arquivo
@@ -23,103 +23,9 @@
#include "KFDGraphicsInterop.hpp"
extern "C" {
#include <xf86drm.h>
#include <amdgpu.h>
#include <amdgpu_drm.h>
}
#include <unistd.h>
#include <sys/param.h>
#include <vector>
#include <cstdio>
#include <cstring>
#include "Dispatch.hpp"
#include "PM4Queue.hpp"
void KFDGraphicsInterop::SetUp() {
ROUTINE_START
KFDMemoryTest::SetUp();
// Try to open and initialize a render node for each device
for (int i = 0; i < MAX_RENDER_NODES; i++) {
m_RenderNodes[i].fd = drmOpenRender(i + 128);
if (m_RenderNodes[i].fd <= 0)
continue;
if (amdgpu_device_initialize(m_RenderNodes[i].fd,
&m_RenderNodes[i].major_version,
&m_RenderNodes[i].minor_version,
&m_RenderNodes[i].device_handle) != 0) {
drmClose(m_RenderNodes[i].fd);
m_RenderNodes[i].fd = 0;
}
// Try to determine the bus-ID from sysfs
char path[PATH_MAX], link[PATH_MAX];
snprintf(path, PATH_MAX, "/sys/class/drm/renderD%d", i+128);
if (readlink(path, link, PATH_MAX) < 0) {
LOG() << "Failed to read sysfs link " << path
<< ", can't determine bus ID." << std::endl;
continue;
}
char *state = NULL;
char *prev = NULL;
char *tok = strtok_r(link, "/", &state);
while (tok && strcmp(tok, "drm")) {
prev = tok;
tok = strtok_r(NULL, "/", &state);
}
unsigned domain, bus, device, func;
if (!prev ||
sscanf(prev, "%04x:%02x:%02x.%1x", &domain, &bus, &device, &func)
!= 4) {
LOG() << "Failed to parse sysfs link " << path
<< ", can't determine bus ID." << std::endl;
continue;
}
m_RenderNodes[i].bdf = (bus << 8) | (device << 3) | func;
}
ROUTINE_END
}
void KFDGraphicsInterop::TearDown() {
ROUTINE_START
for (int i = 0; i < MAX_RENDER_NODES; i++) {
if (m_RenderNodes[i].fd <= 0)
continue;
EXPECT_EQ(0, amdgpu_device_deinitialize(m_RenderNodes[i].device_handle));
EXPECT_EQ(0, drmClose(m_RenderNodes[i].fd));
}
KFDMemoryTest::TearDown();
ROUTINE_END
}
int KFDGraphicsInterop::FindDRMRenderNode(int gpuNode) {
int rn;
const HsaNodeProperties *pNodeProps =
m_NodeInfo.GetNodeProperties(gpuNode);
for (rn = 0; rn < MAX_RENDER_NODES; rn++) {
if (m_RenderNodes[rn].fd <= 0)
continue;
if (m_RenderNodes[rn].bdf == pNodeProps->LocationId)
return rn;
}
LOG() << "Found no render node corresponding to GPU node "
<< gpuNode << std::endl;
LOG() << "Check your device permissions" << std::endl;
return -1;
}
TEST_F(KFDGraphicsInterop, RegisterGraphicsHandle) {
TEST_START(TESTPROFILE_RUNALL)