Skip to content

Commit eae365f

Browse files
refactor sysman init tests (#116)
Related-To: VLCLJ-2335 Signed-off-by: B, Vishnu Khanth <vishnu.khanth.b@intel.com>
1 parent a9904f6 commit eae365f

File tree

8 files changed

+62
-67
lines changed

8 files changed

+62
-67
lines changed

conformance_tests/sysman/test_sysman_init/src/test_init_sysman.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
namespace {
1818

1919
TEST(SysmanInitTests,
20-
GivenCoreNotInitializedWhenSysmanInitializedThenzesDriverGetWorks) {
20+
GivenZesInitWhenZesDriverGetIsCalledThenSuccessIsReturned) {
2121
ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0));
22-
uint32_t pCount = 0;
23-
ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&pCount, nullptr));
24-
ASSERT_GT(pCount, 0);
22+
uint32_t count = 0;
23+
ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&count, nullptr));
24+
ASSERT_GT(count, 0);
2525
}
2626

2727
} // namespace

conformance_tests/sysman/test_sysman_init/src/test_init_sysman_after_core.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@
1616

1717
namespace {
1818

19-
TEST(
20-
SysmanInitTests,
21-
GivenSysmanEnableEnvDisabledAndCoreInitializedFirstWhenSysmanInitializedThenzesDriverGetWorks) {
19+
TEST(SysmanInitTests,
20+
GivenZeInitWithSysmanDisabledWhenZesInitIsCalledThenSuccessIsReturned) {
2221
auto is_sysman_enabled = getenv("ZES_ENABLE_SYSMAN");
2322
// Disabling enable_sysman env if it's defaultly enabled
2423
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
2524
char disable_sysman_env[] = "ZES_ENABLE_SYSMAN=0";
2625
putenv(disable_sysman_env);
2726
}
2827
ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0));
29-
uint32_t zeInitCount = 0;
30-
ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0));
31-
uint32_t zesInitCount = 0;
32-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&zeInitCount, nullptr));
33-
ASSERT_GT(zeInitCount, 0);
34-
ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zesInitCount, nullptr));
35-
ASSERT_GT(zesInitCount, 0);
28+
uint32_t ze_driver_count = 0;
29+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesInit(0));
30+
uint32_t zes_driver_count = 0;
31+
EXPECT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&ze_driver_count, nullptr));
32+
EXPECT_GT(ze_driver_count, 0);
33+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zes_driver_count, nullptr));
34+
EXPECT_GT(zes_driver_count, 0);
3635
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
3736
char enable_sysman_env[] = "ZES_ENABLE_SYSMAN=1";
3837
putenv(enable_sysman_env);

conformance_tests/sysman/test_sysman_init/src/test_init_sysman_before_core.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
namespace {
1818

19-
TEST(SysmanInitTests, GivenSysmanInitializedThenCallingCoreInitSucceeds) {
19+
TEST(SysmanInitTests, GivenZesInitWhenZeInitIsCalledThenSuccessIsReturned) {
2020
ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0));
21-
uint32_t zesInitCount = 0;
22-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0));
23-
uint32_t zeInitCount = 0;
24-
ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zesInitCount, nullptr));
25-
ASSERT_GT(zesInitCount, 0);
26-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&zeInitCount, nullptr));
27-
ASSERT_GT(zeInitCount, 0);
21+
uint32_t zes_driver_count = 0;
22+
EXPECT_EQ(ZE_RESULT_SUCCESS, zeInit(0));
23+
uint32_t ze_driver_count = 0;
24+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zes_driver_count, nullptr));
25+
EXPECT_GT(zes_driver_count, 0);
26+
EXPECT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&ze_driver_count, nullptr));
27+
EXPECT_GT(ze_driver_count, 0);
2828
}
2929

3030
} // namespace

conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_core_handle.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,24 @@ namespace {
1616

1717
TEST(
1818
SysmanInitTests,
19-
GivenSysmanInitializationDoneUsingZesInitFollowedByZeInitAlongWithSysmanFlagEnabledThenWhenSysmanApiZesDeviceEnumFrequencyDomainsIsCalledWithCoreHandleThenUninitializedErrorIsReturned) {
19+
GivenZesInitAndZeInitWithSysmanEnabledWhenSysmanApiIsCalledWithZeDeviceThenUninitializedErrorIsReturned) {
2020
static char sys_env[] = "ZES_ENABLE_SYSMAN=1";
2121
putenv(sys_env);
2222

2323
ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0));
2424
ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0));
2525

26-
uint32_t driver_count = 0;
27-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&driver_count, nullptr));
28-
ASSERT_GT(driver_count, 0);
29-
std::vector<zes_driver_handle_t> drivers(driver_count);
30-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&driver_count, drivers.data()));
31-
32-
uint32_t device_count = 0;
33-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeDeviceGet(drivers[0], &device_count, nullptr));
34-
std::vector<zes_device_handle_t> devices(device_count);
35-
ASSERT_EQ(ZE_RESULT_SUCCESS,
36-
zeDeviceGet(drivers[0], &device_count, devices.data()));
26+
std::vector<ze_driver_handle_t> ze_drivers = lzt::get_all_driver_handles();
27+
EXPECT_FALSE(ze_drivers.empty());
28+
std::vector<ze_device_handle_t> ze_devices =
29+
lzt::get_ze_devices(ze_drivers[0]);
30+
EXPECT_FALSE(ze_devices.empty());
3731

3832
uint32_t count = 0;
39-
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED,
40-
zesDeviceEnumFrequencyDomains(devices[0], &count, nullptr));
33+
EXPECT_EQ(
34+
ZE_RESULT_ERROR_UNINITIALIZED,
35+
zesDeviceEnumFrequencyDomains(
36+
static_cast<zes_device_handle_t>(ze_devices[0]), &count, nullptr));
4137
}
4238

4339
} // namespace

conformance_tests/sysman/test_sysman_init/src/test_init_sysman_enum_freq_with_sysman_handle.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,23 @@ namespace {
1818

1919
TEST(
2020
SysmanInitTests,
21-
GivenSysmanInitializationDoneUsingZesInitFollowedByZeInitAlongWithSysmanFlagEnabledThenWhenSysmanApiZesDeviceEnumFrequencyDomainsIsCalledWithSysmanHandleThenSuccessIsReturned) {
21+
GivenZesInitAndZeInitWithSysmanEnabledWhenSysmanApiIsCalledWithZesDeviceThenSuccessIsReturned) {
2222
static char sys_env[] = "ZES_ENABLE_SYSMAN=1";
2323
putenv(sys_env);
2424

2525
ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0));
2626
ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0));
2727

28-
uint32_t driver_count = 0;
29-
ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&driver_count, nullptr));
30-
ASSERT_GT(driver_count, 0);
31-
std::vector<zes_driver_handle_t> drivers(driver_count);
32-
ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&driver_count, drivers.data()));
33-
34-
uint32_t device_count = 0;
35-
ASSERT_EQ(ZE_RESULT_SUCCESS,
36-
zesDeviceGet(drivers[0], &device_count, nullptr));
37-
std::vector<zes_device_handle_t> devices(device_count);
38-
ASSERT_EQ(ZE_RESULT_SUCCESS,
39-
zesDeviceGet(drivers[0], &device_count, devices.data()));
28+
std::vector<zes_driver_handle_t> zes_drivers =
29+
lzt::get_all_zes_driver_handles();
30+
EXPECT_FALSE(zes_drivers.empty());
31+
std::vector<zes_device_handle_t> zes_devices =
32+
lzt::get_zes_devices(zes_drivers[0]);
33+
EXPECT_FALSE(zes_devices.empty());
4034

4135
uint32_t count = 0;
4236
EXPECT_EQ(ZE_RESULT_SUCCESS,
43-
zesDeviceEnumFrequencyDomains(devices[0], &count, nullptr));
37+
zesDeviceEnumFrequencyDomains(zes_devices[0], &count, nullptr));
4438
}
4539

4640
} // namespace

conformance_tests/sysman/test_sysman_init/src/test_init_sysman_no_env_with_core_handle.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,24 @@ namespace {
1616

1717
TEST(
1818
SysmanInitTests,
19-
GivenSysmanInitializationDoneUsingZesInitFollowedByZeInitAlongWithSysmanFlagDisabledThenWhenSysmanApiZesDeviceEnumFrequencyDomainsIsCalledWithCoreHandleThenUninitializedErrorIsReturned) {
19+
GivenZesInitAndZeInitWithSysmanDisabledWhenSysmanApiIsCalledWithZeDeviceThenUninitializedErrorIsReturned) {
2020
static char sys_env[] = "ZES_ENABLE_SYSMAN=0";
2121
putenv(sys_env);
2222

2323
ASSERT_EQ(ZE_RESULT_SUCCESS, zesInit(0));
2424
ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0));
2525

26-
uint32_t driver_count = 0;
27-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&driver_count, nullptr));
28-
ASSERT_GT(driver_count, 0);
29-
std::vector<zes_driver_handle_t> drivers(driver_count);
30-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeDriverGet(&driver_count, drivers.data()));
31-
32-
uint32_t device_count = 0;
33-
ASSERT_EQ(ZE_RESULT_SUCCESS, zeDeviceGet(drivers[0], &device_count, nullptr));
34-
std::vector<zes_device_handle_t> devices(device_count);
35-
ASSERT_EQ(ZE_RESULT_SUCCESS,
36-
zeDeviceGet(drivers[0], &device_count, devices.data()));
26+
std::vector<ze_driver_handle_t> ze_drivers = lzt::get_all_driver_handles();
27+
EXPECT_FALSE(ze_drivers.empty());
28+
std::vector<ze_device_handle_t> ze_devices =
29+
lzt::get_ze_devices(ze_drivers[0]);
30+
EXPECT_FALSE(ze_devices.empty());
3731

3832
uint32_t count = 0;
39-
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED,
40-
zesDeviceEnumFrequencyDomains(devices[0], &count, nullptr));
33+
EXPECT_EQ(
34+
ZE_RESULT_ERROR_UNINITIALIZED,
35+
zesDeviceEnumFrequencyDomains(
36+
static_cast<zes_device_handle_t>(ze_devices[0]), &count, nullptr));
4137
}
4238

4339
} // namespace

utils/test_harness/include/test_harness/test_harness_device.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2019-2023 Intel Corporation
3+
* Copyright (C) 2019-2024 Intel Corporation
44
*
55
* SPDX-License-Identifier: MIT
66
*
@@ -32,9 +32,15 @@ class zeDevice {
3232

3333
void initialize_core();
3434
ze_device_handle_t get_root_device(ze_device_handle_t device);
35+
uint32_t get_zes_device_count();
36+
uint32_t get_zes_device_count(zes_driver_handle_t driver);
37+
std::vector<zes_device_handle_t> get_zes_devices();
38+
std::vector<zes_device_handle_t> get_zes_devices(uint32_t count);
39+
std::vector<zes_device_handle_t> get_zes_devices(zes_driver_handle_t driver);
40+
std::vector<zes_device_handle_t> get_zes_devices(uint32_t count,
41+
zes_driver_handle_t driver);
3542
uint32_t get_ze_device_count();
3643
uint32_t get_ze_device_count(ze_driver_handle_t driver);
37-
std::vector<zes_device_handle_t> get_zes_devices();
3844
std::vector<ze_device_handle_t> get_ze_devices();
3945
std::vector<ze_device_handle_t> get_ze_devices(uint32_t count);
4046
std::vector<ze_device_handle_t> get_ze_devices(ze_driver_handle_t driver);

utils/test_harness/src/test_harness_device.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2019-2023 Intel Corporation
3+
* Copyright (C) 2019-2024 Intel Corporation
44
*
55
* SPDX-License-Identifier: MIT
66
*
@@ -56,6 +56,10 @@ uint32_t get_zes_device_count() {
5656
return get_zes_device_count(lzt::get_default_zes_driver());
5757
}
5858

59+
std::vector<zes_device_handle_t> get_zes_devices(zes_driver_handle_t driver) {
60+
return get_zes_devices(get_zes_device_count(driver), driver);
61+
}
62+
5963
std::vector<zes_device_handle_t> get_zes_devices(uint32_t count,
6064
zes_driver_handle_t driver) {
6165
uint32_t count_out = count;

0 commit comments

Comments
 (0)