@@ -29,12 +29,16 @@ 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 ;
3234};
3335#define FIRMWARE_TEST FirmwareZesTest
3436#else // USE_ZESINIT
3537class FirmwareTest : public lzt ::SysmanCtsClass {
3638public:
3739 bool is_firmware_supported = false ;
40+ bool is_VRConfig_supported = false ;
41+ bool is_fantable_supported = false ;
3842};
3943#define FIRMWARE_TEST FirmwareTest
4044#endif // USE_ZESINIT
@@ -303,4 +307,116 @@ LZT_TEST_F(
303307 }
304308}
305309
310+ LZT_TEST_F (
311+ FIRMWARE_TEST,
312+ GivenValidFanTableFirmwareHandleWhenFirmwareIsFlashedThenFlashingIsSuccessful) {
313+ auto fwDirEnv = getenv (" ZE_LZT_FIRMWARE_DIRECTORY" );
314+ if (nullptr == fwDirEnv) {
315+ LOG_INFO << " Skipping test as ZE_LZT_FIRMWARE_DIRECTORY not set" ;
316+ GTEST_SKIP ();
317+ }
318+ std::vector<char > testFwImage;
319+ std::string fwDir (fwDirEnv);
320+ for (auto device : devices) {
321+ uint32_t count = lzt::get_firmware_handle_count (device);
322+ auto firmware_handles = lzt::get_firmware_handles (device, count);
323+ zes_firmware_handle_t fan_table_handle = nullptr ;
324+ for (auto fw_handle : firmware_handles) {
325+ zes_firmware_properties_t props = {
326+ ZES_STRUCTURE_TYPE_FIRMWARE_PROPERTIES};
327+ zesFirmwareGetProperties (fw_handle, &props);
328+ if (std::string (props.name ) == " FanTable" ) {
329+ is_fantable_supported = true ;
330+ fan_table_handle = fw_handle;
331+ auto propFw = lzt::get_firmware_properties (fw_handle);
332+ if (propFw.canControl ) {
333+ std::string fwName (reinterpret_cast <char *>(propFw.name ));
334+ std::string fwToLoad = fwDir + " /" + fwName + " .bin" ;
335+ std::ifstream inFileStream (fwToLoad,
336+ std::ios::binary | std::ios::ate);
337+ if (!inFileStream.is_open ()) {
338+ LOG_INFO << " Skipping test as firmware image not found" ;
339+ GTEST_SKIP ();
340+ }
341+ testFwImage.resize (inFileStream.tellg ());
342+ inFileStream.seekg (0 , inFileStream.beg );
343+ inFileStream.read (testFwImage.data (), testFwImage.size ());
344+
345+ lzt::flash_firmware (fan_table_handle,
346+ static_cast <void *>(testFwImage.data ()),
347+ testFwImage.size ());
348+ }
349+ }
350+ }
351+
352+ if (!is_fantable_supported) {
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 (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