SWDEV-416343 - [catch2][dtest] Functional test cases for the hipDeviceGetUuid() API

Change-Id: I6c75f8282d6d78cdee224e018f3e70bfd5512a03
Esse commit está contido em:
SrinivasaRao
2023-08-16 11:39:53 +05:30
commit de Rakesh Roy
commit be7fdcb72c
+92 -2
Ver Arquivo
@@ -1,5 +1,5 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@@ -18,9 +18,14 @@ THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <string.h>
#ifdef __linux__
#include <unistd.h>
#endif
#include <cstring>
#include <cstdio>
/**
* @addtogroup hipDeviceGetUuid hipDeviceGetUuid
* @{
@@ -50,7 +55,6 @@ TEST_CASE("Unit_hipDeviceGetUuid_Positive") {
// Scenario 1
HIP_CHECK(hipDeviceGetUuid(&uuid, device));
// Atleast one non zero value
size_t uuidSize = sizeof(uuid.bytes) / sizeof(uuid.bytes[0]);
for (size_t i = 0; i < uuidSize; i++) {
@@ -92,3 +96,89 @@ TEST_CASE("Unit_hipDeviceGetUuid_Negative") {
REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, numDevices));
}
}
#ifdef __linux__
#if HT_AMD
#define COMMAND_LEN 256
#define BUFFER_LEN 512
/**
* Test Description
* ------------------------
* - Get the UUID from rocminfo and compare it with the value from hipDeviceGetUuid API
* Test source
* ------------------------
* - unit/device/hipDeviceGetUuid.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.7
*/
TEST_CASE("Unit_hipDeviceGetUuid_From_RocmInfo") {
int deviceCount = 0;
hipDevice_t device;
hipUUID uuid{0};
HIP_CHECK(hipGetDeviceCount(&deviceCount));
assert(deviceCount > 0);
FILE *fpipe;
char command[COMMAND_LEN] = "";
const char *rocmInfo = "rocminfo";
snprintf(command, COMMAND_LEN, "%s", rocmInfo);
strncat(command, " | grep -i Uuid:", COMMAND_LEN);
// Execute the rocminfo command and extract the UUID info
fpipe = popen(command, "r");
if (fpipe == nullptr) {
printf("Unable to create command file\n");
return;
}
char command_op[BUFFER_LEN];
int j = 0;
std::string output[deviceCount]; //NOLINT
while (fgets(command_op, BUFFER_LEN, fpipe)) {
std::string rocminfo_line(command_op);
if ((std::string::npos != rocminfo_line.find("CPU-"))) {
continue;
} else if ((std::string::npos != rocminfo_line.find("GPU-"))) {
output[j] = rocminfo_line.substr(31, 16);
}
j++;
}
for (int dev = 0; dev < deviceCount; dev++) {
HIP_CHECK(hipSetDevice(dev));
HIP_CHECK(hipDeviceGet(&device, dev));
HIP_CHECK(hipDeviceGetUuid(&uuid, device));
REQUIRE(output[dev] == uuid.bytes);
}
}
#endif
#endif
/**
* Test Description
* ------------------------
* - Get the UUID from hipGetDeviceProperties and compare it with value from hipDeviceGetUuid API
* Test source
* ------------------------
* - unit/device/hipDeviceGetUuid.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.7
*/
// Guarding it against NVIDIA as this test is faling on it.
#if HT_AMD
TEST_CASE("Unit_hipDeviceGetUuid_VerifyUuidFrm_hipGetDeviceProperties") {
int deviceCount = 0;
hipDevice_t device;
hipDeviceProp_t prop;
hipUUID uuid{0};
HIP_CHECK(hipGetDeviceCount(&deviceCount));
assert(deviceCount > 0);
for (int dev = 0; dev < deviceCount; dev++) {
HIP_CHECK(hipSetDevice(dev));
HIP_CHECK(hipDeviceGet(&device, dev));
HIP_CHECK(hipDeviceGetUuid(&uuid, device));
HIP_CHECK(hipGetDeviceProperties(&prop, dev));
REQUIRE(strcmp(prop.uuid.bytes, uuid.bytes) == 0);
}
}
#endif