Skip to content

Commit 7027d05

Browse files
authored
Fix: Handling GTEST_FAIL logic for multi-device scenario for LED, Memory and Firmware modules (#267)
* Primary JIRA: VLCJ-2513 Sub-tasks: VLCLJ-2572, VLCLJ-2575, VLCLJ-2564 Signed-off-by: viki435 <[email protected]>
1 parent 7298f8d commit 7027d05

File tree

3 files changed

+482
-341
lines changed

3 files changed

+482
-341
lines changed

conformance_tests/sysman/test_sysman_firmware/src/test_sysman_firmware.cpp

Lines changed: 134 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ namespace {
2626
uint32_t get_prop_length(char *prop) { return std::strlen(prop); }
2727

2828
#ifdef USE_ZESINIT
29-
class FirmwareZesTest : public lzt::ZesSysmanCtsClass {};
29+
class FirmwareZesTest : public lzt::ZesSysmanCtsClass {
30+
public:
31+
bool is_firmware_supported = false;
32+
};
3033
#define FIRMWARE_TEST FirmwareZesTest
3134
#else // USE_ZESINIT
32-
class FirmwareTest : public lzt::SysmanCtsClass {};
35+
class FirmwareTest : public lzt::SysmanCtsClass {
36+
public:
37+
bool is_firmware_supported = false;
38+
};
3339
#define FIRMWARE_TEST FirmwareTest
3440
#endif // USE_ZESINIT
3541

@@ -39,44 +45,59 @@ LZT_TEST_F(
3945
for (auto device : devices) {
4046
uint32_t count = 0;
4147
count = lzt::get_firmware_handle_count(device);
42-
if (count == 0) {
43-
FAIL() << "No handles found: "
44-
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
48+
if (count > 0) {
49+
is_firmware_supported = true;
50+
LOG_INFO << "Firmware handles are available on this device! ";
51+
} else {
52+
LOG_INFO << "No firmware handles found for this device! ";
4553
}
4654
}
55+
if (!is_firmware_supported) {
56+
FAIL() << "No firmware handles found on any of the devices! ";
57+
}
4758
}
4859
LZT_TEST_F(
4960
FIRMWARE_TEST,
5061
GivenComponentCountZeroWhenRetrievingFirmwareHandlesThenNotNullFirmwareHandlesAreReturned) {
5162
for (auto device : devices) {
5263
uint32_t count = 0;
53-
auto firmware_handles = lzt::get_firmware_handles(device, count);
54-
if (count == 0) {
55-
FAIL() << "No handles found: "
56-
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
57-
}
58-
59-
ASSERT_EQ(firmware_handles.size(), count);
60-
for (auto firmware_handle : firmware_handles) {
61-
ASSERT_NE(nullptr, firmware_handle);
64+
count = lzt::get_firmware_handle_count(device);
65+
if (count > 0) {
66+
is_firmware_supported = true;
67+
LOG_INFO << "Firmware handles are available on this device! ";
68+
auto firmware_handles = lzt::get_firmware_handles(device, count);
69+
ASSERT_EQ(firmware_handles.size(), count);
70+
for (auto firmware_handle : firmware_handles) {
71+
ASSERT_NE(nullptr, firmware_handle);
72+
}
73+
} else {
74+
LOG_INFO << "No firmware handles found for this device! ";
6275
}
6376
}
77+
if (!is_firmware_supported) {
78+
FAIL() << "No firmware handles found on any of the devices! ";
79+
}
6480
}
6581

6682
LZT_TEST_F(
6783
FIRMWARE_TEST,
6884
GivenInvalidComponentCountWhenRetrievingSysmanFirmwareHandlesThenActualComponentCountIsUpdated) {
6985
for (auto device : devices) {
7086
uint32_t actual_count = 0;
71-
auto firmware_handles = lzt::get_firmware_handles(device, actual_count);
72-
if (actual_count == 0) {
73-
FAIL() << "No handles found: "
74-
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
87+
actual_count = lzt::get_firmware_handle_count(device);
88+
if (actual_count > 0) {
89+
is_firmware_supported = true;
90+
LOG_INFO << "Firmware handles are available on this device! ";
91+
auto firmware_handles = lzt::get_firmware_handles(device, actual_count);
92+
uint32_t test_count = actual_count + 1;
93+
firmware_handles = lzt::get_firmware_handles(device, test_count);
94+
EXPECT_EQ(test_count, actual_count);
95+
} else {
96+
LOG_INFO << "No firmware handles found for this device! ";
7597
}
76-
77-
uint32_t test_count = actual_count + 1;
78-
firmware_handles = lzt::get_firmware_handles(device, test_count);
79-
EXPECT_EQ(test_count, actual_count);
98+
}
99+
if (!is_firmware_supported) {
100+
FAIL() << "No firmware handles found on any of the devices! ";
80101
}
81102
}
82103
LZT_TEST_F(
@@ -85,53 +106,66 @@ LZT_TEST_F(
85106
for (auto device : devices) {
86107
auto deviceProperties = lzt::get_sysman_device_properties(device);
87108
uint32_t count = 0;
88-
auto firmware_handles = lzt::get_firmware_handles(device, count);
89-
if (count == 0) {
90-
FAIL() << "No handles found: "
91-
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
92-
}
93-
94-
for (auto firmware_handle : firmware_handles) {
95-
ASSERT_NE(nullptr, firmware_handle);
96-
auto properties = lzt::get_firmware_properties(firmware_handle);
97-
if (properties.onSubdevice) {
98-
EXPECT_LT(properties.subdeviceId, deviceProperties.numSubdevices);
109+
count = lzt::get_firmware_handle_count(device);
110+
if (count > 0) {
111+
is_firmware_supported = true;
112+
LOG_INFO << "Firmware handles are available on this device! ";
113+
auto firmware_handles = lzt::get_firmware_handles(device, count);
114+
for (auto firmware_handle : firmware_handles) {
115+
ASSERT_NE(nullptr, firmware_handle);
116+
auto properties = lzt::get_firmware_properties(firmware_handle);
117+
if (properties.onSubdevice) {
118+
EXPECT_LT(properties.subdeviceId, deviceProperties.numSubdevices);
119+
}
120+
EXPECT_LT(get_prop_length(properties.name), ZES_STRING_PROPERTY_SIZE);
121+
EXPECT_GT(get_prop_length(properties.name), 0);
122+
EXPECT_LT(get_prop_length(properties.version),
123+
ZES_STRING_PROPERTY_SIZE);
99124
}
100-
EXPECT_LT(get_prop_length(properties.name), ZES_STRING_PROPERTY_SIZE);
101-
EXPECT_GT(get_prop_length(properties.name), 0);
102-
EXPECT_LT(get_prop_length(properties.version), ZES_STRING_PROPERTY_SIZE);
125+
} else {
126+
LOG_INFO << "No firmware handles found for this device! ";
103127
}
104128
}
129+
if (!is_firmware_supported) {
130+
FAIL() << "No firmware handles found on any of the devices! ";
131+
}
105132
}
106133

107134
LZT_TEST_F(
108135
FIRMWARE_TEST,
109136
GivenValidFirmwareHandleWhenRetrievingFirmwarePropertiesThenExpectSamePropertiesReturnedTwice) {
110137
for (auto device : devices) {
111138
uint32_t count = 0;
112-
auto firmware_handles = lzt::get_firmware_handles(device, count);
113-
if (count == 0) {
114-
FAIL() << "No handles found: "
115-
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
116-
}
117-
118-
for (auto firmware_handle : firmware_handles) {
119-
ASSERT_NE(nullptr, firmware_handle);
120-
auto properties_initial = lzt::get_firmware_properties(firmware_handle);
121-
auto properties_later = lzt::get_firmware_properties(firmware_handle);
122-
EXPECT_EQ(properties_initial.onSubdevice, properties_later.onSubdevice);
123-
if (properties_initial.onSubdevice && properties_later.onSubdevice) {
124-
EXPECT_EQ(properties_initial.subdeviceId, properties_later.subdeviceId);
139+
count = lzt::get_firmware_handle_count(device);
140+
if (count > 0) {
141+
is_firmware_supported = true;
142+
LOG_INFO << "Firmware handles are available on this device! ";
143+
auto firmware_handles = lzt::get_firmware_handles(device, count);
144+
for (auto firmware_handle : firmware_handles) {
145+
ASSERT_NE(nullptr, firmware_handle);
146+
auto properties_initial = lzt::get_firmware_properties(firmware_handle);
147+
auto properties_later = lzt::get_firmware_properties(firmware_handle);
148+
EXPECT_EQ(properties_initial.onSubdevice, properties_later.onSubdevice);
149+
if (properties_initial.onSubdevice && properties_later.onSubdevice) {
150+
EXPECT_EQ(properties_initial.subdeviceId,
151+
properties_later.subdeviceId);
152+
}
153+
EXPECT_TRUE(
154+
0 == std::strcmp(reinterpret_cast<char *>(properties_initial.name),
155+
reinterpret_cast<char *>(properties_later.name)));
156+
EXPECT_TRUE(
157+
0 ==
158+
std::strcmp(reinterpret_cast<char *>(properties_initial.version),
159+
reinterpret_cast<char *>(properties_later.version)));
160+
EXPECT_EQ(properties_initial.canControl, properties_later.canControl);
125161
}
126-
EXPECT_TRUE(0 ==
127-
std::strcmp(reinterpret_cast<char *>(properties_initial.name),
128-
reinterpret_cast<char *>(properties_later.name)));
129-
EXPECT_TRUE(
130-
0 == std::strcmp(reinterpret_cast<char *>(properties_initial.version),
131-
reinterpret_cast<char *>(properties_later.version)));
132-
EXPECT_EQ(properties_initial.canControl, properties_later.canControl);
162+
} else {
163+
LOG_INFO << "No firmware handles found for this device! ";
133164
}
134165
}
166+
if (!is_firmware_supported) {
167+
FAIL() << "No firmware handles found on any of the devices! ";
168+
}
135169
}
136170

137171
LZT_TEST_F(
@@ -146,32 +180,38 @@ LZT_TEST_F(
146180
std::string fwDir(fwDirEnv);
147181
for (auto device : devices) {
148182
uint32_t count = 0;
149-
auto firmware_handles = lzt::get_firmware_handles(device, count);
150-
if (count == 0) {
151-
FAIL() << "No handles found: "
152-
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
153-
}
154-
155-
for (auto firmware_handle : firmware_handles) {
156-
ASSERT_NE(nullptr, firmware_handle);
157-
auto propFw = lzt::get_firmware_properties(firmware_handle);
158-
if (propFw.canControl == true) {
159-
std::string fwName(reinterpret_cast<char *>(propFw.name));
160-
std::string fwToLoad = fwDir + "/" + fwName + ".bin";
161-
std::ifstream inFileStream(fwToLoad, std::ios::binary | std::ios::ate);
162-
if (!inFileStream.is_open()) {
163-
LOG_INFO << "Skipping test as firmware image not found";
164-
GTEST_SKIP();
183+
count = lzt::get_firmware_handle_count(device);
184+
if (count > 0) {
185+
is_firmware_supported = true;
186+
LOG_INFO << "Firmware handles are available on this device! ";
187+
auto firmware_handles = lzt::get_firmware_handles(device, count);
188+
for (auto firmware_handle : firmware_handles) {
189+
ASSERT_NE(nullptr, firmware_handle);
190+
auto propFw = lzt::get_firmware_properties(firmware_handle);
191+
if (propFw.canControl == true) {
192+
std::string fwName(reinterpret_cast<char *>(propFw.name));
193+
std::string fwToLoad = fwDir + "/" + fwName + ".bin";
194+
std::ifstream inFileStream(fwToLoad,
195+
std::ios::binary | std::ios::ate);
196+
if (!inFileStream.is_open()) {
197+
LOG_INFO << "Skipping test as firmware image not found";
198+
GTEST_SKIP();
199+
}
200+
testFwImage.resize(inFileStream.tellg());
201+
inFileStream.seekg(0, inFileStream.beg);
202+
inFileStream.read(testFwImage.data(), testFwImage.size());
203+
lzt::flash_firmware(firmware_handle,
204+
static_cast<void *>(testFwImage.data()),
205+
testFwImage.size());
165206
}
166-
testFwImage.resize(inFileStream.tellg());
167-
inFileStream.seekg(0, inFileStream.beg);
168-
inFileStream.read(testFwImage.data(), testFwImage.size());
169-
lzt::flash_firmware(firmware_handle,
170-
static_cast<void *>(testFwImage.data()),
171-
testFwImage.size());
172207
}
208+
} else {
209+
LOG_INFO << "No firmware handles found for this device! ";
173210
}
174211
}
212+
if (!is_firmware_supported) {
213+
FAIL() << "No firmware handles found on any of the devices! ";
214+
}
175215
}
176216

177217
void flash_firmware(zes_firmware_handle_t firmware_handle, std::string fw_dir) {
@@ -243,20 +283,24 @@ LZT_TEST_F(
243283
std::string fw_dir(fw_dir_env);
244284
for (auto device : devices) {
245285
uint32_t count = 0;
246-
auto firmware_handles = lzt::get_firmware_handles(device, count);
247-
if (count == 0) {
248-
FAIL() << "No handles found: "
249-
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
250-
}
251-
252-
for (auto firmware_handle : firmware_handles) {
253-
std::thread firmware_flasher(flash_firmware, firmware_handle, fw_dir);
254-
std::thread progress_tracker(track_firmware_flash, firmware_handle);
255-
256-
firmware_flasher.join();
257-
progress_tracker.join();
286+
count = lzt::get_firmware_handle_count(device);
287+
if (count > 0) {
288+
is_firmware_supported = true;
289+
LOG_INFO << "Firmware handles are available on this device! ";
290+
auto firmware_handles = lzt::get_firmware_handles(device, count);
291+
for (auto firmware_handle : firmware_handles) {
292+
std::thread firmware_flasher(flash_firmware, firmware_handle, fw_dir);
293+
std::thread progress_tracker(track_firmware_flash, firmware_handle);
294+
firmware_flasher.join();
295+
progress_tracker.join();
296+
}
297+
} else {
298+
LOG_INFO << "No firmware handles found for this device! ";
258299
}
259300
}
301+
if (!is_firmware_supported) {
302+
FAIL() << "No firmware handles found on any of the devices! ";
303+
}
260304
}
261305

262306
} // namespace

0 commit comments

Comments
 (0)