Repository navigation
fix(amdsmi): keep the memory partition name inside the caller's buffer #12986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
projects/amdsmi/tests/amd_smi_test/functional/gpu/partition/memorypartition_read.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright Advanced Micro Devices, Inc. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #ifndef TESTS_AMD_SMI_TEST_FUNCTIONAL_MEMORYPARTITION_READ_H_ | ||
| #define TESTS_AMD_SMI_TEST_FUNCTIONAL_MEMORYPARTITION_READ_H_ | ||
|
|
||
| #include "test_base.h" | ||
|
|
||
| class TestMemoryPartitionRead : public TestBase { | ||
| public: | ||
| TestMemoryPartitionRead(); | ||
|
|
||
| // @Brief: Destructor for test case of TestMemoryPartitionRead | ||
| virtual ~TestMemoryPartitionRead(); | ||
|
|
||
| // @Brief: Setup the environment for measurement | ||
| virtual void SetUp(); | ||
|
|
||
| // @Brief: Core measurement execution | ||
| virtual void Run(); | ||
|
|
||
| // @Brief: Clean up and retrieve the resource | ||
| virtual void Close(); | ||
|
|
||
| // @Brief: Display results | ||
| virtual void DisplayResults() const; | ||
|
|
||
| // @Brief: Display information about what this test does | ||
| virtual void DisplayTestInfo(void); | ||
| }; | ||
|
|
||
| #endif // TESTS_AMD_SMI_TEST_FUNCTIONAL_MEMORYPARTITION_READ_H_ |
86 changes: 86 additions & 0 deletions
86
projects/amdsmi/tests/amd_smi_test/functional/gpu/partition/memorypartition_read_test.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Copyright Advanced Micro Devices, Inc. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include "memorypartition_read.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <cstring> | ||
| #include <initializer_list> | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "amd_smi/amdsmi.h" | ||
| #include "test_base.h" | ||
| #include "test_common.h" | ||
|
|
||
| TestMemoryPartitionRead::TestMemoryPartitionRead() : TestBase() { | ||
| set_title("AMDSMI Memory Partition Read Test"); | ||
| set_description( | ||
| "Reads the current memory partition into buffers of several sizes and " | ||
| "verifies that the result always stays inside the caller's buffer."); | ||
| } | ||
|
|
||
| TestMemoryPartitionRead::~TestMemoryPartitionRead(void) {} | ||
|
|
||
| void TestMemoryPartitionRead::SetUp(void) { TestBase::SetUp(); } | ||
|
|
||
| void TestMemoryPartitionRead::DisplayTestInfo(void) { TestBase::DisplayTestInfo(); } | ||
|
|
||
| void TestMemoryPartitionRead::DisplayResults(void) const { TestBase::DisplayResults(); } | ||
|
|
||
| void TestMemoryPartitionRead::Close() { TestBase::Close(); } | ||
|
|
||
| void TestMemoryPartitionRead::Run(void) { | ||
| constexpr uint32_t k255Len = 255; | ||
| constexpr char kGuard = '#'; | ||
|
|
||
| TestBase::Run(); | ||
| PRINT_VERBOSITY(); | ||
| if (setup_failed_) { | ||
| std::cout << "** SetUp Failed for this test. Skipping.**" << std::endl; | ||
| return; | ||
| } | ||
|
|
||
| for (uint32_t dv_ind = 0; dv_ind < num_monitor_devs(); ++dv_ind) { | ||
| PrintDeviceHeader(processor_handles_[dv_ind]); | ||
|
|
||
| char full[k255Len] = {}; | ||
| amdsmi_status_t err = | ||
| amdsmi_get_gpu_memory_partition(processor_handles_[dv_ind], full, k255Len); | ||
| if (err == AMDSMI_STATUS_NOT_SUPPORTED) { | ||
| IF_VERB(STANDARD) { | ||
| std::cout << "\t**Memory partition is not supported on this device" << std::endl; | ||
| } | ||
| continue; | ||
| } | ||
| ASSERT_EQ(err, AMDSMI_STATUS_SUCCESS); | ||
| const std::string name(full); | ||
| if (name.empty()) { | ||
| IF_VERB(STANDARD) { | ||
| std::cout << "\t**Memory partition is empty on this device" << std::endl; | ||
| } | ||
| continue; | ||
| } | ||
| IF_VERB(STANDARD) { std::cout << "\t**Current memory partition: " << name << std::endl; } | ||
|
|
||
| // Each buffer has `len` usable bytes followed by one guard byte. A buffer | ||
| // too small for the name must hold a terminated prefix of it, and a buffer | ||
| // that fits must hold all of it. The guard byte must stay untouched. | ||
| const auto name_len = static_cast<uint32_t>(name.size()); | ||
| for (uint32_t len : {1u, 2u, name_len, name_len + 1}) { | ||
| std::vector<char> buf(len + 1, kGuard); | ||
| err = amdsmi_get_gpu_memory_partition(processor_handles_[dv_ind], buf.data(), len); | ||
| const bool fits = len > name_len; | ||
| EXPECT_EQ(err, fits ? AMDSMI_STATUS_SUCCESS : AMDSMI_STATUS_INSUFFICIENT_SIZE) | ||
| << "len=" << len; | ||
| EXPECT_EQ(buf[len], kGuard) << "wrote past the end of a " << len << "-byte buffer"; | ||
| const size_t used = strnlen(buf.data(), len); | ||
| EXPECT_LT(used, len) << "no terminator inside a " << len << "-byte buffer"; | ||
| EXPECT_EQ(std::string(buf.data(), used), fits ? name : name.substr(0, len - 1)) | ||
| << "len=" << len; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.