blob: ab64aa1333f98d4a7462c4c53862219eb2cd7d47 [file] [log] [blame]
George Liudf9a6d32020-12-22 16:27:16 +08001#include "common/utils.hpp"
2
Andrew Jeffery4668f5c2024-01-15 14:59:17 +10303#include <libpldm/pdr.h>
4
George Liudf9a6d32020-12-22 16:27:16 +08005#include <filesystem>
6
7#include <gtest/gtest.h>
8
9namespace fs = std::filesystem;
10using namespace pldm;
11using namespace pldm::utils;
12
13TEST(EntityAssociation, addObjectPathEntityAssociations1)
14{
George Liuf3c91cf2021-10-15 17:34:35 +080015 pldm_entity entities[8]{};
George Liudf9a6d32020-12-22 16:27:16 +080016
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 Liuf3c91cf2021-10-15 17:34:35 +080039 auto l1 = pldm_entity_association_tree_add_entity(
40 tree, &entities[0], 1, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true,
41 true, 0xFFFF);
George Liudf9a6d32020-12-22 16:27:16 +080042
George Liuf3c91cf2021-10-15 17:34:35 +080043 auto l2 = pldm_entity_association_tree_add_entity(
44 tree, &entities[1], 1, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
45 0xFFFF);
George Liudf9a6d32020-12-22 16:27:16 +080046
George Liuf3c91cf2021-10-15 17:34:35 +080047 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 Liudf9a6d32020-12-22 16:27:16 +080053
George Liuf3c91cf2021-10-15 17:34:35 +080054 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 Liudf9a6d32020-12-22 16:27:16 +080060
George Liuf3c91cf2021-10-15 17:34:35 +080061 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 Liudf9a6d32020-12-22 16:27:16 +080067
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 Liudf9a6d32020-12-22 16:27:16 +080075 {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm0/cpu0", l4a},
76 {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm0/cpu1", l4b},
George Liuf3c91cf2021-10-15 17:34:35 +080077 {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm1", l3b},
George Liudf9a6d32020-12-22 16:27:16 +080078 {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm1/cpu0", l5a},
George Liuf3c91cf2021-10-15 17:34:35 +080079 {"/xyz/openbmc_project/inventory/chassis1/motherboard1/dcm1/cpu1",
80 l5b}};
George Liudf9a6d32020-12-22 16:27:16 +080081
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}