Skip to content

Commit 5c88341

Browse files
committed
Test: Add test cases to verify VR configuration and FanTable firmware flashing
1 parent 433ea9b commit 5c88341

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

conformance_tests/sysman/test_sysman_firmware/src/test_sysman_firmware.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ uint32_t get_prop_length(char *prop) { return std::strlen(prop); }
2929
class FirmwareZesTest : public lzt::ZesSysmanCtsClass {
3030
public:
3131
bool is_firmware_supported = false;
32+
bool is_VRConfig_supported = false;
33+
bool is_fantable_supported = false;
34+
3235
};
3336
#define FIRMWARE_TEST FirmwareZesTest
3437
#else // USE_ZESINIT
@@ -303,4 +306,108 @@ LZT_TEST_F(
303306
}
304307
}
305308

309+
LZT_TEST_F(
310+
FIRMWARE_TEST,
311+
GivenValidFanTableFirmwareHandleWhenFirmwareIsFlashedThenFlashingIsSuccessful) {
312+
auto fwDirEnv = getenv("ZE_LZT_FIRMWARE_DIRECTORY");
313+
if (nullptr == fwDirEnv) {
314+
LOG_INFO << "Skipping test as ZE_LZT_FIRMWARE_DIRECTORY not set";
315+
GTEST_SKIP();
316+
}
317+
std::vector<char> testFwImage;
318+
std::string fwDir(fwDirEnv);
319+
for (auto device : devices) {
320+
uint32_t count = lzt::get_firmware_handle_count(device);
321+
if (count > 0) {
322+
is_fantable_supported = true;
323+
LOG_INFO << "Fan table handles are available on this device!";
324+
auto firmware_handles = lzt::get_firmware_handles(device, count);
325+
zes_firmware_handle_t fan_table_handle = nullptr;
326+
for (auto fw_handle : firmware_handles) {
327+
zes_firmware_properties_t props = {
328+
ZES_STRUCTURE_TYPE_FIRMWARE_PROPERTIES};
329+
zesFirmwareGetProperties(fw_handle, &props);
330+
if (std::string(props.name) == "FanTable") {
331+
fan_table_handle = fw_handle;
332+
auto propFw = lzt::get_firmware_properties(fw_handle);
333+
if (propFw.canControl) {
334+
std::string fwName(reinterpret_cast<char *>(propFw.name));
335+
std::string fwToLoad = fwDir + "/" + fwName + ".bin";
336+
std::ifstream inFileStream(fwToLoad,
337+
std::ios::binary | std::ios::ate);
338+
if (!inFileStream.is_open()) {
339+
LOG_INFO << "Skipping test as firmware image not found";
340+
GTEST_SKIP();
341+
}
342+
testFwImage.resize(inFileStream.tellg());
343+
inFileStream.seekg(0, inFileStream.beg);
344+
inFileStream.read(testFwImage.data(), testFwImage.size());
345+
346+
lzt::flash_firmware(fan_table_handle,
347+
static_cast<void *>(testFwImage.data()),
348+
testFwImage.size());
349+
}
350+
}
351+
}
352+
} else {
353+
LOG_INFO << "No fan table handles found for this device!";
354+
}
355+
}
356+
if (!is_fantable_supported) {
357+
FAIL() << "No fan table handles found on any of the devices!";
358+
}
359+
}
360+
361+
LZT_TEST_F(
362+
FIRMWARE_TEST,
363+
GivenValidVRConfigFirmwareHandleWhenFirmwareIsFlashedThenFlashingIsSuccessful) {
364+
auto fwDirEnv = getenv("ZE_LZT_FIRMWARE_DIRECTORY");
365+
if (nullptr == fwDirEnv) {
366+
LOG_INFO << "Skipping test as ZE_LZT_FIRMWARE_DIRECTORY not set";
367+
GTEST_SKIP();
368+
}
369+
std::vector<char> testFwImage;
370+
std::string fwDir(fwDirEnv);
371+
for (auto device : devices) {
372+
uint32_t count = lzt::get_firmware_handle_count(device);
373+
if (count > 0) {
374+
is_VRConfig_supported = true;
375+
LOG_INFO << "VR Config handles are available on this device!";
376+
auto firmware_handles = lzt::get_firmware_handles(device, count);
377+
zes_firmware_handle_t vr_config_handle = nullptr;
378+
for (auto fw_handle : firmware_handles) {
379+
zes_firmware_properties_t props = {
380+
ZES_STRUCTURE_TYPE_FIRMWARE_PROPERTIES};
381+
zesFirmwareGetProperties(fw_handle, &props);
382+
if (std::string(props.name) == "FanTable") {
383+
vr_config_handle = fw_handle;
384+
auto propFw = lzt::get_firmware_properties(fw_handle);
385+
if (propFw.canControl) {
386+
std::string fwName(reinterpret_cast<char *>(propFw.name));
387+
std::string fwToLoad = fwDir + "/" + fwName + ".bin";
388+
std::ifstream inFileStream(fwToLoad,
389+
std::ios::binary | std::ios::ate);
390+
if (!inFileStream.is_open()) {
391+
LOG_INFO << "Skipping test as firmware image not found";
392+
GTEST_SKIP();
393+
}
394+
testFwImage.resize(inFileStream.tellg());
395+
inFileStream.seekg(0, inFileStream.beg);
396+
inFileStream.read(testFwImage.data(), testFwImage.size());
397+
398+
lzt::flash_firmware(vr_config_handle,
399+
static_cast<void *>(testFwImage.data()),
400+
testFwImage.size());
401+
}
402+
}
403+
}
404+
} else {
405+
LOG_INFO << "No VR config handles found for this device!";
406+
}
407+
}
408+
if (!is_VRConfig_supported) {
409+
FAIL() << "No VR Config handles found on any of the devices!";
410+
}
411+
}
412+
306413
} // namespace

0 commit comments

Comments
 (0)