George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 1 | #include "libpldm/pdr.h" |
| 2 | |
| 3 | #include "common/utils.hpp" |
| 4 | |
| 5 | #include <filesystem> |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | namespace fs = std::filesystem; |
| 10 | using namespace pldm; |
| 11 | using namespace pldm::utils; |
| 12 | |
| 13 | TEST(EntityAssociation, addObjectPathEntityAssociations1) |
| 14 | { |
George Liu | f3c91cf | 2021-10-15 17:34:35 +0800 | [diff] [blame^] | 15 | pldm_entity entities[8]{}; |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 16 | |
| 17 | entities[0].entity_type = 45; |
| 18 | entities[0].entity_container_id = 0; |
| 19 | |
| 20 | entities[1].entity_type = 64; |
| 21 | entities[1].entity_container_id = 1; |
| 22 | |
| 23 | entities[2].entity_type = 67; |
| 24 | entities[2].entity_container_id = 2; |
| 25 | entities[3].entity_type = 67; |
| 26 | entities[3].entity_container_id = 2; |
| 27 | |
| 28 | entities[4].entity_type = 135; |
| 29 | entities[4].entity_container_id = 3; |
| 30 | entities[5].entity_type = 135; |
| 31 | entities[5].entity_container_id = 3; |
| 32 | entities[6].entity_type = 135; |
| 33 | entities[6].entity_container_id = 3; |
| 34 | entities[7].entity_type = 135; |
| 35 | entities[7].entity_container_id = 3; |
| 36 | |
| 37 | auto tree = pldm_entity_association_tree_init(); |
| 38 | |
George Liu | f3c91cf | 2021-10-15 17:34:35 +0800 | [diff] [blame^] | 39 | auto l1 = pldm_entity_association_tree_add_entity( |
| 40 | tree, &entities[0], 1, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, |
| 41 | true, 0xFFFF); |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 42 | |
George Liu | f3c91cf | 2021-10-15 17:34:35 +0800 | [diff] [blame^] | 43 | auto l2 = pldm_entity_association_tree_add_entity( |
| 44 | tree, &entities[1], 1, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true, |
| 45 | 0xFFFF); |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 46 | |
George Liu | f3c91cf | 2021-10-15 17:34:35 +0800 | [diff] [blame^] | 47 | auto l3a = pldm_entity_association_tree_add_entity( |
| 48 | tree, &entities[2], 0, l2, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true, |
| 49 | 0xFFFF); |
| 50 | auto l3b = pldm_entity_association_tree_add_entity( |
| 51 | tree, &entities[3], 1, l2, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true, |
| 52 | 0xFFFF); |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 53 | |
George Liu | f3c91cf | 2021-10-15 17:34:35 +0800 | [diff] [blame^] | 54 | auto l4a = pldm_entity_association_tree_add_entity( |
| 55 | tree, &entities[4], 0, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true, |
| 56 | 0xFFFF); |
| 57 | auto l4b = pldm_entity_association_tree_add_entity( |
| 58 | tree, &entities[5], 1, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true, |
| 59 | 0xFFFF); |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 60 | |
George Liu | f3c91cf | 2021-10-15 17:34:35 +0800 | [diff] [blame^] | 61 | auto l5a = pldm_entity_association_tree_add_entity( |
| 62 | tree, &entities[6], 0, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true, |
| 63 | 0xFFFF); |
| 64 | auto l5b = pldm_entity_association_tree_add_entity( |
| 65 | tree, &entities[7], 1, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true, |
| 66 | 0xFFFF); |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 67 | |
| 68 | EntityAssociations entityAssociations = { |
| 69 | {l1, l2}, {l2, l3a, l3b}, {l3a, l4a, l4b}, {l3b, l5a, l5b}}; |
| 70 | |
| 71 | ObjectPathMaps retObjectMaps = { |
| 72 | {"/xyz/openbmc_project/inventory/chassis1", l1}, |
| 73 | {"/xyz/openbmc_project/inventory/chassis1/motherboard1", l2}, |
| 74 | {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm0", l3a}, |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 75 | {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm0/cpu0", l4a}, |
| 76 | {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm0/cpu1", l4b}, |
George Liu | f3c91cf | 2021-10-15 17:34:35 +0800 | [diff] [blame^] | 77 | {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm1", l3b}, |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 78 | {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm1/cpu0", l5a}, |
George Liu | f3c91cf | 2021-10-15 17:34:35 +0800 | [diff] [blame^] | 79 | {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm1/cpu1", |
| 80 | l5b}}; |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 81 | |
| 82 | ObjectPathMaps objPathMap; |
| 83 | updateEntityAssociation(entityAssociations, tree, objPathMap); |
| 84 | |
| 85 | EXPECT_EQ(objPathMap.size(), retObjectMaps.size()); |
| 86 | |
| 87 | int index = 0; |
| 88 | for (auto& obj : objPathMap) |
| 89 | { |
| 90 | if (retObjectMaps.contains(obj.first)) |
| 91 | { |
| 92 | index++; |
| 93 | pldm_entity entity = pldm_entity_extract(obj.second); |
| 94 | pldm_entity retEntity = |
| 95 | pldm_entity_extract(retObjectMaps[obj.first]); |
| 96 | EXPECT_EQ(entity.entity_type, retEntity.entity_type); |
| 97 | EXPECT_EQ(entity.entity_instance_num, |
| 98 | retEntity.entity_instance_num); |
| 99 | EXPECT_EQ(pldm_entity_node_get_remote_container_id(obj.second), |
| 100 | pldm_entity_node_get_remote_container_id( |
| 101 | retObjectMaps[obj.first])); |
| 102 | } |
| 103 | } |
| 104 | EXPECT_EQ(index, retObjectMaps.size()); |
| 105 | pldm_entity_association_tree_destroy(tree); |
| 106 | } |