Skip to content

Commit b03b128

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

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+
auto firmware_handles = lzt::get_firmware_handles(device, count);
322+
zes_firmware_handle_t fan_table_handle = nullptr;
323+
for (auto fw_handle : firmware_handles) {
324+
zes_firmware_properties_t props = {
325+
ZES_STRUCTURE_TYPE_FIRMWARE_PROPERTIES};
326+
zesFirmwareGetProperties(fw_handle, &props);
327+
if (std::string(props.name) == "FanTable") {
328+
is_fantable_supported = true;
329+
fan_table_handle = fw_handle;
330+
auto propFw = lzt::get_firmware_properties(fw_handle);
331+
if (propFw.canControl) {
332+
std::string fwName(reinterpret_cast<char *>(propFw.name));
333+
std::string fwToLoad = fwDir + "/" + fwName + ".bin";
334+
std::ifstream inFileStream(fwToLoad,
335+
std::ios::binary | std::ios::ate);
336+
if (!inFileStream.is_open()) {
337+
LOG_INFO << "Skipping test as firmware image not found";
338+
GTEST_SKIP();
339+
}
340+
testFwImage.resize(inFileStream.tellg());
341+
inFileStream.seekg(0, inFileStream.beg);
342+
inFileStream.read(testFwImage.data(), testFwImage.size());
343+
344+
lzt::flash_firmware(fan_table_handle,
345+
static_cast<void *>(testFwImage.data()),
346+
testFwImage.size());
347+
}
348+
}
349+
}
350+
351+
if (!is_fantable_supported) {
352+
LOG_INFO << "No fan table handles found for this device!";
353+
}
354+
}
355+
if (!is_fantable_supported) {
356+
FAIL() << "No fan table handles found on any of the devices!";
357+
}
358+
}
359+
360+
LZT_TEST_F(
361+
FIRMWARE_TEST,
362+
GivenValidVRConfigFirmwareHandleWhenFirmwareIsFlashedThenFlashingIsSuccessful) {
363+
auto fwDirEnv = getenv("ZE_LZT_FIRMWARE_DIRECTORY");
364+
if (nullptr == fwDirEnv) {
365+
LOG_INFO << "Skipping test as ZE_LZT_FIRMWARE_DIRECTORY not set";
366+
GTEST_SKIP();
367+
}
368+
std::vector<char> testFwImage;
369+
std::string fwDir(fwDirEnv);
370+
for (auto device : devices) {
371+
uint32_t count = lzt::get_firmware_handle_count(device);
372+
if (count > 0) {
373+
is_VRConfig_supported = true;
374+
LOG_INFO << "VR Config handles are available on this device!";
375+
auto firmware_handles = lzt::get_firmware_handles(device, count);
376+
zes_firmware_handle_t vr_config_handle = nullptr;
377+
for (auto fw_handle : firmware_handles) {
378+
zes_firmware_properties_t props = {
379+
ZES_STRUCTURE_TYPE_FIRMWARE_PROPERTIES};
380+
zesFirmwareGetProperties(fw_handle, &props);
381+
if (std::string(props.name) == "VRConfig") {
382+
is_VRConfig_supported = true;
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)