From 9f245611c5de9b4c2b63f3d54b60d2fae566ec87 Mon Sep 17 00:00:00 2001 From: "Narlo, Joseph" Date: Thu, 24 Apr 2025 12:33:55 -0500 Subject: [PATCH] [SWDEV-489696] Improve Functional Test (#241) Improve Functional Test for - SetCheckPowerCap - TestPowerCapReadWrite --------- Signed-off-by: josnarlo [ROCm/amdsmi commit: 30ebf1989364feddfb94fc1ffe7b2a0f46800e91] --- .../functional/power_cap_read_write.cc | 187 ++++++++++++++---- .../functional/power_cap_read_write.h | 3 + 2 files changed, 148 insertions(+), 42 deletions(-) diff --git a/projects/amdsmi/tests/amd_smi_test/functional/power_cap_read_write.cc b/projects/amdsmi/tests/amd_smi_test/functional/power_cap_read_write.cc index a907b17eec..4059c78551 100644 --- a/projects/amdsmi/tests/amd_smi_test/functional/power_cap_read_write.cc +++ b/projects/amdsmi/tests/amd_smi_test/functional/power_cap_read_write.cc @@ -33,6 +33,8 @@ #include "power_cap_read_write.h" #include "../test_common.h" +const uint64_t MICRO_CONVERSION = 1000000; + TestPowerCapReadWrite::TestPowerCapReadWrite() : TestBase() { set_title("AMDSMI Power Cap Read/Write Test"); @@ -64,12 +66,63 @@ void TestPowerCapReadWrite::Close() { TestBase::Close(); } +void TestPowerCapReadWrite::SetCheckPowerCap(std::string msg, uint32_t dv_ind, uint64_t &curr_cap, + uint64_t &new_cap, amdsmi_status_t &ret) { + amdsmi_status_t ret_expected; + amdsmi_power_cap_info_t info; + clock_t start, end; + double cpu_time_used; + + ret_expected = ret; + + IF_VERB(STANDARD) { + std::cout << msg << std::endl; + std::cout << "[Before Set] Current Power Cap: " << curr_cap << " uW" << std::endl; + std::cout << "[Before Set] Setting new cap to " << new_cap << "..." << std::endl; + } + start = clock(); + ret = amdsmi_set_power_cap(processor_handles_[dv_ind], 0, new_cap); + end = clock(); + cpu_time_used = ((double) (end - start)) * 1000000UL / CLOCKS_PER_SEC; + + if (ret == AMDSMI_STATUS_NOT_SUPPORTED) { + IF_VERB(STANDARD) { + std::cout << "\t** Not supported on this machine" << std::endl; + } + return; + } + ASSERT_EQ(ret, ret_expected); + if (ret == AMDSMI_STATUS_INVAL) { + new_cap = curr_cap; + std::cout << "\t** Expected invalid result" << std::endl; + return; + } + + ret = amdsmi_get_power_cap_info(processor_handles_[dv_ind], 0, &info); + CHK_ERR_ASRT(ret) + + curr_cap = info.power_cap; + // Confirm in watts the values are equal + ASSERT_EQ(curr_cap/MICRO_CONVERSION, new_cap/MICRO_CONVERSION); + + if (ret_expected == AMDSMI_STATUS_INVAL) { + new_cap = curr_cap; + } + + IF_VERB(STANDARD) { + std::cout << "[After Set] Time spent: " << cpu_time_used << " uS" << std::endl; + std::cout << "[After Set] Current Power Cap: " << curr_cap << " uW" << std::endl; + if (ret_expected != AMDSMI_STATUS_INVAL) { + std::cout << "[After Set] Requested Power Cap: " << new_cap << " uW" << std::endl; + } + } + + return; +} + void TestPowerCapReadWrite::Run(void) { amdsmi_status_t ret; - uint64_t default_cap, min, max, new_cap, curr_cap; - clock_t start, end; - double cpu_time_used; - const uint64_t MICRO_CONVERSION = 1000000; + uint64_t default_cap, min_cap, max_cap, new_cap, curr_cap; TestBase::Run(); if (setup_failed_) { @@ -86,56 +139,105 @@ void TestPowerCapReadWrite::Run(void) { // Verify api support checking functionality is working ret = amdsmi_get_power_cap_info(processor_handles_[dv_ind], 0, nullptr); ASSERT_EQ(ret, AMDSMI_STATUS_INVAL); - min = info.min_power_cap; - max = info.max_power_cap; + min_cap = info.min_power_cap; + max_cap = info.max_power_cap; default_cap = info.default_power_cap; curr_cap = info.power_cap; - new_cap = (max + min)/2; - // Check if power cap is within the range - // skip the test otherwise - if (new_cap < min || new_cap > max) { - std::cout << "Power cap requested (" << new_cap - << " uW) is not within the range. Skipping test for " << dv_ind << std::endl; - continue; - } - + new_cap = (max_cap + min_cap)/2; IF_VERB(STANDARD) { std::cout << "[Before Set] Default Power Cap: " << default_cap << " uW" << std::endl; std::cout << "[Before Set] Current Power Cap: " << curr_cap << " uW" << std::endl; - std::cout << "[Before Set] Power Cap Range [max to min]: " << max << " uW to " << min << - " uW" << std::endl; + std::cout << "[Before Set] Power Cap Range [max to min]: " << max_cap << " uW to " << min_cap << + " uW" << std::endl; std::cout << "[Before Set] Setting new cap to " << new_cap << "..." << std::endl; } - start = clock(); - ret = amdsmi_set_power_cap(processor_handles_[dv_ind], 0, new_cap); - end = clock(); - cpu_time_used = ((double) (end - start)) * 1000000UL / CLOCKS_PER_SEC; - if (ret == AMDSMI_STATUS_NOT_SUPPORTED) { - IF_VERB(STANDARD) { - std::cout << "\t** Not supported on this machine" << std::endl; - } + // Check if power cap is within the range + // skip the test otherwise + if (new_cap < min_cap || new_cap > max_cap) { + std::cout << "\t** Power cap requested (" << new_cap << " uW) is failed to set for " << dv_ind << std::endl; continue; } - CHK_ERR_ASRT(ret) - - ret = amdsmi_get_power_cap_info(processor_handles_[dv_ind], 0, &info); - CHK_ERR_ASRT(ret) - curr_cap = info.power_cap; - - IF_VERB(STANDARD) { - std::cout << "[After Set] Time spent: " << cpu_time_used << " uS" << std::endl; - std::cout << "[After Set] Current Power Cap: " << curr_cap << " uW" << std::endl; - std::cout << "[After Set] Requested Power Cap: " << new_cap << " uW" << std::endl; - std::cout << "[After Set] Power Cap Range [max to min]: " << max << " uW to " - << min << " uW" << std::endl; - std::cout << "[After Set] Resetting cap to " << default_cap << "..." << std::endl; + ret = AMDSMI_STATUS_SUCCESS; + SetCheckPowerCap("Setting to Average Power Cap", dv_ind, curr_cap, new_cap, ret); + if (ret == AMDSMI_STATUS_NOT_SUPPORTED) { + continue; + } + IF_VERB(STANDARD) { + if (!new_cap) + std::cout << "\t** Power cap requested (" << new_cap << " uW) is failed to set for " << dv_ind << std::endl; + } + + if (min_cap > 0) + { + new_cap = min_cap; + ret = AMDSMI_STATUS_SUCCESS; + SetCheckPowerCap("Setting to Min Power Cap", dv_ind, curr_cap, new_cap, ret); + IF_VERB(STANDARD) { + if (!new_cap) + std::cout << "\t** Power cap requested (" << new_cap << " uW) is failed to set for " << dv_ind << std::endl; + } + + new_cap = uint64_t(min_cap - 1); + ret = AMDSMI_STATUS_INVAL; + SetCheckPowerCap("Setting to Min Power Cap - 1", dv_ind, curr_cap, new_cap, ret); + if (ret != AMDSMI_STATUS_INVAL) { + IF_VERB(STANDARD) { + if (!new_cap) + std::cout << "\t** Power cap requested (" << new_cap << " uW) is failed to set for " << dv_ind << std::endl; + } + } + + new_cap = uint64_t(static_cast(min_cap) * 0.10F); + ret = AMDSMI_STATUS_INVAL; + SetCheckPowerCap("Setting to Min Power Cap * 0.10", dv_ind, curr_cap, new_cap, ret); + if (ret != AMDSMI_STATUS_INVAL) { + IF_VERB(STANDARD) { + if (!new_cap) + std::cout << "\t** Power cap requested (" << new_cap << " uW) is failed to set for " << dv_ind << std::endl; + } + } + } + else + { + std::cout << "\tPower cap requested is less than or equal to 0, skipping test for " << dv_ind << std::endl; + } + + new_cap = max_cap; + ret = AMDSMI_STATUS_SUCCESS; + SetCheckPowerCap("Setting to Max Power Cap", dv_ind, curr_cap, new_cap, ret); + IF_VERB(STANDARD) { + if (!new_cap) + std::cout << "\t** Power cap requested (" << new_cap << " uW) is failed to set for " << dv_ind << std::endl; + } + + new_cap = uint64_t(max_cap + 1); + ret = AMDSMI_STATUS_INVAL; + SetCheckPowerCap("Setting to Max Power Cap + 1", dv_ind, curr_cap, new_cap, ret); + if (ret != AMDSMI_STATUS_INVAL) { + IF_VERB(STANDARD) { + if (!new_cap) + std::cout << "\t** Power cap requested (" << new_cap << " uW) failed to set for " << dv_ind << std::endl; + } + } + + new_cap = uint64_t(max_cap * 10); + ret = AMDSMI_STATUS_INVAL; + SetCheckPowerCap("Setting to Max Power Cap * 10", dv_ind, curr_cap, new_cap, ret); + if (ret != AMDSMI_STATUS_INVAL) { + IF_VERB(STANDARD) { + if (!new_cap) + std::cout << "\t** Power cap requested (" << new_cap << " uW) is failed to set for " << dv_ind << std::endl; + } } - // Confirm in watts the values are equal - ASSERT_EQ(curr_cap/MICRO_CONVERSION, new_cap/MICRO_CONVERSION); // Reset to default power cap + IF_VERB(STANDARD) { + std::cout << "Resetting Power Cap" << std::endl; + std::cout << "[Before Reset] Current Power Cap: " << curr_cap << " uW" << std::endl; + std::cout << "[Before Reset] Resetting cap to default " << default_cap << "..." << std::endl; + } ret = amdsmi_set_power_cap(processor_handles_[dv_ind], 0, default_cap); CHK_ERR_ASRT(ret) @@ -147,9 +249,10 @@ void TestPowerCapReadWrite::Run(void) { std::cout << "[After Reset] Current Power Cap: " << curr_cap << " uW" << std::endl; std::cout << "[After Reset] Requested Power Cap (default): " << default_cap << " uW" << std::endl; - std::cout << "[After Reset] Power Cap Range [max to min]: " << max << " uW to " - << min << " uW" << std::endl; + std::cout << "[After Reset] Power Cap Range [max to min]: " << max_cap << " uW to " + << min_cap << " uW" << std::endl; } + // Confirm in watts the values are equal ASSERT_EQ(curr_cap/MICRO_CONVERSION, default_cap/MICRO_CONVERSION); } diff --git a/projects/amdsmi/tests/amd_smi_test/functional/power_cap_read_write.h b/projects/amdsmi/tests/amd_smi_test/functional/power_cap_read_write.h index 002c04f174..675a453c07 100644 --- a/projects/amdsmi/tests/amd_smi_test/functional/power_cap_read_write.h +++ b/projects/amdsmi/tests/amd_smi_test/functional/power_cap_read_write.h @@ -29,6 +29,9 @@ class TestPowerCapReadWrite : public TestBase { public: TestPowerCapReadWrite(); + void SetCheckPowerCap(std::string msg, uint32_t dv_ind, uint64_t &curr_cap, + uint64_t &new_cap, amdsmi_status_t &ret); + // @Brief: Destructor for test case of TestPowerCapReadWrite virtual ~TestPowerCapReadWrite();