Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,52 +168,6 @@ LZT_TEST_F(
}
}

LZT_TEST_F(
FIRMWARE_TEST,
GivenValidFirmwareHandleWhenFlashingFirmwareThenExpectFirmwareFlashingSuccess) {
auto fwDirEnv = getenv("ZE_LZT_FIRMWARE_DIRECTORY");
if (nullptr == fwDirEnv) {
LOG_INFO << "Skipping test as ZE_LZT_FIRMWARE_DIRECTORY not set";
GTEST_SKIP();
}
std::vector<char> testFwImage;
std::string fwDir(fwDirEnv);
for (auto device : devices) {
uint32_t count = 0;
count = lzt::get_firmware_handle_count(device);
if (count > 0) {
is_firmware_supported = true;
LOG_INFO << "Firmware handles are available on this device! ";
auto firmware_handles = lzt::get_firmware_handles(device, count);
for (auto firmware_handle : firmware_handles) {
ASSERT_NE(nullptr, firmware_handle);
auto propFw = lzt::get_firmware_properties(firmware_handle);
if (propFw.canControl == true) {
std::string fwName(reinterpret_cast<char *>(propFw.name));
std::string fwToLoad = fwDir + "/" + fwName + ".bin";
std::ifstream inFileStream(fwToLoad,
std::ios::binary | std::ios::ate);
if (!inFileStream.is_open()) {
LOG_INFO << "Skipping test as firmware image not found";
GTEST_SKIP();
}
testFwImage.resize(inFileStream.tellg());
inFileStream.seekg(0, inFileStream.beg);
inFileStream.read(testFwImage.data(), testFwImage.size());
lzt::flash_firmware(firmware_handle,
static_cast<void *>(testFwImage.data()),
testFwImage.size());
}
}
} else {
LOG_INFO << "No firmware handles found for this device! ";
}
}
if (!is_firmware_supported) {
FAIL() << "No firmware handles found on any of the devices! ";
}
}

void flash_firmware(zes_firmware_handle_t firmware_handle, std::string fw_dir) {
std::vector<char> test_fw_image;
ASSERT_NE(nullptr, firmware_handle);
Expand Down Expand Up @@ -303,4 +257,66 @@ LZT_TEST_F(
}
}

class FirmwareFlashParamTest
: public FIRMWARE_TEST,
public ::testing::WithParamInterface<std::string> {
public:
bool is_firmware_supported = false;
};

INSTANTIATE_TEST_SUITE_P(FirmwareTypes, FirmwareFlashParamTest,
::testing::Values("GFX", "OptionROM"));

LZT_TEST_P(
FirmwareFlashParamTest,
GivenValidFirmwareHandleWhenFlashingFirmwareTypeThenExpectFirmwareFlashingSuccess) {
auto fwDirEnv = getenv("ZE_LZT_FIRMWARE_DIRECTORY");
if (nullptr == fwDirEnv) {
LOG_INFO << "Skipping test as ZE_LZT_FIRMWARE_DIRECTORY not set";
GTEST_SKIP();
}
std::string fwDir(fwDirEnv);
std::string fwType = GetParam();

for (auto device : devices) {
uint32_t count = 0;
count = lzt::get_firmware_handle_count(device);
if (count > 0) {
is_firmware_supported = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this LOG_INFO << "Firmware handles are available on this device! "; could be added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

LOG_INFO << "Firmware handles are available on this device! ";
auto firmware_handles = lzt::get_firmware_handles(device, count);
for (auto firmware_handle : firmware_handles) {
ASSERT_NE(nullptr, firmware_handle);
auto propFw = lzt::get_firmware_properties(firmware_handle);

if (propFw.canControl == true &&
std::string(reinterpret_cast<char *>(propFw.name)) == fwType) {
std::string fwName(reinterpret_cast<char *>(propFw.name));
std::string fwToLoad = fwDir + "/" + fwName + ".bin";
LOG_INFO << " Firmware Name: " << fwName;
LOG_INFO << " Firmware Path: " << fwToLoad;
std::ifstream inFileStream(fwToLoad,
Comment on lines +294 to +298
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable names fwName and fwToLoad use inconsistent camelCase naming compared to the existing flash_firmware function which uses fw_name and fw_to_load (snake_case). Consider using snake_case for consistency with the existing codebase.

Suggested change
std::string fwName(reinterpret_cast<char *>(propFw.name));
std::string fwToLoad = fwDir + "/" + fwName + ".bin";
LOG_INFO << " Firmware Name: " << fwName;
LOG_INFO << " Firmware Path: " << fwToLoad;
std::ifstream inFileStream(fwToLoad,
std::string fw_name(reinterpret_cast<char *>(propFw.name));
std::string fw_to_load = fwDir + "/" + fw_name + ".bin";
LOG_INFO << " Firmware Name: " << fw_name;
LOG_INFO << " Firmware Path: " << fw_to_load;
std::ifstream inFileStream(fw_to_load,

Copilot uses AI. Check for mistakes.

std::ios::binary | std::ios::ate);
if (!inFileStream.is_open()) {
LOG_INFO << "Skipping test as firmware image not found";
GTEST_SKIP();
}
std::vector<char> testFwImage(
static_cast<size_t>(inFileStream.tellg()));
inFileStream.seekg(0, inFileStream.beg);
inFileStream.read(testFwImage.data(), testFwImage.size());
Comment on lines +298 to +307
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name inFileStream uses inconsistent camelCase naming compared to the existing flash_firmware function which uses in_filestream (snake_case). Consider using in_filestream for consistency.

Suggested change
std::ifstream inFileStream(fwToLoad,
std::ios::binary | std::ios::ate);
if (!inFileStream.is_open()) {
LOG_INFO << "Skipping test as firmware image not found";
GTEST_SKIP();
}
std::vector<char> testFwImage(
static_cast<size_t>(inFileStream.tellg()));
inFileStream.seekg(0, inFileStream.beg);
inFileStream.read(testFwImage.data(), testFwImage.size());
std::ifstream in_filestream(fwToLoad,
std::ios::binary | std::ios::ate);
if (!in_filestream.is_open()) {
LOG_INFO << "Skipping test as firmware image not found";
GTEST_SKIP();
}
std::vector<char> testFwImage(
static_cast<size_t>(in_filestream.tellg()));
in_filestream.seekg(0, in_filestream.beg);
in_filestream.read(testFwImage.data(), testFwImage.size());

Copilot uses AI. Check for mistakes.

lzt::flash_firmware(firmware_handle,
static_cast<void *>(testFwImage.data()),
testFwImage.size());
Comment on lines +304 to +310
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name testFwImage uses inconsistent naming compared to the existing flash_firmware function which uses test_fw_image (snake_case). Consider using test_fw_image for consistency.

Suggested change
std::vector<char> testFwImage(
static_cast<size_t>(inFileStream.tellg()));
inFileStream.seekg(0, inFileStream.beg);
inFileStream.read(testFwImage.data(), testFwImage.size());
lzt::flash_firmware(firmware_handle,
static_cast<void *>(testFwImage.data()),
testFwImage.size());
std::vector<char> test_fw_image(
static_cast<size_t>(inFileStream.tellg()));
inFileStream.seekg(0, inFileStream.beg);
inFileStream.read(test_fw_image.data(), test_fw_image.size());
lzt::flash_firmware(firmware_handle,
static_cast<void *>(test_fw_image.data()),
test_fw_image.size());

Copilot uses AI. Check for mistakes.

}
}
} else {
LOG_INFO << "No firmware handles found for this device!";
}
}
if (!is_firmware_supported) {
FAIL() << "No firmware handles found on any of the devices!";
}
}

} // namespace
Loading