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