libpldm: Add pldm_entity_extract method
Add the pldm_entity_extract method in libpldm/pdr.h and extract
pldm entity structure explicitly.
Tested: built pldm daemon successfully and the unit test passes.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I330e0c76e75d01093148c3a432fcc18cea1d36e3
diff --git a/libpldm/tests/libpldm_pdr_test.cpp b/libpldm/tests/libpldm_pdr_test.cpp
index bbf950d..454b072 100644
--- a/libpldm/tests/libpldm_pdr_test.cpp
+++ b/libpldm/tests/libpldm_pdr_test.cpp
@@ -607,6 +607,47 @@
EXPECT_EQ(out[8].entity_container_id, 3u);
free(out);
+
+ pldm_entity p1 = pldm_entity_extract(l1);
+ EXPECT_EQ(p1.entity_type, 1u);
+ EXPECT_EQ(p1.entity_instance_num, 1u);
+ EXPECT_EQ(p1.entity_container_id, 0u);
+
+ pldm_entity p2a = pldm_entity_extract(l2a);
+ EXPECT_EQ(p2a.entity_type, 2u);
+ EXPECT_EQ(p2a.entity_instance_num, 1u);
+ EXPECT_EQ(p2a.entity_container_id, 1u);
+ pldm_entity p2b = pldm_entity_extract(l2b);
+ EXPECT_EQ(p2b.entity_type, 2u);
+ EXPECT_EQ(p2b.entity_instance_num, 2u);
+ EXPECT_EQ(p2b.entity_container_id, 1u);
+ pldm_entity p2c = pldm_entity_extract(l2c);
+ EXPECT_EQ(p2c.entity_type, 3u);
+ EXPECT_EQ(p2c.entity_instance_num, 1u);
+ EXPECT_EQ(p2c.entity_container_id, 1u);
+
+ pldm_entity p3a = pldm_entity_extract(l3a);
+ EXPECT_EQ(p3a.entity_type, 4u);
+ EXPECT_EQ(p3a.entity_instance_num, 1u);
+ EXPECT_EQ(p3a.entity_container_id, 2u);
+ pldm_entity p3b = pldm_entity_extract(l3b);
+ EXPECT_EQ(p3b.entity_type, 5u);
+ EXPECT_EQ(p3b.entity_instance_num, 1u);
+ EXPECT_EQ(p3b.entity_container_id, 2u);
+ pldm_entity p3c = pldm_entity_extract(l3c);
+ EXPECT_EQ(p3c.entity_type, 5u);
+ EXPECT_EQ(p3c.entity_instance_num, 2u);
+ EXPECT_EQ(p3c.entity_container_id, 2u);
+
+ pldm_entity p4a = pldm_entity_extract(l4a);
+ EXPECT_EQ(p4a.entity_type, 6u);
+ EXPECT_EQ(p4a.entity_instance_num, 1u);
+ EXPECT_EQ(p4a.entity_container_id, 3u);
+ pldm_entity p4b = pldm_entity_extract(l4b);
+ EXPECT_EQ(p4b.entity_type, 7u);
+ EXPECT_EQ(p4b.entity_instance_num, 1u);
+ EXPECT_EQ(p4b.entity_container_id, 4u);
+
pldm_entity_association_tree_destroy(tree);
}