@@ -29,6 +29,9 @@ uint32_t get_prop_length(char *prop) { return std::strlen(prop); }
2929class FirmwareZesTest : public lzt ::ZesSysmanCtsClass {
3030public:
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,117 @@ 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+
361+ LZT_TEST_F (
362+ FIRMWARE_TEST,
363+ GivenValidVRConfigFirmwareHandleWhenFirmwareIsFlashedThenFlashingIsSuccessful) {
364+ auto fwDirEnv = getenv (" ZE_LZT_FIRMWARE_DIRECTORY" );
365+ if (fwDirEnv == nullptr ) {
366+ LOG_INFO << " Skipping test as ZE_LZT_FIRMWARE_DIRECTORY not set" ;
367+ GTEST_SKIP ();
368+ }
369+
370+ std::vector<char > testFwImage;
371+ std::string fwDir (fwDirEnv);
372+
373+ for (auto device : devices) {
374+ uint32_t count = lzt::get_firmware_handle_count (device);
375+ auto firmware_handles = lzt::get_firmware_handles (device, count);
376+
377+ zes_firmware_handle_t vr_config_handle = nullptr ;
378+
379+ for (auto fw_handle : firmware_handles) {
380+ zes_firmware_properties_t props = {
381+ ZES_STRUCTURE_TYPE_FIRMWARE_PROPERTIES};
382+ zesFirmwareGetProperties (fw_handle, &props);
383+
384+ if (std::string (props.name ) == " VRConfig" ) {
385+ is_VRConfig_supported = true ;
386+ vr_config_handle = fw_handle;
387+
388+ auto propFw = lzt::get_firmware_properties (fw_handle);
389+ if (propFw.canControl ) {
390+ std::string fwName (reinterpret_cast <char *>(propFw.name ));
391+ std::string fwToLoad = fwDir + " /" + fwName + " .bin" ;
392+
393+ std::ifstream inFileStream (fwToLoad,
394+ std::ios::binary | std::ios::ate);
395+
396+ if (!inFileStream.is_open ()) {
397+ LOG_INFO << " Skipping test as firmware image not found" ;
398+ GTEST_SKIP ();
399+ }
400+
401+ testFwImage.resize (static_cast <size_t >(inFileStream.tellg ()));
402+ inFileStream.seekg (0 , std::ios::beg);
403+ inFileStream.read (testFwImage.data (),
404+ static_cast <std::streamsize>(testFwImage.size ()));
405+
406+ lzt::flash_firmware (vr_config_handle,
407+ static_cast <void *>(testFwImage.data ()),
408+ static_cast <uint32_t >(testFwImage.size ()));
409+ }
410+ }
411+ }
412+
413+ if (!is_VRConfig_supported) {
414+ LOG_INFO << " No VRConfig handles found for this device!" ;
415+ }
416+ }
417+
418+ if (!is_VRConfig_supported) {
419+ FAIL () << " No VRConfig handles found on any of the devices!" ;
420+ }
421+ }
306422} // namespace
0 commit comments