@@ -141,14 +141,9 @@ struct umfLevelZeroProviderTest
141141
142142 auto [l0_params, accessor] = this ->GetParam ();
143143 params = l0_params;
144- hDevice = ( ze_device_handle_t )params. level_zero_device_handle ;
144+ memAccessor = accessor ;
145145 hContext = (ze_context_handle_t )params.level_zero_context_handle ;
146146
147- if (params.memory_type == UMF_MEMORY_TYPE_HOST) {
148- ASSERT_EQ (hDevice, nullptr );
149- } else {
150- ASSERT_NE (hDevice, nullptr );
151- }
152147 ASSERT_NE (hContext, nullptr );
153148
154149 switch (params.memory_type ) {
@@ -168,20 +163,14 @@ struct umfLevelZeroProviderTest
168163
169164 ASSERT_NE (zeMemoryTypeExpected, ZE_MEMORY_TYPE_UNKNOWN);
170165
171- memAccessor = accessor;
172166 }
173167
174- void TearDown () override {
175- int ret = destroy_context (hContext);
176- ASSERT_EQ (ret, 0 );
177- test::TearDown ();
178- }
168+ void TearDown () override { test::TearDown (); }
179169
180170 level_zero_memory_provider_params_t params;
181- ze_device_handle_t hDevice = nullptr ;
171+ MemoryAccessor *memAccessor = nullptr ;
182172 ze_context_handle_t hContext = nullptr ;
183173 ze_memory_type_t zeMemoryTypeExpected = ZE_MEMORY_TYPE_UNKNOWN;
184- MemoryAccessor *memAccessor = nullptr ;
185174};
186175
187176GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST (umfLevelZeroProviderTest);
@@ -222,6 +211,97 @@ TEST_P(umfLevelZeroProviderTest, basic) {
222211 umfMemoryProviderDestroy (provider);
223212}
224213
214+ TEST_P (umfLevelZeroProviderTest, getPageSize) {
215+ umf_memory_provider_handle_t provider = nullptr ;
216+ umf_result_t umf_result = umfMemoryProviderCreate (
217+ umfLevelZeroMemoryProviderOps (), ¶ms, &provider);
218+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
219+ ASSERT_NE (provider, nullptr );
220+
221+ size_t recomendedPageSize = 0 ;
222+ umf_result = umfMemoryProviderGetRecommendedPageSize (provider, 0 ,
223+ &recomendedPageSize);
224+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
225+ ASSERT_GE (recomendedPageSize, 0 );
226+
227+ size_t minPageSize = 0 ;
228+ umf_result =
229+ umfMemoryProviderGetMinPageSize (provider, nullptr , &minPageSize);
230+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
231+ ASSERT_GE (minPageSize, 0 );
232+
233+ ASSERT_GE (recomendedPageSize, minPageSize);
234+
235+ umfMemoryProviderDestroy (provider);
236+ }
237+
238+ TEST_P (umfLevelZeroProviderTest, getName) {
239+ umf_memory_provider_handle_t provider = nullptr ;
240+ umf_result_t umf_result = umfMemoryProviderCreate (
241+ umfLevelZeroMemoryProviderOps (), ¶ms, &provider);
242+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
243+ ASSERT_NE (provider, nullptr );
244+
245+ const char *name = umfMemoryProviderGetName (provider);
246+ ASSERT_STREQ (name, " LEVEL_ZERO" );
247+
248+ umfMemoryProviderDestroy (provider);
249+ }
250+
251+ TEST_P (umfLevelZeroProviderTest, allocInvalidSize) {
252+ umf_memory_provider_handle_t provider = nullptr ;
253+ umf_result_t umf_result = umfMemoryProviderCreate (
254+ umfLevelZeroMemoryProviderOps (), ¶ms, &provider);
255+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
256+ ASSERT_NE (provider, nullptr );
257+
258+ // try to alloc (int)-1
259+ void *ptr = nullptr ;
260+ umf_result = umfMemoryProviderAlloc (provider, -1 , 0 , &ptr);
261+ ASSERT_EQ (umf_result, UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC);
262+ const char *message;
263+ int32_t error;
264+ umfMemoryProviderGetLastNativeError (provider, &message, &error);
265+ ASSERT_EQ (error, ZE_RESULT_ERROR_UNSUPPORTED_SIZE);
266+
267+ // in case of size == 0 we should got INVALID_ARGUMENT error
268+ // NOTE: this is invalid only for the DEVICE or SHARED allocations
269+ if (params.memory_type != UMF_MEMORY_TYPE_HOST) {
270+ umf_result = umfMemoryProviderAlloc (provider, 0 , 0 , &ptr);
271+ ASSERT_EQ (umf_result, UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC);
272+ umfMemoryProviderGetLastNativeError (provider, &message, &error);
273+ ASSERT_EQ (error, ZE_RESULT_ERROR_UNSUPPORTED_SIZE);
274+ }
275+
276+ umfMemoryProviderDestroy (provider);
277+ }
278+
279+ TEST_P (umfLevelZeroProviderTest, providerCreateInvalidArgs) {
280+ umf_memory_provider_handle_t provider = nullptr ;
281+ umf_result_t umf_result = umfMemoryProviderCreate (
282+ umfLevelZeroMemoryProviderOps (), nullptr , &provider);
283+ ASSERT_EQ (umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
284+
285+ umf_result = umfMemoryProviderCreate (nullptr , ¶ms, nullptr );
286+ ASSERT_EQ (umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
287+ }
288+
289+ TEST_P (umfLevelZeroProviderTest, getPageSizeInvalidArgs) {
290+ umf_memory_provider_handle_t provider = nullptr ;
291+ umf_result_t umf_result = umfMemoryProviderCreate (
292+ umfLevelZeroMemoryProviderOps (), ¶ms, &provider);
293+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
294+ ASSERT_NE (provider, nullptr );
295+
296+ umf_result = umfMemoryProviderGetMinPageSize (provider, nullptr , nullptr );
297+ ASSERT_EQ (umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
298+
299+ umf_result = umfMemoryProviderGetRecommendedPageSize (provider, 0 , nullptr );
300+ ASSERT_EQ (umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
301+
302+ umfMemoryProviderDestroy (provider);
303+ }
304+
225305// TODO add Level Zero Memory Provider specyfic tests
226306// TODO add negative test and check for Level Zero native errors
227307// TODO add tests that mixes Level Zero Memory Provider and Disjoint Pool
0 commit comments