Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests for zeInitDrivers #110

Merged
merged 1 commit into from
Nov 20, 2024
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
82 changes: 82 additions & 0 deletions conformance_tests/core/test_driver/src/test_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 42 additions & 0 deletions negative_tests/core/test_driver_errors/src/test_driver_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion scripts/level_zero_report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading