From 3efa0330f494d75507f5d05881f985a376690f1e Mon Sep 17 00:00:00 2001 From: Pichika Uday Kiran Date: Thu, 14 Oct 2021 10:39:09 +0000 Subject: [PATCH] firmware: Avoid adding the FWtype if already exists in vector - Avoid adding the duplicate FWtypes in case of multi GPU devices Related-To: LOCI-2623 Signed-off-by: Pichika Uday Kiran --- .../sysman/firmware/linux/os_firmware_imp.cpp | 4 +++- .../firmware/linux/mock_zes_sysman_firmware.h | 5 +++++ .../firmware/linux/test_zes_sysman_firmware.cpp | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/level_zero/tools/source/sysman/firmware/linux/os_firmware_imp.cpp b/level_zero/tools/source/sysman/firmware/linux/os_firmware_imp.cpp index 7b805c3a38..0704ebfeb3 100644 --- a/level_zero/tools/source/sysman/firmware/linux/os_firmware_imp.cpp +++ b/level_zero/tools/source/sysman/firmware/linux/os_firmware_imp.cpp @@ -27,7 +27,9 @@ ze_result_t OsFirmware::getSupportedFwTypes(std::vector &supportedF for (const auto &readByteLine : mtdDescriptorStrings) { for (const auto &fwType : deviceSupportedFwTypes) { if (std::string::npos != readByteLine.find(fwType)) { - supportedFwTypes.push_back(fwType); + if (std::find(supportedFwTypes.begin(), supportedFwTypes.end(), fwType) == supportedFwTypes.end()) { + supportedFwTypes.push_back(fwType); + } } } } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/mock_zes_sysman_firmware.h b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/mock_zes_sysman_firmware.h index 8d93fab27d..774f2a15a2 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/mock_zes_sysman_firmware.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/mock_zes_sysman_firmware.h @@ -30,6 +30,11 @@ struct Mock : public FirmwareFsAccess { val.push_back("mtd5: 00200000 00001000 \"i915-spi.42.auto.OptionROM\""); return ZE_RESULT_SUCCESS; } + ze_result_t readMtdValSuccess(const std::string file, std::vector &val) { + val.push_back("mtd3: 005ef000 00001000 \"i915-spi.42.auto.GSC\""); + val.push_back("mtd3: 005ef000 00001000 \"i915-spi.42.auto.GSC\""); + return ZE_RESULT_SUCCESS; + } ze_result_t readValFailure(const std::string file, std::vector &val) { return ZE_RESULT_ERROR_NOT_AVAILABLE; } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp index cb1214255c..0dba0d0847 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp @@ -146,6 +146,19 @@ TEST_F(ZesFirmwareFixture, GivenFailedFirmwareInitializationWhenInitializingFirm EXPECT_EQ(0u, pSysmanDeviceImp->pFirmwareHandleContext->handleList.size()); } +TEST_F(ZesFirmwareFixture, GivenRepeatedFWTypesWhenInitializingFirmwareContextThenexpectNoHandles) { + for (const auto &handle : pSysmanDeviceImp->pFirmwareHandleContext->handleList) { + delete handle; + } + pSysmanDeviceImp->pFirmwareHandleContext->handleList.clear(); + ON_CALL(*pFsAccess.get(), read(_, _)) + .WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock::readMtdValSuccess)); + + pSysmanDeviceImp->pFirmwareHandleContext->init(); + + EXPECT_EQ(1u, pSysmanDeviceImp->pFirmwareHandleContext->handleList.size()); +} + TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleWhenFlashingGscFirmwareThenSuccessIsReturned) { FirmwareImp *ptestFirmwareImp = new FirmwareImp(pSysmanDeviceImp->pFirmwareHandleContext->pOsSysman, mockSupportedFwTypes[0]); pSysmanDeviceImp->pFirmwareHandleContext->handleList.push_back(ptestFirmwareImp);