Adding more unit tests to reach 80% (#177)
* Adding more unit tests to reach 80% * Adding pmc and command builder tests * tests for spm, sqtt and trace config * removing non-existent struct members from test * Adding logger tests * aqlprofile_v2 tests * spm builder tests * Addressed feedback --------- Co-authored-by: gobhardw <gopesh.bhardwaj@amd.com> Co-authored-by: systems-assistant[bot] <systems-assistant[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
66f0df465e
commit
5b9ba5bda0
@@ -0,0 +1,29 @@
|
||||
include(GoogleTest)
|
||||
find_package(GTest REQUIRED)
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
|
||||
add_executable(utility_tests)
|
||||
SET(AQLPROFILE_UTILITY_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../hsa_rsrc_factory.cpp
|
||||
)
|
||||
|
||||
target_sources(utility_tests PRIVATE ${AQLPROFILE_UTILITY_SOURCES})
|
||||
target_include_directories(utility_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIB_DIR} ${LIB_DIR}/core/include)
|
||||
target_link_libraries(
|
||||
utility_tests
|
||||
PRIVATE
|
||||
hsa-runtime64::hsa-runtime64
|
||||
GTest::gtest
|
||||
GTest::gtest_main)
|
||||
|
||||
|
||||
gtest_add_tests(
|
||||
TARGET utility_tests
|
||||
SOURCES ${AQLPROFILE_UTILITY_SOURCES}
|
||||
TEST_LIST utility_tests_TESTS
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set_tests_properties(
|
||||
${utility_tests_TESTS} PROPERTIES TIMEOUT 45 LABELS "unittests" FAIL_REGULAR_EXPRESSION
|
||||
"${AQLPROFILE_DEFAULT_FAIL_REGEX}")
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "util/hsa_rsrc_factory.h"
|
||||
|
||||
// Test fixture for HsaRsrcFactory
|
||||
class HsaRsrcFactoryTest : public ::testing::Test {
|
||||
protected:
|
||||
void TearDown() override {
|
||||
HsaRsrcFactory::Destroy();
|
||||
}
|
||||
};
|
||||
|
||||
// Test: Factory instance creation and destruction (happy path)
|
||||
TEST_F(HsaRsrcFactoryTest, FactoryCreationAndDestruction) {
|
||||
HsaRsrcFactory* factory = HsaRsrcFactory::Create();
|
||||
ASSERT_NE(factory, nullptr);
|
||||
HsaRsrcFactory::Destroy();
|
||||
}
|
||||
|
||||
// Test: Singleton pattern is enforced
|
||||
TEST_F(HsaRsrcFactoryTest, SingletonBehavior) {
|
||||
HsaRsrcFactory* factory1 = HsaRsrcFactory::Create();
|
||||
HsaRsrcFactory* factory2 = HsaRsrcFactory::Create();
|
||||
EXPECT_EQ(factory1, factory2);
|
||||
HsaRsrcFactory::Destroy();
|
||||
}
|
||||
|
||||
// Test: At least one CPU agent is detected (edge: system dependent)
|
||||
TEST_F(HsaRsrcFactoryTest, CpuAgentCountNonZero) {
|
||||
HsaRsrcFactory* factory = HsaRsrcFactory::Create();
|
||||
EXPECT_GT(factory->GetCountOfCpuAgents(), 0u);
|
||||
}
|
||||
|
||||
// Test: GPU agent count is valid (edge: may be zero if no GPU present)
|
||||
TEST_F(HsaRsrcFactoryTest, GpuAgentCountValid) {
|
||||
HsaRsrcFactory* factory = HsaRsrcFactory::Create();
|
||||
EXPECT_GE(factory->GetCountOfGpuAgents(), 0u);
|
||||
}
|
||||
|
||||
// Test: GetCpuAgentInfo returns valid info for first CPU agent (happy path)
|
||||
TEST_F(HsaRsrcFactoryTest, GetCpuAgentInfoReturnsValid) {
|
||||
HsaRsrcFactory* factory = HsaRsrcFactory::Create();
|
||||
const AgentInfo* info = nullptr;
|
||||
bool ok = factory->GetCpuAgentInfo(0, &info);
|
||||
EXPECT_TRUE(ok);
|
||||
EXPECT_NE(info, nullptr);
|
||||
}
|
||||
|
||||
// Test: GetCpuAgentInfo returns false for out-of-range index (edge case)
|
||||
TEST_F(HsaRsrcFactoryTest, GetCpuAgentInfoOutOfRange) {
|
||||
HsaRsrcFactory* factory = HsaRsrcFactory::Create();
|
||||
const AgentInfo* info = nullptr;
|
||||
size_t count = factory->GetCountOfCpuAgents();
|
||||
bool ok = factory->GetCpuAgentInfo(count, &info);
|
||||
EXPECT_FALSE(ok);
|
||||
EXPECT_EQ(info, nullptr);
|
||||
}
|
||||
|
||||
// Test: GetGpuAgentInfo returns false for out-of-range index (edge case)
|
||||
TEST_F(HsaRsrcFactoryTest, GetGpuAgentInfoOutOfRange) {
|
||||
HsaRsrcFactory* factory = HsaRsrcFactory::Create();
|
||||
const AgentInfo* info = nullptr;
|
||||
size_t count = factory->GetCountOfGpuAgents();
|
||||
bool ok = factory->GetGpuAgentInfo(count, &info);
|
||||
EXPECT_FALSE(ok);
|
||||
EXPECT_EQ(info, nullptr);
|
||||
}
|
||||
Reference in New Issue
Block a user