blob: 2e237e305ec493ca5294c92e1ff18be2e65a1805 [file] [log] [blame]
#include "common/utils.hpp"
#include "fw-update/device_updater.hpp"
#include "fw-update/package_parser.hpp"
#include "pldmd/dbus_impl_requester.hpp"
#include "requester/handler.hpp"
#include <libpldm/firmware_update.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace pldm;
using namespace pldm::fw_update;
class DeviceUpdaterTest : public testing::Test
{
protected:
DeviceUpdaterTest() :
package("./test_pkg", std::ios::binary | std::ios::in | std::ios::ate)
{
fwDeviceIDRecord = {
1,
{0x00},
"VersionString2",
{{PLDM_FWUP_UUID,
std::vector<uint8_t>{0x16, 0x20, 0x23, 0xC9, 0x3E, 0xC5, 0x41,
0x15, 0x95, 0xF4, 0x48, 0x70, 0x1D, 0x49,
0xD6, 0x75}}},
{}};
compImageInfos = {
{10, 100, 0xFFFFFFFF, 0, 0, 139, 1024, "VersionString3"}};
compInfo = {{std::make_pair(10, 100), 1}};
}
int fd = -1;
std::ifstream package;
FirmwareDeviceIDRecord fwDeviceIDRecord;
ComponentImageInfos compImageInfos;
ComponentInfo compInfo;
};
TEST_F(DeviceUpdaterTest, validatePackage)
{
constexpr uintmax_t testPkgSize = 1163;
uintmax_t packageSize = package.tellg();
EXPECT_EQ(packageSize, testPkgSize);
package.seekg(0);
std::vector<uint8_t> packageHeader(sizeof(pldm_package_header_information));
package.read(reinterpret_cast<char*>(packageHeader.data()),
sizeof(pldm_package_header_information));
auto pkgHeaderInfo =
reinterpret_cast<const pldm_package_header_information*>(
packageHeader.data());
auto pkgHeaderInfoSize = sizeof(pldm_package_header_information) +
pkgHeaderInfo->package_version_string_length;
packageHeader.clear();
packageHeader.resize(pkgHeaderInfoSize);
package.seekg(0);
package.read(reinterpret_cast<char*>(packageHeader.data()),
pkgHeaderInfoSize);
auto parser = parsePkgHeader(packageHeader);
EXPECT_NE(parser, nullptr);
package.seekg(0);
packageHeader.resize(parser->pkgHeaderSize);
package.read(reinterpret_cast<char*>(packageHeader.data()),
parser->pkgHeaderSize);
parser->parse(packageHeader, packageSize);
const auto& fwDeviceIDRecords = parser->getFwDeviceIDRecords();
const auto& testPkgCompImageInfos = parser->getComponentImageInfos();
EXPECT_EQ(fwDeviceIDRecords.size(), 1);
EXPECT_EQ(compImageInfos.size(), 1);
EXPECT_EQ(fwDeviceIDRecords[0], fwDeviceIDRecord);
EXPECT_EQ(testPkgCompImageInfos, compImageInfos);
}
TEST_F(DeviceUpdaterTest, ReadPackage512B)
{
DeviceUpdater deviceUpdater(0, package, fwDeviceIDRecord, compImageInfos,
compInfo, 512, nullptr);
constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) +
sizeof(pldm_request_firmware_data_req)>
reqFwDataReq{0x8A, 0x05, 0x15, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00};
constexpr uint8_t instanceId = 0x0A;
constexpr uint8_t completionCode = PLDM_SUCCESS;
constexpr uint32_t length = 512;
auto requestMsg = reinterpret_cast<const pldm_msg*>(reqFwDataReq.data());
auto response = deviceUpdater.requestFwData(
requestMsg, sizeof(pldm_request_firmware_data_req));
EXPECT_EQ(response.size(),
sizeof(pldm_msg_hdr) + sizeof(completionCode) + length);
auto responeMsg = reinterpret_cast<const pldm_msg*>(response.data());
EXPECT_EQ(responeMsg->hdr.request, PLDM_RESPONSE);
EXPECT_EQ(responeMsg->hdr.instance_id, instanceId);
EXPECT_EQ(responeMsg->hdr.type, PLDM_FWUP);
EXPECT_EQ(responeMsg->hdr.command, PLDM_REQUEST_FIRMWARE_DATA);
EXPECT_EQ(response[sizeof(pldm_msg_hdr)], completionCode);
const std::vector<uint8_t> compFirst512B{
0x0A, 0x05, 0x15, 0x00, 0x48, 0xD2, 0x1E, 0x80, 0x2E, 0x77, 0x71, 0x2C,
0x8E, 0xE3, 0x1F, 0x6F, 0x30, 0x76, 0x65, 0x08, 0xB8, 0x1B, 0x4B, 0x03,
0x7E, 0x96, 0xD9, 0x2A, 0x36, 0x3A, 0xA2, 0x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