From 949046af170f8d2478b39e2729551789e804c761 Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Tue, 19 Nov 2024 17:21:16 -0800 Subject: [PATCH] Add Tests for zeInitDrivers Signed-off-by: Neil R. Spruit --- .../core/test_driver/src/test_driver.cpp | 82 +++++++++++++++++++ .../src/test_driver_errors.cpp | 42 ++++++++++ scripts/level_zero_report_utils.py | 3 +- 3 files changed, 126 insertions(+), 1 deletion(-) diff --git a/conformance_tests/core/test_driver/src/test_driver.cpp b/conformance_tests/core/test_driver/src/test_driver.cpp index 7e31ac62..a148f5be 100644 --- a/conformance_tests/core/test_driver/src/test_driver.cpp +++ b/conformance_tests/core/test_driver/src/test_driver.cpp @@ -67,4 +67,86 @@ TEST(zeDriverGetLastErrorDescription, } } +#ifdef ZE_API_VERSION_CURRENT_M +TEST( + zeInitDrivers, + GivenCallToZeInitDriversWithAllCombinationsOfFlagsThenExpectAtLeastOneValidDriverHandle) { + + uint32_t pCount = 0; + ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC}; + desc.pNext = nullptr; + + // Test with GPU only + desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU; + EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_GE(pCount, 0); + + // Test with NPU only + pCount = 0; + desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_NPU; + auto result = zeInitDrivers(&pCount, nullptr, &desc); + EXPECT_TRUE(result == ZE_RESULT_SUCCESS || + result == ZE_RESULT_ERROR_UNINITIALIZED); + EXPECT_GE(pCount, 0); + + // Test with GPU and NPU + pCount = 0; + desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU | ZE_INIT_DRIVER_TYPE_FLAG_NPU; + EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_GT(pCount, 0); + + // Test with all flags + pCount = 0; + desc.flags = UINT32_MAX; + EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_GT(pCount, 0); +} + +TEST( + zeInitDrivers, + GivenCallToZeInitDriversAndZeInitWithAllCombinationsOfFlagsThenExpectAtLeastOneValidDriverHandle) { + + uint32_t pCount = 0; + ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC}; + desc.pNext = nullptr; + + // Test with GPU only + desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU; + EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_GE(pCount, 0); + lzt::ze_init(ZE_INIT_FLAG_GPU_ONLY); + auto drivers = lzt::get_all_driver_handles(); + EXPECT_GE(drivers.size(), 0); + + // Test with NPU only + pCount = 0; + desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_NPU; + auto result = zeInitDrivers(&pCount, nullptr, &desc); + EXPECT_TRUE(result == ZE_RESULT_SUCCESS || + result == ZE_RESULT_ERROR_UNINITIALIZED); + EXPECT_GE(pCount, 0); + lzt::ze_init(ZE_INIT_FLAG_VPU_ONLY); + drivers = lzt::get_all_driver_handles(); + EXPECT_GE(drivers.size(), 0); + + // Test with GPU and NPU + pCount = 0; + desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU | ZE_INIT_DRIVER_TYPE_FLAG_NPU; + EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_GT(pCount, 0); + lzt::ze_init(ZE_INIT_FLAG_GPU_ONLY | ZE_INIT_FLAG_VPU_ONLY); + drivers = lzt::get_all_driver_handles(); + EXPECT_GT(drivers.size(), 0); + + // Test with all flags + pCount = 0; + desc.flags = UINT32_MAX; + EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_GT(pCount, 0); + lzt::ze_init(0); + drivers = lzt::get_all_driver_handles(); + EXPECT_GT(drivers.size(), 0); +} +#endif + } // namespace diff --git a/negative_tests/core/test_driver_errors/src/test_driver_errors.cpp b/negative_tests/core/test_driver_errors/src/test_driver_errors.cpp index 4c9f836c..c5a40c5d 100644 --- a/negative_tests/core/test_driver_errors/src/test_driver_errors.cpp +++ b/negative_tests/core/test_driver_errors/src/test_driver_errors.cpp @@ -34,4 +34,46 @@ TEST( EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, zeDriverGet(nullptr, nullptr)); } +#ifdef ZE_API_VERSION_CURRENT_M +TEST( + zeInitDriversNegativeTests, + GivenCallToZeInitDriversWithNoFlagsThenExpectFailure) { + + uint32_t pCount = 0; + ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC}; + desc.pNext = nullptr; + + // Test with no flags + desc.flags = 0; + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ENUMERATION, zeInitDrivers(&pCount, nullptr, &desc)); + EXPECT_EQ(pCount, 0); +} + +TEST( + zeInitDriversNegativeTests, + GivenCallToZeInitDriversWithNullPointerCountThenExpectFailure) { + + uint32_t pCount = 0; + ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC}; + desc.pNext = nullptr; + + // Test with nullptr pCount + desc.flags = 0; + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, zeInitDrivers(nullptr, nullptr, &desc)); +} + +TEST( + zeInitDriversNegativeTests, + GivenCallToZeInitDriversWithNullPointerDescThenExpectFailure) { + + uint32_t pCount = 0; + ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC}; + desc.pNext = nullptr; + + // Test with nullptr Desc + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, zeInitDrivers(&pCount, nullptr, nullptr)); + EXPECT_EQ(pCount, 0); +} +#endif + } // namespace diff --git a/scripts/level_zero_report_utils.py b/scripts/level_zero_report_utils.py index 58e81fef..b3c70f2f 100644 --- a/scripts/level_zero_report_utils.py +++ b/scripts/level_zero_report_utils.py @@ -188,7 +188,8 @@ def assign_test_feature_tag(test_feature: str, test_name: str, test_section: str (re.search('GivenOutOfOrderImmediateCommandListWhenAppendLaunchKernelInstructionCounterEventThenVerifyWaitForEvent', test_name, re.IGNORECASE)) or \ (re.search('GivenInOrderMixedCommandListWhenAppendLaunchKernelInstructionCounterEventThenVerifyImmediateExecution', test_name, re.IGNORECASE)) or \ (re.search('zeCheckMiscFunctionsTestsInstantiate_zeCheckMiscFunctionsTests_GivenFunctionInKernelWhenLaunchingKernelsThenFunctionWorksCorrectly', test_name, re.IGNORECASE)) or \ - re.search('fabric', test_name, re.IGNORECASE): + re.search('fabric', test_name, re.IGNORECASE) or \ + re.search('zeInitDrivers', test_name, re.IGNORECASE): test_feature_tag = "advanced" else: test_feature_tag = "basic"