libpldm: PDR API: endianness fixes
The API wouldn't work on a BE system. Fixed the same.
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: I809fcce5b5e5d64a729884cf57d3c5d560d99c14
diff --git a/libpldm/tests/libpldm_pdr_test.cpp b/libpldm/tests/libpldm_pdr_test.cpp
index 9dd172b..2f6b58d 100644
--- a/libpldm/tests/libpldm_pdr_test.cpp
+++ b/libpldm/tests/libpldm_pdr_test.cpp
@@ -230,15 +230,15 @@
pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(outData);
EXPECT_EQ(hdr->version, 1);
EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET);
- EXPECT_EQ(hdr->length, sizeof(pldm_pdr_fru_record_set));
- EXPECT_EQ(hdr->record_handle, 1);
+ EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set)));
+ EXPECT_EQ(hdr->record_handle, htole32(1));
pldm_pdr_fru_record_set* fru = reinterpret_cast<pldm_pdr_fru_record_set*>(
outData + sizeof(pldm_pdr_hdr));
- EXPECT_EQ(fru->terminus_handle, 1);
- EXPECT_EQ(fru->fru_rsi, 10);
- EXPECT_EQ(fru->entity_type, 1);
- EXPECT_EQ(fru->entity_instance_num, 0);
- EXPECT_EQ(fru->container_id, 100);
+ EXPECT_EQ(fru->terminus_handle, htole16(1));
+ EXPECT_EQ(fru->fru_rsi, htole16(10));
+ EXPECT_EQ(fru->entity_type, htole16(1));
+ EXPECT_EQ(fru->entity_instance_num, htole16(0));
+ EXPECT_EQ(fru->container_id, htole16(100));
outData = nullptr;
handle = pldm_pdr_add_fru_record_set(repo, 2, 11, 2, 1, 101);
@@ -253,15 +253,15 @@
hdr = reinterpret_cast<pldm_pdr_hdr*>(outData);
EXPECT_EQ(hdr->version, 1);
EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET);
- EXPECT_EQ(hdr->length, sizeof(pldm_pdr_fru_record_set));
- EXPECT_EQ(hdr->record_handle, 2);
+ EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set)));
+ EXPECT_EQ(hdr->record_handle, htole32(2));
fru = reinterpret_cast<pldm_pdr_fru_record_set*>(outData +
sizeof(pldm_pdr_hdr));
- EXPECT_EQ(fru->terminus_handle, 2);
- EXPECT_EQ(fru->fru_rsi, 11);
- EXPECT_EQ(fru->entity_type, 2);
- EXPECT_EQ(fru->entity_instance_num, 1);
- EXPECT_EQ(fru->container_id, 101);
+ EXPECT_EQ(fru->terminus_handle, htole16(2));
+ EXPECT_EQ(fru->fru_rsi, htole16(11));
+ EXPECT_EQ(fru->entity_type, htole16(2));
+ EXPECT_EQ(fru->entity_instance_num, htole16(1));
+ EXPECT_EQ(fru->container_id, htole16(101));
outData = nullptr;
hdl = pldm_pdr_find_record(repo, 1, &outData, &size, &nextRecHdl);
@@ -271,15 +271,15 @@
hdr = reinterpret_cast<pldm_pdr_hdr*>(outData);
EXPECT_EQ(hdr->version, 1);
EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET);
- EXPECT_EQ(hdr->length, sizeof(pldm_pdr_fru_record_set));
- EXPECT_EQ(hdr->record_handle, 1);
+ EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set)));
+ EXPECT_EQ(hdr->record_handle, htole32(1));
fru = reinterpret_cast<pldm_pdr_fru_record_set*>(outData +
sizeof(pldm_pdr_hdr));
- EXPECT_EQ(fru->terminus_handle, 1);
- EXPECT_EQ(fru->fru_rsi, 10);
- EXPECT_EQ(fru->entity_type, 1);
- EXPECT_EQ(fru->entity_instance_num, 0);
- EXPECT_EQ(fru->container_id, 100);
+ EXPECT_EQ(fru->terminus_handle, htole16(1));
+ EXPECT_EQ(fru->fru_rsi, htole16(10));
+ EXPECT_EQ(fru->entity_type, htole16(1));
+ EXPECT_EQ(fru->entity_instance_num, htole16(0));
+ EXPECT_EQ(fru->container_id, htole16(100));
outData = nullptr;
pldm_pdr_destroy(repo);
@@ -647,32 +647,32 @@
sizeof(pldm_entity)));
uint8_t* start = data;
pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
- EXPECT_EQ(hdr->record_handle, 1);
+ EXPECT_EQ(le32toh(hdr->record_handle), 1);
EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
- EXPECT_EQ(hdr->length, size - sizeof(struct pldm_pdr_hdr));
+ EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
start += sizeof(pldm_pdr_hdr);
uint16_t* containerId = reinterpret_cast<uint16_t*>(start);
- EXPECT_EQ(*containerId, 1);
+ EXPECT_EQ(le16toh(*containerId), 1);
start += sizeof(uint16_t);
EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL);
start += sizeof(uint8_t);
pldm_entity* entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 1);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 0);
+ EXPECT_EQ(le16toh(entity->entity_type), 1);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 0);
start += sizeof(pldm_entity);
EXPECT_EQ(*start,
pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_LOGICAL));
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 3);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 1);
+ EXPECT_EQ(le16toh(entity->entity_type), 3);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 1);
start += sizeof(pldm_entity);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 3);
- EXPECT_EQ(entity->entity_instance_num, 2);
- EXPECT_EQ(entity->entity_container_id, 1);
+ EXPECT_EQ(le16toh(entity->entity_type), 3);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 2);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 1);
start += sizeof(pldm_entity);
currRecHandle = nextRecHandle;
@@ -683,32 +683,32 @@
sizeof(pldm_entity)));
start = data;
hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
- EXPECT_EQ(hdr->record_handle, 2);
+ EXPECT_EQ(le32toh(hdr->record_handle), 2);
EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
- EXPECT_EQ(hdr->length, size - sizeof(struct pldm_pdr_hdr));
+ EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
start += sizeof(pldm_pdr_hdr);
containerId = reinterpret_cast<uint16_t*>(start);
- EXPECT_EQ(*containerId, 1);
+ EXPECT_EQ(le16toh(*containerId), 1);
start += sizeof(uint16_t);
EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL);
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 1);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 0);
+ EXPECT_EQ(le16toh(entity->entity_type), 1);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 0);
start += sizeof(pldm_entity);
EXPECT_EQ(*start, pldm_entity_get_num_children(
l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL));
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 2);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 1);
+ EXPECT_EQ(le16toh(entity->entity_type), 2);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 1);
start += sizeof(pldm_entity);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 2);
- EXPECT_EQ(entity->entity_instance_num, 2);
- EXPECT_EQ(entity->entity_container_id, 1);
+ EXPECT_EQ(le16toh(entity->entity_type), 2);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 2);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 1);
start += sizeof(pldm_entity);
currRecHandle = nextRecHandle;
@@ -719,32 +719,32 @@
sizeof(pldm_entity)));
start = data;
hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
- EXPECT_EQ(hdr->record_handle, 3);
+ EXPECT_EQ(le32toh(hdr->record_handle), 3);
EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
- EXPECT_EQ(hdr->length, size - sizeof(struct pldm_pdr_hdr));
+ EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
start += sizeof(pldm_pdr_hdr);
containerId = reinterpret_cast<uint16_t*>(start);
- EXPECT_EQ(*containerId, 2);
+ EXPECT_EQ(le16toh(*containerId), 2);
start += sizeof(uint16_t);
EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL);
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 2);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 1);
+ EXPECT_EQ(le16toh(entity->entity_type), 2);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 1);
start += sizeof(pldm_entity);
EXPECT_EQ(*start, pldm_entity_get_num_children(
l2a, PLDM_ENTITY_ASSOCIAION_LOGICAL));
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 5);
- EXPECT_EQ(entity->entity_instance_num, 2);
- EXPECT_EQ(entity->entity_container_id, 2);
+ EXPECT_EQ(le16toh(entity->entity_type), 5);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 2);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 2);
start += sizeof(pldm_entity);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 5);
- EXPECT_EQ(entity->entity_instance_num, 3);
- EXPECT_EQ(entity->entity_container_id, 2);
+ EXPECT_EQ(le16toh(entity->entity_type), 5);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 3);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 2);
start += sizeof(pldm_entity);
currRecHandle = nextRecHandle;
@@ -755,32 +755,32 @@
sizeof(pldm_entity)));
start = data;
hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
- EXPECT_EQ(hdr->record_handle, 4);
+ EXPECT_EQ(le32toh(hdr->record_handle), 4);
EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
- EXPECT_EQ(hdr->length, size - sizeof(struct pldm_pdr_hdr));
+ EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
start += sizeof(pldm_pdr_hdr);
containerId = reinterpret_cast<uint16_t*>(start);
- EXPECT_EQ(*containerId, 2);
+ EXPECT_EQ(le16toh(*containerId), 2);
start += sizeof(uint16_t);
EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL);
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 2);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 1);
+ EXPECT_EQ(le16toh(entity->entity_type), 2);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 1);
start += sizeof(pldm_entity);
EXPECT_EQ(*start, pldm_entity_get_num_children(
l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL));
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 4);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 2);
+ EXPECT_EQ(le16toh(entity->entity_type), 4);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 2);
start += sizeof(pldm_entity);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 5);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 2);
+ EXPECT_EQ(le16toh(entity->entity_type), 5);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 2);
start += sizeof(pldm_entity);
currRecHandle = nextRecHandle;
@@ -791,27 +791,27 @@
sizeof(pldm_entity)));
start = data;
hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
- EXPECT_EQ(hdr->record_handle, 5);
+ EXPECT_EQ(le32toh(hdr->record_handle), 5);
EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
- EXPECT_EQ(hdr->length, size - sizeof(struct pldm_pdr_hdr));
+ EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
start += sizeof(pldm_pdr_hdr);
containerId = reinterpret_cast<uint16_t*>(start);
- EXPECT_EQ(*containerId, 3);
+ EXPECT_EQ(le16toh(*containerId), 3);
start += sizeof(uint16_t);
EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL);
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 4);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 2);
+ EXPECT_EQ(le16toh(entity->entity_type), 4);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 2);
start += sizeof(pldm_entity);
EXPECT_EQ(*start, pldm_entity_get_num_children(
l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL));
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 6);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 3);
+ EXPECT_EQ(le16toh(entity->entity_type), 6);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 3);
start += sizeof(pldm_entity);
currRecHandle = nextRecHandle;
@@ -822,27 +822,27 @@
sizeof(pldm_entity)));
start = data;
hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
- EXPECT_EQ(hdr->record_handle, 6);
+ EXPECT_EQ(le32toh(hdr->record_handle), 6);
EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
- EXPECT_EQ(hdr->length, size - sizeof(struct pldm_pdr_hdr));
+ EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
start += sizeof(pldm_pdr_hdr);
containerId = reinterpret_cast<uint16_t*>(start);
- EXPECT_EQ(*containerId, 4);
+ EXPECT_EQ(le16toh(*containerId), 4);
start += sizeof(uint16_t);
EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL);
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 5);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 2);
+ EXPECT_EQ(le16toh(entity->entity_type), 5);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 2);
start += sizeof(pldm_entity);
EXPECT_EQ(*start, pldm_entity_get_num_children(
l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL));
start += sizeof(uint8_t);
entity = reinterpret_cast<pldm_entity*>(start);
- EXPECT_EQ(entity->entity_type, 7);
- EXPECT_EQ(entity->entity_instance_num, 1);
- EXPECT_EQ(entity->entity_container_id, 4);
+ EXPECT_EQ(le16toh(entity->entity_type), 7);
+ EXPECT_EQ(le16toh(entity->entity_instance_num), 1);
+ EXPECT_EQ(le16toh(entity->entity_container_id), 4);
EXPECT_EQ(nextRecHandle, 0);