Skip to content

Commit c81f957

Browse files
authored
[SYCL] Fix bugs in PI Mock (#6852)
1 parent ce11646 commit c81f957

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

sycl/unittests/helpers/PiMock.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,21 @@ class PiMock {
104104
// Create new mock plugin platform and plugin handles
105105
// Note: Mock plugin will be generated if it has not been yet.
106106
MPlatformImpl = GetMockPlatformImpl();
107-
const detail::plugin &OriginalPiPlugin = MPlatformImpl->getPlugin();
108-
// Copy the PiPlugin, thus untying our to-be mock platform from other
109-
// platforms within the context. Reset our platform to use the new plugin.
110-
auto NewPluginPtr = std::make_shared<detail::plugin>(
111-
OriginalPiPlugin.getPiPluginPtr(), OriginalPiPlugin.getBackend(),
112-
OriginalPiPlugin.getLibraryHandle());
107+
std::shared_ptr<detail::plugin> NewPluginPtr;
108+
{
109+
const detail::plugin &OriginalPiPlugin = MPlatformImpl->getPlugin();
110+
// Copy the PiPlugin, thus untying our to-be mock platform from other
111+
// platforms within the context. Reset our platform to use the new plugin.
112+
NewPluginPtr = std::make_shared<detail::plugin>(
113+
OriginalPiPlugin.getPiPluginPtr(), OriginalPiPlugin.getBackend(),
114+
OriginalPiPlugin.getLibraryHandle());
115+
// Save a copy of the platform resource
116+
OrigFuncTable = OriginalPiPlugin.getPiPlugin().PiFunctionTable;
117+
}
113118
MPlatformImpl->setPlugin(NewPluginPtr);
114119
// Extract the new PiPlugin instance by a non-const pointer,
115120
// explicitly allowing modification
116121
MPiPluginMockPtr = &NewPluginPtr->getPiPlugin();
117-
// Save a copy of the platform resource
118-
OrigFuncTable = OriginalPiPlugin.getPiPlugin().PiFunctionTable;
119122
}
120123

121124
PiMock(PiMock &&Other) {

sycl/unittests/helpers/PiMockPlugin.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ inline pi_result mock_piPlatformGetInfo(pi_platform platform,
4949
return PI_SUCCESS;
5050
}
5151
default: {
52+
constexpr const char *FallbackValue = "str";
53+
constexpr size_t FallbackValueSize = std::strlen(FallbackValue) + 1;
5254
if (param_value_size_ret)
53-
*param_value_size_ret = 3;
55+
*param_value_size_ret = FallbackValueSize;
5456

55-
if (param_value && param_value_size >= 3)
56-
*static_cast<const char **>(param_value) = "str";
57+
if (param_value && param_value_size >= FallbackValueSize)
58+
std::memcpy(param_value, FallbackValue, FallbackValueSize);
5759

5860
return PI_SUCCESS;
5961
}

0 commit comments

Comments
 (0)