From be7fdcb72c58cb6486b7743063eb9f7be0818d94 Mon Sep 17 00:00:00 2001 From: SrinivasaRao Date: Wed, 16 Aug 2023 11:39:53 +0530 Subject: [PATCH] SWDEV-416343 - [catch2][dtest] Functional test cases for the hipDeviceGetUuid() API Change-Id: I6c75f8282d6d78cdee224e018f3e70bfd5512a03 --- catch/unit/device/hipDeviceGetUuid.cc | 94 ++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/catch/unit/device/hipDeviceGetUuid.cc b/catch/unit/device/hipDeviceGetUuid.cc index d02f595673..42a3d8d0e5 100644 --- a/catch/unit/device/hipDeviceGetUuid.cc +++ b/catch/unit/device/hipDeviceGetUuid.cc @@ -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 +#include +#ifdef __linux__ +#include +#endif #include #include + /** * @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