Sysman Fix FirmwareUtil Cleanup
Fixed by avoiding library function access if library is unavailable. Related-To: LOCI-2719 Signed-off-by: Ranjan, Joshua Santhosh <joshua.santosh.ranjan@intel.com>
This commit is contained in:
parent
b813171797
commit
5a2a19fa1a
|
@ -180,8 +180,8 @@ FirmwareUtilImp::FirmwareUtilImp(const std::string &pciBDF) {
|
|||
};
|
||||
|
||||
FirmwareUtilImp::~FirmwareUtilImp() {
|
||||
deviceClose(&fwDeviceHandle);
|
||||
if (nullptr != libraryHandle) {
|
||||
deviceClose(&fwDeviceHandle);
|
||||
delete libraryHandle;
|
||||
libraryHandle = nullptr;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(igsc_FOUND)
|
||||
set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL_TEST
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_fw_util.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
|
@ -11,6 +17,7 @@ if(UNIX)
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysman_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_procfs_access_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysfs_access_fixture.h
|
||||
${L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL_TEST}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -36,5 +36,17 @@ struct MockLinuxFwUtilInterface : public LinuxFwUtilInterface {
|
|||
ADDMETHOD_NOBASE_VOIDRETURN(getDeviceSupportedFwTypes, (std::vector<std::string> & fwTypes));
|
||||
};
|
||||
|
||||
class LinuxOsLibrary : public OsLibrary {};
|
||||
struct MockOsLibrary : public LinuxOsLibrary {
|
||||
public:
|
||||
virtual ~MockOsLibrary() = default;
|
||||
void *getProcAddress(const std::string &procName) override {
|
||||
return nullptr;
|
||||
}
|
||||
bool isLoaded() override {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.h"
|
||||
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
|
||||
|
||||
extern bool sysmanUltsEnable;
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
static uint32_t mockFwUtilDeviceCloseCallCount = 0;
|
||||
|
||||
TEST(LinuxFwUtilDeleteTest, GivenLibraryWasNotSetWhenFirmwareUtilInterfaceIsDeletedThenLibraryFunctionIsNotAccessed) {
|
||||
|
||||
mockFwUtilDeviceCloseCallCount = 0;
|
||||
|
||||
if (!sysmanUltsEnable) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
VariableBackup<decltype(deviceClose)> mockDeviceClose(&deviceClose, [](struct igsc_device_handle *handle) -> int {
|
||||
mockFwUtilDeviceCloseCallCount++;
|
||||
return 0;
|
||||
});
|
||||
|
||||
std::string pciBdf("0000:00:00.0");
|
||||
FirmwareUtilImp *pFwUtilImp = new FirmwareUtilImp(pciBdf);
|
||||
pFwUtilImp->libraryHandle = nullptr;
|
||||
delete pFwUtilImp;
|
||||
EXPECT_EQ(mockFwUtilDeviceCloseCallCount, 0u);
|
||||
}
|
||||
|
||||
TEST(LinuxFwUtilDeleteTest, GivenLibraryWasSetWhenFirmwareUtilInterfaceIsDeletedThenLibraryFunctionIsAccessed) {
|
||||
|
||||
mockFwUtilDeviceCloseCallCount = 0;
|
||||
|
||||
if (!sysmanUltsEnable) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
VariableBackup<decltype(deviceClose)> mockDeviceClose(&deviceClose, [](struct igsc_device_handle *handle) -> int {
|
||||
mockFwUtilDeviceCloseCallCount++;
|
||||
return 0;
|
||||
});
|
||||
|
||||
std::string pciBdf("0000:00:00.0");
|
||||
FirmwareUtilImp *pFwUtilImp = new FirmwareUtilImp(pciBdf);
|
||||
// Prepare dummy OsLibrary for library, since no access is expected
|
||||
pFwUtilImp->libraryHandle = static_cast<OsLibrary *>(new MockOsLibrary());
|
||||
delete pFwUtilImp;
|
||||
EXPECT_EQ(mockFwUtilDeviceCloseCallCount, 1u);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
Loading…
Reference in New Issue