Skip to content

Commit 800e115

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

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

conformance_tests/sysman/test_sysman_firmware/src/test_sysman_firmware.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ 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;
3234
};
3335
#define FIRMWARE_TEST FirmwareZesTest
3436
#else // USE_ZESINIT
@@ -303,4 +305,116 @@ LZT_TEST_F(
303305
}
304306
}
305307

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

0 commit comments

Comments
 (0)