libpldm: Migrate to subproject
Organize files in libpldm to make it a subproject
In the current state, libpldm is not readily consumable
as a subproject.This commit does all the necessary re-organisation
of the source code to make it work as a subproject.
There are no .c/.h files changes in this commit, only meson
changes and re-organising the code structure.
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: I20a71c0c972b1fd81fb359d604433618799102c6
diff --git a/.gitignore b/.gitignore
index 8ad1400..516b46f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
subprojects/*
+!subprojects/libpldm*
!subprojects/*.wrap
# Template from
diff --git a/fw-update/inventory_manager.hpp b/fw-update/inventory_manager.hpp
index a14d58c..c71130b 100644
--- a/fw-update/inventory_manager.hpp
+++ b/fw-update/inventory_manager.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "common/types.hpp"
#include "pldmd/dbus_impl_requester.hpp"
diff --git a/fw-update/manager.hpp b/fw-update/manager.hpp
index 9bdcbe2..8b09026 100644
--- a/fw-update/manager.hpp
+++ b/fw-update/manager.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "activation.hpp"
#include "common/types.hpp"
diff --git a/fw-update/update_manager.hpp b/fw-update/update_manager.hpp
index 5d4fe47..e33ab56 100644
--- a/fw-update/update_manager.hpp
+++ b/fw-update/update_manager.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "libpldm/base.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "common/types.hpp"
#include "device_updater.hpp"
@@ -133,4 +133,4 @@
} // namespace fw_update
-} // namespace pldm
\ No newline at end of file
+} // namespace pldm
diff --git a/host-bmc/dbus_to_event_handler.cpp b/host-bmc/dbus_to_event_handler.cpp
index 9fcf3ba..5501e56 100644
--- a/host-bmc/dbus_to_event_handler.cpp
+++ b/host-bmc/dbus_to_event_handler.cpp
@@ -1,6 +1,6 @@
#include "dbus_to_event_handler.hpp"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "libpldmresponder/pdr.hpp"
diff --git a/host-bmc/dbus_to_host_effecters.cpp b/host-bmc/dbus_to_host_effecters.cpp
index 86c00e8..299abd3 100644
--- a/host-bmc/dbus_to_host_effecters.cpp
+++ b/host-bmc/dbus_to_host_effecters.cpp
@@ -2,7 +2,7 @@
#include "libpldm/pdr.h"
#include "libpldm/platform.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/State/OperatingSystem/Status/server.hpp>
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 75d3e61..52b6206 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -2,7 +2,7 @@
#include "host_pdr_handler.hpp"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include <assert.h>
diff --git a/libpldm/meson.build b/libpldm/meson.build
deleted file mode 100644
index 9c719d3..0000000
--- a/libpldm/meson.build
+++ /dev/null
@@ -1,79 +0,0 @@
-headers = [
- 'base.h',
- 'pldm_types.h',
- 'platform.h',
- 'bios.h',
- 'bios_table.h',
- 'entity.h',
- 'states.h',
- 'state_set.h',
- 'fru.h',
- 'utils.h',
- 'pdr.h',
- 'firmware_update.h'
-]
-
-sources = [
- 'base.c',
- 'platform.c',
- 'bios.c',
- 'bios_table.c',
- 'fru.c',
- 'utils.c',
- 'pdr.c',
- 'firmware_update.c'
-]
-
-libpldm_headers = ['.', '..']
-
-if get_option('oem-ibm').enabled()
- headers += [
- 'oem/ibm/libpldm/entity_oem_ibm.h',
- 'oem/ibm/libpldm/file_io.h',
- 'oem/ibm/libpldm/host.h',
- 'oem/ibm/libpldm/platform_oem_ibm.h',
- 'oem/ibm/libpldm/state_set_oem_ibm.h'
- ]
- sources += [
- 'oem/ibm/libpldm/file_io.c',
- 'oem/ibm/libpldm/host.c',
- 'oem/ibm/libpldm/platform_oem_ibm.c'
- ]
- libpldm_headers += ['oem/ibm']
-endif
-
-if get_option('requester-api').enabled()
- headers += [
- 'requester/pldm.h'
- ]
- sources += [
- 'requester/pldm.c'
- ]
- libpldm_headers += ['requester']
-endif
-
-install_headers(
- headers,
- subdir: 'libpldm')
-
-libpldm = library(
- 'pldm',
- sources,
- implicit_include_directories: false,
- include_directories: include_directories(libpldm_headers),
- version: meson.project_version(),
- install: true)
-
-libpldm_dep = declare_dependency(
- include_directories: include_directories(libpldm_headers),
- link_with: libpldm)
-
-import('pkgconfig').generate(
- name: 'libpldm',
- description: 'PLDM protocol encode/decode C lib',
- version: meson.project_version(),
- libraries: libpldm)
-
-if get_option('tests').enabled()
- subdir('tests')
-endif
diff --git a/libpldm/oem/ibm/libpldm/tests/libpldm_fileio_test.cpp b/libpldm/oem/ibm/libpldm/tests/libpldm_fileio_test.cpp
deleted file mode 100644
index 5979ff4..0000000
--- a/libpldm/oem/ibm/libpldm/tests/libpldm_fileio_test.cpp
+++ /dev/null
@@ -1,2180 +0,0 @@
-#include "libpldm/base.h"
-#include "libpldm/file_io.h"
-
-#include <string.h>
-
-#include <array>
-
-#include <gtest/gtest.h>
-
-constexpr auto hdrSize = sizeof(pldm_msg_hdr);
-
-TEST(ReadWriteFileMemory, testGoodDecodeRequest)
-{
- std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES + hdrSize> requestMsg{};
-
- // Random value for fileHandle, offset, length, address
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x13245768;
- uint64_t address = 0x124356879ACBDE0F;
- uint32_t fileHandleLe = htole32(fileHandle);
- uint32_t offsetLe = htole32(offset);
- uint32_t lengthLe = htole32(length);
- uint64_t addressLe = htole64(address);
-
- memcpy(requestMsg.data() + hdrSize, &fileHandleLe,
- sizeof(fileHandleLe));
- memcpy(requestMsg.data() + sizeof(fileHandleLe) + hdrSize, &offsetLe,
- sizeof(offsetLe));
- memcpy(requestMsg.data() + sizeof(fileHandleLe) + sizeof(offsetLe) +
- hdrSize,
- &lengthLe, sizeof(lengthLe));
- memcpy(requestMsg.data() + sizeof(fileHandleLe) + sizeof(offsetLe) +
- sizeof(lengthLe) + hdrSize,
- &addressLe, sizeof(addressLe));
-
- uint32_t retFileHandle = 0;
- uint32_t retOffset = 0;
- uint32_t retLength = 0;
- uint64_t retAddress = 0;
-
- auto request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Invoke decode the read file memory request
- auto rc = decode_rw_file_memory_req(
- request, requestMsg.size() - hdrSize, &retFileHandle, &retOffset,
- &retLength, &retAddress);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(offset, retOffset);
- ASSERT_EQ(length, retLength);
- ASSERT_EQ(address, retAddress);
-}
-
-TEST(ReadWriteFileMemory, testBadDecodeRequest)
-{
- uint32_t fileHandle = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
- uint64_t address = 0;
-
- // Request payload message is missing
- auto rc = decode_rw_file_memory_req(NULL, 0, &fileHandle, &offset,
- &length, &address);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES> requestMsg{};
-
- auto request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Address is NULL
- rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize,
- &fileHandle, &offset, &length, NULL);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_rw_file_memory_req(request, 0, &fileHandle, &offset,
- &length, &address);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadWriteFileMemory, testGoodEncodeResponse)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES>
- responseMsg{};
- uint32_t length = 0xFF00EE11;
- uint32_t lengthLe = htole32(length);
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // ReadFileIntoMemory
- auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
- PLDM_SUCCESS, length, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
- ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
- ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
- &lengthLe, sizeof(lengthLe)));
-
- // WriteFileFromMemory
- rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
- PLDM_SUCCESS, length, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY);
- ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
- ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
- &lengthLe, sizeof(lengthLe)));
-}
-
-TEST(ReadWriteFileMemory, testBadEncodeResponse)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES>
- responseMsg{};
- uint32_t length = 0;
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // ReadFileIntoMemory
- auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
- PLDM_ERROR, length, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-
- // WriteFileFromMemory
- rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
- PLDM_ERROR, length, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-}
-
-TEST(ReadWriteFileIntoMemory, testGoodDecodeResponse)
-{
- std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES + hdrSize>
- responseMsg{};
- // Random value for length
- uint32_t length = 0xFF00EE12;
- uint32_t lengthLe = htole32(length);
- uint8_t completionCode = 0;
-
- memcpy(responseMsg.data() + hdrSize, &completionCode,
- sizeof(completionCode));
- memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &lengthLe,
- sizeof(lengthLe));
-
- uint8_t retCompletionCode = 0;
- uint32_t retLength = 0;
-
- auto response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Invoke decode the read file memory response
- auto rc =
- decode_rw_file_memory_resp(response, responseMsg.size() - hdrSize,
- &retCompletionCode, &retLength);
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
- ASSERT_EQ(length, retLength);
-}
-
-TEST(ReadWriteFileIntoMemory, testBadDecodeResponse)
-{
- uint32_t length = 0;
- uint8_t completionCode = 0;
-
- // Request payload message is missing
- auto rc = decode_rw_file_memory_resp(NULL, 0, &completionCode, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES> responseMsg{};
-
- auto response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Payload length is invalid
- rc = decode_rw_file_memory_resp(response, 0, &completionCode, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadWriteFileIntoMemory, testGoodEncodeRequest)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_REQ_BYTES>
- requestMsg{};
-
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x13245768;
- uint64_t address = 0x124356879ACBDE0F;
- uint32_t fileHandleLe = htole32(fileHandle);
- uint32_t offsetLe = htole32(offset);
- uint32_t lengthLe = htole32(length);
- uint64_t addressLe = htole64(address);
-
- pldm_msg *request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- auto rc =
- encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle,
- offset, length, address, request);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(request->hdr.instance_id, 0);
- ASSERT_EQ(request->hdr.type, PLDM_OEM);
- ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
-
- ASSERT_EQ(
- 0, memcmp(request->payload, &fileHandleLe, sizeof(fileHandleLe)));
-
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe), &offsetLe,
- sizeof(offsetLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe) +
- sizeof(offsetLe),
- &lengthLe, sizeof(lengthLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe) +
- sizeof(offsetLe) + sizeof(lengthLe),
- &addressLe, sizeof(addressLe)));
-}
-
-TEST(ReadWriteFileIntoMemory, testBadEncodeRequest)
-{
- uint32_t fileHandle = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
- uint64_t address = 0;
-
- auto rc =
- encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle,
- offset, length, address, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(GetFileTable, GoodDecodeRequest)
-{
- std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES + hdrSize>
- requestMsg{};
-
- // Random value for DataTransferHandle, TransferOperationFlag, TableType
- uint32_t transferHandle = 0x12345678;
- uint32_t transferHandleLe = htole32(transferHandle);
- uint8_t transferOpFlag = 1;
- uint8_t tableType = 1;
-
- memcpy(requestMsg.data() + hdrSize, &transferHandleLe,
- sizeof(transferHandleLe));
- memcpy(requestMsg.data() + sizeof(transferHandle) + hdrSize,
- &transferOpFlag, sizeof(transferOpFlag));
- memcpy(requestMsg.data() + sizeof(transferHandle) +
- sizeof(transferOpFlag) + hdrSize,
- &tableType, sizeof(tableType));
-
- uint32_t retTransferHandle = 0;
- uint8_t retTransferOpFlag = 0;
- uint8_t retTableType = 0;
-
- auto request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Invoke decode get file table request
- auto rc = decode_get_file_table_req(
- request, requestMsg.size() - hdrSize, &retTransferHandle,
- &retTransferOpFlag, &retTableType);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(transferHandle, retTransferHandle);
- ASSERT_EQ(transferOpFlag, retTransferOpFlag);
- ASSERT_EQ(tableType, retTableType);
-}
-
-TEST(GetFileTable, BadDecodeRequest)
-{
- uint32_t transferHandle = 0;
- uint8_t transferOpFlag = 0;
- uint8_t tableType = 0;
-
- // Request payload message is missing
- auto rc = decode_get_file_table_req(nullptr, 0, &transferHandle,
- &transferOpFlag, &tableType);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES> requestMsg{};
-
- auto request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // TableType is NULL
- rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize,
- &transferHandle, &transferOpFlag,
- nullptr);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_get_file_table_req(request, 0, &transferHandle,
- &transferOpFlag, &tableType);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(GetFileTable, GoodEncodeResponse)
-{
- // Random value for NextDataTransferHandle and TransferFlag
- uint8_t completionCode = 0;
- uint32_t nextTransferHandle = 0x87654321;
- uint32_t nextTransferHandleLe = htole32(nextTransferHandle);
- uint8_t transferFlag = 5;
- // Mock file table contents of size 5
- std::array<uint8_t, 5> fileTable = {1, 2, 3, 4, 5};
- constexpr size_t responseSize = sizeof(completionCode) +
- sizeof(nextTransferHandle) +
- sizeof(transferFlag) + fileTable.size();
-
- std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{};
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // GetFileTable
- auto rc = encode_get_file_table_resp(
- 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, fileTable.data(),
- fileTable.size(), response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE);
- ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
- ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
- &nextTransferHandleLe, sizeof(nextTransferHandle)));
- ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
- sizeof(nextTransferHandle),
- &transferFlag, sizeof(transferFlag)));
- ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
- sizeof(nextTransferHandle),
- &transferFlag, sizeof(transferFlag)));
- ASSERT_EQ(0,
- memcmp(response->payload + sizeof(response->payload[0]) +
- sizeof(nextTransferHandle) + sizeof(transferFlag),
- fileTable.data(), fileTable.size()));
-}
-
-TEST(GetFileTable, BadEncodeResponse)
-{
- uint8_t completionCode = 0;
- uint32_t nextTransferHandle = 0;
- uint8_t transferFlag = 0;
- constexpr size_t responseSize = sizeof(completionCode) +
- sizeof(nextTransferHandle) +
- sizeof(transferFlag);
-
- std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{};
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // GetFileTable
- auto rc =
- encode_get_file_table_resp(0, PLDM_ERROR, nextTransferHandle,
- transferFlag, nullptr, 0, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-}
-
-TEST(GetFileTable, GoodEncodeRequest)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) + PLDM_GET_FILE_TABLE_REQ_BYTES>
- requestMsg{};
- uint32_t transferHandle = 0x0;
- uint8_t transferOpFlag = 0x01;
- uint8_t tableType = PLDM_FILE_ATTRIBUTE_TABLE;
-
- auto request = reinterpret_cast<pldm_msg *>(requestMsg.data());
- auto rc = encode_get_file_table_req(0, transferHandle, transferOpFlag,
- tableType, request);
- EXPECT_EQ(rc, PLDM_SUCCESS);
-
- struct pldm_get_file_table_req *req =
- reinterpret_cast<struct pldm_get_file_table_req *>(
- request->payload);
- EXPECT_EQ(transferHandle, le32toh(req->transfer_handle));
- EXPECT_EQ(transferOpFlag, req->operation_flag);
- EXPECT_EQ(tableType, req->table_type);
-}
-
-TEST(GetFileTable, BadEncodeRequest)
-{
- uint32_t transferHandle = 0x0;
- uint8_t transferOpFlag = 0x01;
- uint8_t tableType = PLDM_FILE_ATTRIBUTE_TABLE;
-
- auto rc = encode_get_file_table_req(0, transferHandle, transferOpFlag,
- tableType, nullptr);
-
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(GetFileTable, GoodDecodeResponse)
-{
- uint32_t nextTransferHandle = 32;
- uint8_t completionCode = PLDM_SUCCESS;
- uint8_t transferFlag = PLDM_START_AND_END;
- std::vector<uint8_t> fileTableData = {1, 2, 3, 4, 5, 6, 7, 8, 9};
-
- std::vector<uint8_t> responseMsg(hdrSize +
- PLDM_GET_FILE_TABLE_MIN_RESP_BYTES +
- fileTableData.size());
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - hdrSize;
-
- auto resp = reinterpret_cast<struct pldm_get_file_table_resp *>(
- responsePtr->payload);
-
- resp->completion_code = completionCode;
- resp->next_transfer_handle = htole32(nextTransferHandle);
- resp->transfer_flag = transferFlag;
- memcpy(resp->table_data, fileTableData.data(), fileTableData.size());
-
- uint8_t retCompletionCode;
- uint32_t retNextTransferHandle;
- uint8_t retTransferFlag;
- std::vector<uint8_t> retFileTableData(9, 0);
- size_t retFileTableDataLength = 0;
-
- auto rc = decode_get_file_table_resp(
- responsePtr, payload_length, &retCompletionCode,
- &retNextTransferHandle, &retTransferFlag, retFileTableData.data(),
- &retFileTableDataLength);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
- ASSERT_EQ(nextTransferHandle, retNextTransferHandle);
- ASSERT_EQ(transferFlag, retTransferFlag);
- ASSERT_EQ(0, memcmp(fileTableData.data(), resp->table_data,
- retFileTableDataLength));
- ASSERT_EQ(fileTableData.size(), retFileTableDataLength);
-}
-
-TEST(GetFileTable, BadDecodeResponse)
-{
- uint32_t nextTransferHandle = 32;
- uint8_t completionCode = PLDM_SUCCESS;
- uint8_t transferFlag = PLDM_START_AND_END;
- std::vector<uint8_t> fileTableData(9, 0);
- size_t file_table_data_length = 0;
-
- std::vector<uint8_t> responseMsg(hdrSize +
- PLDM_GET_FILE_TABLE_MIN_RESP_BYTES +
- fileTableData.size());
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc = decode_get_file_table_resp(
- nullptr, 0, &completionCode, &nextTransferHandle, &transferFlag,
- fileTableData.data(), &file_table_data_length);
-
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- rc = decode_get_file_table_resp(
- responsePtr, 0, &completionCode, &nextTransferHandle, &transferFlag,
- fileTableData.data(), &file_table_data_length);
-
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadFile, testGoodDecodeRequest)
-{
- std::array<uint8_t, PLDM_READ_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
- auto request =
- reinterpret_cast<pldm_read_file_req *>(requestPtr->payload);
-
- // Random value for fileHandle, offset and length
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x13245768;
-
- request->file_handle = htole32(fileHandle);
- request->offset = htole32(offset);
- request->length = htole32(length);
-
- uint32_t retFileHandle = 0;
- uint32_t retOffset = 0;
- uint32_t retLength = 0;
-
- // Invoke decode the read file request
- auto rc = decode_read_file_req(requestPtr, payload_length,
- &retFileHandle, &retOffset, &retLength);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(offset, retOffset);
- ASSERT_EQ(length, retLength);
-}
-
-TEST(WriteFile, testGoodDecodeRequest)
-{
- // Random value for fileHandle, offset, length and file data
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x467;
-
- std::vector<uint8_t> requestMsg(PLDM_WRITE_FILE_REQ_BYTES +
- sizeof(pldm_msg_hdr) + length);
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
- auto request =
- reinterpret_cast<pldm_write_file_req *>(requestPtr->payload);
-
- size_t fileDataOffset =
- sizeof(fileHandle) + sizeof(offset) + sizeof(length);
-
- request->file_handle = htole32(fileHandle);
- request->offset = htole32(offset);
- request->length = htole32(length);
-
- uint32_t retFileHandle = 0;
- uint32_t retOffset = 0;
- uint32_t retLength = 0;
- size_t retFileDataOffset = 0;
-
- // Invoke decode the write file request
- auto rc =
- decode_write_file_req(requestPtr, payload_length, &retFileHandle,
- &retOffset, &retLength, &retFileDataOffset);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(offset, retOffset);
- ASSERT_EQ(length, retLength);
- ASSERT_EQ(fileDataOffset, retFileDataOffset);
-}
-
-TEST(ReadFile, testGoodDecodeResponse)
-{
- // Random value for length
- uint32_t length = 0x10;
- uint8_t completionCode = PLDM_SUCCESS;
-
- std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
- sizeof(pldm_msg_hdr) + length);
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
- auto response =
- reinterpret_cast<pldm_read_file_resp *>(responsePtr->payload);
-
- response->completion_code = completionCode;
- response->length = htole32(length);
-
- size_t fileDataOffset = sizeof(completionCode) + sizeof(length);
-
- uint32_t retLength = 0;
- uint8_t retCompletionCode = 0;
- size_t retFileDataOffset = 0;
-
- // Invoke decode the read file response
- auto rc = decode_read_file_resp(responsePtr, payload_length,
- &retCompletionCode, &retLength,
- &retFileDataOffset);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
- ASSERT_EQ(length, retLength);
- ASSERT_EQ(fileDataOffset, retFileDataOffset);
-}
-
-TEST(WriteFile, testGoodDecodeResponse)
-{
- std::array<uint8_t, PLDM_WRITE_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
- auto response =
- reinterpret_cast<pldm_write_file_resp *>(responsePtr->payload);
-
- uint8_t completionCode = PLDM_SUCCESS;
- uint32_t length = 0x4678;
-
- response->completion_code = completionCode;
- response->length = htole32(length);
-
- uint32_t retLength = 0;
- uint8_t retCompletionCode = 0;
-
- // Invoke decode the write file response
- auto rc = decode_write_file_resp(responsePtr, payload_length,
- &retCompletionCode, &retLength);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
- ASSERT_EQ(length, retLength);
-}
-
-TEST(ReadWriteFile, testBadDecodeResponse)
-{
- uint32_t length = 0;
- uint8_t completionCode = 0;
- size_t fileDataOffset = 0;
-
- // Bad decode response for read file
- std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
- sizeof(pldm_msg_hdr) + length);
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Request payload message is missing
- auto rc = decode_read_file_resp(NULL, 0, &completionCode, &length,
- &fileDataOffset);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_read_file_resp(responsePtr, 0, &completionCode, &length,
- &fileDataOffset);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- // Bad decode response for write file
- std::array<uint8_t, PLDM_WRITE_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsgWr{};
- auto responseWr = reinterpret_cast<pldm_msg *>(responseMsgWr.data());
-
- // Request payload message is missing
- rc = decode_write_file_resp(NULL, 0, &completionCode, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_write_file_resp(responseWr, 0, &completionCode, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadWriteFile, testBadDecodeRequest)
-{
- uint32_t fileHandle = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
-
- // Bad decode request for read file
- std::array<uint8_t, PLDM_READ_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Request payload message is missing
- auto rc = decode_read_file_req(NULL, 0, &fileHandle, &offset, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_read_file_req(requestPtr, 0, &fileHandle, &offset, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- // Bad decode request for write file
- size_t fileDataOffset = 0;
- std::array<uint8_t, PLDM_WRITE_FILE_REQ_BYTES> requestMsgWr{};
- auto requestWr = reinterpret_cast<pldm_msg *>(requestMsgWr.data());
-
- // Request payload message is missing
- rc = decode_write_file_req(NULL, 0, &fileHandle, &offset, &length,
- &fileDataOffset);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_write_file_req(requestWr, 0, &fileHandle, &offset, &length,
- &fileDataOffset);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadFile, testGoodEncodeResponse)
-{
- // Good encode response for read file
- uint32_t length = 0x4;
-
- std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
- sizeof(pldm_msg_hdr) + length);
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- auto response =
- reinterpret_cast<pldm_read_file_resp *>(responsePtr->payload);
-
- // ReadFile
- auto rc = encode_read_file_resp(0, PLDM_SUCCESS, length, responsePtr);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(responsePtr->hdr.instance_id, 0);
- ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
- ASSERT_EQ(responsePtr->hdr.command, PLDM_READ_FILE);
- ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
- ASSERT_EQ(le32toh(response->length), length);
-}
-
-TEST(WriteFile, testGoodEncodeResponse)
-{
- uint32_t length = 0x467;
-
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_RESP_BYTES>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- auto response =
- reinterpret_cast<pldm_write_file_resp *>(responsePtr->payload);
-
- // WriteFile
- auto rc = encode_write_file_resp(0, PLDM_SUCCESS, length, responsePtr);
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(responsePtr->hdr.instance_id, 0);
- ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
- ASSERT_EQ(responsePtr->hdr.command, PLDM_WRITE_FILE);
- ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
- ASSERT_EQ(le32toh(response->length), length);
-}
-
-TEST(ReadFile, testGoodEncodeRequest)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_REQ_BYTES>
- requestMsg{};
-
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x13245768;
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- auto request =
- reinterpret_cast<pldm_read_file_req *>(requestPtr->payload);
-
- // ReadFile
- auto rc =
- encode_read_file_req(0, fileHandle, offset, length, requestPtr);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(requestPtr->hdr.instance_id, 0);
- ASSERT_EQ(requestPtr->hdr.type, PLDM_OEM);
- ASSERT_EQ(requestPtr->hdr.command, PLDM_READ_FILE);
- ASSERT_EQ(le32toh(request->file_handle), fileHandle);
- ASSERT_EQ(le32toh(request->offset), offset);
- ASSERT_EQ(le32toh(request->length), length);
-}
-
-TEST(WriteFile, testGoodEncodeRequest)
-{
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x456;
-
- std::vector<uint8_t> requestMsg(PLDM_WRITE_FILE_REQ_BYTES +
- sizeof(pldm_msg_hdr) + length);
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- auto request =
- reinterpret_cast<pldm_write_file_req *>(requestPtr->payload);
-
- // WriteFile
- auto rc =
- encode_write_file_req(0, fileHandle, offset, length, requestPtr);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(requestPtr->hdr.instance_id, 0);
- ASSERT_EQ(requestPtr->hdr.type, PLDM_OEM);
- ASSERT_EQ(requestPtr->hdr.command, PLDM_WRITE_FILE);
- ASSERT_EQ(le32toh(request->file_handle), fileHandle);
- ASSERT_EQ(le32toh(request->offset), offset);
- ASSERT_EQ(le32toh(request->length), length);
-}
-
-TEST(ReadWriteFile, testBadEncodeRequest)
-{
- // Bad encode request for read file
- uint32_t fileHandle = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
-
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_REQ_BYTES>
- requestMsg{};
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // ReadFile check invalid file length
- auto rc =
- encode_read_file_req(0, fileHandle, offset, length, requestPtr);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-
- // Bad encode request for write file
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_REQ_BYTES>
- requestMsgWr{};
- auto requestWr = reinterpret_cast<pldm_msg *>(requestMsgWr.data());
-
- // WriteFile check for invalid file length
- rc = encode_write_file_req(0, fileHandle, offset, length, requestWr);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadWriteFile, testBadEncodeResponse)
-{
- // Bad encode response for read file
- uint32_t length = 0;
-
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_RESP_BYTES>
- responseMsg{};
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // ReadFile
- auto rc = encode_read_file_resp(0, PLDM_ERROR, length, responsePtr);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(responsePtr->hdr.instance_id, 0);
- ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
- ASSERT_EQ(responsePtr->hdr.command, PLDM_READ_FILE);
- ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR);
-
- // Bad encode response for write file
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_RESP_BYTES>
- responseMsgWr{};
- auto responseWr = reinterpret_cast<pldm_msg *>(responseMsgWr.data());
-
- // WriteFile
- rc = encode_write_file_resp(0, PLDM_ERROR, length, responseWr);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(responseWr->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(responseWr->hdr.instance_id, 0);
- ASSERT_EQ(responseWr->hdr.type, PLDM_OEM);
- ASSERT_EQ(responseWr->hdr.command, PLDM_WRITE_FILE);
- ASSERT_EQ(responseWr->payload[0], PLDM_ERROR);
-}
-
-TEST(ReadWriteFileByTypeMemory, testGoodDecodeRequest)
-{
- std::array<uint8_t,
- PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
- auto request =
- reinterpret_cast<pldm_read_write_file_by_type_memory_req *>(
- requestPtr->payload);
-
- // Random value for fileHandle, offset and length
- uint16_t fileType = 0;
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x13245768;
- uint64_t address = 0x124356879ACBD456;
-
- request->file_type = htole16(fileType);
- request->file_handle = htole32(fileHandle);
- request->offset = htole32(offset);
- request->length = htole32(length);
- request->address = htole64(address);
-
- uint16_t retFileType = 0x1;
- uint32_t retFileHandle = 0;
- uint32_t retOffset = 0;
- uint32_t retLength = 0;
- uint64_t retAddress = 0;
-
- // Invoke decode the read file request
- auto rc = decode_rw_file_by_type_memory_req(
- requestPtr, payload_length, &retFileType, &retFileHandle,
- &retOffset, &retLength, &retAddress);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileType, retFileType);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(offset, retOffset);
- ASSERT_EQ(length, retLength);
- ASSERT_EQ(address, retAddress);
-}
-
-TEST(ReadWriteFileByTypeMemory, testGoodDecodeResponse)
-{
- std::array<uint8_t,
- PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
- auto response =
- reinterpret_cast<pldm_read_write_file_by_type_memory_resp *>(
- responsePtr->payload);
-
- // Random value for completion code and length
- uint8_t completionCode = 0x0;
- uint32_t length = 0x13245768;
-
- response->completion_code = completionCode;
- response->length = htole32(length);
-
- uint8_t retCompletionCode = 0x1;
- uint32_t retLength = 0;
-
- // Invoke decode the read/write file response
- auto rc = decode_rw_file_by_type_memory_resp(
- responsePtr, payload_length, &retCompletionCode, &retLength);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
- ASSERT_EQ(length, retLength);
-}
-
-TEST(ReadWriteFileByTypeMemory, testBadDecodeRequest)
-{
- uint16_t fileType = 0;
- uint32_t fileHandle = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
- uint64_t address = 0;
-
- // Request payload message is missing
- auto rc = decode_rw_file_by_type_memory_req(
- NULL, 0, &fileType, &fileHandle, &offset, &length, &address);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t,
- PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Address is NULL
- rc = decode_rw_file_by_type_memory_req(
- requestPtr, requestMsg.size() - hdrSize, &fileType, &fileHandle,
- &offset, &length, NULL);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_rw_file_by_type_memory_req(
- requestPtr, 0, &fileType, &fileHandle, &offset, &length, &address);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadWriteFileByTypeMemory, testBadDecodeResponse)
-{
- uint32_t length = 0;
- uint8_t completionCode = 0;
-
- // Request payload message is missing
- auto rc = decode_rw_file_by_type_memory_resp(NULL, 0, &completionCode,
- &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t,
- PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Length is NULL
- rc = decode_rw_file_by_type_memory_resp(
- responsePtr, responseMsg.size() - hdrSize, &completionCode, NULL);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_rw_file_by_type_memory_resp(responsePtr, 0, &completionCode,
- &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadWriteFileByTypeMemory, testGoodEncodeRequest)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES>
- requestMsg{};
-
- uint16_t fileType = 0;
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x13245768;
- uint64_t address = 0x124356879ACBDE0F;
- uint16_t fileTypeLe = htole16(fileType);
- uint32_t fileHandleLe = htole32(fileHandle);
- uint32_t offsetLe = htole32(offset);
- uint32_t lengthLe = htole32(length);
- uint64_t addressLe = htole64(address);
-
- pldm_msg *request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- auto rc = encode_rw_file_by_type_memory_req(
- 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, fileType, fileHandle, offset,
- length, address, request);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(request->hdr.instance_id, 0);
- ASSERT_EQ(request->hdr.type, PLDM_OEM);
- ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
-
- ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe),
- &fileHandleLe, sizeof(fileHandleLe)));
-
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe),
- &offsetLe, sizeof(offsetLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(offsetLe),
- &lengthLe, sizeof(lengthLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(offsetLe) +
- sizeof(lengthLe),
- &addressLe, sizeof(addressLe)));
-}
-
-TEST(ReadWriteFileByTypeMemory, testGoodEncodeResponse)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES>
- responseMsg{};
-
- uint32_t length = 0x13245768;
- uint32_t lengthLe = htole32(length);
- uint8_t completionCode = 0x0;
-
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc = encode_rw_file_by_type_memory_resp(
- 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, completionCode, length,
- response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
-
- ASSERT_EQ(0, memcmp(response->payload, &completionCode,
- sizeof(completionCode)));
- ASSERT_EQ(0, memcmp(response->payload + sizeof(completionCode),
- &lengthLe, sizeof(lengthLe)));
-}
-
-TEST(ReadWriteFileByTypeMemory, testBadEncodeResponse)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES>
- responseMsg{};
- uint32_t length = 0;
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // completion code is PLDM_ERROR
- auto rc = encode_rw_file_by_type_memory_resp(
- 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_ERROR, length,
- response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-
- // response is NULL pointer
- rc = encode_rw_file_by_type_memory_resp(
- 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_SUCCESS, length, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(ReadWriteFileByTypeMemory, testBadEncodeRequest)
-{
- uint8_t fileType = 0;
- uint32_t fileHandle = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
- uint64_t address = 0;
-
- // request is NULL pointer
- auto rc = encode_rw_file_by_type_memory_req(
- 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, fileType, fileHandle, offset,
- length, address, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(NewFile, testGoodDecodeRequest)
-{
- std::array<uint8_t, PLDM_NEW_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
- auto request =
- reinterpret_cast<pldm_new_file_req *>(requestPtr->payload);
-
- // Random value for fileHandle and length
- uint16_t fileType = 0xFF;
- uint32_t fileHandle = 0x12345678;
- uint64_t length = 0x13245768;
-
- request->file_type = htole16(fileType);
- request->file_handle = htole32(fileHandle);
- request->length = htole64(length);
-
- uint16_t retFileType = 0xFF;
- uint32_t retFileHandle = 0;
- uint64_t retLength = 0;
-
- // Invoke decode the read file request
- auto rc = decode_new_file_req(requestPtr, payload_length, &retFileType,
- &retFileHandle, &retLength);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileType, retFileType);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(length, retLength);
-}
-
-TEST(NewFile, testGoodDecodeResponse)
-{
- std::array<uint8_t, PLDM_NEW_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
- auto response =
- reinterpret_cast<pldm_new_file_resp *>(responsePtr->payload);
-
- // Random value for completion code
- uint8_t completionCode = 0x0;
-
- response->completion_code = completionCode;
-
- uint8_t retCompletionCode = PLDM_SUCCESS;
-
- // Invoke decode the read/write file response
- auto rc = decode_new_file_resp(responsePtr, payload_length,
- &retCompletionCode);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
-}
-
-TEST(NewFile, testBadDecodeRequest)
-{
- uint16_t fileType = 0;
- uint32_t fileHandle = 0;
- uint64_t length = 0;
-
- // Request payload message is missing
- auto rc = decode_new_file_req(NULL, 0, &fileType, &fileHandle, &length);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_NEW_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Payload length is invalid
- rc =
- decode_new_file_req(requestPtr, 0, &fileType, &fileHandle, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(NewFile, testBadDecodeResponse)
-{
- uint8_t completionCode = 0;
-
- // Request payload message is missing
- auto rc = decode_new_file_resp(NULL, 0, &completionCode);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_NEW_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Payload length is invalid
- rc = decode_new_file_resp(responsePtr, 0, &completionCode);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(NewFile, testGoodEncodeRequest)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_REQ_BYTES>
- requestMsg{};
-
- uint16_t fileType = 0xFF;
- uint32_t fileHandle = 0x12345678;
- uint32_t length = 0x13245768;
- uint16_t fileTypeLe = htole16(fileType);
- uint32_t fileHandleLe = htole32(fileHandle);
- uint32_t lengthLe = htole32(length);
-
- pldm_msg *request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- auto rc = encode_new_file_req(0, fileType, fileHandle, length, request);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(request->hdr.instance_id, 0);
- ASSERT_EQ(request->hdr.type, PLDM_OEM);
- ASSERT_EQ(request->hdr.command, PLDM_NEW_FILE_AVAILABLE);
- ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe),
- &fileHandleLe, sizeof(fileHandleLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe),
- &lengthLe, sizeof(lengthLe)));
-}
-
-TEST(NewFile, testGoodEncodeResponse)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_RESP_BYTES>
- responseMsg{};
-
- uint8_t completionCode = 0x0;
-
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc = encode_new_file_resp(0, completionCode, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE);
- ASSERT_EQ(0, memcmp(response->payload, &completionCode,
- sizeof(completionCode)));
-}
-
-TEST(NewFile, testBadEncodeResponse)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_RESP_BYTES>
- responseMsg{};
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // completion code is PLDM_ERROR
- auto rc = encode_new_file_resp(0, PLDM_ERROR, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-
- // response is NULL pointer
- rc = encode_new_file_resp(0, PLDM_SUCCESS, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(NewFile, testBadEncodeRequest)
-{
- uint8_t fileType = 0xFF;
- uint32_t fileHandle = 0;
- uint32_t length = 0;
-
- // request is NULL pointer
- auto rc = encode_new_file_req(0, fileType, fileHandle, length, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(ReadWriteFileByType, testGoodDecodeRequest)
-{
- std::array<uint8_t,
- PLDM_RW_FILE_BY_TYPE_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
- auto request = reinterpret_cast<pldm_read_write_file_by_type_req *>(
- requestPtr->payload);
-
- // Random value for fileHandle, offset and length
- uint16_t fileType = 0;
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x13245768;
-
- request->file_handle = htole32(fileHandle);
- request->offset = htole32(offset);
- request->length = htole32(length);
-
- uint16_t retFileType = 0x1;
- uint32_t retFileHandle = 0;
- uint32_t retOffset = 0;
- uint32_t retLength = 0;
-
- // Invoke decode the read file request
- auto rc =
- decode_rw_file_by_type_req(requestPtr, payload_length, &retFileType,
- &retFileHandle, &retOffset, &retLength);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileType, retFileType);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(offset, retOffset);
- ASSERT_EQ(length, retLength);
-}
-
-TEST(ReadWriteFileByType, testGoodDecodeResponse)
-{
- std::array<uint8_t,
- PLDM_RW_FILE_BY_TYPE_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
- auto response = reinterpret_cast<pldm_read_write_file_by_type_resp *>(
- responsePtr->payload);
-
- // Random value for completion code and length
- uint8_t completionCode = 0x0;
- uint32_t length = 0x13245768;
-
- response->completion_code = completionCode;
- response->length = htole32(length);
-
- uint8_t retCompletionCode = 0x1;
- uint32_t retLength = 0;
-
- // Invoke decode the read/write file response
- auto rc = decode_rw_file_by_type_resp(responsePtr, payload_length,
- &retCompletionCode, &retLength);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
- ASSERT_EQ(length, retLength);
-}
-
-TEST(ReadWriteFileByType, testBadDecodeRequest)
-{
- uint16_t fileType = 0;
- uint32_t fileHandle = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
-
- // Request payload message is missing
- auto rc = decode_rw_file_by_type_req(NULL, 0, &fileType, &fileHandle,
- &offset, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t,
- PLDM_RW_FILE_BY_TYPE_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Payload length is invalid
- rc = decode_rw_file_by_type_req(requestPtr, 0, &fileType, &fileHandle,
- &offset, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadWriteFileByType, testBadDecodeResponse)
-{
- uint32_t length = 0;
- uint8_t completionCode = 0;
-
- // Request payload message is missing
- auto rc =
- decode_rw_file_by_type_resp(NULL, 0, &completionCode, &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t,
- PLDM_RW_FILE_BY_TYPE_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Length is NULL
- rc = decode_rw_file_by_type_resp(
- responsePtr, responseMsg.size() - hdrSize, &completionCode, NULL);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- // Payload length is invalid
- rc = decode_rw_file_by_type_resp(responsePtr, 0, &completionCode,
- &length);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(ReadWriteFileByType, testGoodEncodeRequest)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_REQ_BYTES>
- requestMsg{};
-
- uint16_t fileType = 0;
- uint32_t fileHandle = 0x12345678;
- uint32_t offset = 0x87654321;
- uint32_t length = 0x13245768;
- uint16_t fileTypeLe = htole16(fileType);
- uint32_t fileHandleLe = htole32(fileHandle);
- uint32_t offsetLe = htole32(offset);
- uint32_t lengthLe = htole32(length);
-
- pldm_msg *request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- auto rc =
- encode_rw_file_by_type_req(0, PLDM_READ_FILE_BY_TYPE, fileType,
- fileHandle, offset, length, request);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(request->hdr.instance_id, 0);
- ASSERT_EQ(request->hdr.type, PLDM_OEM);
- ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_BY_TYPE);
-
- ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe),
- &fileHandleLe, sizeof(fileHandleLe)));
-
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe),
- &offsetLe, sizeof(offsetLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(offsetLe),
- &lengthLe, sizeof(lengthLe)));
-}
-
-TEST(ReadWriteFileByType, testGoodEncodeResponse)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_RESP_BYTES>
- responseMsg{};
-
- uint32_t length = 0x13245768;
- uint32_t lengthLe = htole32(length);
- uint8_t completionCode = 0x0;
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE,
- completionCode, length, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE);
-
- ASSERT_EQ(0, memcmp(response->payload, &completionCode,
- sizeof(completionCode)));
- ASSERT_EQ(0, memcmp(response->payload + sizeof(completionCode),
- &lengthLe, sizeof(lengthLe)));
-}
-
-TEST(ReadWriteFileByType, testBadEncodeResponse)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_RESP_BYTES>
- responseMsg{};
- uint32_t length = 0;
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // completion code is PLDM_ERROR
- auto rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE,
- PLDM_ERROR, length, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-
- // response is NULL pointer
- rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE,
- PLDM_SUCCESS, length, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(ReadWriteFileByType, testBadEncodeRequest)
-{
- uint8_t fileType = 0;
- uint32_t fileHandle = 0;
- uint32_t offset = 0;
- uint32_t length = 0;
-
- // request is NULL pointer
- auto rc =
- encode_rw_file_by_type_req(0, PLDM_READ_FILE_BY_TYPE, fileType,
- fileHandle, offset, length, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(FileAck, testGoodDecodeRequest)
-{
- std::array<uint8_t, PLDM_FILE_ACK_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
- auto request =
- reinterpret_cast<pldm_file_ack_req *>(requestPtr->payload);
-
- // Random value for fileHandle
- uint16_t fileType = 0xFFFF;
- uint32_t fileHandle = 0x12345678;
- uint8_t fileStatus = 0xFF;
-
- request->file_type = htole16(fileType);
- request->file_handle = htole32(fileHandle);
- request->file_status = fileStatus;
-
- uint16_t retFileType = 0xFF;
- uint32_t retFileHandle = 0;
- uint8_t retFileStatus = 0;
-
- // Invoke decode the read file request
- auto rc = decode_file_ack_req(requestPtr, payload_length, &retFileType,
- &retFileHandle, &retFileStatus);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileType, retFileType);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(fileStatus, retFileStatus);
-}
-
-TEST(FileAck, testGoodDecodeResponse)
-{
- std::array<uint8_t, PLDM_FILE_ACK_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
- auto response =
- reinterpret_cast<pldm_file_ack_resp *>(responsePtr->payload);
-
- // Random value for completion code
- uint8_t completionCode = 0x0;
-
- response->completion_code = completionCode;
-
- uint8_t retCompletionCode = PLDM_SUCCESS;
-
- // Invoke decode the read/write file response
- auto rc = decode_file_ack_resp(responsePtr, payload_length,
- &retCompletionCode);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
-}
-
-TEST(FileAck, testBadDecodeRequest)
-{
- uint16_t fileType = 0;
- uint32_t fileHandle = 0;
- uint8_t fileStatus = 0;
-
- // Request payload message is missing
- auto rc =
- decode_file_ack_req(NULL, 0, &fileType, &fileHandle, &fileStatus);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_FILE_ACK_REQ_BYTES + sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Payload length is invalid
- rc = decode_file_ack_req(requestPtr, 0, &fileType, &fileHandle,
- &fileStatus);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(FileAck, testBadDecodeResponse)
-{
- uint8_t completionCode = 0;
-
- // Request payload message is missing
- auto rc = decode_file_ack_resp(NULL, 0, &completionCode);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_FILE_ACK_RESP_BYTES + sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Payload length is invalid
- rc = decode_file_ack_resp(responsePtr, 0, &completionCode);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(FileAck, testGoodEncodeRequest)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_REQ_BYTES>
- requestMsg{};
-
- uint16_t fileType = 0xFFFF;
- uint32_t fileHandle = 0x12345678;
- uint8_t fileStatus = 0xFF;
- uint16_t fileTypeLe = htole16(fileType);
- uint32_t fileHandleLe = htole32(fileHandle);
-
- pldm_msg *request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- auto rc =
- encode_file_ack_req(0, fileType, fileHandle, fileStatus, request);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(request->hdr.instance_id, 0);
- ASSERT_EQ(request->hdr.type, PLDM_OEM);
- ASSERT_EQ(request->hdr.command, PLDM_FILE_ACK);
- ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe),
- &fileHandleLe, sizeof(fileHandleLe)));
-}
-
-TEST(FileAck, testGoodEncodeResponse)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_RESP_BYTES>
- responseMsg{};
-
- uint8_t completionCode = 0x0;
-
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc = encode_file_ack_resp(0, completionCode, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK);
- ASSERT_EQ(0, memcmp(response->payload, &completionCode,
- sizeof(completionCode)));
-}
-
-TEST(FileAck, testBadEncodeResponse)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_RESP_BYTES>
- responseMsg{};
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // completion code is PLDM_ERROR
- auto rc = encode_file_ack_resp(0, PLDM_ERROR, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-
- // response is NULL pointer
- rc = encode_file_ack_resp(0, PLDM_SUCCESS, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(FileAck, testBadEncodeRequest)
-{
- uint8_t fileType = 0xFF;
- uint32_t fileHandle = 0;
- uint8_t fileStatus = 0;
-
- // request is NULL pointer
- auto rc =
- encode_file_ack_req(0, fileType, fileHandle, fileStatus, nullptr);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(FileAckWithMetadata, testGoodEncodeResponse)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) +
- PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES>
- responseMsg{};
-
- uint8_t completionCode = 0x0;
-
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc =
- encode_file_ack_with_meta_data_resp(0, completionCode, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
- ASSERT_EQ(0, memcmp(response->payload, &completionCode,
- sizeof(completionCode)));
-}
-
-TEST(FileAckWithMetadata, testBadEncodeResponse)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) +
- PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES>
- responseMsg{};
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // completion code is PLDM_ERROR
- auto rc = encode_file_ack_with_meta_data_resp(0, PLDM_ERROR, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-
- // response is NULL pointer
- rc = encode_file_ack_with_meta_data_resp(0, PLDM_SUCCESS, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(FileAckWithMetadata, testGoodDecodeResponse)
-{
- std::array<uint8_t, PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES +
- sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
- auto response = reinterpret_cast<pldm_file_ack_with_meta_data_resp *>(
- responsePtr->payload);
-
- // Random value for completion code
- uint8_t completionCode = 0x0;
-
- response->completion_code = completionCode;
-
- uint8_t retCompletionCode = PLDM_SUCCESS;
-
- // Invoke decode the read/write file response
- auto rc = decode_file_ack_with_meta_data_resp(
- responsePtr, payload_length, &retCompletionCode);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
-}
-
-TEST(FileAckWithMetadata, testBadDecodeResponse)
-{
- uint8_t completionCode = 0;
-
- // Request payload message is missing
- auto rc = decode_file_ack_with_meta_data_resp(NULL, 0, &completionCode);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES +
- sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Payload length is invalid
- rc = decode_file_ack_with_meta_data_resp(responsePtr, 0,
- &completionCode);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(FileAckWithMetadata, testGoodEncodeRequest)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) +
- PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES>
- requestMsg{};
-
- uint16_t fileType = 0xFFFF;
- uint32_t fileHandle = 0x12345678;
- uint8_t fileStatus = 0xFF;
- uint32_t fileMetaData1 = 0xFFFFFFFF;
- uint32_t fileMetaData2 = 0xFFFFFFFF;
- uint32_t fileMetaData3 = 0xFFFFFFFF;
- uint32_t fileMetaData4 = 0xFFFFFFFF;
-
- uint16_t fileTypeLe = htole16(fileType);
- uint32_t fileHandleLe = htole32(fileHandle);
- uint32_t fileMetaData1Le = htole32(fileMetaData1);
- uint32_t fileMetaData2Le = htole32(fileMetaData2);
- uint32_t fileMetaData3Le = htole32(fileMetaData3);
- uint32_t fileMetaData4Le = htole32(fileMetaData4);
-
- pldm_msg *request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- auto rc = encode_file_ack_with_meta_data_req(
- 0, fileType, fileHandle, fileStatus, fileMetaData1, fileMetaData2,
- fileMetaData3, fileMetaData4, request);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(request->hdr.instance_id, 0);
- ASSERT_EQ(request->hdr.type, PLDM_OEM);
- ASSERT_EQ(request->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
- ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe),
- &fileHandleLe, sizeof(fileHandleLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe),
- &fileStatus, sizeof(fileStatus)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(fileStatus),
- &fileMetaData1Le, sizeof(fileMetaData1Le)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(fileStatus) +
- sizeof(fileMetaData1Le),
- &fileMetaData2Le, sizeof(fileMetaData2Le)));
-
- ASSERT_EQ(0,
- memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(fileStatus) +
- sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le),
- &fileMetaData3Le, sizeof(fileMetaData3Le)));
-
- ASSERT_EQ(0,
- memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(fileStatus) +
- sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le) +
- sizeof(fileMetaData3Le),
- &fileMetaData4Le, sizeof(fileMetaData4Le)));
-}
-
-TEST(FileAckWithMetadata, testBadEncodeRequest)
-{
- uint8_t fileType = 0xFF;
- uint32_t fileHandle = 0;
- uint8_t fileStatus = 0;
- uint32_t fileMetaData1 = 0;
- uint32_t fileMetaData2 = 0;
- uint32_t fileMetaData3 = 0;
- uint32_t fileMetaData4 = 0;
-
- // request is NULL pointer
- auto rc = encode_file_ack_with_meta_data_req(
- 0, fileType, fileHandle, fileStatus, fileMetaData1, fileMetaData2,
- fileMetaData3, fileMetaData4, nullptr);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(FileAckWithMetadata, testGoodDecodeRequest)
-{
- std::array<uint8_t, sizeof(pldm_msg_hdr) +
- PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
- auto request = reinterpret_cast<pldm_file_ack_with_meta_data_req *>(
- requestPtr->payload);
-
- uint16_t fileType = 0xFFFF;
- uint32_t fileHandle = 0x12345678;
- uint8_t fileStatus = 0xFF;
- uint32_t fileMetaData1 = 0x12345678;
- uint32_t fileMetaData2 = 0x87654321;
- uint32_t fileMetaData3 = 0x22121117;
- uint32_t fileMetaData4 = 0x12334345;
-
- request->file_type = htole16(fileType);
- request->file_handle = htole32(fileHandle);
- request->file_status = fileStatus;
- request->file_meta_data_1 = htole32(fileMetaData1);
- request->file_meta_data_2 = htole32(fileMetaData2);
- request->file_meta_data_3 = htole32(fileMetaData3);
- request->file_meta_data_4 = htole32(fileMetaData4);
-
- uint16_t retFileType = 0xFFFF;
- uint32_t retFileHandle = 0;
- uint8_t retFileStatus = 0;
- uint32_t retFileMetaData1 = 0;
- uint32_t retFileMetaData2 = 0;
- uint32_t retFileMetaData3 = 0;
- uint32_t retFileMetaData4 = 0;
-
- auto rc = decode_file_ack_with_meta_data_req(
- requestPtr, payload_length, &retFileType, &retFileHandle,
- &retFileStatus, &retFileMetaData1, &retFileMetaData2,
- &retFileMetaData3, &retFileMetaData4);
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileType, retFileType);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(fileStatus, retFileStatus);
- ASSERT_EQ(fileMetaData1, retFileMetaData1);
- ASSERT_EQ(fileMetaData2, retFileMetaData2);
- ASSERT_EQ(fileMetaData3, retFileMetaData3);
- ASSERT_EQ(fileMetaData4, retFileMetaData4);
-}
-
-TEST(FileAckWithMetadata, testBadDecodeRequest)
-{
- uint16_t fileType = 0;
- uint32_t fileHandle = 0;
- uint8_t fileStatus = 0;
- uint32_t fileMetaData1 = 0;
- uint32_t fileMetaData2 = 0;
- uint32_t fileMetaData3 = 0;
- uint32_t fileMetaData4 = 0;
-
- // Request payload message is missing
- auto rc = decode_file_ack_with_meta_data_req(
- NULL, 0, &fileType, &fileHandle, &fileStatus, &fileMetaData1,
- &fileMetaData2, &fileMetaData3, &fileMetaData4);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES +
- sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Payload length is invalid
- rc = decode_file_ack_with_meta_data_req(
- requestPtr, 0, &fileType, &fileHandle, &fileStatus, &fileMetaData1,
- &fileMetaData2, &fileMetaData3, &fileMetaData4);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(NewFileAvailableWithMetaData, testGoodEncodeResponse)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) +
- PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES>
- responseMsg{};
-
- uint8_t completionCode = 0x0;
-
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc =
- encode_new_file_with_metadata_resp(0, completionCode, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command,
- PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA);
- ASSERT_EQ(0, memcmp(response->payload, &completionCode,
- sizeof(completionCode)));
-}
-
-TEST(NewFileAvailableWithMetaData, testBadEncodeResponse)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) +
- PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES>
- responseMsg{};
- pldm_msg *response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // completion code is PLDM_ERROR
- auto rc = encode_new_file_with_metadata_resp(0, PLDM_ERROR, response);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
- ASSERT_EQ(response->hdr.instance_id, 0);
- ASSERT_EQ(response->hdr.type, PLDM_OEM);
- ASSERT_EQ(response->hdr.command,
- PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA);
- ASSERT_EQ(response->payload[0], PLDM_ERROR);
-
- // response is NULL pointer
- rc = encode_new_file_resp(0, PLDM_SUCCESS, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(NewFileAvailableWithMetaData, testGoodDecodeResponse)
-{
- std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES +
- sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
- size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
- auto response = reinterpret_cast<pldm_file_ack_with_meta_data_resp *>(
- responsePtr->payload);
-
- // Random value for completion code
- uint8_t completionCode = 0x0;
-
- response->completion_code = completionCode;
-
- uint8_t retCompletionCode = PLDM_SUCCESS;
-
- // Invoke decode the read/write file response
- auto rc = decode_new_file_with_metadata_resp(
- responsePtr, payload_length, &retCompletionCode);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(completionCode, retCompletionCode);
-}
-
-TEST(NewFileAvailableWithMetaData, testBadDecodeResponse)
-{
- uint8_t completionCode = 0;
-
- // Request payload message is missing
- auto rc = decode_new_file_with_metadata_resp(NULL, 0, &completionCode);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES +
- sizeof(pldm_msg_hdr)>
- responseMsg{};
-
- auto responsePtr = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- // Payload length is invalid
- rc =
- decode_new_file_with_metadata_resp(responsePtr, 0, &completionCode);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(NewFileAvailableWithMetaData, testGoodEncodeRequest)
-{
- std::array<uint8_t,
- sizeof(pldm_msg_hdr) +
- PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES>
- requestMsg{};
-
- uint16_t fileType = 0xFFFF;
- uint32_t fileHandle = 0x12345678;
- uint32_t length = 0x13245768;
- uint64_t fileMetaData1 = 0xFFFFFFFF;
- uint32_t fileMetaData2 = 0xFFFFFFFF;
- uint32_t fileMetaData3 = 0xFFFFFFFF;
- uint32_t fileMetaData4 = 0xFFFFFFFF;
-
- uint16_t fileTypeLe = htole16(fileType);
- uint32_t fileHandleLe = htole32(fileHandle);
- uint64_t lengthLe = htole64(length);
- uint32_t fileMetaData1Le = htole32(fileMetaData1);
- uint32_t fileMetaData2Le = htole32(fileMetaData2);
- uint32_t fileMetaData3Le = htole32(fileMetaData3);
- uint32_t fileMetaData4Le = htole32(fileMetaData4);
-
- pldm_msg *request = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- auto rc = encode_new_file_with_metadata_req(
- 0, fileType, fileHandle, length, fileMetaData1, fileMetaData2,
- fileMetaData3, fileMetaData4, request);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
- ASSERT_EQ(request->hdr.instance_id, 0);
- ASSERT_EQ(request->hdr.type, PLDM_OEM);
- ASSERT_EQ(request->hdr.command, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA);
- ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe),
- &fileHandleLe, sizeof(fileHandleLe)));
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe),
- &lengthLe, sizeof(lengthLe)));
-
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(lengthLe),
- &fileMetaData1Le, sizeof(fileMetaData1Le)));
-
- ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(lengthLe) +
- sizeof(fileMetaData1Le),
- &fileMetaData2Le, sizeof(fileMetaData2Le)));
-
- ASSERT_EQ(0,
- memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(lengthLe) +
- sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le),
- &fileMetaData3Le, sizeof(fileMetaData3Le)));
-
- ASSERT_EQ(0,
- memcmp(request->payload + sizeof(fileTypeLe) +
- sizeof(fileHandleLe) + sizeof(lengthLe) +
- sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le) +
- sizeof(fileMetaData3Le),
- &fileMetaData4Le, sizeof(fileMetaData4Le)));
-}
-
-TEST(NewFileAvailableWithMetaData, testBadEncodeRequest)
-{
- uint8_t fileType = 0xFF;
- uint32_t fileHandle = 0;
- uint32_t length = 0;
- uint32_t fileMetaData1 = 0;
- uint32_t fileMetaData2 = 0;
- uint32_t fileMetaData3 = 0;
- uint32_t fileMetaData4 = 0;
-
- // request is NULL pointer
- auto rc = encode_new_file_with_metadata_req(
- 0, fileType, fileHandle, length, fileMetaData1, fileMetaData2,
- fileMetaData3, fileMetaData4, NULL);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(NewFileAvailableWithMetaData, testGoodDecodeRequest)
-{
- std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES +
- sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
- size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
- auto request = reinterpret_cast<pldm_new_file_with_metadata_req *>(
- requestPtr->payload);
-
- // Random value for fileHandle and length
- uint16_t fileType = 0xFFFF;
- uint32_t fileHandle = 0x12345678;
- uint64_t length = 0x13245768;
- uint32_t fileMetaData1 = 0x12345678;
- uint32_t fileMetaData2 = 0x87654321;
- uint32_t fileMetaData3 = 0x22121117;
- uint32_t fileMetaData4 = 0x12334345;
-
- request->file_type = htole16(fileType);
- request->file_handle = htole32(fileHandle);
- request->length = htole64(length);
- request->file_meta_data_1 = htole32(fileMetaData1);
- request->file_meta_data_2 = htole32(fileMetaData2);
- request->file_meta_data_3 = htole32(fileMetaData3);
- request->file_meta_data_4 = htole32(fileMetaData4);
-
- uint16_t retFileType = 0xFFFF;
- uint32_t retFileHandle = 0;
- uint64_t retLength = 0;
- uint32_t retFileMetaData1 = 0;
- uint32_t retFileMetaData2 = 0;
- uint32_t retFileMetaData3 = 0;
- uint32_t retFileMetaData4 = 0;
-
- // Invoke decode the read file request
- auto rc = decode_new_file_with_metadata_req(
- requestPtr, payload_length, &retFileType, &retFileHandle,
- &retLength, &retFileMetaData1, &retFileMetaData2, &retFileMetaData3,
- &retFileMetaData4);
-
- ASSERT_EQ(rc, PLDM_SUCCESS);
- ASSERT_EQ(fileType, retFileType);
- ASSERT_EQ(fileHandle, retFileHandle);
- ASSERT_EQ(length, retLength);
- ASSERT_EQ(fileMetaData1, retFileMetaData1);
- ASSERT_EQ(fileMetaData2, retFileMetaData2);
- ASSERT_EQ(fileMetaData3, retFileMetaData3);
- ASSERT_EQ(fileMetaData4, retFileMetaData4);
-}
-
-TEST(NewFileAvailableWithMetaData, testBadDecodeRequest)
-{
- uint16_t fileType = 0;
- uint32_t fileHandle = 0;
- uint64_t length = 0;
- uint32_t fileMetaData1 = 0;
- uint32_t fileMetaData2 = 0;
- uint32_t fileMetaData3 = 0;
- uint32_t fileMetaData4 = 0;
-
- // Request payload message is missing
- auto rc = decode_new_file_with_metadata_req(
- NULL, 0, &fileType, &fileHandle, &length, &fileMetaData1,
- &fileMetaData2, &fileMetaData3, &fileMetaData4);
-
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES +
- sizeof(pldm_msg_hdr)>
- requestMsg{};
-
- auto requestPtr = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- // Payload length is invalid
- rc = decode_new_file_with_metadata_req(
- requestPtr, 0, &fileType, &fileHandle, &length, &fileMetaData1,
- &fileMetaData2, &fileMetaData3, &fileMetaData4);
- ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
diff --git a/libpldm/oem/ibm/libpldm/tests/libpldm_host_test.cpp b/libpldm/oem/ibm/libpldm/tests/libpldm_host_test.cpp
deleted file mode 100644
index 39f8e70..0000000
--- a/libpldm/oem/ibm/libpldm/tests/libpldm_host_test.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-#include "oem/ibm/libpldm/host.h"
-
-#include <string.h>
-
-#include <array>
-
-#include <gtest/gtest.h>
-
-constexpr auto hdrSize = sizeof(pldm_msg_hdr);
-
-TEST(GetAlertStatus, testGoodEncodeRequest)
-{
- std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES>
- requestMsg{};
-
- uint8_t versionId = 0x0;
-
- auto request = reinterpret_cast<pldm_msg *>(requestMsg.data());
- auto rc = encode_get_alert_status_req(0, versionId, request,
- PLDM_GET_ALERT_STATUS_REQ_BYTES);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(versionId, request->payload[0]);
-}
-
-TEST(GetAlertStatus, testBadEncodeRequest)
-{
- std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES>
- requestMsg{};
-
- auto request = reinterpret_cast<pldm_msg *>(requestMsg.data());
- auto rc = encode_get_alert_status_req(
- 0, 0x0, request, PLDM_GET_ALERT_STATUS_REQ_BYTES + 1);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(GetAlertStatus, testGoodDecodeResponse)
-{
- uint8_t completionCode = PLDM_SUCCESS;
- uint32_t rack_entry = 0xFF000030;
- uint32_t pri_cec_node = 0x00008030;
- std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_RESP_BYTES>
- responseMsg{};
-
- uint8_t retCompletionCode = 0;
- uint32_t retRack_entry = 0;
- uint32_t retPri_cec_node = 0;
-
- auto response = reinterpret_cast<pldm_msg *>(responseMsg.data());
- struct pldm_get_alert_status_resp *resp =
- reinterpret_cast<struct pldm_get_alert_status_resp *>(
- response->payload);
- resp->completion_code = completionCode;
- resp->rack_entry = htole32(rack_entry);
- resp->pri_cec_node = htole32(pri_cec_node);
-
- auto rc = decode_get_alert_status_resp(
- response, responseMsg.size() - hdrSize, &retCompletionCode,
- &retRack_entry, &retPri_cec_node);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(retCompletionCode, completionCode);
- EXPECT_EQ(retRack_entry, rack_entry);
- EXPECT_EQ(retPri_cec_node, pri_cec_node);
-}
-
-TEST(GetAlertStatus, testBadDecodeResponse)
-{
- auto rc = decode_get_alert_status_resp(NULL, 0, NULL, NULL, NULL);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-
- uint8_t completionCode = PLDM_SUCCESS;
- uint32_t rack_entry = 0xFF000030;
- uint32_t pri_cec_node = 0x00008030;
- std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_RESP_BYTES>
- responseMsg{};
-
- uint8_t retCompletionCode = 0;
- uint32_t retRack_entry = 0;
- uint32_t retPri_cec_node = 0;
-
- auto response = reinterpret_cast<pldm_msg *>(responseMsg.data());
- struct pldm_get_alert_status_resp *resp =
- reinterpret_cast<struct pldm_get_alert_status_resp *>(
- response->payload);
- resp->completion_code = completionCode;
- resp->rack_entry = htole32(rack_entry);
- resp->pri_cec_node = htole32(pri_cec_node);
-
- rc = decode_get_alert_status_resp(
- response, responseMsg.size() - hdrSize + 1, &retCompletionCode,
- &retRack_entry, &retPri_cec_node);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
-
-TEST(GetAlertStatus, testGoodEncodeResponse)
-{
- uint8_t completionCode = 0;
- uint32_t rack_entry = 0xFF000030;
- uint32_t pri_cec_node = 0x00008030;
-
- std::vector<uint8_t> responseMsg(hdrSize +
- PLDM_GET_ALERT_STATUS_RESP_BYTES);
- auto response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc = encode_get_alert_status_resp(0, PLDM_SUCCESS, rack_entry,
- pri_cec_node, response,
- responseMsg.size() - hdrSize);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- struct pldm_get_alert_status_resp *resp =
- reinterpret_cast<struct pldm_get_alert_status_resp *>(
- response->payload);
-
- EXPECT_EQ(completionCode, resp->completion_code);
- EXPECT_EQ(rack_entry, le32toh(resp->rack_entry));
- EXPECT_EQ(pri_cec_node, le32toh(resp->pri_cec_node));
-}
-
-TEST(GetAlertStatus, testBadEncodeResponse)
-{
- uint32_t rack_entry = 0xFF000030;
- uint32_t pri_cec_node = 0x00008030;
-
- std::vector<uint8_t> responseMsg(hdrSize +
- PLDM_GET_ALERT_STATUS_RESP_BYTES);
- auto response = reinterpret_cast<pldm_msg *>(responseMsg.data());
-
- auto rc = encode_get_alert_status_resp(
- 0, PLDM_SUCCESS, rack_entry, pri_cec_node, response,
- responseMsg.size() - hdrSize + 1);
-
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
-}
-
-TEST(GetAlertStatus, testGoodDecodeRequest)
-{
- std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES>
- requestMsg{};
-
- uint8_t versionId = 0x0;
- uint8_t retVersionId;
-
- auto req = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- req->payload[0] = versionId;
-
- auto rc = decode_get_alert_status_req(req, requestMsg.size() - hdrSize,
- &retVersionId);
-
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(retVersionId, versionId);
-}
-
-TEST(GetAlertStatus, testBadDecodeRequest)
-{
- std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES>
- requestMsg{};
-
- uint8_t versionId = 0x0;
- uint8_t retVersionId;
-
- auto req = reinterpret_cast<pldm_msg *>(requestMsg.data());
-
- req->payload[0] = versionId;
-
- auto rc = decode_get_alert_status_req(
- req, requestMsg.size() - hdrSize + 1, &retVersionId);
-
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
-}
diff --git a/libpldm/tests/meson.build b/libpldm/tests/meson.build
deleted file mode 100644
index 12dab0a..0000000
--- a/libpldm/tests/meson.build
+++ /dev/null
@@ -1,30 +0,0 @@
-tests = [
- 'libpldm_base_test',
- 'libpldm_platform_test',
- 'libpldm_bios_test',
- 'libpldm_bios_table_test',
- 'libpldm_fru_test',
- 'libpldm_utils_test',
- 'libpldm_pdr_test',
- 'libpldm_firmware_update_test'
-]
-
-if get_option('oem-ibm').enabled()
- tests += [
- '../oem/ibm/libpldm/tests/libpldm_fileio_test',
- '../oem/ibm/libpldm/tests/libpldm_host_test',
- ]
-endif
-
-foreach t : tests
- test(t, executable(t.underscorify(), t + '.cpp',
- implicit_include_directories: false,
- link_args: dynamic_linker,
- build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
- dependencies: [
- libpldm_dep,
- gtest,
- gmock]),
- workdir: meson.current_source_dir())
-endforeach
-
diff --git a/libpldmresponder/base.cpp b/libpldmresponder/base.cpp
index 4c5b757..42bc458 100644
--- a/libpldmresponder/base.cpp
+++ b/libpldmresponder/base.cpp
@@ -5,7 +5,7 @@
#include "libpldm/bios.h"
#include "libpldm/fru.h"
#include "libpldm/platform.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "base.hpp"
#include "common/utils.hpp"
diff --git a/meson.build b/meson.build
index ca005f4..55fc434 100644
--- a/meson.build
+++ b/meson.build
@@ -133,7 +133,7 @@
endif
endif
-subdir('libpldm')
+libpldm_dep = dependency('libpldm', fallback:['libpldm','libpldm_dep'])
if get_option('libpldm-only').disabled()
diff --git a/oem/ibm/libpldmresponder/file_io.hpp b/oem/ibm/libpldmresponder/file_io.hpp
index b1fe17c..4c74463 100644
--- a/oem/ibm/libpldmresponder/file_io.hpp
+++ b/oem/ibm/libpldmresponder/file_io.hpp
@@ -3,8 +3,8 @@
#include "config.h"
#include "libpldm/base.h"
-#include "oem/ibm/libpldm/file_io.h"
-#include "oem/ibm/libpldm/host.h"
+#include "libpldm/file_io.h"
+#include "libpldm/host.h"
#include "common/utils.hpp"
#include "oem/ibm/requester/dbus_to_file_handler.hpp"
diff --git a/oem/ibm/libpldmresponder/file_io_by_type.cpp b/oem/ibm/libpldmresponder/file_io_by_type.cpp
index 493a20a..c465c0d 100644
--- a/oem/ibm/libpldmresponder/file_io_by_type.cpp
+++ b/oem/ibm/libpldmresponder/file_io_by_type.cpp
@@ -3,7 +3,7 @@
#include "file_io_by_type.hpp"
#include "libpldm/base.h"
-#include "oem/ibm/libpldm/file_io.h"
+#include "libpldm/file_io.h"
#include "common/utils.hpp"
#include "file_io_type_cert.hpp"
diff --git a/oem/ibm/libpldmresponder/file_io_type_cert.cpp b/oem/ibm/libpldmresponder/file_io_type_cert.cpp
index 83d082e..5f0d220 100644
--- a/oem/ibm/libpldmresponder/file_io_type_cert.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_cert.cpp
@@ -1,7 +1,7 @@
#include "file_io_type_cert.hpp"
#include "libpldm/base.h"
-#include "oem/ibm/libpldm/file_io.h"
+#include "libpldm/file_io.h"
#include "common/utils.hpp"
diff --git a/oem/ibm/libpldmresponder/file_io_type_dump.cpp b/oem/ibm/libpldmresponder/file_io_type_dump.cpp
index 1ff1f54..94821b4 100644
--- a/oem/ibm/libpldmresponder/file_io_type_dump.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_dump.cpp
@@ -1,7 +1,7 @@
#include "file_io_type_dump.hpp"
#include "libpldm/base.h"
-#include "oem/ibm/libpldm/file_io.h"
+#include "libpldm/file_io.h"
#include "common/utils.hpp"
#include "utils.hpp"
diff --git a/oem/ibm/libpldmresponder/file_io_type_pel.cpp b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
index 6a40ebb..022b75e 100644
--- a/oem/ibm/libpldmresponder/file_io_type_pel.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
@@ -3,7 +3,7 @@
#include "file_io_type_pel.hpp"
#include "libpldm/base.h"
-#include "oem/ibm/libpldm/file_io.h"
+#include "libpldm/file_io.h"
#include "common/utils.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
index 0881869..abe9e69 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -1,7 +1,7 @@
#include "oem_ibm_handler.hpp"
#include "libpldm/entity.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "file_io_type_lid.hpp"
#include "libpldmresponder/file_io.hpp"
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.hpp b/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
index 6c1983c..b5f4032 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "libpldm/entity.h"
#include "libpldm/platform.h"
-#include "oem/ibm/libpldm/state_set_oem_ibm.h"
+#include "libpldm/state_set_oem_ibm.h"
#include "inband_code_update.hpp"
#include "libpldmresponder/oem_handler.hpp"
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
index 35dc058..3f090a9 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
@@ -1,7 +1,7 @@
#include "platform_oem_ibm.hpp"
#include "libpldm/platform_oem_ibm.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "common/utils.hpp"
#include "libpldmresponder/pdr.hpp"
diff --git a/oem/ibm/requester/dbus_to_file_handler.cpp b/oem/ibm/requester/dbus_to_file_handler.cpp
index 67ea9fb..3f031bc 100644
--- a/oem/ibm/requester/dbus_to_file_handler.cpp
+++ b/oem/ibm/requester/dbus_to_file_handler.cpp
@@ -1,7 +1,7 @@
#include "dbus_to_file_handler.hpp"
-#include "libpldm/requester/pldm.h"
-#include "oem/ibm/libpldm/file_io.h"
+#include "libpldm/file_io.h"
+#include "libpldm/pldm.h"
#include "common/utils.hpp"
diff --git a/pldmtool/oem/ibm/oem_ibm_state_set.hpp b/pldmtool/oem/ibm/oem_ibm_state_set.hpp
index d69e2fc..7799c61 100644
--- a/pldmtool/oem/ibm/oem_ibm_state_set.hpp
+++ b/pldmtool/oem/ibm/oem_ibm_state_set.hpp
@@ -1,4 +1,4 @@
-#include "oem/ibm/libpldm/state_set_oem_ibm.h"
+#include "libpldm/state_set_oem_ibm.h"
#include <libpldm/entity.h>
#include <libpldm/entity_oem_ibm.h>
diff --git a/pldmtool/oem/ibm/pldm_oem_ibm.cpp b/pldmtool/oem/ibm/pldm_oem_ibm.cpp
index 11b0b5d..86081f4 100644
--- a/pldmtool/oem/ibm/pldm_oem_ibm.cpp
+++ b/pldmtool/oem/ibm/pldm_oem_ibm.cpp
@@ -1,8 +1,8 @@
#include "pldm_oem_ibm.hpp"
-#include "oem/ibm/libpldm/file_io.h"
-#include "oem/ibm/libpldm/host.h"
-#include "pldm_types.h"
+#include "libpldm/file_io.h"
+#include "libpldm/host.h"
+#include "libpldm/pldm_types.h"
#include "../../pldm_cmd_helper.hpp"
diff --git a/pldmtool/pldm_cmd_helper.cpp b/pldmtool/pldm_cmd_helper.cpp
index b8a4b6d..039e984 100644
--- a/pldmtool/pldm_cmd_helper.cpp
+++ b/pldmtool/pldm_cmd_helper.cpp
@@ -1,6 +1,6 @@
#include "pldm_cmd_helper.hpp"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "xyz/openbmc_project/Common/error.hpp"
diff --git a/pldmtool/pldm_fru_cmd.cpp b/pldmtool/pldm_fru_cmd.cpp
index 6b3b399..6882916 100644
--- a/pldmtool/pldm_fru_cmd.cpp
+++ b/pldmtool/pldm_fru_cmd.cpp
@@ -3,7 +3,7 @@
#include "pldm_cmd_helper.hpp"
#ifdef OEM_IBM
-#include "oem/ibm/libpldm/fru.h"
+#include "libpldm/fru_oem_ibm.h"
#endif
#include <endian.h>
diff --git a/requester/handler.hpp b/requester/handler.hpp
index 2d0343a..8776359 100644
--- a/requester/handler.hpp
+++ b/requester/handler.hpp
@@ -3,7 +3,7 @@
#include "config.h"
#include "libpldm/base.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "common/types.hpp"
#include "pldmd/dbus_impl_requester.hpp"
diff --git a/requester/mctp_endpoint_discovery.cpp b/requester/mctp_endpoint_discovery.cpp
index d13c979..afdceaa 100644
--- a/requester/mctp_endpoint_discovery.cpp
+++ b/requester/mctp_endpoint_discovery.cpp
@@ -1,6 +1,6 @@
#include "mctp_endpoint_discovery.hpp"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "common/types.hpp"
#include "common/utils.hpp"
@@ -103,4 +103,4 @@
}
}
-} // namespace pldm
\ No newline at end of file
+} // namespace pldm
diff --git a/requester/request.hpp b/requester/request.hpp
index 8df3d03..c8256ed 100644
--- a/requester/request.hpp
+++ b/requester/request.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "libpldm/base.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "common/flight_recorder.hpp"
#include "common/types.hpp"
diff --git a/softoff/softoff.cpp b/softoff/softoff.cpp
index 1b6f16e..edfd29a 100644
--- a/softoff/softoff.cpp
+++ b/softoff/softoff.cpp
@@ -4,7 +4,7 @@
#include "libpldm/entity.h"
#include "libpldm/platform.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "libpldm/state_set.h"
#include "common/utils.hpp"
diff --git a/softoff/softoff.hpp b/softoff/softoff.hpp
index e9a8f44..b756a0a 100644
--- a/softoff/softoff.hpp
+++ b/softoff/softoff.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include "common/types.hpp"
diff --git a/libpldm/.clang-format b/subprojects/libpldm/.clang-format
similarity index 100%
rename from libpldm/.clang-format
rename to subprojects/libpldm/.clang-format
diff --git a/subprojects/libpldm/LICENSE b/subprojects/libpldm/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/subprojects/libpldm/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/libpldm/base.h b/subprojects/libpldm/include/libpldm/base.h
similarity index 100%
rename from libpldm/base.h
rename to subprojects/libpldm/include/libpldm/base.h
diff --git a/libpldm/bios.h b/subprojects/libpldm/include/libpldm/bios.h
similarity index 100%
rename from libpldm/bios.h
rename to subprojects/libpldm/include/libpldm/bios.h
diff --git a/libpldm/bios_table.h b/subprojects/libpldm/include/libpldm/bios_table.h
similarity index 100%
rename from libpldm/bios_table.h
rename to subprojects/libpldm/include/libpldm/bios_table.h
diff --git a/libpldm/entity.h b/subprojects/libpldm/include/libpldm/entity.h
similarity index 100%
rename from libpldm/entity.h
rename to subprojects/libpldm/include/libpldm/entity.h
diff --git a/libpldm/firmware_update.h b/subprojects/libpldm/include/libpldm/firmware_update.h
similarity index 100%
rename from libpldm/firmware_update.h
rename to subprojects/libpldm/include/libpldm/firmware_update.h
diff --git a/libpldm/fru.h b/subprojects/libpldm/include/libpldm/fru.h
similarity index 100%
rename from libpldm/fru.h
rename to subprojects/libpldm/include/libpldm/fru.h
diff --git a/subprojects/libpldm/include/libpldm/meson.build b/subprojects/libpldm/include/libpldm/meson.build
new file mode 100644
index 0000000..0d25754
--- /dev/null
+++ b/subprojects/libpldm/include/libpldm/meson.build
@@ -0,0 +1,35 @@
+libpldm_include_dir += include_directories('.')
+
+libpldm_headers += files(
+ 'base.h',
+ 'pldm_types.h',
+ 'platform.h',
+ 'bios.h',
+ 'bios_table.h',
+ 'entity.h',
+ 'states.h',
+ 'state_set.h',
+ 'fru.h',
+ 'utils.h',
+ 'pdr.h',
+ 'firmware_update.h'
+ )
+
+if get_option('oem-ibm').enabled()
+ libpldm_include_dir += include_directories('oem/ibm')
+ libpldm_headers += files(
+ 'oem/ibm/libpldm/entity_oem_ibm.h',
+ 'oem/ibm/libpldm/file_io.h',
+ 'oem/ibm/libpldm/host.h',
+ 'oem/ibm/libpldm/fru_oem_ibm.h',
+ 'oem/ibm/libpldm/platform_oem_ibm.h',
+ 'oem/ibm/libpldm/state_set_oem_ibm.h'
+ )
+endif
+
+if get_option('requester-api').enabled()
+ libpldm_headers += files(
+ 'requester/pldm.h'
+ )
+endif
+
diff --git a/libpldm/oem/ibm/libpldm/entity_oem_ibm.h b/subprojects/libpldm/include/libpldm/oem/ibm/libpldm/entity_oem_ibm.h
similarity index 100%
rename from libpldm/oem/ibm/libpldm/entity_oem_ibm.h
rename to subprojects/libpldm/include/libpldm/oem/ibm/libpldm/entity_oem_ibm.h
diff --git a/libpldm/oem/ibm/libpldm/file_io.h b/subprojects/libpldm/include/libpldm/oem/ibm/libpldm/file_io.h
similarity index 100%
rename from libpldm/oem/ibm/libpldm/file_io.h
rename to subprojects/libpldm/include/libpldm/oem/ibm/libpldm/file_io.h
diff --git a/libpldm/oem/ibm/libpldm/fru.h b/subprojects/libpldm/include/libpldm/oem/ibm/libpldm/fru_oem_ibm.h
similarity index 100%
rename from libpldm/oem/ibm/libpldm/fru.h
rename to subprojects/libpldm/include/libpldm/oem/ibm/libpldm/fru_oem_ibm.h
diff --git a/libpldm/oem/ibm/libpldm/host.h b/subprojects/libpldm/include/libpldm/oem/ibm/libpldm/host.h
similarity index 100%
rename from libpldm/oem/ibm/libpldm/host.h
rename to subprojects/libpldm/include/libpldm/oem/ibm/libpldm/host.h
diff --git a/libpldm/oem/ibm/libpldm/platform_oem_ibm.h b/subprojects/libpldm/include/libpldm/oem/ibm/libpldm/platform_oem_ibm.h
similarity index 100%
rename from libpldm/oem/ibm/libpldm/platform_oem_ibm.h
rename to subprojects/libpldm/include/libpldm/oem/ibm/libpldm/platform_oem_ibm.h
diff --git a/libpldm/oem/ibm/libpldm/state_set_oem_ibm.h b/subprojects/libpldm/include/libpldm/oem/ibm/libpldm/state_set_oem_ibm.h
similarity index 100%
rename from libpldm/oem/ibm/libpldm/state_set_oem_ibm.h
rename to subprojects/libpldm/include/libpldm/oem/ibm/libpldm/state_set_oem_ibm.h
diff --git a/libpldm/pdr.h b/subprojects/libpldm/include/libpldm/pdr.h
similarity index 100%
rename from libpldm/pdr.h
rename to subprojects/libpldm/include/libpldm/pdr.h
diff --git a/libpldm/platform.h b/subprojects/libpldm/include/libpldm/platform.h
similarity index 100%
rename from libpldm/platform.h
rename to subprojects/libpldm/include/libpldm/platform.h
diff --git a/libpldm/pldm.h b/subprojects/libpldm/include/libpldm/pldm.h
similarity index 100%
rename from libpldm/pldm.h
rename to subprojects/libpldm/include/libpldm/pldm.h
diff --git a/libpldm/pldm_types.h b/subprojects/libpldm/include/libpldm/pldm_types.h
similarity index 100%
rename from libpldm/pldm_types.h
rename to subprojects/libpldm/include/libpldm/pldm_types.h
diff --git a/libpldm/requester/pldm.h b/subprojects/libpldm/include/libpldm/requester/pldm.h
similarity index 100%
rename from libpldm/requester/pldm.h
rename to subprojects/libpldm/include/libpldm/requester/pldm.h
diff --git a/libpldm/state_set.h b/subprojects/libpldm/include/libpldm/state_set.h
similarity index 100%
rename from libpldm/state_set.h
rename to subprojects/libpldm/include/libpldm/state_set.h
diff --git a/libpldm/states.h b/subprojects/libpldm/include/libpldm/states.h
similarity index 100%
rename from libpldm/states.h
rename to subprojects/libpldm/include/libpldm/states.h
diff --git a/libpldm/utils.h b/subprojects/libpldm/include/libpldm/utils.h
similarity index 100%
rename from libpldm/utils.h
rename to subprojects/libpldm/include/libpldm/utils.h
diff --git a/libpldm/libpldm.pc.in b/subprojects/libpldm/libpldm.pc.in
similarity index 100%
rename from libpldm/libpldm.pc.in
rename to subprojects/libpldm/libpldm.pc.in
diff --git a/subprojects/libpldm/meson.build b/subprojects/libpldm/meson.build
new file mode 100644
index 0000000..fe06a35
--- /dev/null
+++ b/subprojects/libpldm/meson.build
@@ -0,0 +1,50 @@
+project('libpldm', ['c','cpp'],
+ default_options: [
+ 'buildtype=debugoptimized',
+ 'warning_level=3',
+ 'werror=true',
+ 'cpp_std=c++20',
+ 'c_std=c17',
+ 'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
+ ],
+ version: '0.1.0',
+ meson_version: '>=0.63.0',
+)
+
+add_project_arguments('-D_DEFAULT_SOURCE',language:['c'])
+
+libpldm_sources = files()
+subdir('src')
+
+libpldm_include_dir = ['include']
+libpldm_headers = files()
+
+subdir('include/libpldm')
+
+libpldm = library(
+ 'pldm',
+ libpldm_sources,
+ implicit_include_directories: false,
+ include_directories: libpldm_include_dir,
+ version: meson.project_version(),
+ install: true
+ )
+
+install_headers(
+ libpldm_headers,
+ subdir:'libpldm'
+ )
+
+libpldm_dep = declare_dependency(
+ include_directories: libpldm_include_dir,
+ link_with: libpldm)
+
+import('pkgconfig').generate(
+ name: 'libpldm',
+ description: 'PLDM protocol encode/decode C lib',
+ version: meson.project_version(),
+ libraries: libpldm)
+
+if get_option('tests').enabled()
+ subdir('tests')
+endif
diff --git a/subprojects/libpldm/meson_options.txt b/subprojects/libpldm/meson_options.txt
new file mode 100644
index 0000000..0197fa9
--- /dev/null
+++ b/subprojects/libpldm/meson_options.txt
@@ -0,0 +1,3 @@
+option('tests', type: 'feature', description: 'Build tests', value: 'enabled')
+option('oem-ibm', type: 'feature', description: 'Enable IBM OEM PLDM', yield: true)
+option('requester-api', type: 'feature', description: 'Enable libpldm requester API', value: 'enabled')
diff --git a/libpldm/base.c b/subprojects/libpldm/src/base.c
similarity index 100%
rename from libpldm/base.c
rename to subprojects/libpldm/src/base.c
diff --git a/libpldm/bios.c b/subprojects/libpldm/src/bios.c
similarity index 100%
rename from libpldm/bios.c
rename to subprojects/libpldm/src/bios.c
diff --git a/libpldm/bios_table.c b/subprojects/libpldm/src/bios_table.c
similarity index 100%
rename from libpldm/bios_table.c
rename to subprojects/libpldm/src/bios_table.c
diff --git a/libpldm/firmware_update.c b/subprojects/libpldm/src/firmware_update.c
similarity index 100%
rename from libpldm/firmware_update.c
rename to subprojects/libpldm/src/firmware_update.c
diff --git a/libpldm/fru.c b/subprojects/libpldm/src/fru.c
similarity index 100%
rename from libpldm/fru.c
rename to subprojects/libpldm/src/fru.c
diff --git a/subprojects/libpldm/src/meson.build b/subprojects/libpldm/src/meson.build
new file mode 100644
index 0000000..fc44e8a
--- /dev/null
+++ b/subprojects/libpldm/src/meson.build
@@ -0,0 +1,19 @@
+
+libpldm_sources += files(
+ 'base.c',
+ 'bios.c',
+ 'platform.c',
+ 'bios_table.c',
+ 'firmware_update.c',
+ 'fru.c',
+ 'pdr.c',
+ 'utils.c'
+ )
+
+if get_option('oem-ibm').enabled()
+ subdir('oem/ibm')
+endif
+
+if get_option('requester-api').enabled()
+ subdir('requester')
+endif
diff --git a/libpldm/oem/ibm/libpldm/file_io.c b/subprojects/libpldm/src/oem/ibm/file_io.c
similarity index 99%
rename from libpldm/oem/ibm/libpldm/file_io.c
rename to subprojects/libpldm/src/oem/ibm/file_io.c
index fae3a9c..b3464cb 100644
--- a/libpldm/oem/ibm/libpldm/file_io.c
+++ b/subprojects/libpldm/src/oem/ibm/file_io.c
@@ -1,4 +1,4 @@
-#include "file_io.h"
+#include "libpldm/file_io.h"
#include <endian.h>
#include <string.h>
diff --git a/libpldm/oem/ibm/libpldm/host.c b/subprojects/libpldm/src/oem/ibm/host.c
similarity index 98%
rename from libpldm/oem/ibm/libpldm/host.c
rename to subprojects/libpldm/src/oem/ibm/host.c
index caaaf9e..d557a41 100644
--- a/libpldm/oem/ibm/libpldm/host.c
+++ b/subprojects/libpldm/src/oem/ibm/host.c
@@ -1,7 +1,7 @@
#include <endian.h>
#include <string.h>
-#include "host.h"
+#include "libpldm/host.h"
int encode_get_alert_status_req(uint8_t instance_id, uint8_t version_id,
struct pldm_msg *msg, size_t payload_length)
diff --git a/subprojects/libpldm/src/oem/ibm/meson.build b/subprojects/libpldm/src/oem/ibm/meson.build
new file mode 100644
index 0000000..04bb24f
--- /dev/null
+++ b/subprojects/libpldm/src/oem/ibm/meson.build
@@ -0,0 +1,5 @@
+libpldm_sources += files(
+ 'file_io.c',
+ 'host.c',
+ 'platform.c'
+ )
diff --git a/libpldm/oem/ibm/libpldm/platform_oem_ibm.c b/subprojects/libpldm/src/oem/ibm/platform.c
similarity index 94%
rename from libpldm/oem/ibm/libpldm/platform_oem_ibm.c
rename to subprojects/libpldm/src/oem/ibm/platform.c
index db7090a..15e9463 100644
--- a/libpldm/oem/ibm/libpldm/platform_oem_ibm.c
+++ b/subprojects/libpldm/src/oem/ibm/platform.c
@@ -1,5 +1,5 @@
-#include "platform_oem_ibm.h"
-#include "platform.h"
+#include "libpldm/platform.h"
+#include "libpldm/platform_oem_ibm.h"
#include <string.h>
int encode_bios_attribute_update_event_req(uint8_t instance_id,
@@ -47,4 +47,4 @@
num_handles * sizeof(uint16_t));
return PLDM_SUCCESS;
-}
\ No newline at end of file
+}
diff --git a/libpldm/pdr.c b/subprojects/libpldm/src/pdr.c
similarity index 100%
rename from libpldm/pdr.c
rename to subprojects/libpldm/src/pdr.c
diff --git a/libpldm/platform.c b/subprojects/libpldm/src/platform.c
similarity index 100%
rename from libpldm/platform.c
rename to subprojects/libpldm/src/platform.c
diff --git a/subprojects/libpldm/src/requester/meson.build b/subprojects/libpldm/src/requester/meson.build
new file mode 100644
index 0000000..6798d02
--- /dev/null
+++ b/subprojects/libpldm/src/requester/meson.build
@@ -0,0 +1,3 @@
+libpldm_sources += files(
+ 'pldm.c'
+ )
diff --git a/libpldm/requester/pldm.c b/subprojects/libpldm/src/requester/pldm.c
similarity index 100%
rename from libpldm/requester/pldm.c
rename to subprojects/libpldm/src/requester/pldm.c
diff --git a/libpldm/utils.c b/subprojects/libpldm/src/utils.c
similarity index 100%
rename from libpldm/utils.c
rename to subprojects/libpldm/src/utils.c
diff --git a/subprojects/libpldm/subprojects/googletest.wrap b/subprojects/libpldm/subprojects/googletest.wrap
new file mode 100644
index 0000000..56da9ef
--- /dev/null
+++ b/subprojects/libpldm/subprojects/googletest.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/google/googletest
+revision = HEAD
diff --git a/libpldm/tests/.clang-format b/subprojects/libpldm/tests/.clang-format
similarity index 100%
rename from libpldm/tests/.clang-format
rename to subprojects/libpldm/tests/.clang-format
diff --git a/libpldm/tests/libpldm_base_test.cpp b/subprojects/libpldm/tests/libpldm_base_test.cpp
similarity index 100%
rename from libpldm/tests/libpldm_base_test.cpp
rename to subprojects/libpldm/tests/libpldm_base_test.cpp
diff --git a/libpldm/tests/libpldm_bios_table_test.cpp b/subprojects/libpldm/tests/libpldm_bios_table_test.cpp
similarity index 100%
rename from libpldm/tests/libpldm_bios_table_test.cpp
rename to subprojects/libpldm/tests/libpldm_bios_table_test.cpp
diff --git a/libpldm/tests/libpldm_bios_test.cpp b/subprojects/libpldm/tests/libpldm_bios_test.cpp
similarity index 100%
rename from libpldm/tests/libpldm_bios_test.cpp
rename to subprojects/libpldm/tests/libpldm_bios_test.cpp
diff --git a/libpldm/tests/libpldm_firmware_update_test.cpp b/subprojects/libpldm/tests/libpldm_firmware_update_test.cpp
similarity index 100%
rename from libpldm/tests/libpldm_firmware_update_test.cpp
rename to subprojects/libpldm/tests/libpldm_firmware_update_test.cpp
diff --git a/libpldm/tests/libpldm_fru_test.cpp b/subprojects/libpldm/tests/libpldm_fru_test.cpp
similarity index 100%
rename from libpldm/tests/libpldm_fru_test.cpp
rename to subprojects/libpldm/tests/libpldm_fru_test.cpp
diff --git a/libpldm/tests/libpldm_pdr_test.cpp b/subprojects/libpldm/tests/libpldm_pdr_test.cpp
similarity index 100%
rename from libpldm/tests/libpldm_pdr_test.cpp
rename to subprojects/libpldm/tests/libpldm_pdr_test.cpp
diff --git a/libpldm/tests/libpldm_platform_test.cpp b/subprojects/libpldm/tests/libpldm_platform_test.cpp
similarity index 100%
rename from libpldm/tests/libpldm_platform_test.cpp
rename to subprojects/libpldm/tests/libpldm_platform_test.cpp
diff --git a/libpldm/tests/libpldm_utils_test.cpp b/subprojects/libpldm/tests/libpldm_utils_test.cpp
similarity index 100%
rename from libpldm/tests/libpldm_utils_test.cpp
rename to subprojects/libpldm/tests/libpldm_utils_test.cpp
diff --git a/subprojects/libpldm/tests/meson.build b/subprojects/libpldm/tests/meson.build
new file mode 100644
index 0000000..1955487
--- /dev/null
+++ b/subprojects/libpldm/tests/meson.build
@@ -0,0 +1,43 @@
+gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
+gmock_dep = dependency('gmock', disabler: true, required: false)
+if not gtest_dep.found() or not gmock_dep.found()
+ gtest_proj = import('cmake').subproject('googletest', required: true)
+ gtest_dep = declare_dependency(
+ dependencies: [
+ dependency('threads'),
+ gtest_proj.dependency('gtest'),
+ gtest_proj.dependency('gtest_main'),
+ ]
+ )
+ gmock_dep = gtest_proj.dependency('gmock')
+endif
+
+
+tests = [
+ 'libpldm_base_test',
+ 'libpldm_platform_test',
+ 'libpldm_bios_test',
+ 'libpldm_bios_table_test',
+ 'libpldm_fru_test',
+ 'libpldm_utils_test',
+ 'libpldm_pdr_test',
+ 'libpldm_firmware_update_test'
+]
+
+if get_option('oem-ibm').enabled()
+ tests += [
+ 'oem/ibm/libpldm_fileio_test',
+ 'oem/ibm/libpldm_host_test',
+ ]
+endif
+
+foreach t : tests
+ test(t, executable(t.underscorify(), t + '.cpp',
+ implicit_include_directories: false,
+ dependencies: [
+ libpldm_dep,
+ gtest_dep,
+ gmock_dep]),
+ workdir: meson.current_source_dir())
+endforeach
+
diff --git a/subprojects/libpldm/tests/oem/ibm/libpldm_fileio_test.cpp b/subprojects/libpldm/tests/oem/ibm/libpldm_fileio_test.cpp
new file mode 100644
index 0000000..f6c94e7
--- /dev/null
+++ b/subprojects/libpldm/tests/oem/ibm/libpldm_fileio_test.cpp
@@ -0,0 +1,2124 @@
+#include <string.h>
+
+#include <array>
+
+#include "libpldm/base.h"
+#include "libpldm/file_io.h"
+
+#include <gtest/gtest.h>
+
+constexpr auto hdrSize = sizeof(pldm_msg_hdr);
+
+TEST(ReadWriteFileMemory, testGoodDecodeRequest)
+{
+ std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES + hdrSize> requestMsg{};
+
+ // Random value for fileHandle, offset, length, address
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x13245768;
+ uint64_t address = 0x124356879ACBDE0F;
+ uint32_t fileHandleLe = htole32(fileHandle);
+ uint32_t offsetLe = htole32(offset);
+ uint32_t lengthLe = htole32(length);
+ uint64_t addressLe = htole64(address);
+
+ memcpy(requestMsg.data() + hdrSize, &fileHandleLe, sizeof(fileHandleLe));
+ memcpy(requestMsg.data() + sizeof(fileHandleLe) + hdrSize, &offsetLe,
+ sizeof(offsetLe));
+ memcpy(requestMsg.data() + sizeof(fileHandleLe) + sizeof(offsetLe) +
+ hdrSize,
+ &lengthLe, sizeof(lengthLe));
+ memcpy(requestMsg.data() + sizeof(fileHandleLe) + sizeof(offsetLe) +
+ sizeof(lengthLe) + hdrSize,
+ &addressLe, sizeof(addressLe));
+
+ uint32_t retFileHandle = 0;
+ uint32_t retOffset = 0;
+ uint32_t retLength = 0;
+ uint64_t retAddress = 0;
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Invoke decode the read file memory request
+ auto rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize,
+ &retFileHandle, &retOffset, &retLength,
+ &retAddress);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(offset, retOffset);
+ ASSERT_EQ(length, retLength);
+ ASSERT_EQ(address, retAddress);
+}
+
+TEST(ReadWriteFileMemory, testBadDecodeRequest)
+{
+ uint32_t fileHandle = 0;
+ uint32_t offset = 0;
+ uint32_t length = 0;
+ uint64_t address = 0;
+
+ // Request payload message is missing
+ auto rc = decode_rw_file_memory_req(NULL, 0, &fileHandle, &offset, &length,
+ &address);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES> requestMsg{};
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Address is NULL
+ rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize,
+ &fileHandle, &offset, &length, NULL);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_rw_file_memory_req(request, 0, &fileHandle, &offset, &length,
+ &address);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadWriteFileMemory, testGoodEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES>
+ responseMsg{};
+ uint32_t length = 0xFF00EE11;
+ uint32_t lengthLe = htole32(length);
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // ReadFileIntoMemory
+ auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_SUCCESS, length, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
+ ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
+ ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
+ &lengthLe, sizeof(lengthLe)));
+
+ // WriteFileFromMemory
+ rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY,
+ PLDM_SUCCESS, length, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY);
+ ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
+ ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
+ &lengthLe, sizeof(lengthLe)));
+}
+
+TEST(ReadWriteFileMemory, testBadEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES>
+ responseMsg{};
+ uint32_t length = 0;
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // ReadFileIntoMemory
+ auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY,
+ PLDM_ERROR, length, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+
+ // WriteFileFromMemory
+ rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY, PLDM_ERROR,
+ length, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+}
+
+TEST(ReadWriteFileIntoMemory, testGoodDecodeResponse)
+{
+ std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES + hdrSize> responseMsg{};
+ // Random value for length
+ uint32_t length = 0xFF00EE12;
+ uint32_t lengthLe = htole32(length);
+ uint8_t completionCode = 0;
+
+ memcpy(responseMsg.data() + hdrSize, &completionCode,
+ sizeof(completionCode));
+ memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &lengthLe,
+ sizeof(lengthLe));
+
+ uint8_t retCompletionCode = 0;
+ uint32_t retLength = 0;
+
+ auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Invoke decode the read file memory response
+ auto rc = decode_rw_file_memory_resp(response, responseMsg.size() - hdrSize,
+ &retCompletionCode, &retLength);
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+ ASSERT_EQ(length, retLength);
+}
+
+TEST(ReadWriteFileIntoMemory, testBadDecodeResponse)
+{
+ uint32_t length = 0;
+ uint8_t completionCode = 0;
+
+ // Request payload message is missing
+ auto rc = decode_rw_file_memory_resp(NULL, 0, &completionCode, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES> responseMsg{};
+
+ auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Payload length is invalid
+ rc = decode_rw_file_memory_resp(response, 0, &completionCode, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadWriteFileIntoMemory, testGoodEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_REQ_BYTES>
+ requestMsg{};
+
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x13245768;
+ uint64_t address = 0x124356879ACBDE0F;
+ uint32_t fileHandleLe = htole32(fileHandle);
+ uint32_t offsetLe = htole32(offset);
+ uint32_t lengthLe = htole32(length);
+ uint64_t addressLe = htole64(address);
+
+ pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ auto rc =
+ encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle,
+ offset, length, address, request);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(request->hdr.instance_id, 0);
+ ASSERT_EQ(request->hdr.type, PLDM_OEM);
+ ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_INTO_MEMORY);
+
+ ASSERT_EQ(0, memcmp(request->payload, &fileHandleLe, sizeof(fileHandleLe)));
+
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe), &offsetLe,
+ sizeof(offsetLe)));
+ ASSERT_EQ(0,
+ memcmp(request->payload + sizeof(fileHandleLe) + sizeof(offsetLe),
+ &lengthLe, sizeof(lengthLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe) +
+ sizeof(offsetLe) + sizeof(lengthLe),
+ &addressLe, sizeof(addressLe)));
+}
+
+TEST(ReadWriteFileIntoMemory, testBadEncodeRequest)
+{
+ uint32_t fileHandle = 0;
+ uint32_t offset = 0;
+ uint32_t length = 0;
+ uint64_t address = 0;
+
+ auto rc =
+ encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle,
+ offset, length, address, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(GetFileTable, GoodDecodeRequest)
+{
+ std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES + hdrSize> requestMsg{};
+
+ // Random value for DataTransferHandle, TransferOperationFlag, TableType
+ uint32_t transferHandle = 0x12345678;
+ uint32_t transferHandleLe = htole32(transferHandle);
+ uint8_t transferOpFlag = 1;
+ uint8_t tableType = 1;
+
+ memcpy(requestMsg.data() + hdrSize, &transferHandleLe,
+ sizeof(transferHandleLe));
+ memcpy(requestMsg.data() + sizeof(transferHandle) + hdrSize,
+ &transferOpFlag, sizeof(transferOpFlag));
+ memcpy(requestMsg.data() + sizeof(transferHandle) + sizeof(transferOpFlag) +
+ hdrSize,
+ &tableType, sizeof(tableType));
+
+ uint32_t retTransferHandle = 0;
+ uint8_t retTransferOpFlag = 0;
+ uint8_t retTableType = 0;
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Invoke decode get file table request
+ auto rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize,
+ &retTransferHandle, &retTransferOpFlag,
+ &retTableType);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(transferHandle, retTransferHandle);
+ ASSERT_EQ(transferOpFlag, retTransferOpFlag);
+ ASSERT_EQ(tableType, retTableType);
+}
+
+TEST(GetFileTable, BadDecodeRequest)
+{
+ uint32_t transferHandle = 0;
+ uint8_t transferOpFlag = 0;
+ uint8_t tableType = 0;
+
+ // Request payload message is missing
+ auto rc = decode_get_file_table_req(nullptr, 0, &transferHandle,
+ &transferOpFlag, &tableType);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES> requestMsg{};
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // TableType is NULL
+ rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize,
+ &transferHandle, &transferOpFlag, nullptr);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_get_file_table_req(request, 0, &transferHandle, &transferOpFlag,
+ &tableType);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(GetFileTable, GoodEncodeResponse)
+{
+ // Random value for NextDataTransferHandle and TransferFlag
+ uint8_t completionCode = 0;
+ uint32_t nextTransferHandle = 0x87654321;
+ uint32_t nextTransferHandleLe = htole32(nextTransferHandle);
+ uint8_t transferFlag = 5;
+ // Mock file table contents of size 5
+ std::array<uint8_t, 5> fileTable = {1, 2, 3, 4, 5};
+ constexpr size_t responseSize = sizeof(completionCode) +
+ sizeof(nextTransferHandle) +
+ sizeof(transferFlag) + fileTable.size();
+
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{};
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // GetFileTable
+ auto rc = encode_get_file_table_resp(0, PLDM_SUCCESS, nextTransferHandle,
+ transferFlag, fileTable.data(),
+ fileTable.size(), response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE);
+ ASSERT_EQ(response->payload[0], PLDM_SUCCESS);
+ ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
+ &nextTransferHandleLe, sizeof(nextTransferHandle)));
+ ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
+ sizeof(nextTransferHandle),
+ &transferFlag, sizeof(transferFlag)));
+ ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
+ sizeof(nextTransferHandle),
+ &transferFlag, sizeof(transferFlag)));
+ ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
+ sizeof(nextTransferHandle) + sizeof(transferFlag),
+ fileTable.data(), fileTable.size()));
+}
+
+TEST(GetFileTable, BadEncodeResponse)
+{
+ uint8_t completionCode = 0;
+ uint32_t nextTransferHandle = 0;
+ uint8_t transferFlag = 0;
+ constexpr size_t responseSize = sizeof(completionCode) +
+ sizeof(nextTransferHandle) +
+ sizeof(transferFlag);
+
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{};
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // GetFileTable
+ auto rc = encode_get_file_table_resp(0, PLDM_ERROR, nextTransferHandle,
+ transferFlag, nullptr, 0, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+}
+
+TEST(GetFileTable, GoodEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_FILE_TABLE_REQ_BYTES>
+ requestMsg{};
+ uint32_t transferHandle = 0x0;
+ uint8_t transferOpFlag = 0x01;
+ uint8_t tableType = PLDM_FILE_ATTRIBUTE_TABLE;
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ auto rc = encode_get_file_table_req(0, transferHandle, transferOpFlag,
+ tableType, request);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ struct pldm_get_file_table_req* req =
+ reinterpret_cast<struct pldm_get_file_table_req*>(request->payload);
+ EXPECT_EQ(transferHandle, le32toh(req->transfer_handle));
+ EXPECT_EQ(transferOpFlag, req->operation_flag);
+ EXPECT_EQ(tableType, req->table_type);
+}
+
+TEST(GetFileTable, BadEncodeRequest)
+{
+ uint32_t transferHandle = 0x0;
+ uint8_t transferOpFlag = 0x01;
+ uint8_t tableType = PLDM_FILE_ATTRIBUTE_TABLE;
+
+ auto rc = encode_get_file_table_req(0, transferHandle, transferOpFlag,
+ tableType, nullptr);
+
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(GetFileTable, GoodDecodeResponse)
+{
+ uint32_t nextTransferHandle = 32;
+ uint8_t completionCode = PLDM_SUCCESS;
+ uint8_t transferFlag = PLDM_START_AND_END;
+ std::vector<uint8_t> fileTableData = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+
+ std::vector<uint8_t> responseMsg(
+ hdrSize + PLDM_GET_FILE_TABLE_MIN_RESP_BYTES + fileTableData.size());
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - hdrSize;
+
+ auto resp = reinterpret_cast<struct pldm_get_file_table_resp*>(
+ responsePtr->payload);
+
+ resp->completion_code = completionCode;
+ resp->next_transfer_handle = htole32(nextTransferHandle);
+ resp->transfer_flag = transferFlag;
+ memcpy(resp->table_data, fileTableData.data(), fileTableData.size());
+
+ uint8_t retCompletionCode;
+ uint32_t retNextTransferHandle;
+ uint8_t retTransferFlag;
+ std::vector<uint8_t> retFileTableData(9, 0);
+ size_t retFileTableDataLength = 0;
+
+ auto rc = decode_get_file_table_resp(
+ responsePtr, payload_length, &retCompletionCode, &retNextTransferHandle,
+ &retTransferFlag, retFileTableData.data(), &retFileTableDataLength);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+ ASSERT_EQ(nextTransferHandle, retNextTransferHandle);
+ ASSERT_EQ(transferFlag, retTransferFlag);
+ ASSERT_EQ(0, memcmp(fileTableData.data(), resp->table_data,
+ retFileTableDataLength));
+ ASSERT_EQ(fileTableData.size(), retFileTableDataLength);
+}
+
+TEST(GetFileTable, BadDecodeResponse)
+{
+ uint32_t nextTransferHandle = 32;
+ uint8_t completionCode = PLDM_SUCCESS;
+ uint8_t transferFlag = PLDM_START_AND_END;
+ std::vector<uint8_t> fileTableData(9, 0);
+ size_t file_table_data_length = 0;
+
+ std::vector<uint8_t> responseMsg(
+ hdrSize + PLDM_GET_FILE_TABLE_MIN_RESP_BYTES + fileTableData.size());
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc = decode_get_file_table_resp(
+ nullptr, 0, &completionCode, &nextTransferHandle, &transferFlag,
+ fileTableData.data(), &file_table_data_length);
+
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = decode_get_file_table_resp(
+ responsePtr, 0, &completionCode, &nextTransferHandle, &transferFlag,
+ fileTableData.data(), &file_table_data_length);
+
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadFile, testGoodDecodeRequest)
+{
+ std::array<uint8_t, PLDM_READ_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
+ auto request = reinterpret_cast<pldm_read_file_req*>(requestPtr->payload);
+
+ // Random value for fileHandle, offset and length
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x13245768;
+
+ request->file_handle = htole32(fileHandle);
+ request->offset = htole32(offset);
+ request->length = htole32(length);
+
+ uint32_t retFileHandle = 0;
+ uint32_t retOffset = 0;
+ uint32_t retLength = 0;
+
+ // Invoke decode the read file request
+ auto rc = decode_read_file_req(requestPtr, payload_length, &retFileHandle,
+ &retOffset, &retLength);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(offset, retOffset);
+ ASSERT_EQ(length, retLength);
+}
+
+TEST(WriteFile, testGoodDecodeRequest)
+{
+ // Random value for fileHandle, offset, length and file data
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x467;
+
+ std::vector<uint8_t> requestMsg(PLDM_WRITE_FILE_REQ_BYTES +
+ sizeof(pldm_msg_hdr) + length);
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
+ auto request = reinterpret_cast<pldm_write_file_req*>(requestPtr->payload);
+
+ size_t fileDataOffset =
+ sizeof(fileHandle) + sizeof(offset) + sizeof(length);
+
+ request->file_handle = htole32(fileHandle);
+ request->offset = htole32(offset);
+ request->length = htole32(length);
+
+ uint32_t retFileHandle = 0;
+ uint32_t retOffset = 0;
+ uint32_t retLength = 0;
+ size_t retFileDataOffset = 0;
+
+ // Invoke decode the write file request
+ auto rc = decode_write_file_req(requestPtr, payload_length, &retFileHandle,
+ &retOffset, &retLength, &retFileDataOffset);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(offset, retOffset);
+ ASSERT_EQ(length, retLength);
+ ASSERT_EQ(fileDataOffset, retFileDataOffset);
+}
+
+TEST(ReadFile, testGoodDecodeResponse)
+{
+ // Random value for length
+ uint32_t length = 0x10;
+ uint8_t completionCode = PLDM_SUCCESS;
+
+ std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
+ sizeof(pldm_msg_hdr) + length);
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
+ auto response =
+ reinterpret_cast<pldm_read_file_resp*>(responsePtr->payload);
+
+ response->completion_code = completionCode;
+ response->length = htole32(length);
+
+ size_t fileDataOffset = sizeof(completionCode) + sizeof(length);
+
+ uint32_t retLength = 0;
+ uint8_t retCompletionCode = 0;
+ size_t retFileDataOffset = 0;
+
+ // Invoke decode the read file response
+ auto rc =
+ decode_read_file_resp(responsePtr, payload_length, &retCompletionCode,
+ &retLength, &retFileDataOffset);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+ ASSERT_EQ(length, retLength);
+ ASSERT_EQ(fileDataOffset, retFileDataOffset);
+}
+
+TEST(WriteFile, testGoodDecodeResponse)
+{
+ std::array<uint8_t, PLDM_WRITE_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
+ auto response =
+ reinterpret_cast<pldm_write_file_resp*>(responsePtr->payload);
+
+ uint8_t completionCode = PLDM_SUCCESS;
+ uint32_t length = 0x4678;
+
+ response->completion_code = completionCode;
+ response->length = htole32(length);
+
+ uint32_t retLength = 0;
+ uint8_t retCompletionCode = 0;
+
+ // Invoke decode the write file response
+ auto rc = decode_write_file_resp(responsePtr, payload_length,
+ &retCompletionCode, &retLength);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+ ASSERT_EQ(length, retLength);
+}
+
+TEST(ReadWriteFile, testBadDecodeResponse)
+{
+ uint32_t length = 0;
+ uint8_t completionCode = 0;
+ size_t fileDataOffset = 0;
+
+ // Bad decode response for read file
+ std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
+ sizeof(pldm_msg_hdr) + length);
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Request payload message is missing
+ auto rc = decode_read_file_resp(NULL, 0, &completionCode, &length,
+ &fileDataOffset);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_read_file_resp(responsePtr, 0, &completionCode, &length,
+ &fileDataOffset);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ // Bad decode response for write file
+ std::array<uint8_t, PLDM_WRITE_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsgWr{};
+ auto responseWr = reinterpret_cast<pldm_msg*>(responseMsgWr.data());
+
+ // Request payload message is missing
+ rc = decode_write_file_resp(NULL, 0, &completionCode, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_write_file_resp(responseWr, 0, &completionCode, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadWriteFile, testBadDecodeRequest)
+{
+ uint32_t fileHandle = 0;
+ uint32_t offset = 0;
+ uint32_t length = 0;
+
+ // Bad decode request for read file
+ std::array<uint8_t, PLDM_READ_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Request payload message is missing
+ auto rc = decode_read_file_req(NULL, 0, &fileHandle, &offset, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_read_file_req(requestPtr, 0, &fileHandle, &offset, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ // Bad decode request for write file
+ size_t fileDataOffset = 0;
+ std::array<uint8_t, PLDM_WRITE_FILE_REQ_BYTES> requestMsgWr{};
+ auto requestWr = reinterpret_cast<pldm_msg*>(requestMsgWr.data());
+
+ // Request payload message is missing
+ rc = decode_write_file_req(NULL, 0, &fileHandle, &offset, &length,
+ &fileDataOffset);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_write_file_req(requestWr, 0, &fileHandle, &offset, &length,
+ &fileDataOffset);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadFile, testGoodEncodeResponse)
+{
+ // Good encode response for read file
+ uint32_t length = 0x4;
+
+ std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES +
+ sizeof(pldm_msg_hdr) + length);
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ auto response =
+ reinterpret_cast<pldm_read_file_resp*>(responsePtr->payload);
+
+ // ReadFile
+ auto rc = encode_read_file_resp(0, PLDM_SUCCESS, length, responsePtr);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(responsePtr->hdr.instance_id, 0);
+ ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
+ ASSERT_EQ(responsePtr->hdr.command, PLDM_READ_FILE);
+ ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
+ ASSERT_EQ(le32toh(response->length), length);
+}
+
+TEST(WriteFile, testGoodEncodeResponse)
+{
+ uint32_t length = 0x467;
+
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_RESP_BYTES>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ auto response =
+ reinterpret_cast<pldm_write_file_resp*>(responsePtr->payload);
+
+ // WriteFile
+ auto rc = encode_write_file_resp(0, PLDM_SUCCESS, length, responsePtr);
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(responsePtr->hdr.instance_id, 0);
+ ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
+ ASSERT_EQ(responsePtr->hdr.command, PLDM_WRITE_FILE);
+ ASSERT_EQ(response->completion_code, PLDM_SUCCESS);
+ ASSERT_EQ(le32toh(response->length), length);
+}
+
+TEST(ReadFile, testGoodEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_REQ_BYTES>
+ requestMsg{};
+
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x13245768;
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ auto request = reinterpret_cast<pldm_read_file_req*>(requestPtr->payload);
+
+ // ReadFile
+ auto rc = encode_read_file_req(0, fileHandle, offset, length, requestPtr);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(requestPtr->hdr.instance_id, 0);
+ ASSERT_EQ(requestPtr->hdr.type, PLDM_OEM);
+ ASSERT_EQ(requestPtr->hdr.command, PLDM_READ_FILE);
+ ASSERT_EQ(le32toh(request->file_handle), fileHandle);
+ ASSERT_EQ(le32toh(request->offset), offset);
+ ASSERT_EQ(le32toh(request->length), length);
+}
+
+TEST(WriteFile, testGoodEncodeRequest)
+{
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x456;
+
+ std::vector<uint8_t> requestMsg(PLDM_WRITE_FILE_REQ_BYTES +
+ sizeof(pldm_msg_hdr) + length);
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ auto request = reinterpret_cast<pldm_write_file_req*>(requestPtr->payload);
+
+ // WriteFile
+ auto rc = encode_write_file_req(0, fileHandle, offset, length, requestPtr);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(requestPtr->hdr.instance_id, 0);
+ ASSERT_EQ(requestPtr->hdr.type, PLDM_OEM);
+ ASSERT_EQ(requestPtr->hdr.command, PLDM_WRITE_FILE);
+ ASSERT_EQ(le32toh(request->file_handle), fileHandle);
+ ASSERT_EQ(le32toh(request->offset), offset);
+ ASSERT_EQ(le32toh(request->length), length);
+}
+
+TEST(ReadWriteFile, testBadEncodeRequest)
+{
+ // Bad encode request for read file
+ uint32_t fileHandle = 0;
+ uint32_t offset = 0;
+ uint32_t length = 0;
+
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_REQ_BYTES>
+ requestMsg{};
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // ReadFile check invalid file length
+ auto rc = encode_read_file_req(0, fileHandle, offset, length, requestPtr);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ // Bad encode request for write file
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_REQ_BYTES>
+ requestMsgWr{};
+ auto requestWr = reinterpret_cast<pldm_msg*>(requestMsgWr.data());
+
+ // WriteFile check for invalid file length
+ rc = encode_write_file_req(0, fileHandle, offset, length, requestWr);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadWriteFile, testBadEncodeResponse)
+{
+ // Bad encode response for read file
+ uint32_t length = 0;
+
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_RESP_BYTES>
+ responseMsg{};
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // ReadFile
+ auto rc = encode_read_file_resp(0, PLDM_ERROR, length, responsePtr);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(responsePtr->hdr.instance_id, 0);
+ ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM);
+ ASSERT_EQ(responsePtr->hdr.command, PLDM_READ_FILE);
+ ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR);
+
+ // Bad encode response for write file
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_RESP_BYTES>
+ responseMsgWr{};
+ auto responseWr = reinterpret_cast<pldm_msg*>(responseMsgWr.data());
+
+ // WriteFile
+ rc = encode_write_file_resp(0, PLDM_ERROR, length, responseWr);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(responseWr->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(responseWr->hdr.instance_id, 0);
+ ASSERT_EQ(responseWr->hdr.type, PLDM_OEM);
+ ASSERT_EQ(responseWr->hdr.command, PLDM_WRITE_FILE);
+ ASSERT_EQ(responseWr->payload[0], PLDM_ERROR);
+}
+
+TEST(ReadWriteFileByTypeMemory, testGoodDecodeRequest)
+{
+ std::array<uint8_t,
+ PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
+ auto request = reinterpret_cast<pldm_read_write_file_by_type_memory_req*>(
+ requestPtr->payload);
+
+ // Random value for fileHandle, offset and length
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x13245768;
+ uint64_t address = 0x124356879ACBD456;
+
+ request->file_type = htole16(fileType);
+ request->file_handle = htole32(fileHandle);
+ request->offset = htole32(offset);
+ request->length = htole32(length);
+ request->address = htole64(address);
+
+ uint16_t retFileType = 0x1;
+ uint32_t retFileHandle = 0;
+ uint32_t retOffset = 0;
+ uint32_t retLength = 0;
+ uint64_t retAddress = 0;
+
+ // Invoke decode the read file request
+ auto rc = decode_rw_file_by_type_memory_req(
+ requestPtr, payload_length, &retFileType, &retFileHandle, &retOffset,
+ &retLength, &retAddress);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileType, retFileType);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(offset, retOffset);
+ ASSERT_EQ(length, retLength);
+ ASSERT_EQ(address, retAddress);
+}
+
+TEST(ReadWriteFileByTypeMemory, testGoodDecodeResponse)
+{
+ std::array<uint8_t,
+ PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
+ auto response = reinterpret_cast<pldm_read_write_file_by_type_memory_resp*>(
+ responsePtr->payload);
+
+ // Random value for completion code and length
+ uint8_t completionCode = 0x0;
+ uint32_t length = 0x13245768;
+
+ response->completion_code = completionCode;
+ response->length = htole32(length);
+
+ uint8_t retCompletionCode = 0x1;
+ uint32_t retLength = 0;
+
+ // Invoke decode the read/write file response
+ auto rc = decode_rw_file_by_type_memory_resp(
+ responsePtr, payload_length, &retCompletionCode, &retLength);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+ ASSERT_EQ(length, retLength);
+}
+
+TEST(ReadWriteFileByTypeMemory, testBadDecodeRequest)
+{
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0;
+ uint32_t offset = 0;
+ uint32_t length = 0;
+ uint64_t address = 0;
+
+ // Request payload message is missing
+ auto rc = decode_rw_file_by_type_memory_req(NULL, 0, &fileType, &fileHandle,
+ &offset, &length, &address);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t,
+ PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Address is NULL
+ rc = decode_rw_file_by_type_memory_req(
+ requestPtr, requestMsg.size() - hdrSize, &fileType, &fileHandle,
+ &offset, &length, NULL);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_rw_file_by_type_memory_req(
+ requestPtr, 0, &fileType, &fileHandle, &offset, &length, &address);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadWriteFileByTypeMemory, testBadDecodeResponse)
+{
+ uint32_t length = 0;
+ uint8_t completionCode = 0;
+
+ // Request payload message is missing
+ auto rc =
+ decode_rw_file_by_type_memory_resp(NULL, 0, &completionCode, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t,
+ PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Length is NULL
+ rc = decode_rw_file_by_type_memory_resp(
+ responsePtr, responseMsg.size() - hdrSize, &completionCode, NULL);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_rw_file_by_type_memory_resp(responsePtr, 0, &completionCode,
+ &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadWriteFileByTypeMemory, testGoodEncodeRequest)
+{
+ std::array<uint8_t,
+ sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES>
+ requestMsg{};
+
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x13245768;
+ uint64_t address = 0x124356879ACBDE0F;
+ uint16_t fileTypeLe = htole16(fileType);
+ uint32_t fileHandleLe = htole32(fileHandle);
+ uint32_t offsetLe = htole32(offset);
+ uint32_t lengthLe = htole32(length);
+ uint64_t addressLe = htole64(address);
+
+ pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ auto rc = encode_rw_file_by_type_memory_req(
+ 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, fileType, fileHandle, offset,
+ length, address, request);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(request->hdr.instance_id, 0);
+ ASSERT_EQ(request->hdr.type, PLDM_OEM);
+ ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
+
+ ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
+ sizeof(fileHandleLe)));
+
+ ASSERT_EQ(
+ 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
+ &offsetLe, sizeof(offsetLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(offsetLe),
+ &lengthLe, sizeof(lengthLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(offsetLe) +
+ sizeof(lengthLe),
+ &addressLe, sizeof(addressLe)));
+}
+
+TEST(ReadWriteFileByTypeMemory, testGoodEncodeResponse)
+{
+ std::array<uint8_t,
+ sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES>
+ responseMsg{};
+
+ uint32_t length = 0x13245768;
+ uint32_t lengthLe = htole32(length);
+ uint8_t completionCode = 0x0;
+
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc = encode_rw_file_by_type_memory_resp(
+ 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, completionCode, length,
+ response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
+
+ ASSERT_EQ(
+ 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
+ ASSERT_EQ(0, memcmp(response->payload + sizeof(completionCode), &lengthLe,
+ sizeof(lengthLe)));
+}
+
+TEST(ReadWriteFileByTypeMemory, testBadEncodeResponse)
+{
+ std::array<uint8_t,
+ sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES>
+ responseMsg{};
+ uint32_t length = 0;
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // completion code is PLDM_ERROR
+ auto rc = encode_rw_file_by_type_memory_resp(
+ 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_ERROR, length, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+
+ // response is NULL pointer
+ rc = encode_rw_file_by_type_memory_resp(
+ 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_SUCCESS, length, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(ReadWriteFileByTypeMemory, testBadEncodeRequest)
+{
+ uint8_t fileType = 0;
+ uint32_t fileHandle = 0;
+ uint32_t offset = 0;
+ uint32_t length = 0;
+ uint64_t address = 0;
+
+ // request is NULL pointer
+ auto rc = encode_rw_file_by_type_memory_req(
+ 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, fileType, fileHandle, offset,
+ length, address, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(NewFile, testGoodDecodeRequest)
+{
+ std::array<uint8_t, PLDM_NEW_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
+ auto request = reinterpret_cast<pldm_new_file_req*>(requestPtr->payload);
+
+ // Random value for fileHandle and length
+ uint16_t fileType = 0xFF;
+ uint32_t fileHandle = 0x12345678;
+ uint64_t length = 0x13245768;
+
+ request->file_type = htole16(fileType);
+ request->file_handle = htole32(fileHandle);
+ request->length = htole64(length);
+
+ uint16_t retFileType = 0xFF;
+ uint32_t retFileHandle = 0;
+ uint64_t retLength = 0;
+
+ // Invoke decode the read file request
+ auto rc = decode_new_file_req(requestPtr, payload_length, &retFileType,
+ &retFileHandle, &retLength);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileType, retFileType);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(length, retLength);
+}
+
+TEST(NewFile, testGoodDecodeResponse)
+{
+ std::array<uint8_t, PLDM_NEW_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
+ auto response = reinterpret_cast<pldm_new_file_resp*>(responsePtr->payload);
+
+ // Random value for completion code
+ uint8_t completionCode = 0x0;
+
+ response->completion_code = completionCode;
+
+ uint8_t retCompletionCode = PLDM_SUCCESS;
+
+ // Invoke decode the read/write file response
+ auto rc =
+ decode_new_file_resp(responsePtr, payload_length, &retCompletionCode);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+}
+
+TEST(NewFile, testBadDecodeRequest)
+{
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0;
+ uint64_t length = 0;
+
+ // Request payload message is missing
+ auto rc = decode_new_file_req(NULL, 0, &fileType, &fileHandle, &length);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_NEW_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Payload length is invalid
+ rc = decode_new_file_req(requestPtr, 0, &fileType, &fileHandle, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(NewFile, testBadDecodeResponse)
+{
+ uint8_t completionCode = 0;
+
+ // Request payload message is missing
+ auto rc = decode_new_file_resp(NULL, 0, &completionCode);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_NEW_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Payload length is invalid
+ rc = decode_new_file_resp(responsePtr, 0, &completionCode);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(NewFile, testGoodEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_REQ_BYTES>
+ requestMsg{};
+
+ uint16_t fileType = 0xFF;
+ uint32_t fileHandle = 0x12345678;
+ uint32_t length = 0x13245768;
+ uint16_t fileTypeLe = htole16(fileType);
+ uint32_t fileHandleLe = htole32(fileHandle);
+ uint32_t lengthLe = htole32(length);
+
+ pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ auto rc = encode_new_file_req(0, fileType, fileHandle, length, request);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(request->hdr.instance_id, 0);
+ ASSERT_EQ(request->hdr.type, PLDM_OEM);
+ ASSERT_EQ(request->hdr.command, PLDM_NEW_FILE_AVAILABLE);
+ ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
+ sizeof(fileHandleLe)));
+ ASSERT_EQ(
+ 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
+ &lengthLe, sizeof(lengthLe)));
+}
+
+TEST(NewFile, testGoodEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_RESP_BYTES>
+ responseMsg{};
+
+ uint8_t completionCode = 0x0;
+
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc = encode_new_file_resp(0, completionCode, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE);
+ ASSERT_EQ(
+ 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
+}
+
+TEST(NewFile, testBadEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_RESP_BYTES>
+ responseMsg{};
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // completion code is PLDM_ERROR
+ auto rc = encode_new_file_resp(0, PLDM_ERROR, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+
+ // response is NULL pointer
+ rc = encode_new_file_resp(0, PLDM_SUCCESS, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(NewFile, testBadEncodeRequest)
+{
+ uint8_t fileType = 0xFF;
+ uint32_t fileHandle = 0;
+ uint32_t length = 0;
+
+ // request is NULL pointer
+ auto rc = encode_new_file_req(0, fileType, fileHandle, length, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(ReadWriteFileByType, testGoodDecodeRequest)
+{
+ std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
+ auto request = reinterpret_cast<pldm_read_write_file_by_type_req*>(
+ requestPtr->payload);
+
+ // Random value for fileHandle, offset and length
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x13245768;
+
+ request->file_handle = htole32(fileHandle);
+ request->offset = htole32(offset);
+ request->length = htole32(length);
+
+ uint16_t retFileType = 0x1;
+ uint32_t retFileHandle = 0;
+ uint32_t retOffset = 0;
+ uint32_t retLength = 0;
+
+ // Invoke decode the read file request
+ auto rc =
+ decode_rw_file_by_type_req(requestPtr, payload_length, &retFileType,
+ &retFileHandle, &retOffset, &retLength);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileType, retFileType);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(offset, retOffset);
+ ASSERT_EQ(length, retLength);
+}
+
+TEST(ReadWriteFileByType, testGoodDecodeResponse)
+{
+ std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
+ auto response = reinterpret_cast<pldm_read_write_file_by_type_resp*>(
+ responsePtr->payload);
+
+ // Random value for completion code and length
+ uint8_t completionCode = 0x0;
+ uint32_t length = 0x13245768;
+
+ response->completion_code = completionCode;
+ response->length = htole32(length);
+
+ uint8_t retCompletionCode = 0x1;
+ uint32_t retLength = 0;
+
+ // Invoke decode the read/write file response
+ auto rc = decode_rw_file_by_type_resp(responsePtr, payload_length,
+ &retCompletionCode, &retLength);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+ ASSERT_EQ(length, retLength);
+}
+
+TEST(ReadWriteFileByType, testBadDecodeRequest)
+{
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0;
+ uint32_t offset = 0;
+ uint32_t length = 0;
+
+ // Request payload message is missing
+ auto rc = decode_rw_file_by_type_req(NULL, 0, &fileType, &fileHandle,
+ &offset, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Payload length is invalid
+ rc = decode_rw_file_by_type_req(requestPtr, 0, &fileType, &fileHandle,
+ &offset, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadWriteFileByType, testBadDecodeResponse)
+{
+ uint32_t length = 0;
+ uint8_t completionCode = 0;
+
+ // Request payload message is missing
+ auto rc = decode_rw_file_by_type_resp(NULL, 0, &completionCode, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Length is NULL
+ rc = decode_rw_file_by_type_resp(responsePtr, responseMsg.size() - hdrSize,
+ &completionCode, NULL);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ // Payload length is invalid
+ rc = decode_rw_file_by_type_resp(responsePtr, 0, &completionCode, &length);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(ReadWriteFileByType, testGoodEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_REQ_BYTES>
+ requestMsg{};
+
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0x12345678;
+ uint32_t offset = 0x87654321;
+ uint32_t length = 0x13245768;
+ uint16_t fileTypeLe = htole16(fileType);
+ uint32_t fileHandleLe = htole32(fileHandle);
+ uint32_t offsetLe = htole32(offset);
+ uint32_t lengthLe = htole32(length);
+
+ pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ auto rc = encode_rw_file_by_type_req(0, PLDM_READ_FILE_BY_TYPE, fileType,
+ fileHandle, offset, length, request);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(request->hdr.instance_id, 0);
+ ASSERT_EQ(request->hdr.type, PLDM_OEM);
+ ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_BY_TYPE);
+
+ ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
+ sizeof(fileHandleLe)));
+
+ ASSERT_EQ(
+ 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
+ &offsetLe, sizeof(offsetLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(offsetLe),
+ &lengthLe, sizeof(lengthLe)));
+}
+
+TEST(ReadWriteFileByType, testGoodEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_RESP_BYTES>
+ responseMsg{};
+
+ uint32_t length = 0x13245768;
+ uint32_t lengthLe = htole32(length);
+ uint8_t completionCode = 0x0;
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE,
+ completionCode, length, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE);
+
+ ASSERT_EQ(
+ 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
+ ASSERT_EQ(0, memcmp(response->payload + sizeof(completionCode), &lengthLe,
+ sizeof(lengthLe)));
+}
+
+TEST(ReadWriteFileByType, testBadEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_RESP_BYTES>
+ responseMsg{};
+ uint32_t length = 0;
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // completion code is PLDM_ERROR
+ auto rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE, PLDM_ERROR,
+ length, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+
+ // response is NULL pointer
+ rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE, PLDM_SUCCESS,
+ length, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(ReadWriteFileByType, testBadEncodeRequest)
+{
+ uint8_t fileType = 0;
+ uint32_t fileHandle = 0;
+ uint32_t offset = 0;
+ uint32_t length = 0;
+
+ // request is NULL pointer
+ auto rc = encode_rw_file_by_type_req(0, PLDM_READ_FILE_BY_TYPE, fileType,
+ fileHandle, offset, length, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(FileAck, testGoodDecodeRequest)
+{
+ std::array<uint8_t, PLDM_FILE_ACK_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
+ auto request = reinterpret_cast<pldm_file_ack_req*>(requestPtr->payload);
+
+ // Random value for fileHandle
+ uint16_t fileType = 0xFFFF;
+ uint32_t fileHandle = 0x12345678;
+ uint8_t fileStatus = 0xFF;
+
+ request->file_type = htole16(fileType);
+ request->file_handle = htole32(fileHandle);
+ request->file_status = fileStatus;
+
+ uint16_t retFileType = 0xFF;
+ uint32_t retFileHandle = 0;
+ uint8_t retFileStatus = 0;
+
+ // Invoke decode the read file request
+ auto rc = decode_file_ack_req(requestPtr, payload_length, &retFileType,
+ &retFileHandle, &retFileStatus);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileType, retFileType);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(fileStatus, retFileStatus);
+}
+
+TEST(FileAck, testGoodDecodeResponse)
+{
+ std::array<uint8_t, PLDM_FILE_ACK_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
+ auto response = reinterpret_cast<pldm_file_ack_resp*>(responsePtr->payload);
+
+ // Random value for completion code
+ uint8_t completionCode = 0x0;
+
+ response->completion_code = completionCode;
+
+ uint8_t retCompletionCode = PLDM_SUCCESS;
+
+ // Invoke decode the read/write file response
+ auto rc =
+ decode_file_ack_resp(responsePtr, payload_length, &retCompletionCode);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+}
+
+TEST(FileAck, testBadDecodeRequest)
+{
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0;
+ uint8_t fileStatus = 0;
+
+ // Request payload message is missing
+ auto rc = decode_file_ack_req(NULL, 0, &fileType, &fileHandle, &fileStatus);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_FILE_ACK_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Payload length is invalid
+ rc =
+ decode_file_ack_req(requestPtr, 0, &fileType, &fileHandle, &fileStatus);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(FileAck, testBadDecodeResponse)
+{
+ uint8_t completionCode = 0;
+
+ // Request payload message is missing
+ auto rc = decode_file_ack_resp(NULL, 0, &completionCode);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_FILE_ACK_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Payload length is invalid
+ rc = decode_file_ack_resp(responsePtr, 0, &completionCode);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(FileAck, testGoodEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_REQ_BYTES>
+ requestMsg{};
+
+ uint16_t fileType = 0xFFFF;
+ uint32_t fileHandle = 0x12345678;
+ uint8_t fileStatus = 0xFF;
+ uint16_t fileTypeLe = htole16(fileType);
+ uint32_t fileHandleLe = htole32(fileHandle);
+
+ pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ auto rc = encode_file_ack_req(0, fileType, fileHandle, fileStatus, request);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(request->hdr.instance_id, 0);
+ ASSERT_EQ(request->hdr.type, PLDM_OEM);
+ ASSERT_EQ(request->hdr.command, PLDM_FILE_ACK);
+ ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
+ sizeof(fileHandleLe)));
+}
+
+TEST(FileAck, testGoodEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_RESP_BYTES>
+ responseMsg{};
+
+ uint8_t completionCode = 0x0;
+
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc = encode_file_ack_resp(0, completionCode, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK);
+ ASSERT_EQ(
+ 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
+}
+
+TEST(FileAck, testBadEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_RESP_BYTES>
+ responseMsg{};
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // completion code is PLDM_ERROR
+ auto rc = encode_file_ack_resp(0, PLDM_ERROR, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+
+ // response is NULL pointer
+ rc = encode_file_ack_resp(0, PLDM_SUCCESS, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(FileAck, testBadEncodeRequest)
+{
+ uint8_t fileType = 0xFF;
+ uint32_t fileHandle = 0;
+ uint8_t fileStatus = 0;
+
+ // request is NULL pointer
+ auto rc = encode_file_ack_req(0, fileType, fileHandle, fileStatus, nullptr);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(FileAckWithMetadata, testGoodEncodeResponse)
+{
+ std::array<uint8_t,
+ sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES>
+ responseMsg{};
+
+ uint8_t completionCode = 0x0;
+
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc = encode_file_ack_with_meta_data_resp(0, completionCode, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
+ ASSERT_EQ(
+ 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
+}
+
+TEST(FileAckWithMetadata, testBadEncodeResponse)
+{
+ std::array<uint8_t,
+ sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES>
+ responseMsg{};
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // completion code is PLDM_ERROR
+ auto rc = encode_file_ack_with_meta_data_resp(0, PLDM_ERROR, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+
+ // response is NULL pointer
+ rc = encode_file_ack_with_meta_data_resp(0, PLDM_SUCCESS, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(FileAckWithMetadata, testGoodDecodeResponse)
+{
+ std::array<uint8_t,
+ PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
+ auto response = reinterpret_cast<pldm_file_ack_with_meta_data_resp*>(
+ responsePtr->payload);
+
+ // Random value for completion code
+ uint8_t completionCode = 0x0;
+
+ response->completion_code = completionCode;
+
+ uint8_t retCompletionCode = PLDM_SUCCESS;
+
+ // Invoke decode the read/write file response
+ auto rc = decode_file_ack_with_meta_data_resp(responsePtr, payload_length,
+ &retCompletionCode);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+}
+
+TEST(FileAckWithMetadata, testBadDecodeResponse)
+{
+ uint8_t completionCode = 0;
+
+ // Request payload message is missing
+ auto rc = decode_file_ack_with_meta_data_resp(NULL, 0, &completionCode);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t,
+ PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES + sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Payload length is invalid
+ rc = decode_file_ack_with_meta_data_resp(responsePtr, 0, &completionCode);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(FileAckWithMetadata, testGoodEncodeRequest)
+{
+ std::array<uint8_t,
+ sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES>
+ requestMsg{};
+
+ uint16_t fileType = 0xFFFF;
+ uint32_t fileHandle = 0x12345678;
+ uint8_t fileStatus = 0xFF;
+ uint32_t fileMetaData1 = 0xFFFFFFFF;
+ uint32_t fileMetaData2 = 0xFFFFFFFF;
+ uint32_t fileMetaData3 = 0xFFFFFFFF;
+ uint32_t fileMetaData4 = 0xFFFFFFFF;
+
+ uint16_t fileTypeLe = htole16(fileType);
+ uint32_t fileHandleLe = htole32(fileHandle);
+ uint32_t fileMetaData1Le = htole32(fileMetaData1);
+ uint32_t fileMetaData2Le = htole32(fileMetaData2);
+ uint32_t fileMetaData3Le = htole32(fileMetaData3);
+ uint32_t fileMetaData4Le = htole32(fileMetaData4);
+
+ pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ auto rc = encode_file_ack_with_meta_data_req(
+ 0, fileType, fileHandle, fileStatus, fileMetaData1, fileMetaData2,
+ fileMetaData3, fileMetaData4, request);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(request->hdr.instance_id, 0);
+ ASSERT_EQ(request->hdr.type, PLDM_OEM);
+ ASSERT_EQ(request->hdr.command, PLDM_FILE_ACK_WITH_META_DATA);
+ ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
+ sizeof(fileHandleLe)));
+ ASSERT_EQ(
+ 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
+ &fileStatus, sizeof(fileStatus)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(fileStatus),
+ &fileMetaData1Le, sizeof(fileMetaData1Le)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(fileStatus) +
+ sizeof(fileMetaData1Le),
+ &fileMetaData2Le, sizeof(fileMetaData2Le)));
+
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(fileStatus) +
+ sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le),
+ &fileMetaData3Le, sizeof(fileMetaData3Le)));
+
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(fileStatus) +
+ sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le) +
+ sizeof(fileMetaData3Le),
+ &fileMetaData4Le, sizeof(fileMetaData4Le)));
+}
+
+TEST(FileAckWithMetadata, testBadEncodeRequest)
+{
+ uint8_t fileType = 0xFF;
+ uint32_t fileHandle = 0;
+ uint8_t fileStatus = 0;
+ uint32_t fileMetaData1 = 0;
+ uint32_t fileMetaData2 = 0;
+ uint32_t fileMetaData3 = 0;
+ uint32_t fileMetaData4 = 0;
+
+ // request is NULL pointer
+ auto rc = encode_file_ack_with_meta_data_req(
+ 0, fileType, fileHandle, fileStatus, fileMetaData1, fileMetaData2,
+ fileMetaData3, fileMetaData4, nullptr);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(FileAckWithMetadata, testGoodDecodeRequest)
+{
+ std::array<uint8_t,
+ sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
+ auto request = reinterpret_cast<pldm_file_ack_with_meta_data_req*>(
+ requestPtr->payload);
+
+ uint16_t fileType = 0xFFFF;
+ uint32_t fileHandle = 0x12345678;
+ uint8_t fileStatus = 0xFF;
+ uint32_t fileMetaData1 = 0x12345678;
+ uint32_t fileMetaData2 = 0x87654321;
+ uint32_t fileMetaData3 = 0x22121117;
+ uint32_t fileMetaData4 = 0x12334345;
+
+ request->file_type = htole16(fileType);
+ request->file_handle = htole32(fileHandle);
+ request->file_status = fileStatus;
+ request->file_meta_data_1 = htole32(fileMetaData1);
+ request->file_meta_data_2 = htole32(fileMetaData2);
+ request->file_meta_data_3 = htole32(fileMetaData3);
+ request->file_meta_data_4 = htole32(fileMetaData4);
+
+ uint16_t retFileType = 0xFFFF;
+ uint32_t retFileHandle = 0;
+ uint8_t retFileStatus = 0;
+ uint32_t retFileMetaData1 = 0;
+ uint32_t retFileMetaData2 = 0;
+ uint32_t retFileMetaData3 = 0;
+ uint32_t retFileMetaData4 = 0;
+
+ auto rc = decode_file_ack_with_meta_data_req(
+ requestPtr, payload_length, &retFileType, &retFileHandle,
+ &retFileStatus, &retFileMetaData1, &retFileMetaData2, &retFileMetaData3,
+ &retFileMetaData4);
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileType, retFileType);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(fileStatus, retFileStatus);
+ ASSERT_EQ(fileMetaData1, retFileMetaData1);
+ ASSERT_EQ(fileMetaData2, retFileMetaData2);
+ ASSERT_EQ(fileMetaData3, retFileMetaData3);
+ ASSERT_EQ(fileMetaData4, retFileMetaData4);
+}
+
+TEST(FileAckWithMetadata, testBadDecodeRequest)
+{
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0;
+ uint8_t fileStatus = 0;
+ uint32_t fileMetaData1 = 0;
+ uint32_t fileMetaData2 = 0;
+ uint32_t fileMetaData3 = 0;
+ uint32_t fileMetaData4 = 0;
+
+ // Request payload message is missing
+ auto rc = decode_file_ack_with_meta_data_req(
+ NULL, 0, &fileType, &fileHandle, &fileStatus, &fileMetaData1,
+ &fileMetaData2, &fileMetaData3, &fileMetaData4);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t,
+ PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES + sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Payload length is invalid
+ rc = decode_file_ack_with_meta_data_req(
+ requestPtr, 0, &fileType, &fileHandle, &fileStatus, &fileMetaData1,
+ &fileMetaData2, &fileMetaData3, &fileMetaData4);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(NewFileAvailableWithMetaData, testGoodEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) +
+ PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES>
+ responseMsg{};
+
+ uint8_t completionCode = 0x0;
+
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc = encode_new_file_with_metadata_resp(0, completionCode, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA);
+ ASSERT_EQ(
+ 0, memcmp(response->payload, &completionCode, sizeof(completionCode)));
+}
+
+TEST(NewFileAvailableWithMetaData, testBadEncodeResponse)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) +
+ PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES>
+ responseMsg{};
+ pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // completion code is PLDM_ERROR
+ auto rc = encode_new_file_with_metadata_resp(0, PLDM_ERROR, response);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(response->hdr.request, PLDM_RESPONSE);
+ ASSERT_EQ(response->hdr.instance_id, 0);
+ ASSERT_EQ(response->hdr.type, PLDM_OEM);
+ ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA);
+ ASSERT_EQ(response->payload[0], PLDM_ERROR);
+
+ // response is NULL pointer
+ rc = encode_new_file_resp(0, PLDM_SUCCESS, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(NewFileAvailableWithMetaData, testGoodDecodeResponse)
+{
+ std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES +
+ sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr);
+ auto response = reinterpret_cast<pldm_file_ack_with_meta_data_resp*>(
+ responsePtr->payload);
+
+ // Random value for completion code
+ uint8_t completionCode = 0x0;
+
+ response->completion_code = completionCode;
+
+ uint8_t retCompletionCode = PLDM_SUCCESS;
+
+ // Invoke decode the read/write file response
+ auto rc = decode_new_file_with_metadata_resp(responsePtr, payload_length,
+ &retCompletionCode);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(completionCode, retCompletionCode);
+}
+
+TEST(NewFileAvailableWithMetaData, testBadDecodeResponse)
+{
+ uint8_t completionCode = 0;
+
+ // Request payload message is missing
+ auto rc = decode_new_file_with_metadata_resp(NULL, 0, &completionCode);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES +
+ sizeof(pldm_msg_hdr)>
+ responseMsg{};
+
+ auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ // Payload length is invalid
+ rc = decode_new_file_with_metadata_resp(responsePtr, 0, &completionCode);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(NewFileAvailableWithMetaData, testGoodEncodeRequest)
+{
+ std::array<uint8_t, sizeof(pldm_msg_hdr) +
+ PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES>
+ requestMsg{};
+
+ uint16_t fileType = 0xFFFF;
+ uint32_t fileHandle = 0x12345678;
+ uint32_t length = 0x13245768;
+ uint64_t fileMetaData1 = 0xFFFFFFFF;
+ uint32_t fileMetaData2 = 0xFFFFFFFF;
+ uint32_t fileMetaData3 = 0xFFFFFFFF;
+ uint32_t fileMetaData4 = 0xFFFFFFFF;
+
+ uint16_t fileTypeLe = htole16(fileType);
+ uint32_t fileHandleLe = htole32(fileHandle);
+ uint64_t lengthLe = htole64(length);
+ uint32_t fileMetaData1Le = htole32(fileMetaData1);
+ uint32_t fileMetaData2Le = htole32(fileMetaData2);
+ uint32_t fileMetaData3Le = htole32(fileMetaData3);
+ uint32_t fileMetaData4Le = htole32(fileMetaData4);
+
+ pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ auto rc = encode_new_file_with_metadata_req(
+ 0, fileType, fileHandle, length, fileMetaData1, fileMetaData2,
+ fileMetaData3, fileMetaData4, request);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(request->hdr.request, PLDM_REQUEST);
+ ASSERT_EQ(request->hdr.instance_id, 0);
+ ASSERT_EQ(request->hdr.type, PLDM_OEM);
+ ASSERT_EQ(request->hdr.command, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA);
+ ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe)));
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe,
+ sizeof(fileHandleLe)));
+ ASSERT_EQ(
+ 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe),
+ &lengthLe, sizeof(lengthLe)));
+
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(lengthLe),
+ &fileMetaData1Le, sizeof(fileMetaData1Le)));
+
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(lengthLe) +
+ sizeof(fileMetaData1Le),
+ &fileMetaData2Le, sizeof(fileMetaData2Le)));
+
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(lengthLe) +
+ sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le),
+ &fileMetaData3Le, sizeof(fileMetaData3Le)));
+
+ ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) +
+ sizeof(fileHandleLe) + sizeof(lengthLe) +
+ sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le) +
+ sizeof(fileMetaData3Le),
+ &fileMetaData4Le, sizeof(fileMetaData4Le)));
+}
+
+TEST(NewFileAvailableWithMetaData, testBadEncodeRequest)
+{
+ uint8_t fileType = 0xFF;
+ uint32_t fileHandle = 0;
+ uint32_t length = 0;
+ uint32_t fileMetaData1 = 0;
+ uint32_t fileMetaData2 = 0;
+ uint32_t fileMetaData3 = 0;
+ uint32_t fileMetaData4 = 0;
+
+ // request is NULL pointer
+ auto rc = encode_new_file_with_metadata_req(
+ 0, fileType, fileHandle, length, fileMetaData1, fileMetaData2,
+ fileMetaData3, fileMetaData4, NULL);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(NewFileAvailableWithMetaData, testGoodDecodeRequest)
+{
+ std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES +
+ sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr);
+ auto request =
+ reinterpret_cast<pldm_new_file_with_metadata_req*>(requestPtr->payload);
+
+ // Random value for fileHandle and length
+ uint16_t fileType = 0xFFFF;
+ uint32_t fileHandle = 0x12345678;
+ uint64_t length = 0x13245768;
+ uint32_t fileMetaData1 = 0x12345678;
+ uint32_t fileMetaData2 = 0x87654321;
+ uint32_t fileMetaData3 = 0x22121117;
+ uint32_t fileMetaData4 = 0x12334345;
+
+ request->file_type = htole16(fileType);
+ request->file_handle = htole32(fileHandle);
+ request->length = htole64(length);
+ request->file_meta_data_1 = htole32(fileMetaData1);
+ request->file_meta_data_2 = htole32(fileMetaData2);
+ request->file_meta_data_3 = htole32(fileMetaData3);
+ request->file_meta_data_4 = htole32(fileMetaData4);
+
+ uint16_t retFileType = 0xFFFF;
+ uint32_t retFileHandle = 0;
+ uint64_t retLength = 0;
+ uint32_t retFileMetaData1 = 0;
+ uint32_t retFileMetaData2 = 0;
+ uint32_t retFileMetaData3 = 0;
+ uint32_t retFileMetaData4 = 0;
+
+ // Invoke decode the read file request
+ auto rc = decode_new_file_with_metadata_req(
+ requestPtr, payload_length, &retFileType, &retFileHandle, &retLength,
+ &retFileMetaData1, &retFileMetaData2, &retFileMetaData3,
+ &retFileMetaData4);
+
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+ ASSERT_EQ(fileType, retFileType);
+ ASSERT_EQ(fileHandle, retFileHandle);
+ ASSERT_EQ(length, retLength);
+ ASSERT_EQ(fileMetaData1, retFileMetaData1);
+ ASSERT_EQ(fileMetaData2, retFileMetaData2);
+ ASSERT_EQ(fileMetaData3, retFileMetaData3);
+ ASSERT_EQ(fileMetaData4, retFileMetaData4);
+}
+
+TEST(NewFileAvailableWithMetaData, testBadDecodeRequest)
+{
+ uint16_t fileType = 0;
+ uint32_t fileHandle = 0;
+ uint64_t length = 0;
+ uint32_t fileMetaData1 = 0;
+ uint32_t fileMetaData2 = 0;
+ uint32_t fileMetaData3 = 0;
+ uint32_t fileMetaData4 = 0;
+
+ // Request payload message is missing
+ auto rc = decode_new_file_with_metadata_req(
+ NULL, 0, &fileType, &fileHandle, &length, &fileMetaData1,
+ &fileMetaData2, &fileMetaData3, &fileMetaData4);
+
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES +
+ sizeof(pldm_msg_hdr)>
+ requestMsg{};
+
+ auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ // Payload length is invalid
+ rc = decode_new_file_with_metadata_req(
+ requestPtr, 0, &fileType, &fileHandle, &length, &fileMetaData1,
+ &fileMetaData2, &fileMetaData3, &fileMetaData4);
+ ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
diff --git a/subprojects/libpldm/tests/oem/ibm/libpldm_host_test.cpp b/subprojects/libpldm/tests/oem/ibm/libpldm_host_test.cpp
new file mode 100644
index 0000000..26ae5aa
--- /dev/null
+++ b/subprojects/libpldm/tests/oem/ibm/libpldm_host_test.cpp
@@ -0,0 +1,162 @@
+#include <string.h>
+
+#include <array>
+
+#include "oem/ibm/libpldm/host.h"
+
+#include <gtest/gtest.h>
+
+constexpr auto hdrSize = sizeof(pldm_msg_hdr);
+
+TEST(GetAlertStatus, testGoodEncodeRequest)
+{
+ std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
+
+ uint8_t versionId = 0x0;
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ auto rc = encode_get_alert_status_req(0, versionId, request,
+ PLDM_GET_ALERT_STATUS_REQ_BYTES);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(versionId, request->payload[0]);
+}
+
+TEST(GetAlertStatus, testBadEncodeRequest)
+{
+ std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
+
+ auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ auto rc = encode_get_alert_status_req(0, 0x0, request,
+ PLDM_GET_ALERT_STATUS_REQ_BYTES + 1);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(GetAlertStatus, testGoodDecodeResponse)
+{
+ uint8_t completionCode = PLDM_SUCCESS;
+ uint32_t rack_entry = 0xFF000030;
+ uint32_t pri_cec_node = 0x00008030;
+ std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_RESP_BYTES>
+ responseMsg{};
+
+ uint8_t retCompletionCode = 0;
+ uint32_t retRack_entry = 0;
+ uint32_t retPri_cec_node = 0;
+
+ auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ struct pldm_get_alert_status_resp* resp =
+ reinterpret_cast<struct pldm_get_alert_status_resp*>(response->payload);
+ resp->completion_code = completionCode;
+ resp->rack_entry = htole32(rack_entry);
+ resp->pri_cec_node = htole32(pri_cec_node);
+
+ auto rc = decode_get_alert_status_resp(
+ response, responseMsg.size() - hdrSize, &retCompletionCode,
+ &retRack_entry, &retPri_cec_node);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(retCompletionCode, completionCode);
+ EXPECT_EQ(retRack_entry, rack_entry);
+ EXPECT_EQ(retPri_cec_node, pri_cec_node);
+}
+
+TEST(GetAlertStatus, testBadDecodeResponse)
+{
+ auto rc = decode_get_alert_status_resp(NULL, 0, NULL, NULL, NULL);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ uint8_t completionCode = PLDM_SUCCESS;
+ uint32_t rack_entry = 0xFF000030;
+ uint32_t pri_cec_node = 0x00008030;
+ std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_RESP_BYTES>
+ responseMsg{};
+
+ uint8_t retCompletionCode = 0;
+ uint32_t retRack_entry = 0;
+ uint32_t retPri_cec_node = 0;
+
+ auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+ struct pldm_get_alert_status_resp* resp =
+ reinterpret_cast<struct pldm_get_alert_status_resp*>(response->payload);
+ resp->completion_code = completionCode;
+ resp->rack_entry = htole32(rack_entry);
+ resp->pri_cec_node = htole32(pri_cec_node);
+
+ rc = decode_get_alert_status_resp(
+ response, responseMsg.size() - hdrSize + 1, &retCompletionCode,
+ &retRack_entry, &retPri_cec_node);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
+
+TEST(GetAlertStatus, testGoodEncodeResponse)
+{
+ uint8_t completionCode = 0;
+ uint32_t rack_entry = 0xFF000030;
+ uint32_t pri_cec_node = 0x00008030;
+
+ std::vector<uint8_t> responseMsg(hdrSize +
+ PLDM_GET_ALERT_STATUS_RESP_BYTES);
+ auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc =
+ encode_get_alert_status_resp(0, PLDM_SUCCESS, rack_entry, pri_cec_node,
+ response, responseMsg.size() - hdrSize);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ struct pldm_get_alert_status_resp* resp =
+ reinterpret_cast<struct pldm_get_alert_status_resp*>(response->payload);
+
+ EXPECT_EQ(completionCode, resp->completion_code);
+ EXPECT_EQ(rack_entry, le32toh(resp->rack_entry));
+ EXPECT_EQ(pri_cec_node, le32toh(resp->pri_cec_node));
+}
+
+TEST(GetAlertStatus, testBadEncodeResponse)
+{
+ uint32_t rack_entry = 0xFF000030;
+ uint32_t pri_cec_node = 0x00008030;
+
+ std::vector<uint8_t> responseMsg(hdrSize +
+ PLDM_GET_ALERT_STATUS_RESP_BYTES);
+ auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
+
+ auto rc = encode_get_alert_status_resp(0, PLDM_SUCCESS, rack_entry,
+ pri_cec_node, response,
+ responseMsg.size() - hdrSize + 1);
+
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}
+
+TEST(GetAlertStatus, testGoodDecodeRequest)
+{
+ std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
+
+ uint8_t versionId = 0x0;
+ uint8_t retVersionId;
+
+ auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ req->payload[0] = versionId;
+
+ auto rc = decode_get_alert_status_req(req, requestMsg.size() - hdrSize,
+ &retVersionId);
+
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+ EXPECT_EQ(retVersionId, versionId);
+}
+
+TEST(GetAlertStatus, testBadDecodeRequest)
+{
+ std::array<uint8_t, hdrSize + PLDM_GET_ALERT_STATUS_REQ_BYTES> requestMsg{};
+
+ uint8_t versionId = 0x0;
+ uint8_t retVersionId;
+
+ auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
+
+ req->payload[0] = versionId;
+
+ auto rc = decode_get_alert_status_req(req, requestMsg.size() - hdrSize + 1,
+ &retVersionId);
+
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+}
diff --git a/utilities/requester/set_state_effecter.cpp b/utilities/requester/set_state_effecter.cpp
index 4df2c64..5384fa1 100644
--- a/utilities/requester/set_state_effecter.cpp
+++ b/utilities/requester/set_state_effecter.cpp
@@ -1,5 +1,5 @@
#include "libpldm/platform.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include <CLI/CLI.hpp>
diff --git a/utilities/requester/set_state_effecter_async.cpp b/utilities/requester/set_state_effecter_async.cpp
index 303aefe..f0b13b5 100644
--- a/utilities/requester/set_state_effecter_async.cpp
+++ b/utilities/requester/set_state_effecter_async.cpp
@@ -1,6 +1,6 @@
#include "libpldm/base.h"
#include "libpldm/platform.h"
-#include "libpldm/requester/pldm.h"
+#include "libpldm/pldm.h"
#include <CLI/CLI.hpp>
#include <sdeventplus/event.hpp>