@@ -145,6 +145,33 @@ class PersistenDeviceCodeCache : public ::testing::Test {
145
145
std::unique_ptr<unittest::PiMock> Mock;
146
146
};
147
147
148
+ /* Checks that key values with \0 symbols are processed correctly
149
+ */
150
+ TEST_F (PersistenDeviceCodeCache, KeysWithNullTermSymbol) {
151
+ if (Plt.is_host () || Plt.get_backend () != backend::opencl) {
152
+ return ;
153
+ }
154
+ std::string Key{' 1' , ' \0 ' , ' 3' , ' 4' , ' \0 ' };
155
+ std::vector<unsigned char > SpecConst (Key.begin (), Key.end ());
156
+ std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath (
157
+ Dev, Img, SpecConst, Key);
158
+ llvm::sys::fs::remove_directories (ItemDir);
159
+
160
+ detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, SpecConst, Key,
161
+ NativeProg);
162
+ auto Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img,
163
+ SpecConst, Key);
164
+ assert (Res.size () != 0 && " Failed to load cache item" );
165
+ for (int i = 0 ; i < Res.size (); ++i) {
166
+ assert (Res[i].size () != 0 && " Failed to device image" );
167
+ for (int j = 0 ; j < Res[i].size (); ++j) {
168
+ assert (Res[i][j] == i && " Corrupted image loaded from persistent cache" );
169
+ }
170
+ }
171
+
172
+ llvm::sys::fs::remove_directories (ItemDir);
173
+ }
174
+
148
175
/* Do read/write for the same cache item to/from 300 threads for small device
149
176
* code size. Make sure that there is no data corruption or crashes.
150
177
*/
0 commit comments