diff --git a/source/lib/ze_libapi.cpp b/source/lib/ze_libapi.cpp index 25e82cba..24b79c82 100644 --- a/source/lib/ze_libapi.cpp +++ b/source/lib/ze_libapi.cpp @@ -267,6 +267,10 @@ zeInitDrivers( return ZE_RESULT_ERROR_UNINITIALIZED; } + if (ze_lib::context->zeDdiTable.load() == nullptr) { + return ZE_RESULT_ERROR_UNINITIALIZED; + } + auto pfnInitDrivers = ze_lib::context->zeDdiTable.load()->Global.pfnInitDrivers; if( nullptr == pfnInitDrivers ) { if(!ze_lib::context->isInitialized) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0e487e8d..0abc3217 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -160,6 +160,8 @@ add_test(NAME tests_missing_api COMMAND tests --gtest_filter=*GivenZeInitDrivers set_property(TEST tests_missing_api PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1;ZE_ENABLE_NULL_DRIVER=1") add_test(NAME tests_multi_call_failure COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithTypesUnsupportedWithFailureThenSupportedTypesThenSuccessReturned*) set_property(TEST tests_multi_call_failure PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1;ZE_ENABLE_NULL_DRIVER=1") +add_test(NAME tests_no_initialization COMMAND tests --gtest_filter=*LoaderInit.GivenNoInitializationWhenCallingZeInitDriversThenErrorUninitializedIsReturned*) +set_property(TEST tests_no_initialization PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1") # Run with multiple drivers add_test(NAME tests_multi_driver_missing_initDrivers COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWithMultipleDriversMissingInitDriversWhenCallingZeInitDriversThenExpectSuccessForZeInit) diff --git a/test/loader_api.cpp b/test/loader_api.cpp index e7786aef..cb0d0bcf 100644 --- a/test/loader_api.cpp +++ b/test/loader_api.cpp @@ -9,6 +9,7 @@ #include "gtest/gtest.h" #include "loader/ze_loader.h" +#include "source/lib/ze_lib.h" #include "ze_api.h" #include "zes_api.h" #include "zer_api.h" @@ -254,6 +255,22 @@ TEST( EXPECT_GT(pCount, 0); } +TEST( + LoaderInit, + GivenNoInitializationWhenCallingZeInitDriversThenErrorUninitializedIsReturned) { + + uint32_t pCount = 0; + ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC}; + desc.flags = UINT32_MAX; + desc.pNext = nullptr; + EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_EQ(pCount, 0); + + pCount = 0; + EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_EQ(pCount, 0); +} + TEST( LoaderInit, GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithGPUTypeThenExpectPassWithGPUorAllOnly) { @@ -3979,6 +3996,5 @@ TEST_F(DriverOrderingTest, EXPECT_NE(errorDesc, nullptr); EXPECT_EQ(0, strcmp(errorDesc, "ERROR UNSUPPORTED FEATURE")); } - } // namespace