Skip to content

Commit 789f2aa

Browse files
[hipDNN] ALMIOPEN-2193 Fix superbuild logging test flakiness
1 parent fc34ca4 commit 789f2aa

2 files changed

Lines changed: 232 additions & 1 deletion

File tree

projects/hipdnn/backend/tests/TestUserLoggingApis.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class IntegrationBackendUserLoggingApis : public ::testing::Test
4545

4646
// Clear any previous callback (may fail if not registered — that's OK)
4747
setIsolatedUserCallback(HIPDNN_SEV_OFF, HIPDNN_LOG_CALLBACK_ASYNC);
48+
49+
// These tests use hipdnnCreate/hipdnnDestroy only as backend log sources.
50+
// Force an empty absolute plugin search path so superbuild provider plugins
51+
// do not turn logging API tests into provider lifecycle stress tests.
52+
isolatePluginLoadingForLoggingTests();
4853
}
4954

5055
void TearDown() override
@@ -58,13 +63,35 @@ class IntegrationBackendUserLoggingApis : public ::testing::Test
5863
_logLevelGuard.reset();
5964
_logFileGuard.reset();
6065

66+
restoreDefaultPluginLoading();
67+
6168
// Clean up any test log file
6269
if(!_logFile.empty())
6370
{
6471
std::remove(_logFile.c_str());
6572
}
6673
}
6774

75+
static void isolatePluginLoadingForLoggingTests()
76+
{
77+
// hipdnnSet*PluginPaths_ext only dereferences pluginPaths when numPaths > 0.
78+
// numPaths == 0 maps to an empty path vector; ABSOLUTE mode then suppresses
79+
// default provider discovery for handle creation in this fixture.
80+
ASSERT_EQ(hipdnnSetEnginePluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ABSOLUTE),
81+
HIPDNN_STATUS_SUCCESS);
82+
ASSERT_EQ(hipdnnSetHeuristicPluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ABSOLUTE),
83+
HIPDNN_STATUS_SUCCESS);
84+
}
85+
86+
static void restoreDefaultPluginLoading()
87+
{
88+
// ADDITIVE mode with an empty path vector restores normal default discovery.
89+
EXPECT_EQ(hipdnnSetEnginePluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ADDITIVE),
90+
HIPDNN_STATUS_SUCCESS);
91+
EXPECT_EQ(hipdnnSetHeuristicPluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ADDITIVE),
92+
HIPDNN_STATUS_SUCCESS);
93+
}
94+
6895
// Set the isolated user callback. Returns the status without asserting.
6996
hipdnnStatus_t setIsolatedUserCallback(hipdnnSeverity_t minLevel, hipdnnLogCallbackMode_t mode)
7097
{

projects/hipdnn/tests/backend/IntegrationSetPluginPathsExt.cpp

Lines changed: 205 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,140 @@
55
#include "hipdnn_backend.h"
66
#include <array>
77
#include <filesystem>
8+
#include <string>
9+
#include <vector>
10+
811
#include <gtest/gtest.h>
912
#include <hipdnn_data_sdk/utilities/PlatformUtils.hpp>
1013
#include <hipdnn_flatbuffers_sdk/data_objects/graph_generated.h>
1114
#include <hipdnn_test_sdk/utilities/ScopedEnvironmentVariableSetter.hpp>
12-
#include <vector>
1315

1416
using namespace hipdnn_data_sdk::utilities;
1517
using namespace hipdnn_tests::plugin_constants;
1618
namespace fs = std::filesystem;
1719

20+
namespace
21+
{
22+
struct HeuristicPolicyInfoForTest
23+
{
24+
std::string policyName;
25+
std::string pluginName;
26+
};
27+
28+
bool getHeuristicPolicyInfos(hipdnnHandle_t handle,
29+
std::vector<HeuristicPolicyInfoForTest>& policyInfos)
30+
{
31+
size_t numPolicies = 0;
32+
auto status = hipdnnGetHeuristicPolicyCount_ext(handle, &numPolicies);
33+
if(status != HIPDNN_STATUS_SUCCESS)
34+
{
35+
ADD_FAILURE() << "Failed to query heuristic policy count: " << status;
36+
return false;
37+
}
38+
39+
policyInfos.clear();
40+
policyInfos.reserve(numPolicies);
41+
42+
for(size_t i = 0; i < numPolicies; ++i)
43+
{
44+
size_t policyNameLen = 0;
45+
size_t pluginNameLen = 0;
46+
size_t pluginVersionLen = 0;
47+
size_t apiVersionLen = 0;
48+
status = hipdnnGetHeuristicPolicyInfo_ext(handle,
49+
i,
50+
nullptr,
51+
nullptr,
52+
&policyNameLen,
53+
nullptr,
54+
&pluginNameLen,
55+
nullptr,
56+
&pluginVersionLen,
57+
nullptr,
58+
&apiVersionLen);
59+
if(status != HIPDNN_STATUS_SUCCESS)
60+
{
61+
ADD_FAILURE() << "Failed to query heuristic policy info sizes for index " << i << ": "
62+
<< status;
63+
return false;
64+
}
65+
66+
if(policyNameLen == 0 || pluginNameLen == 0 || pluginVersionLen == 0 || apiVersionLen == 0)
67+
{
68+
ADD_FAILURE() << "Heuristic policy info for index " << i
69+
<< " reported an empty metadata field";
70+
return false;
71+
}
72+
73+
std::vector<char> policyName(policyNameLen);
74+
std::vector<char> pluginName(pluginNameLen);
75+
std::vector<char> pluginVersion(pluginVersionLen);
76+
std::vector<char> apiVersion(apiVersionLen);
77+
status = hipdnnGetHeuristicPolicyInfo_ext(handle,
78+
i,
79+
nullptr,
80+
policyName.data(),
81+
&policyNameLen,
82+
pluginName.data(),
83+
&pluginNameLen,
84+
pluginVersion.data(),
85+
&pluginVersionLen,
86+
apiVersion.data(),
87+
&apiVersionLen);
88+
if(status != HIPDNN_STATUS_SUCCESS)
89+
{
90+
ADD_FAILURE() << "Failed to retrieve heuristic policy info for index " << i << ": "
91+
<< status;
92+
return false;
93+
}
94+
95+
policyInfos.push_back({policyName.data(), pluginName.data()});
96+
}
97+
98+
return true;
99+
}
100+
101+
bool heuristicPolicyIsLoaded(hipdnnHandle_t handle, const char* expectedPolicyName)
102+
{
103+
std::vector<HeuristicPolicyInfoForTest> policyInfos;
104+
if(!getHeuristicPolicyInfos(handle, policyInfos))
105+
{
106+
return false;
107+
}
108+
109+
for(const auto& policyInfo : policyInfos)
110+
{
111+
if(policyInfo.policyName == expectedPolicyName)
112+
{
113+
return true;
114+
}
115+
}
116+
117+
return false;
118+
}
119+
120+
bool onlyBuiltInHeuristicPoliciesAreLoaded(hipdnnHandle_t handle)
121+
{
122+
std::vector<HeuristicPolicyInfoForTest> policyInfos;
123+
if(!getHeuristicPolicyInfos(handle, policyInfos))
124+
{
125+
return false;
126+
}
127+
128+
for(const auto& policyInfo : policyInfos)
129+
{
130+
if(policyInfo.pluginName.rfind("BuiltIn", 0) != 0)
131+
{
132+
ADD_FAILURE() << "Loaded path-discovered heuristic policy '" << policyInfo.policyName
133+
<< "' from plugin '" << policyInfo.pluginName << "'";
134+
return false;
135+
}
136+
}
137+
138+
return true;
139+
}
140+
} // namespace
141+
18142
TEST(IntegrationSetPluginPathsExt, ValidInputs)
19143
{
20144
std::array<const char*, 3> paths = {getTestPluginCustomDir().c_str(), "./", "../directory/"};
@@ -45,6 +169,70 @@ TEST(IntegrationSetPluginPathsExt, InvalidAndValidNullptrCorrectness)
45169
EXPECT_EQ(hipdnnDestroy(handle), HIPDNN_STATUS_SUCCESS);
46170
}
47171

172+
TEST(IntegrationSetPluginPathsExt, HeuristicInvalidAndValidNullptrCorrectness)
173+
{
174+
const hipdnn_test_sdk::utilities::ScopedEnvironmentVariableSetter envSetter(
175+
"HIPDNN_HEURISTIC_PLUGIN_DIR",
176+
fs::path(testGoodHeuristicPluginPath()).parent_path().string());
177+
178+
hipdnnStatus_t status
179+
= hipdnnSetHeuristicPluginPaths_ext(1, nullptr, HIPDNN_PLUGIN_LOADING_ABSOLUTE);
180+
EXPECT_EQ(status, HIPDNN_STATUS_BAD_PARAM_NULL_POINTER);
181+
182+
status = hipdnnSetHeuristicPluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ABSOLUTE);
183+
EXPECT_EQ(status, HIPDNN_STATUS_SUCCESS);
184+
185+
hipdnnHandle_t handle = nullptr;
186+
status = hipdnnCreate(&handle);
187+
ASSERT_EQ(status, HIPDNN_STATUS_SUCCESS);
188+
ASSERT_NE(handle, nullptr);
189+
190+
// Built-in heuristic policies are always registered. Empty ABSOLUTE paths should suppress
191+
// only path-discovered external heuristic plugins, including the env-sourced test plugin.
192+
EXPECT_TRUE(onlyBuiltInHeuristicPoliciesAreLoaded(handle));
193+
194+
EXPECT_EQ(hipdnnDestroy(handle), HIPDNN_STATUS_SUCCESS);
195+
EXPECT_EQ(hipdnnSetHeuristicPluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ADDITIVE),
196+
HIPDNN_STATUS_SUCCESS);
197+
}
198+
199+
TEST(IntegrationSetPluginPathsExt, HeuristicNullStringInList)
200+
{
201+
std::array<const char*, 2> paths = {testGoodHeuristicPluginPath().c_str(), nullptr};
202+
203+
const hipdnnStatus_t status = hipdnnSetHeuristicPluginPaths_ext(
204+
paths.size(), paths.data(), HIPDNN_PLUGIN_LOADING_ABSOLUTE);
205+
206+
EXPECT_EQ(status, HIPDNN_STATUS_BAD_PARAM_NULL_POINTER);
207+
}
208+
209+
TEST(IntegrationSetPluginPathsExt, HeuristicEmptyAdditiveLoadsDefault)
210+
{
211+
const hipdnn_test_sdk::utilities::ScopedEnvironmentVariableSetter envSetter(
212+
"HIPDNN_HEURISTIC_PLUGIN_DIR",
213+
fs::path(testGoodHeuristicPluginPath()).parent_path().string());
214+
215+
hipdnnStatus_t status
216+
= hipdnnSetHeuristicPluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ABSOLUTE);
217+
ASSERT_EQ(status, HIPDNN_STATUS_SUCCESS);
218+
219+
status = hipdnnSetHeuristicPluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ADDITIVE);
220+
ASSERT_EQ(status, HIPDNN_STATUS_SUCCESS);
221+
222+
hipdnnHandle_t handle = nullptr;
223+
status = hipdnnCreate(&handle);
224+
ASSERT_EQ(status, HIPDNN_STATUS_SUCCESS);
225+
ASSERT_NE(handle, nullptr);
226+
227+
EXPECT_TRUE(heuristicPolicyIsLoaded(handle, testGoodHeuristicPolicyName()));
228+
229+
EXPECT_EQ(hipdnnDestroy(handle), HIPDNN_STATUS_SUCCESS);
230+
EXPECT_EQ(hipdnnSetHeuristicPluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ABSOLUTE),
231+
HIPDNN_STATUS_SUCCESS);
232+
EXPECT_EQ(hipdnnSetHeuristicPluginPaths_ext(0, nullptr, HIPDNN_PLUGIN_LOADING_ADDITIVE),
233+
HIPDNN_STATUS_SUCCESS);
234+
}
235+
48236
TEST(IntegrationSetPluginPathsExt, NullStringInList)
49237
{
50238
std::array<const char*, 2> paths = {"./valid/path.so", nullptr};
@@ -76,6 +264,22 @@ TEST(IntegrationSetPluginPathsExt, IneligibleHandle)
76264
EXPECT_EQ(status, HIPDNN_STATUS_BAD_PARAM_NULL_POINTER);
77265
}
78266

267+
TEST(IntegrationSetPluginPathsExt, HeuristicIneligibleHandle)
268+
{
269+
hipdnnHandle_t handle = nullptr;
270+
hipdnnStatus_t status = hipdnnCreate(&handle);
271+
ASSERT_EQ(status, HIPDNN_STATUS_SUCCESS);
272+
ASSERT_NE(handle, nullptr);
273+
274+
const std::array<const char*, 1> paths = {testGoodHeuristicPluginPath().c_str()};
275+
status = hipdnnSetHeuristicPluginPaths_ext(
276+
paths.size(), paths.data(), HIPDNN_PLUGIN_LOADING_ABSOLUTE);
277+
278+
EXPECT_EQ(status, HIPDNN_STATUS_NOT_SUPPORTED);
279+
280+
EXPECT_EQ(hipdnnDestroy(handle), HIPDNN_STATUS_SUCCESS);
281+
}
282+
79283
TEST(IntegrationSetPluginPathsExt, GetLoadedPluginPathsLoadsDefault)
80284
{
81285
const hipdnn_test_sdk::utilities::ScopedEnvironmentVariableSetter envSetter(

0 commit comments

Comments
 (0)