Skip to content

Commit

Permalink
refactor sysman init tests (#116)
Browse files Browse the repository at this point in the history
Related-To: VLCLJ-2335

Signed-off-by: B, Vishnu Khanth <[email protected]>
  • Loading branch information
vishnu-khanth authored Nov 29, 2024
1 parent a9904f6 commit eae365f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@

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) {
char disable_sysman_env[] = "ZES_ENABLE_SYSMAN=0";
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<zes_driver_handle_t> 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<zes_device_handle_t> devices(device_count);
ASSERT_EQ(ZE_RESULT_SUCCESS,
zeDeviceGet(drivers[0], &device_count, devices.data()));
std::vector<ze_driver_handle_t> ze_drivers = lzt::get_all_driver_handles();
EXPECT_FALSE(ze_drivers.empty());
std::vector<ze_device_handle_t> 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<zes_device_handle_t>(ze_devices[0]), &count, nullptr));
}

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -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<zes_driver_handle_t> 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<zes_device_handle_t> devices(device_count);
ASSERT_EQ(ZE_RESULT_SUCCESS,
zesDeviceGet(drivers[0], &device_count, devices.data()));
std::vector<zes_driver_handle_t> zes_drivers =
lzt::get_all_zes_driver_handles();
EXPECT_FALSE(zes_drivers.empty());
std::vector<zes_device_handle_t> 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
Original file line number Diff line number Diff line change
Expand Up @@ -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<zes_driver_handle_t> 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<zes_device_handle_t> devices(device_count);
ASSERT_EQ(ZE_RESULT_SUCCESS,
zeDeviceGet(drivers[0], &device_count, devices.data()));
std::vector<ze_driver_handle_t> ze_drivers = lzt::get_all_driver_handles();
EXPECT_FALSE(ze_drivers.empty());
std::vector<ze_device_handle_t> 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<zes_device_handle_t>(ze_devices[0]), &count, nullptr));
}

} // namespace
10 changes: 8 additions & 2 deletions utils/test_harness/include/test_harness/test_harness_device.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -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<zes_device_handle_t> get_zes_devices();
std::vector<zes_device_handle_t> get_zes_devices(uint32_t count);
std::vector<zes_device_handle_t> get_zes_devices(zes_driver_handle_t driver);
std::vector<zes_device_handle_t> 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<zes_device_handle_t> get_zes_devices();
std::vector<ze_device_handle_t> get_ze_devices();
std::vector<ze_device_handle_t> get_ze_devices(uint32_t count);
std::vector<ze_device_handle_t> get_ze_devices(ze_driver_handle_t driver);
Expand Down
6 changes: 5 additions & 1 deletion utils/test_harness/src/test_harness_device.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -56,6 +56,10 @@ uint32_t get_zes_device_count() {
return get_zes_device_count(lzt::get_default_zes_driver());
}

std::vector<zes_device_handle_t> get_zes_devices(zes_driver_handle_t driver) {
return get_zes_devices(get_zes_device_count(driver), driver);
}

std::vector<zes_device_handle_t> get_zes_devices(uint32_t count,
zes_driver_handle_t driver) {
uint32_t count_out = count;
Expand Down

0 comments on commit eae365f

Please sign in to comment.