Skip to content
Merged
Show file tree
Hide file tree
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 @@ -26,10 +26,16 @@ namespace {
uint32_t get_prop_length(char *prop) { return std::strlen(prop); }

#ifdef USE_ZESINIT
class FirmwareZesTest : public lzt::ZesSysmanCtsClass {};
class FirmwareZesTest : public lzt::ZesSysmanCtsClass {
public:
bool is_firmware_supported = false;
};
#define FIRMWARE_TEST FirmwareZesTest
#else // USE_ZESINIT
class FirmwareTest : public lzt::SysmanCtsClass {};
class FirmwareTest : public lzt::SysmanCtsClass {
public:
bool is_firmware_supported = false;
};
#define FIRMWARE_TEST FirmwareTest
#endif // USE_ZESINIT

Expand All @@ -39,44 +45,59 @@ LZT_TEST_F(
for (auto device : devices) {
uint32_t count = 0;
count = lzt::get_firmware_handle_count(device);
if (count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
if (count > 0) {
is_firmware_supported = true;
LOG_INFO << "Firmware handles are available on this device! ";
} else {
LOG_INFO << "No firmware handles found for this device! ";
}
}
if (!is_firmware_supported) {
FAIL() << "No firmware handles found on any of the devices! ";
}
}
LZT_TEST_F(
FIRMWARE_TEST,
GivenComponentCountZeroWhenRetrievingFirmwareHandlesThenNotNullFirmwareHandlesAreReturned) {
for (auto device : devices) {
uint32_t count = 0;
auto firmware_handles = lzt::get_firmware_handles(device, count);
if (count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}

ASSERT_EQ(firmware_handles.size(), count);
for (auto firmware_handle : firmware_handles) {
ASSERT_NE(nullptr, firmware_handle);
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);
ASSERT_EQ(firmware_handles.size(), count);
for (auto firmware_handle : firmware_handles) {
ASSERT_NE(nullptr, firmware_handle);
}
} else {
LOG_INFO << "No firmware handles found for this device! ";
}
}
if (!is_firmware_supported) {
FAIL() << "No firmware handles found on any of the devices! ";
}
}

LZT_TEST_F(
FIRMWARE_TEST,
GivenInvalidComponentCountWhenRetrievingSysmanFirmwareHandlesThenActualComponentCountIsUpdated) {
for (auto device : devices) {
uint32_t actual_count = 0;
auto firmware_handles = lzt::get_firmware_handles(device, actual_count);
if (actual_count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
actual_count = lzt::get_firmware_handle_count(device);
if (actual_count > 0) {
is_firmware_supported = true;
LOG_INFO << "Firmware handles are available on this device! ";
auto firmware_handles = lzt::get_firmware_handles(device, actual_count);
uint32_t test_count = actual_count + 1;
firmware_handles = lzt::get_firmware_handles(device, test_count);
EXPECT_EQ(test_count, actual_count);
} else {
LOG_INFO << "No firmware handles found for this device! ";
}

uint32_t test_count = actual_count + 1;
firmware_handles = lzt::get_firmware_handles(device, test_count);
EXPECT_EQ(test_count, actual_count);
}
if (!is_firmware_supported) {
FAIL() << "No firmware handles found on any of the devices! ";
}
}
LZT_TEST_F(
Expand All @@ -85,53 +106,66 @@ LZT_TEST_F(
for (auto device : devices) {
auto deviceProperties = lzt::get_sysman_device_properties(device);
uint32_t count = 0;
auto firmware_handles = lzt::get_firmware_handles(device, count);
if (count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}

for (auto firmware_handle : firmware_handles) {
ASSERT_NE(nullptr, firmware_handle);
auto properties = lzt::get_firmware_properties(firmware_handle);
if (properties.onSubdevice) {
EXPECT_LT(properties.subdeviceId, deviceProperties.numSubdevices);
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 properties = lzt::get_firmware_properties(firmware_handle);
if (properties.onSubdevice) {
EXPECT_LT(properties.subdeviceId, deviceProperties.numSubdevices);
}
EXPECT_LT(get_prop_length(properties.name), ZES_STRING_PROPERTY_SIZE);
EXPECT_GT(get_prop_length(properties.name), 0);
EXPECT_LT(get_prop_length(properties.version),
ZES_STRING_PROPERTY_SIZE);
}
EXPECT_LT(get_prop_length(properties.name), ZES_STRING_PROPERTY_SIZE);
EXPECT_GT(get_prop_length(properties.name), 0);
EXPECT_LT(get_prop_length(properties.version), ZES_STRING_PROPERTY_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! ";
}
}

LZT_TEST_F(
FIRMWARE_TEST,
GivenValidFirmwareHandleWhenRetrievingFirmwarePropertiesThenExpectSamePropertiesReturnedTwice) {
for (auto device : devices) {
uint32_t count = 0;
auto firmware_handles = lzt::get_firmware_handles(device, count);
if (count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}

for (auto firmware_handle : firmware_handles) {
ASSERT_NE(nullptr, firmware_handle);
auto properties_initial = lzt::get_firmware_properties(firmware_handle);
auto properties_later = lzt::get_firmware_properties(firmware_handle);
EXPECT_EQ(properties_initial.onSubdevice, properties_later.onSubdevice);
if (properties_initial.onSubdevice && properties_later.onSubdevice) {
EXPECT_EQ(properties_initial.subdeviceId, properties_later.subdeviceId);
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 properties_initial = lzt::get_firmware_properties(firmware_handle);
auto properties_later = lzt::get_firmware_properties(firmware_handle);
EXPECT_EQ(properties_initial.onSubdevice, properties_later.onSubdevice);
if (properties_initial.onSubdevice && properties_later.onSubdevice) {
EXPECT_EQ(properties_initial.subdeviceId,
properties_later.subdeviceId);
}
EXPECT_TRUE(
0 == std::strcmp(reinterpret_cast<char *>(properties_initial.name),
reinterpret_cast<char *>(properties_later.name)));
EXPECT_TRUE(
0 ==
std::strcmp(reinterpret_cast<char *>(properties_initial.version),
reinterpret_cast<char *>(properties_later.version)));
EXPECT_EQ(properties_initial.canControl, properties_later.canControl);
}
EXPECT_TRUE(0 ==
std::strcmp(reinterpret_cast<char *>(properties_initial.name),
reinterpret_cast<char *>(properties_later.name)));
EXPECT_TRUE(
0 == std::strcmp(reinterpret_cast<char *>(properties_initial.version),
reinterpret_cast<char *>(properties_later.version)));
EXPECT_EQ(properties_initial.canControl, properties_later.canControl);
} else {
LOG_INFO << "No firmware handles found for this device! ";
}
}
if (!is_firmware_supported) {
FAIL() << "No firmware handles found on any of the devices! ";
}
}

LZT_TEST_F(
Expand All @@ -146,32 +180,38 @@ LZT_TEST_F(
std::string fwDir(fwDirEnv);
for (auto device : devices) {
uint32_t count = 0;
auto firmware_handles = lzt::get_firmware_handles(device, count);
if (count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}

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();
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());
}
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) {
Expand Down Expand Up @@ -243,20 +283,24 @@ LZT_TEST_F(
std::string fw_dir(fw_dir_env);
for (auto device : devices) {
uint32_t count = 0;
auto firmware_handles = lzt::get_firmware_handles(device, count);
if (count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}

for (auto firmware_handle : firmware_handles) {
std::thread firmware_flasher(flash_firmware, firmware_handle, fw_dir);
std::thread progress_tracker(track_firmware_flash, firmware_handle);

firmware_flasher.join();
progress_tracker.join();
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) {
std::thread firmware_flasher(flash_firmware, firmware_handle, fw_dir);
std::thread progress_tracker(track_firmware_flash, firmware_handle);
firmware_flasher.join();
progress_tracker.join();
}
} 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
Loading