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"); |
Kamalkumar Patel | 15ce5a1 | 2024-05-07 11:45:11 -0500 | [diff] [blame^] | 92 | updateEntityAssociation(entityAssociations, tree, objPathMap, entityMaps, |
| 93 | nullptr); |
George Liu | df9a6d3 | 2020-12-22 16:27:16 +0800 | [diff] [blame] | 94 | |
| 95 | EXPECT_EQ(objPathMap.size(), retObjectMaps.size()); |
| 96 | |
| 97 | int index = 0; |
| 98 | for (auto& obj : objPathMap) |
| 99 | { |
| 100 | if (retObjectMaps.contains(obj.first)) |
| 101 | { |
| 102 | index++; |
| 103 | pldm_entity entity = pldm_entity_extract(obj.second); |
| 104 | pldm_entity retEntity = |
| 105 | pldm_entity_extract(retObjectMaps[obj.first]); |
| 106 | EXPECT_EQ(entity.entity_type, retEntity.entity_type); |
| 107 | EXPECT_EQ(entity.entity_instance_num, |
| 108 | retEntity.entity_instance_num); |
| 109 | EXPECT_EQ(pldm_entity_node_get_remote_container_id(obj.second), |
| 110 | pldm_entity_node_get_remote_container_id( |
| 111 | retObjectMaps[obj.first])); |
| 112 | } |
| 113 | } |
| 114 | EXPECT_EQ(index, retObjectMaps.size()); |
| 115 | pldm_entity_association_tree_destroy(tree); |
| 116 | } |