Skip to content

Commit e27fdce

Browse files
Add CTS for Sysmandevicemapping to verify UUID's (#62)
* zesDeviceGetSubDevicePropertiesExp is used to retrieve Subdevice UUID's. * Sysman UUID's are compared with Core UUID's (FLAT Mode) Related-To: VLCLJ-2256 Signed-off-by: Vishnu Khanth <[email protected]>
1 parent b4fd275 commit e27fdce

File tree

2 files changed

+103
-44
lines changed

2 files changed

+103
-44
lines changed

conformance_tests/sysman/test_sysman_device/src/test_sysman_device.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ TEST_F(
143143
putenv(enable_sysman_env);
144144
}
145145
}
146+
147+
TEST_F(
148+
SYSMAN_DEVICE_TEST,
149+
GivenHierarchyModeFlatAndSysmanEnableEnvDisabledThenUUIDFromCoreAndSysmanMatches) {
150+
auto is_sysman_enabled = getenv("ZES_ENABLE_SYSMAN");
151+
// Disabling enable_sysman env if it's defaultly enabled
152+
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
153+
char disable_sysman_env[] = "ZES_ENABLE_SYSMAN=0";
154+
putenv(disable_sysman_env);
155+
}
156+
run_child_process("FLAT");
157+
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
158+
char enable_sysman_env[] = "ZES_ENABLE_SYSMAN=1";
159+
putenv(enable_sysman_env);
160+
}
161+
}
146162
#endif // USE_ZESINIT
147163

148164
TEST_F(
Lines changed: 87 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023 Intel Corporation
3+
* Copyright (C) 2023-2024 Intel Corporation
44
*
55
* SPDX-License-Identifier: MIT
66
*
@@ -12,43 +12,68 @@
1212

1313
namespace lzt = level_zero_tests;
1414

15-
void get_sysman_devices_uuids(std::vector<zes_device_handle_t> sysman_devices,
16-
std::vector<zes_uuid_t> &sysman_device_uuids) {
17-
for (const auto &sysman_device : sysman_devices) {
18-
zes_device_properties_t properties = {ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES};
19-
zes_device_ext_properties_t ext_properties = {
20-
ZES_STRUCTURE_TYPE_DEVICE_EXT_PROPERTIES};
21-
properties.pNext = &ext_properties;
22-
ze_result_t result = zesDeviceGetProperties(sysman_device, &properties);
23-
auto sysman_device_uuid = ext_properties.uuid;
24-
sysman_device_uuids.push_back(sysman_device_uuid);
15+
typedef std::array<uint8_t, ZE_MAX_DEVICE_UUID_SIZE> UUID;
16+
17+
#define TO_STD_ARRAY(x) \
18+
[](const uint8_t(&arr)[ZE_MAX_DEVICE_UUID_SIZE]) { \
19+
UUID uuid; \
20+
std::copy(std::begin(arr), std::end(arr), uuid.begin()); \
21+
return uuid; \
22+
}(x)
23+
24+
UUID get_sysman_device_uuid(zes_device_handle_t sysman_device) {
25+
zes_device_properties_t properties = {ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES};
26+
zes_device_ext_properties_t ext_properties = {
27+
ZES_STRUCTURE_TYPE_DEVICE_EXT_PROPERTIES};
28+
properties.pNext = &ext_properties;
29+
EXPECT_EQ(ZE_RESULT_SUCCESS,
30+
zesDeviceGetProperties(sysman_device, &properties));
31+
auto sysman_device_uuid = ext_properties.uuid;
32+
return TO_STD_ARRAY(sysman_device_uuid.id);
33+
}
34+
35+
void get_sysman_sub_devices_uuids(zes_device_handle_t sysman_device,
36+
std::vector<UUID> &sysman_device_uuids) {
37+
uint32_t num_sub_devices = 0;
38+
auto sub_device_properties =
39+
lzt::get_sysman_subdevice_properties(sysman_device, num_sub_devices);
40+
for (uint32_t sub_device_index = 0; sub_device_index < num_sub_devices;
41+
sub_device_index++) {
42+
sysman_device_uuids.push_back(
43+
TO_STD_ARRAY(sub_device_properties[sub_device_index].uuid.id));
2544
}
2645
}
2746

28-
void get_ze_root_uuids(std::vector<ze_device_handle_t> ze_devices,
29-
std::vector<ze_device_uuid_t> &ze_root_uuids,
30-
char *device_hierarchy) {
31-
for (const auto &ze_device : ze_devices) {
32-
ze_device_handle_t ze_root_device;
33-
if (strcmp(device_hierarchy, "COMBINED") == 0) {
34-
ze_root_device = lzt::get_root_device(ze_device);
35-
if (ze_root_device == nullptr) {
36-
ze_root_device = ze_device;
37-
}
38-
} else if (strcmp(device_hierarchy, "COMPOSITE") == 0) {
47+
UUID get_ze_device_uuid(ze_device_handle_t ze_device) {
48+
auto ze_device_properties = lzt::get_device_properties(ze_device);
49+
auto ze_device_uuid = ze_device_properties.uuid;
50+
return TO_STD_ARRAY(ze_device_uuid.id);
51+
}
52+
53+
UUID get_ze_root_uuid(ze_device_handle_t ze_device, char *device_hierarchy) {
54+
ze_device_handle_t ze_root_device;
55+
if (strcmp(device_hierarchy, "COMBINED") == 0) {
56+
ze_root_device = lzt::get_root_device(ze_device);
57+
if (ze_root_device == nullptr) {
3958
ze_root_device = ze_device;
40-
} else {
41-
LOG_WARNING << "Unhandled ZE_FLAT_DEVICE_HIERARCHY mode:"
42-
<< device_hierarchy;
43-
continue;
44-
}
45-
auto root_device_properties = lzt::get_device_properties(ze_root_device);
46-
auto root_uuid = root_device_properties.uuid;
47-
if (std::find(ze_root_uuids.begin(), ze_root_uuids.end(), root_uuid) ==
48-
ze_root_uuids.end()) {
49-
ze_root_uuids.push_back(root_uuid);
5059
}
60+
} else if (strcmp(device_hierarchy, "COMPOSITE") == 0) {
61+
ze_root_device = ze_device;
62+
} else {
63+
LOG_WARNING << "Unhandled ZE_FLAT_DEVICE_HIERARCHY mode:"
64+
<< device_hierarchy;
5165
}
66+
67+
return get_ze_device_uuid(ze_root_device);
68+
}
69+
70+
bool compare_core_and_sysman_uuid(std::vector<UUID> core_uuids,
71+
std::vector<UUID> sysman_uuids) {
72+
std::sort(core_uuids.begin(), core_uuids.end());
73+
std::sort(sysman_uuids.begin(), sysman_uuids.end());
74+
return (
75+
core_uuids.size() == sysman_uuids.size() &&
76+
std::equal(core_uuids.begin(), core_uuids.end(), sysman_uuids.begin()));
5277
}
5378

5479
int main(int argc, char **argv) {
@@ -74,23 +99,41 @@ int main(int argc, char **argv) {
7499
auto sysman_devices = lzt::get_zes_devices();
75100
EXPECT_FALSE(sysman_devices.empty());
76101

77-
std::vector<zes_uuid_t> sysman_device_uuids;
78-
get_sysman_devices_uuids(sysman_devices, sysman_device_uuids);
102+
std::vector<UUID> sysman_device_uuids{};
103+
std::vector<UUID> ze_device_uuids{};
79104

80-
std::vector<ze_device_uuid_t> ze_root_uuids;
81-
get_ze_root_uuids(ze_devices, ze_root_uuids, device_hierarchy);
105+
if (strcmp(device_hierarchy, "FLAT") != 0) { // composite or combined mode
106+
for (const auto &sysman_device : sysman_devices) {
107+
sysman_device_uuids.push_back(get_sysman_device_uuid(sysman_device));
108+
}
82109

83-
for (const auto &ze_root_uuid : ze_root_uuids) {
84-
bool ze_and_sysman_uuid_equal = false;
85-
for (const auto &sysman_device_uuid : sysman_device_uuids) {
86-
if (memcmp(ze_root_uuid.id, sysman_device_uuid.id,
87-
ZE_MAX_DEVICE_UUID_SIZE) == false) {
88-
ze_and_sysman_uuid_equal = true;
89-
break;
110+
for (const auto &ze_device : ze_devices) {
111+
auto ze_root_uuid = get_ze_root_uuid(ze_device, device_hierarchy);
112+
if (std::find(ze_device_uuids.begin(), ze_device_uuids.end(),
113+
ze_root_uuid) == ze_device_uuids.end()) {
114+
ze_device_uuids.push_back(ze_root_uuid);
115+
}
116+
}
117+
} else { // flat mode
118+
for (const auto &sysman_device : sysman_devices) {
119+
auto device_properties = lzt::get_sysman_device_properties(sysman_device);
120+
uint32_t sub_devices_count = device_properties.numSubdevices;
121+
if (sub_devices_count > 0) {
122+
get_sysman_sub_devices_uuids(sysman_device, sysman_device_uuids);
123+
} else {
124+
// if subdevice doesn't exist for a device, then root device UUID
125+
// is retrieved to match with core UUID's retrieved from flat mode
126+
sysman_device_uuids.push_back(get_sysman_device_uuid(sysman_device));
90127
}
91128
}
92-
EXPECT_TRUE(ze_and_sysman_uuid_equal);
129+
130+
for (const auto &ze_device : ze_devices) {
131+
ze_device_uuids.push_back(get_ze_device_uuid(ze_device));
132+
}
93133
}
94134

135+
EXPECT_TRUE(
136+
compare_core_and_sysman_uuid(ze_device_uuids, sysman_device_uuids));
137+
95138
exit(0);
96139
}

0 commit comments

Comments
 (0)