From eae365f5f2764af2739d1c49ef4320860f2e7923 Mon Sep 17 00:00:00 2001 From: Vishnu Khanth Date: Fri, 29 Nov 2024 14:36:17 +0000 Subject: [PATCH] refactor sysman init tests (#116) Related-To: VLCLJ-2335 Signed-off-by: B, Vishnu Khanth --- .../test_sysman_init/src/test_init_sysman.cpp | 8 +++---- .../src/test_init_sysman_after_core.cpp | 19 +++++++-------- .../src/test_init_sysman_before_core.cpp | 16 ++++++------- ...init_sysman_enum_freq_with_core_handle.cpp | 24 ++++++++----------- ...it_sysman_enum_freq_with_sysman_handle.cpp | 22 +++++++---------- ...st_init_sysman_no_env_with_core_handle.cpp | 24 ++++++++----------- .../test_harness/test_harness_device.hpp | 10 ++++++-- .../test_harness/src/test_harness_device.cpp | 6 ++++- 8 files changed, 62 insertions(+), 67 deletions(-) diff --git a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman.cpp b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman.cpp index a87c0d22..6d9ff88a 100644 --- a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman.cpp +++ b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman.cpp @@ -17,11 +17,11 @@ namespace { TEST(SysmanInitTests, - GivenCoreNotInitializedWhenSysmanInitializedThenzesDriverGetWorks) { + GivenZesInitWhenZesDriverGetIsCalledThenSuccessIsReturned) { ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0)); - uint32_t pCount = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&pCount, nullptr)); - ASSERT_GT(pCount, 0); + uint32_t count = 0; + ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&count, nullptr)); + ASSERT_GT(count, 0); } } // namespace diff --git a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_after_core.cpp b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_after_core.cpp index efc874e4..bd9d3b7b 100644 --- a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_after_core.cpp +++ b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_after_core.cpp @@ -16,9 +16,8 @@ namespace { -TEST( - SysmanInitTests, - GivenSysmanEnableEnvDisabledAndCoreInitializedFirstWhenSysmanInitializedThenzesDriverGetWorks) { +TEST(SysmanInitTests, + GivenZeInitWithSysmanDisabledWhenZesInitIsCalledThenSuccessIsReturned) { auto is_sysman_enabled = getenv("ZES_ENABLE_SYSMAN"); // Disabling enable_sysman env if it's defaultly enabled if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) { @@ -26,13 +25,13 @@ TEST( putenv(disable_sysman_env); } ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0)); - uint32_t zeInitCount = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0)); - uint32_t zesInitCount = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&zeInitCount, nullptr)); - ASSERT_GT(zeInitCount, 0); - ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zesInitCount, nullptr)); - ASSERT_GT(zesInitCount, 0); + uint32_t ze_driver_count = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, zesInit(0)); + uint32_t zes_driver_count = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&ze_driver_count, nullptr)); + EXPECT_GT(ze_driver_count, 0); + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zes_driver_count, nullptr)); + EXPECT_GT(zes_driver_count, 0); if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) { char enable_sysman_env[] = "ZES_ENABLE_SYSMAN=1"; putenv(enable_sysman_env); diff --git a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_before_core.cpp b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_before_core.cpp index 2ad96a64..a24de36d 100644 --- a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_before_core.cpp +++ b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_before_core.cpp @@ -16,15 +16,15 @@ namespace { -TEST(SysmanInitTests, GivenSysmanInitializedThenCallingCoreInitSucceeds) { +TEST(SysmanInitTests, GivenZesInitWhenZeInitIsCalledThenSuccessIsReturned) { ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0)); - uint32_t zesInitCount = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0)); - uint32_t zeInitCount = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zesInitCount, nullptr)); - ASSERT_GT(zesInitCount, 0); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&zeInitCount, nullptr)); - ASSERT_GT(zeInitCount, 0); + uint32_t zes_driver_count = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, zeInit(0)); + uint32_t ze_driver_count = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zes_driver_count, nullptr)); + EXPECT_GT(zes_driver_count, 0); + EXPECT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&ze_driver_count, nullptr)); + EXPECT_GT(ze_driver_count, 0); } } // namespace diff --git a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_core_handle.cpp b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_core_handle.cpp index 887a54af..eea375b9 100644 --- a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_core_handle.cpp +++ b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_core_handle.cpp @@ -16,28 +16,24 @@ namespace { TEST( SysmanInitTests, - GivenSysmanInitializationDoneUsingZesInitFollowedByZeInitAlongWithSysmanFlagEnabledThenWhenSysmanApiZesDeviceEnumFrequencyDomainsIsCalledWithCoreHandleThenUninitializedErrorIsReturned) { + GivenZesInitAndZeInitWithSysmanEnabledWhenSysmanApiIsCalledWithZeDeviceThenUninitializedErrorIsReturned) { static char sys_env[] = "ZES_ENABLE_SYSMAN=1"; putenv(sys_env); ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0)); ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0)); - uint32_t driver_count = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&driver_count, nullptr)); - ASSERT_GT(driver_count, 0); - std::vector drivers(driver_count); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&driver_count, drivers.data())); - - uint32_t device_count = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeDeviceGet(drivers[0], &device_count, nullptr)); - std::vector devices(device_count); - ASSERT_EQ(ZE_RESULT_SUCCESS, - zeDeviceGet(drivers[0], &device_count, devices.data())); + std::vector ze_drivers = lzt::get_all_driver_handles(); + EXPECT_FALSE(ze_drivers.empty()); + std::vector ze_devices = + lzt::get_ze_devices(ze_drivers[0]); + EXPECT_FALSE(ze_devices.empty()); uint32_t count = 0; - EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, - zesDeviceEnumFrequencyDomains(devices[0], &count, nullptr)); + EXPECT_EQ( + ZE_RESULT_ERROR_UNINITIALIZED, + zesDeviceEnumFrequencyDomains( + static_cast(ze_devices[0]), &count, nullptr)); } } // namespace diff --git a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_sysman_handle.cpp b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_sysman_handle.cpp index 1bab294d..48c57dcd 100644 --- a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_sysman_handle.cpp +++ b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_sysman_handle.cpp @@ -18,29 +18,23 @@ namespace { TEST( SysmanInitTests, - GivenSysmanInitializationDoneUsingZesInitFollowedByZeInitAlongWithSysmanFlagEnabledThenWhenSysmanApiZesDeviceEnumFrequencyDomainsIsCalledWithSysmanHandleThenSuccessIsReturned) { + GivenZesInitAndZeInitWithSysmanEnabledWhenSysmanApiIsCalledWithZesDeviceThenSuccessIsReturned) { static char sys_env[] = "ZES_ENABLE_SYSMAN=1"; putenv(sys_env); ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0)); ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0)); - uint32_t driver_count = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&driver_count, nullptr)); - ASSERT_GT(driver_count, 0); - std::vector drivers(driver_count); - ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&driver_count, drivers.data())); - - uint32_t device_count = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, - zesDeviceGet(drivers[0], &device_count, nullptr)); - std::vector devices(device_count); - ASSERT_EQ(ZE_RESULT_SUCCESS, - zesDeviceGet(drivers[0], &device_count, devices.data())); + std::vector zes_drivers = + lzt::get_all_zes_driver_handles(); + EXPECT_FALSE(zes_drivers.empty()); + std::vector zes_devices = + lzt::get_zes_devices(zes_drivers[0]); + EXPECT_FALSE(zes_devices.empty()); uint32_t count = 0; EXPECT_EQ(ZE_RESULT_SUCCESS, - zesDeviceEnumFrequencyDomains(devices[0], &count, nullptr)); + zesDeviceEnumFrequencyDomains(zes_devices[0], &count, nullptr)); } } // namespace diff --git a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_no_env_with_core_handle.cpp b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_no_env_with_core_handle.cpp index a029f1e1..a124dae9 100644 --- a/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_no_env_with_core_handle.cpp +++ b/conformance_tests/sysman/test_sysman_init/src/test_init_sysman_no_env_with_core_handle.cpp @@ -16,28 +16,24 @@ namespace { TEST( SysmanInitTests, - GivenSysmanInitializationDoneUsingZesInitFollowedByZeInitAlongWithSysmanFlagDisabledThenWhenSysmanApiZesDeviceEnumFrequencyDomainsIsCalledWithCoreHandleThenUninitializedErrorIsReturned) { + GivenZesInitAndZeInitWithSysmanDisabledWhenSysmanApiIsCalledWithZeDeviceThenUninitializedErrorIsReturned) { static char sys_env[] = "ZES_ENABLE_SYSMAN=0"; putenv(sys_env); ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0)); ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0)); - uint32_t driver_count = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&driver_count, nullptr)); - ASSERT_GT(driver_count, 0); - std::vector drivers(driver_count); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&driver_count, drivers.data())); - - uint32_t device_count = 0; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeDeviceGet(drivers[0], &device_count, nullptr)); - std::vector devices(device_count); - ASSERT_EQ(ZE_RESULT_SUCCESS, - zeDeviceGet(drivers[0], &device_count, devices.data())); + std::vector ze_drivers = lzt::get_all_driver_handles(); + EXPECT_FALSE(ze_drivers.empty()); + std::vector ze_devices = + lzt::get_ze_devices(ze_drivers[0]); + EXPECT_FALSE(ze_devices.empty()); uint32_t count = 0; - EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, - zesDeviceEnumFrequencyDomains(devices[0], &count, nullptr)); + EXPECT_EQ( + ZE_RESULT_ERROR_UNINITIALIZED, + zesDeviceEnumFrequencyDomains( + static_cast(ze_devices[0]), &count, nullptr)); } } // namespace diff --git a/utils/test_harness/include/test_harness/test_harness_device.hpp b/utils/test_harness/include/test_harness/test_harness_device.hpp index 02861d9a..05ff6f63 100644 --- a/utils/test_harness/include/test_harness/test_harness_device.hpp +++ b/utils/test_harness/include/test_harness/test_harness_device.hpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -32,9 +32,15 @@ class zeDevice { void initialize_core(); ze_device_handle_t get_root_device(ze_device_handle_t device); +uint32_t get_zes_device_count(); +uint32_t get_zes_device_count(zes_driver_handle_t driver); +std::vector get_zes_devices(); +std::vector get_zes_devices(uint32_t count); +std::vector get_zes_devices(zes_driver_handle_t driver); +std::vector get_zes_devices(uint32_t count, + zes_driver_handle_t driver); uint32_t get_ze_device_count(); uint32_t get_ze_device_count(ze_driver_handle_t driver); -std::vector get_zes_devices(); std::vector get_ze_devices(); std::vector get_ze_devices(uint32_t count); std::vector get_ze_devices(ze_driver_handle_t driver); diff --git a/utils/test_harness/src/test_harness_device.cpp b/utils/test_harness/src/test_harness_device.cpp index 47ccd22c..47a75371 100644 --- a/utils/test_harness/src/test_harness_device.cpp +++ b/utils/test_harness/src/test_harness_device.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -56,6 +56,10 @@ uint32_t get_zes_device_count() { return get_zes_device_count(lzt::get_default_zes_driver()); } +std::vector get_zes_devices(zes_driver_handle_t driver) { + return get_zes_devices(get_zes_device_count(driver), driver); +} + std::vector get_zes_devices(uint32_t count, zes_driver_handle_t driver) { uint32_t count_out = count;