@@ -763,6 +763,58 @@ TEST_F(ContextMemoryTest, whenRetrievingAddressRangeForDeviceAllocationThenRange
763763 EXPECT_EQ (result, ZE_RESULT_SUCCESS);
764764}
765765
766+ TEST_F (ContextMemoryTest, whenRetrievingAddressRangeForDeviceAllocationWithNoBaseArgumentThenSizeIsCorrectAndSuccessIsReturned) {
767+ size_t allocSize = 4096u ;
768+ size_t alignment = 1u ;
769+ void *allocPtr = nullptr ;
770+
771+ ze_device_mem_alloc_desc_t deviceDesc = {};
772+ ze_result_t result = context->allocDeviceMem (device->toHandle (),
773+ &deviceDesc,
774+ allocSize, alignment, &allocPtr);
775+ EXPECT_EQ (ZE_RESULT_SUCCESS, result);
776+ EXPECT_NE (nullptr , allocPtr);
777+
778+ size_t size = 0u ;
779+ void *pPtr = reinterpret_cast <void *>(reinterpret_cast <uint64_t >(allocPtr) + 77 );
780+ result = context->getMemAddressRange (pPtr, nullptr , &size);
781+ EXPECT_EQ (ZE_RESULT_SUCCESS, result);
782+ EXPECT_GE (size, allocSize);
783+
784+ result = context->freeMem (allocPtr);
785+ EXPECT_EQ (result, ZE_RESULT_SUCCESS);
786+ }
787+
788+ TEST_F (ContextMemoryTest, whenRetrievingAddressRangeForDeviceAllocationWithNoSizeArgumentThenRangeIsCorrectAndSuccessIsReturned) {
789+ size_t allocSize = 4096u ;
790+ size_t alignment = 1u ;
791+ void *allocPtr = nullptr ;
792+
793+ ze_device_mem_alloc_desc_t deviceDesc = {};
794+ ze_result_t result = context->allocDeviceMem (device->toHandle (),
795+ &deviceDesc,
796+ allocSize, alignment, &allocPtr);
797+ EXPECT_EQ (ZE_RESULT_SUCCESS, result);
798+ EXPECT_NE (nullptr , allocPtr);
799+
800+ void *base = nullptr ;
801+ void *pPtr = reinterpret_cast <void *>(reinterpret_cast <uint64_t >(allocPtr) + 77 );
802+ result = context->getMemAddressRange (pPtr, &base, nullptr );
803+ EXPECT_EQ (ZE_RESULT_SUCCESS, result);
804+ EXPECT_EQ (base, allocPtr);
805+
806+ result = context->freeMem (allocPtr);
807+ EXPECT_EQ (result, ZE_RESULT_SUCCESS);
808+ }
809+
810+ TEST_F (ContextMemoryTest, whenRetrievingAddressRangeForUnknownDeviceAllocationThenResultUnknownIsReturned) {
811+ void *base = nullptr ;
812+ size_t size = 0u ;
813+ uint64_t var = 0 ;
814+ ze_result_t res = context->getMemAddressRange (&var, &base, &size);
815+ EXPECT_EQ (ZE_RESULT_ERROR_UNKNOWN, res);
816+ }
817+
766818TEST_F (ContextMemoryTest, givenSystemAllocatedPointerThenGetAllocPropertiesReturnsUnknownType) {
767819 size_t size = 10 ;
768820 int *ptr = new int [size];
0 commit comments