Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions scripts/templates/nullddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ ${tbl['export']['name']}(
%endfor
)
{
%if n == 'zer':
auto zer_api_disable = getenv_string( "ZEL_TEST_NULL_DRIVER_DISABLE_ZER_API" );
#ifndef ZEL_NULL_DRIVER_ID
#define ZEL_NULL_DRIVER_ID 1
#endif
std::string null_driver_id_str = std::to_string(ZEL_NULL_DRIVER_ID);
auto zer_api_unsupported = (zer_api_disable == null_driver_id_str);
if(zer_api_unsupported)
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;

%endif
if( nullptr == pDdiTable )
return ${X}_RESULT_ERROR_INVALID_NULL_POINTER;

Expand Down
52 changes: 39 additions & 13 deletions source/drivers/null/ze_null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ namespace driver
//////////////////////////////////////////////////////////////////////////
context_t::context_t()
{
auto ddi_test_disable = getenv_string( "ZEL_TEST_NULL_DRIVER_DISABLE_DDI_EXT" );
#ifndef ZEL_NULL_DRIVER_ID
#define ZEL_NULL_DRIVER_ID 1
#endif
std::string null_driver_id_str = std::to_string(ZEL_NULL_DRIVER_ID);
ddiExtensionSupported = (ddi_test_disable != null_driver_id_str && ddi_test_disable != "3");

zesDdiTable.Driver.pfnGet = [](
uint32_t* pCount,
ze_driver_handle_t* phDrivers )
Expand Down Expand Up @@ -69,15 +76,9 @@ namespace driver
{
auto pNext = reinterpret_cast<ze_base_properties_t *>(pDriverProperties->pNext);
while (pNext) {
auto ddi_test_disable = getenv_string( "ZEL_TEST_NULL_DRIVER_DISABLE_DDI_EXT" );
#ifndef ZEL_NULL_DRIVER_ID
#define ZEL_NULL_DRIVER_ID 1
#endif
std::string null_driver_id_str = std::to_string(ZEL_NULL_DRIVER_ID);
if (pNext->stype == ZE_STRUCTURE_TYPE_DRIVER_DDI_HANDLES_EXT_PROPERTIES && (ddi_test_disable != null_driver_id_str && ddi_test_disable != "3")) {
if (pNext->stype == ZE_STRUCTURE_TYPE_DRIVER_DDI_HANDLES_EXT_PROPERTIES && context.ddiExtensionSupported) {
ze_driver_ddi_handles_ext_properties_t *pDdiHandlesExtProperties = reinterpret_cast<ze_driver_ddi_handles_ext_properties_t *>(pNext);
pDdiHandlesExtProperties->flags = ze_driver_ddi_handle_ext_flag_t::ZE_DRIVER_DDI_HANDLE_EXT_FLAG_DDI_HANDLE_EXT_SUPPORTED;
context.ddiExtensionRequested = true;
}
pNext = reinterpret_cast<ze_base_properties_t *>(pNext->pNext);
}
Expand Down Expand Up @@ -487,17 +488,32 @@ namespace driver
{
if( nullptr != pExtensionProperties )
{
ze_driver_extension_properties_t driverExtensionProperties = {};
ze_driver_extension_properties_t tracingExtension = {};
#if defined(_WIN32)
strcpy_s( tracingExtension.name, ZET_API_TRACING_EXP_NAME );
#else
strcpy( tracingExtension.name, ZET_API_TRACING_EXP_NAME );
#endif
tracingExtension.version = ZET_API_TRACING_EXP_VERSION_1_0;
pExtensionProperties[0] = tracingExtension;

ze_driver_extension_properties_t ddiHandlesExtension = {};
#if defined(_WIN32)
strcpy_s( driverExtensionProperties.name, ZET_API_TRACING_EXP_NAME );
strcpy_s( ddiHandlesExtension.name, ZE_DRIVER_DDI_HANDLES_EXT_NAME );
#else
strcpy( driverExtensionProperties.name, ZET_API_TRACING_EXP_NAME );
strcpy( ddiHandlesExtension.name, ZE_DRIVER_DDI_HANDLES_EXT_NAME );
#endif
driverExtensionProperties.version = ZET_API_TRACING_EXP_VERSION_1_0;

*pExtensionProperties = driverExtensionProperties;
auto ddi_version_env = getenv_string("ZEL_TEST_DDI_HANDLES_EXT_VERSION");
if (!ddi_version_env.empty() && ddi_version_env == "1_0") {
ddiHandlesExtension.version = ZE_DRIVER_DDI_HANDLES_EXT_VERSION_1_0;
} else {
ddiHandlesExtension.version = ZE_DRIVER_DDI_HANDLES_EXT_VERSION_1_1;
}

pExtensionProperties[1] = ddiHandlesExtension;
}
*pCount = 1;
*pCount = 2;

return ZE_RESULT_SUCCESS;
};
Expand Down Expand Up @@ -629,6 +645,16 @@ namespace driver
pSysman.Driver = &zesDdiTable.Driver;
pSysman.isValidFlag = 1;
pSysman.version = ZE_API_VERSION_CURRENT;

static zer_global_dditable_t runtimeDdiTable;
runtimeDdiTable.pfnGetLastErrorDescription = driver::zerGetLastErrorDescription;
runtimeDdiTable.pfnTranslateDeviceHandleToIdentifier = driver::zerTranslateDeviceHandleToIdentifier;
runtimeDdiTable.pfnTranslateIdentifierToDeviceHandle = driver::zerTranslateIdentifierToDeviceHandle;
runtimeDdiTable.pfnGetDefaultContext = driver::zerGetDefaultContext;

pRuntime.Global = &runtimeDdiTable;
pRuntime.isValidFlag = 1;
pRuntime.version = ZE_API_VERSION_CURRENT;
}

char *context_t::setenv_var_with_driver_id(const std::string &key, uint32_t driverId)
Expand Down
9 changes: 7 additions & 2 deletions source/drivers/null/ze_null.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ namespace driver
zes_dditable_t zesDdiTable = {};
zer_dditable_t zerDdiTable = {};
std::vector<BaseNullHandle*> globalBaseNullHandle;
bool ddiExtensionRequested = false;
bool ddiExtensionSupported = false;
std::vector<char *> env_vars{};
context_t();
~context_t();

void* get( void )
{
static uint64_t count = 0x80800000 >> ZEL_NULL_DRIVER_ID;
if (ddiExtensionRequested) {
if (ddiExtensionSupported) {
globalBaseNullHandle.push_back(new BaseNullHandle());
return reinterpret_cast<void*>(globalBaseNullHandle.back());
} else {
Expand All @@ -64,6 +64,11 @@ namespace driver
char *setenv_var_with_driver_id(const std::string &key, uint32_t driverId);
};

ze_result_t ZE_APICALL zerGetLastErrorDescription(const char **ppString);
uint32_t ZE_APICALL zerTranslateDeviceHandleToIdentifier(ze_device_handle_t hDevice);
ze_device_handle_t ZE_APICALL zerTranslateIdentifierToDeviceHandle(uint32_t identifier);
ze_context_handle_t ZE_APICALL zerGetDefaultContext(void);

extern context_t context;
} // namespace driver

Expand Down
9 changes: 9 additions & 0 deletions source/drivers/null/zer_nullddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ zerGetGlobalProcAddrTable(
zer_global_dditable_t* pDdiTable ///< [in,out] pointer to table of DDI function pointers
)
{
auto zer_api_disable = getenv_string( "ZEL_TEST_NULL_DRIVER_DISABLE_ZER_API" );
#ifndef ZEL_NULL_DRIVER_ID
#define ZEL_NULL_DRIVER_ID 1
#endif
std::string null_driver_id_str = std::to_string(ZEL_NULL_DRIVER_ID);
auto zer_api_unsupported = (zer_api_disable == null_driver_id_str);
if(zer_api_unsupported)
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;

if( nullptr == pDdiTable )
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;

Expand Down
57 changes: 56 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ add_test(NAME driver_ordering_parse_driver_order COMMAND tests --gtest_filter=Dr
set_property(TEST driver_ordering_parse_driver_order PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1;ZE_ENABLE_NULL_DRIVER=1")



# These tests are currently not supported on Windows. The reason is that the std::cerr is not being redirected to a pipe in Windows to be then checked against the expected output.
if(NOT MSVC)
add_test(NAME tests_event_deadlock COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeCommandListAppendMemoryCopyWithCircularDependencyOnEventsThenValidationLayerPrintsWarningOfDeadlock*)
Expand All @@ -607,3 +606,59 @@ if(NOT MSVC)
add_test(NAME tests_event_reset_reuse COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeEventHostResetWithAlreadySignaledEventThenUsingEventAgainThenValidationLayerDoesNotPrintsWarningOfIllegalUsage*)
set_property(TEST tests_event_reset_reuse PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1;ZE_ENABLE_NULL_DRIVER=1;ZE_ENABLE_VALIDATION_LAYER=1;ZEL_ENABLE_EVENTS_CHECKER=1")
endif()

# ZER Runtime API Tests

# Helper function to add runtime API tests
function(add_runtime_api_test test_scenario init_method driver_config)
set(test_name "tests_${driver_config}_runtime_api_${test_scenario}_${init_method}")

# Define test scenarios and their corresponding gtest filters
if(test_scenario STREQUAL "ddi_ext_v1_1")
set(gtest_filter "*GivenLevelZeroLoaderPresentWithLoaderInterceptEnabledAndDdiExtSupportedWhenCallingRuntimeApisAfter${init_method}ThenExpectNullDriverIsReachedSuccessfully")
elseif(test_scenario STREQUAL "ddi_ext_unsupported")
set(gtest_filter "*GivenLevelZeroLoaderPresentWithLoaderInterceptEnabledAndDdiExtNotSupportedWhenCallingRuntimeApisAfter${init_method}ThenExpectNullDriverIsReachedSuccessfully")
elseif(test_scenario STREQUAL "ddi_ext_v1_0")
set(gtest_filter "*GivenLevelZeroLoaderPresentWithLoaderInterceptEnabledAndDdiExtSupportedWithVersion1_0WhenCallingRuntimeApisAfter${init_method}ThenExpectErrorUninitialized")
elseif(test_scenario STREQUAL "runtime_api_unsupported")
set(gtest_filter "*GivenLevelZeroLoaderPresentWithLoaderInterceptEnabledAndRuntimeApiUnsupportedWhenCallingRuntimeApisAfter${init_method}ThenExpectErrorUnsupportedFeature")
endif()

# Add the test
add_test(NAME ${test_name} COMMAND tests --gtest_filter=${gtest_filter})

# Set base environment variables
set(base_env "ZE_ENABLE_LOADER_DRIVER_DDI_PATH=1;ZE_ENABLE_LOADER_DEBUG_TRACE=1")

if(driver_config STREQUAL "single_driver")
# Single driver configuration
set_property(TEST ${test_name} PROPERTY ENVIRONMENT "${base_env};ZE_ENABLE_NULL_DRIVER=1")
elseif(driver_config STREQUAL "multi_driver")
# Multi-driver configuration
if(MSVC)
set(alt_drivers "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/ze_null_test1.dll,${CMAKE_BINARY_DIR}/bin/$<CONFIG>/ze_null_test2.dll")
else()
set(alt_drivers "${CMAKE_BINARY_DIR}/lib/libze_null_test1.so,${CMAKE_BINARY_DIR}/lib/libze_null_test2.so")
endif()
set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT "${base_env};ZE_ENABLE_ALT_DRIVERS=${alt_drivers}")
endif()
endfunction()

# Generate all ZER Runtime API tests using loops
set(test_scenarios "ddi_ext_v1_1;ddi_ext_unsupported;ddi_ext_v1_0")
set(init_methods "ZeInitDrivers;ZeInit")

foreach(init_method IN LISTS init_methods)
foreach(test_scenario IN LISTS test_scenarios)
# Add single driver tests
add_runtime_api_test(${test_scenario} ${init_method} "single_driver")

# Add multi-driver tests
add_runtime_api_test(${test_scenario} ${init_method} "multi_driver")
endforeach()

# Add runtime_api_unsupported tests for single driver
if(init_method STREQUAL "ZeInitDrivers")
add_runtime_api_test("runtime_api_unsupported" ${init_method} "single_driver")
endif()
endforeach()
Loading
Loading