Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 1 | #include <endian.h> |
Andrew Jeffery | efb4006 | 2023-11-10 13:48:39 +1030 | [diff] [blame] | 2 | #include <libpldm/pdr.h> |
| 3 | #include <libpldm/platform.h> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 4 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 5 | #include <array> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 6 | #include <cstdint> |
Andrew Jeffery | 5a70607 | 2023-04-05 19:45:31 +0930 | [diff] [blame] | 7 | #include <cstdlib> |
| 8 | #include <cstring> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 9 | #include <vector> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 10 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 11 | #include <gtest/gtest.h> |
| 12 | |
| 13 | TEST(PDRAccess, testInit) |
| 14 | { |
| 15 | auto repo = pldm_pdr_init(); |
| 16 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
| 17 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), 0u); |
| 18 | pldm_pdr_destroy(repo); |
| 19 | } |
| 20 | |
| 21 | TEST(PDRUpdate, testAdd) |
| 22 | { |
| 23 | auto repo = pldm_pdr_init(); |
| 24 | |
| 25 | std::array<uint8_t, 10> data{}; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 26 | uint32_t handle = 0; |
| 27 | EXPECT_EQ( |
| 28 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &handle), |
| 29 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 30 | EXPECT_EQ(handle, 1u); |
| 31 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 32 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), data.size()); |
| 33 | |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 34 | handle = 0; |
| 35 | EXPECT_EQ( |
| 36 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &handle), |
| 37 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 38 | EXPECT_EQ(handle, 2u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 39 | |
| 40 | handle = 0; |
| 41 | EXPECT_EQ( |
| 42 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &handle), |
| 43 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 44 | EXPECT_EQ(handle, 3u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 45 | |
| 46 | handle = 0xdeeddeedu; |
| 47 | EXPECT_EQ( |
| 48 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &handle), |
| 49 | 0); |
| 50 | EXPECT_EQ(handle, 0xdeeddeed); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 51 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 52 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), data.size() * 4u); |
| 53 | |
| 54 | pldm_pdr_destroy(repo); |
| 55 | } |
| 56 | |
| 57 | TEST(PDRRemoveByTerminus, testRemoveByTerminus) |
| 58 | { |
| 59 | std::array<uint8_t, 10> data{}; |
| 60 | |
| 61 | auto repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 62 | |
| 63 | EXPECT_EQ( |
| 64 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 65 | pldm_pdr_remove_pdrs_by_terminus_handle(repo, 1); |
| 66 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
| 67 | pldm_pdr_destroy(repo); |
| 68 | |
| 69 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 70 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 2, NULL), |
| 71 | 0); |
| 72 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 73 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 74 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
| 75 | pldm_pdr_remove_pdrs_by_terminus_handle(repo, 1); |
| 76 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 77 | pldm_pdr_destroy(repo); |
| 78 | |
| 79 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 80 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 81 | 0); |
| 82 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 2, NULL), |
| 83 | 0); |
| 84 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 2, NULL), |
| 85 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 86 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
| 87 | pldm_pdr_remove_pdrs_by_terminus_handle(repo, 2); |
| 88 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 89 | pldm_pdr_destroy(repo); |
| 90 | |
| 91 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 92 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 93 | 0); |
| 94 | EXPECT_EQ( |
| 95 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 2, NULL), 0); |
| 96 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 97 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 98 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
| 99 | pldm_pdr_remove_remote_pdrs(repo); |
| 100 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 101 | pldm_pdr_remove_pdrs_by_terminus_handle(repo, 1); |
| 102 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 103 | pldm_pdr_remove_pdrs_by_terminus_handle(repo, 2); |
| 104 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
| 105 | pldm_pdr_destroy(repo); |
| 106 | } |
| 107 | |
| 108 | TEST(PDRUpdate, testRemove) |
| 109 | { |
| 110 | std::array<uint8_t, 10> data{}; |
| 111 | |
| 112 | auto repo = pldm_pdr_init(); |
| 113 | pldm_pdr_remove_remote_pdrs(repo); |
| 114 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
| 115 | pldm_pdr_destroy(repo); |
| 116 | |
| 117 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 118 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 119 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 120 | pldm_pdr_remove_remote_pdrs(repo); |
| 121 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
| 122 | pldm_pdr_destroy(repo); |
| 123 | |
| 124 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 125 | EXPECT_EQ( |
| 126 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 127 | pldm_pdr_remove_remote_pdrs(repo); |
| 128 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 129 | pldm_pdr_destroy(repo); |
| 130 | |
| 131 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 132 | EXPECT_EQ( |
| 133 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 134 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 135 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 136 | pldm_pdr_remove_remote_pdrs(repo); |
| 137 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 138 | pldm_pdr_destroy(repo); |
| 139 | |
| 140 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 141 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 142 | 0); |
| 143 | EXPECT_EQ( |
| 144 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 145 | pldm_pdr_remove_remote_pdrs(repo); |
| 146 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 147 | pldm_pdr_destroy(repo); |
| 148 | |
| 149 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 150 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 151 | 0); |
| 152 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 153 | 0); |
| 154 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 155 | 0); |
| 156 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 157 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 158 | pldm_pdr_remove_remote_pdrs(repo); |
| 159 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 160 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 161 | 0); |
| 162 | EXPECT_EQ( |
| 163 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 164 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
| 165 | pldm_pdr_destroy(repo); |
| 166 | |
| 167 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 168 | EXPECT_EQ( |
| 169 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 170 | EXPECT_EQ( |
| 171 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 172 | EXPECT_EQ( |
| 173 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 174 | EXPECT_EQ( |
| 175 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 176 | pldm_pdr_remove_remote_pdrs(repo); |
| 177 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 178 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 179 | 0); |
| 180 | EXPECT_EQ( |
| 181 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 182 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 6u); |
| 183 | pldm_pdr_destroy(repo); |
| 184 | |
| 185 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 186 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 187 | 0); |
| 188 | EXPECT_EQ( |
| 189 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 190 | EXPECT_EQ( |
| 191 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 192 | EXPECT_EQ( |
| 193 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 194 | pldm_pdr_remove_remote_pdrs(repo); |
| 195 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 196 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 197 | 0); |
| 198 | EXPECT_EQ( |
| 199 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 200 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u); |
| 201 | pldm_pdr_destroy(repo); |
| 202 | |
| 203 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 204 | EXPECT_EQ( |
| 205 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 206 | EXPECT_EQ( |
| 207 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 208 | EXPECT_EQ( |
| 209 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 210 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 211 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 212 | pldm_pdr_remove_remote_pdrs(repo); |
| 213 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 214 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 215 | 0); |
| 216 | EXPECT_EQ( |
| 217 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 218 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u); |
| 219 | pldm_pdr_destroy(repo); |
| 220 | |
| 221 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 222 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 223 | 0); |
| 224 | EXPECT_EQ( |
| 225 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 226 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 227 | 0); |
| 228 | EXPECT_EQ( |
| 229 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 230 | pldm_pdr_remove_remote_pdrs(repo); |
| 231 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 232 | EXPECT_EQ( |
| 233 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 234 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 235 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 236 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 237 | pldm_pdr_destroy(repo); |
| 238 | |
| 239 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 240 | EXPECT_EQ( |
| 241 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 242 | EXPECT_EQ( |
| 243 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 244 | EXPECT_EQ( |
| 245 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 246 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 247 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 248 | pldm_pdr_remove_remote_pdrs(repo); |
| 249 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 250 | EXPECT_EQ( |
| 251 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 252 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 253 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 254 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u); |
| 255 | pldm_pdr_destroy(repo); |
| 256 | |
| 257 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 258 | EXPECT_EQ( |
| 259 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 260 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 261 | 0); |
| 262 | EXPECT_EQ( |
| 263 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 264 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 265 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 266 | pldm_pdr_remove_remote_pdrs(repo); |
| 267 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 268 | EXPECT_EQ( |
| 269 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 270 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 271 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 272 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 273 | pldm_pdr_destroy(repo); |
| 274 | |
| 275 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 276 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 277 | 0); |
| 278 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 279 | 0); |
| 280 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 281 | 0); |
| 282 | EXPECT_EQ( |
| 283 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 284 | pldm_pdr_remove_remote_pdrs(repo); |
| 285 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 286 | EXPECT_EQ( |
| 287 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 288 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 289 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 290 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
| 291 | pldm_pdr_destroy(repo); |
| 292 | |
| 293 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 294 | EXPECT_EQ( |
| 295 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 296 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 297 | 0); |
| 298 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 299 | 0); |
| 300 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 301 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 302 | pldm_pdr_remove_remote_pdrs(repo); |
| 303 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 304 | EXPECT_EQ( |
| 305 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 306 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 307 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 308 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
| 309 | pldm_pdr_destroy(repo); |
| 310 | |
| 311 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 312 | EXPECT_EQ( |
| 313 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 314 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 315 | 0); |
| 316 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 317 | 0); |
| 318 | EXPECT_EQ( |
| 319 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 320 | pldm_pdr_remove_remote_pdrs(repo); |
| 321 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 322 | EXPECT_EQ( |
| 323 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 324 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 325 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 326 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 327 | pldm_pdr_destroy(repo); |
| 328 | |
| 329 | repo = pldm_pdr_init(); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 330 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 331 | 0); |
| 332 | EXPECT_EQ( |
| 333 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 334 | EXPECT_EQ( |
| 335 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, NULL), 0); |
| 336 | EXPECT_EQ(pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, NULL), |
| 337 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 338 | pldm_pdr_remove_remote_pdrs(repo); |
| 339 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 340 | uint32_t handle = 0; |
| 341 | EXPECT_EQ( |
| 342 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &handle), |
| 343 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 344 | EXPECT_EQ(handle, 3u); |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 345 | handle = 0; |
| 346 | EXPECT_EQ( |
| 347 | pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, &handle), |
| 348 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 349 | EXPECT_EQ(handle, 4u); |
| 350 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 351 | pldm_pdr_destroy(repo); |
| 352 | } |
| 353 | |
| 354 | TEST(PDRAccess, testGet) |
| 355 | { |
| 356 | auto repo = pldm_pdr_init(); |
| 357 | |
| 358 | std::array<uint32_t, 10> in{100, 345, 3, 6, 89, 0, 11, 45, 23434, 123123}; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 359 | uint32_t handle = 1; |
| 360 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<uint8_t*>(in.data()), |
| 361 | sizeof(in), false, 1, &handle), |
| 362 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 363 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 364 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in)); |
| 365 | uint32_t size{}; |
| 366 | uint32_t nextRecHdl{}; |
| 367 | uint8_t* outData = nullptr; |
| 368 | auto hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 369 | EXPECT_NE(hdl, nullptr); |
| 370 | EXPECT_EQ(size, sizeof(in)); |
| 371 | EXPECT_EQ(nextRecHdl, 0u); |
| 372 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 373 | outData = nullptr; |
| 374 | |
| 375 | auto hdl2 = pldm_pdr_find_record(repo, 1, &outData, &size, &nextRecHdl); |
| 376 | EXPECT_EQ(hdl, hdl2); |
| 377 | EXPECT_NE(hdl, nullptr); |
| 378 | EXPECT_EQ(size, sizeof(in)); |
| 379 | EXPECT_EQ(nextRecHdl, 0u); |
| 380 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 381 | outData = nullptr; |
| 382 | |
| 383 | hdl = pldm_pdr_find_record(repo, htole32(0xdeaddead), &outData, &size, |
| 384 | &nextRecHdl); |
| 385 | EXPECT_EQ(hdl, nullptr); |
| 386 | EXPECT_EQ(size, 0u); |
| 387 | EXPECT_EQ(nextRecHdl, 0u); |
| 388 | EXPECT_EQ(outData, nullptr); |
| 389 | outData = nullptr; |
| 390 | |
| 391 | std::array<uint32_t, 10> in2{1000, 3450, 30, 60, 890, |
| 392 | 0, 110, 450, 234034, 123123}; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 393 | handle = 2; |
| 394 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<uint8_t*>(in2.data()), |
| 395 | sizeof(in2), false, 1, &handle), |
| 396 | 0); |
| 397 | handle = 3; |
| 398 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<uint8_t*>(in2.data()), |
| 399 | sizeof(in2), false, 1, &handle), |
| 400 | 0); |
| 401 | handle = 4; |
| 402 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<uint8_t*>(in2.data()), |
| 403 | sizeof(in2), true, 1, &handle), |
| 404 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 405 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 406 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in2) * 4); |
| 407 | hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 408 | EXPECT_NE(hdl, nullptr); |
| 409 | EXPECT_EQ(size, sizeof(in)); |
| 410 | EXPECT_EQ(nextRecHdl, 2u); |
| 411 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 412 | outData = nullptr; |
| 413 | hdl2 = pldm_pdr_find_record(repo, 1, &outData, &size, &nextRecHdl); |
| 414 | EXPECT_EQ(hdl, hdl2); |
| 415 | EXPECT_NE(hdl, nullptr); |
| 416 | EXPECT_EQ(size, sizeof(in)); |
| 417 | EXPECT_EQ(nextRecHdl, 2u); |
| 418 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 419 | outData = nullptr; |
| 420 | hdl = pldm_pdr_find_record(repo, 2, &outData, &size, &nextRecHdl); |
| 421 | EXPECT_NE(hdl, nullptr); |
| 422 | EXPECT_EQ(size, sizeof(in2)); |
| 423 | EXPECT_EQ(nextRecHdl, 3u); |
| 424 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 425 | outData = nullptr; |
| 426 | hdl = pldm_pdr_find_record(repo, 3, &outData, &size, &nextRecHdl); |
| 427 | EXPECT_NE(hdl, nullptr); |
| 428 | EXPECT_EQ(pldm_pdr_record_is_remote(hdl), false); |
| 429 | EXPECT_EQ(size, sizeof(in2)); |
| 430 | EXPECT_EQ(nextRecHdl, 4u); |
| 431 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 432 | outData = nullptr; |
| 433 | hdl = pldm_pdr_find_record(repo, 4, &outData, &size, &nextRecHdl); |
| 434 | EXPECT_NE(hdl, nullptr); |
| 435 | EXPECT_EQ(pldm_pdr_record_is_remote(hdl), true); |
| 436 | EXPECT_EQ(size, sizeof(in2)); |
| 437 | EXPECT_EQ(nextRecHdl, 0u); |
| 438 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 439 | outData = nullptr; |
| 440 | |
| 441 | pldm_pdr_destroy(repo); |
| 442 | } |
| 443 | |
| 444 | TEST(PDRAccess, testGetNext) |
| 445 | { |
| 446 | auto repo = pldm_pdr_init(); |
| 447 | |
| 448 | std::array<uint32_t, 10> in{100, 345, 3, 6, 89, 0, 11, 45, 23434, 123123}; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 449 | uint32_t handle = 1; |
| 450 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<uint8_t*>(in.data()), |
| 451 | sizeof(in), false, 1, &handle), |
| 452 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 453 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 454 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in)); |
| 455 | uint32_t size{}; |
| 456 | uint32_t nextRecHdl{}; |
| 457 | uint8_t* outData = nullptr; |
| 458 | auto hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 459 | EXPECT_NE(hdl, nullptr); |
| 460 | EXPECT_EQ(size, sizeof(in)); |
| 461 | EXPECT_EQ(nextRecHdl, 0u); |
| 462 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 463 | outData = nullptr; |
| 464 | |
| 465 | std::array<uint32_t, 10> in2{1000, 3450, 30, 60, 890, |
| 466 | 0, 110, 450, 234034, 123123}; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 467 | handle = 2; |
| 468 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<uint8_t*>(in2.data()), |
| 469 | sizeof(in2), false, 1, &handle), |
| 470 | 0); |
| 471 | handle = 3; |
| 472 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<uint8_t*>(in2.data()), |
| 473 | sizeof(in2), false, 1, &handle), |
| 474 | 0); |
| 475 | handle = 4; |
| 476 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<uint8_t*>(in2.data()), |
| 477 | sizeof(in2), false, 1, &handle), |
| 478 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 479 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 480 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in2) * 4); |
| 481 | hdl = pldm_pdr_get_next_record(repo, hdl, &outData, &size, &nextRecHdl); |
| 482 | EXPECT_NE(hdl, nullptr); |
| 483 | EXPECT_EQ(size, sizeof(in2)); |
| 484 | EXPECT_EQ(nextRecHdl, 3u); |
| 485 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 486 | outData = nullptr; |
| 487 | hdl = pldm_pdr_get_next_record(repo, hdl, &outData, &size, &nextRecHdl); |
| 488 | EXPECT_NE(hdl, nullptr); |
| 489 | EXPECT_EQ(size, sizeof(in2)); |
| 490 | EXPECT_EQ(nextRecHdl, 4u); |
| 491 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 492 | outData = nullptr; |
| 493 | hdl = pldm_pdr_get_next_record(repo, hdl, &outData, &size, &nextRecHdl); |
| 494 | EXPECT_NE(hdl, nullptr); |
| 495 | EXPECT_EQ(size, sizeof(in2)); |
| 496 | EXPECT_EQ(nextRecHdl, 0u); |
| 497 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 498 | outData = nullptr; |
| 499 | |
| 500 | pldm_pdr_destroy(repo); |
| 501 | } |
| 502 | |
| 503 | TEST(PDRAccess, testFindByType) |
| 504 | { |
| 505 | auto repo = pldm_pdr_init(); |
| 506 | |
| 507 | std::array<uint8_t, sizeof(pldm_pdr_hdr)> data{}; |
| 508 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(data.data()); |
| 509 | hdr->type = 1; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 510 | uint32_t first = 0; |
| 511 | EXPECT_EQ( |
| 512 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &first), |
| 513 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 514 | hdr->type = 2; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 515 | uint32_t second = 0; |
| 516 | EXPECT_EQ( |
| 517 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &second), |
| 518 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 519 | hdr->type = 3; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 520 | uint32_t third = 0; |
| 521 | EXPECT_EQ( |
| 522 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &third), |
| 523 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 524 | hdr->type = 4; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 525 | uint32_t fourth = 0; |
| 526 | EXPECT_EQ( |
| 527 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &fourth), |
| 528 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 529 | |
| 530 | uint8_t* outData = nullptr; |
| 531 | uint32_t size{}; |
| 532 | auto firstRec = |
| 533 | pldm_pdr_find_record_by_type(repo, 1, nullptr, &outData, &size); |
| 534 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, firstRec), first); |
| 535 | outData = nullptr; |
| 536 | auto secondRec = |
| 537 | pldm_pdr_find_record_by_type(repo, 2, nullptr, &outData, &size); |
| 538 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, secondRec), second); |
| 539 | outData = nullptr; |
| 540 | auto thirdRec = |
| 541 | pldm_pdr_find_record_by_type(repo, 3, nullptr, &outData, &size); |
| 542 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, thirdRec), third); |
| 543 | outData = nullptr; |
| 544 | auto fourthRec = |
| 545 | pldm_pdr_find_record_by_type(repo, 4, nullptr, &outData, &size); |
| 546 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, fourthRec), fourth); |
| 547 | outData = nullptr; |
| 548 | auto fifthRec = |
| 549 | pldm_pdr_find_record_by_type(repo, 5, nullptr, &outData, &size); |
| 550 | EXPECT_EQ(fifthRec, nullptr); |
| 551 | EXPECT_EQ(outData, nullptr); |
| 552 | EXPECT_EQ(size, 0u); |
| 553 | |
| 554 | auto rec = |
| 555 | pldm_pdr_find_record_by_type(repo, 3, secondRec, &outData, &size); |
| 556 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, rec), third); |
| 557 | outData = nullptr; |
| 558 | rec = pldm_pdr_find_record_by_type(repo, 4, secondRec, &outData, &size); |
| 559 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, rec), fourth); |
| 560 | outData = nullptr; |
| 561 | rec = pldm_pdr_find_record_by_type(repo, 2, firstRec, &outData, &size); |
| 562 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, rec), second); |
| 563 | outData = nullptr; |
| 564 | |
| 565 | pldm_pdr_destroy(repo); |
| 566 | } |
| 567 | |
| 568 | TEST(PDRUpdate, testAddFruRecordSet) |
| 569 | { |
| 570 | auto repo = pldm_pdr_init(); |
| 571 | |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 572 | uint32_t handle = 0; |
| 573 | EXPECT_EQ( |
| 574 | pldm_pdr_add_fru_record_set_check(repo, 1, 10, 1, 0, 100, &handle), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 575 | EXPECT_EQ(handle, 1u); |
| 576 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 577 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), |
| 578 | sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set)); |
| 579 | uint32_t size{}; |
| 580 | uint32_t nextRecHdl{}; |
| 581 | uint8_t* outData = nullptr; |
| 582 | auto hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 583 | EXPECT_NE(hdl, nullptr); |
| 584 | EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set)); |
| 585 | EXPECT_EQ(nextRecHdl, 0u); |
| 586 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(outData); |
| 587 | EXPECT_EQ(hdr->version, 1u); |
| 588 | EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET); |
| 589 | EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set))); |
| 590 | EXPECT_EQ(hdr->record_handle, htole32(1)); |
| 591 | pldm_pdr_fru_record_set* fru = reinterpret_cast<pldm_pdr_fru_record_set*>( |
| 592 | outData + sizeof(pldm_pdr_hdr)); |
| 593 | EXPECT_EQ(fru->terminus_handle, htole16(1)); |
| 594 | EXPECT_EQ(fru->fru_rsi, htole16(10)); |
| 595 | EXPECT_EQ(fru->entity_type, htole16(1)); |
| 596 | EXPECT_EQ(fru->entity_instance_num, htole16(0)); |
| 597 | EXPECT_EQ(fru->container_id, htole16(100)); |
| 598 | outData = nullptr; |
| 599 | |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 600 | handle = 0; |
| 601 | EXPECT_EQ( |
| 602 | pldm_pdr_add_fru_record_set_check(repo, 2, 11, 2, 1, 101, &handle), 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 603 | EXPECT_EQ(handle, 2u); |
| 604 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
| 605 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), |
| 606 | 2 * (sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set))); |
| 607 | hdl = pldm_pdr_find_record(repo, 2, &outData, &size, &nextRecHdl); |
| 608 | EXPECT_NE(hdl, nullptr); |
| 609 | EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set)); |
| 610 | EXPECT_EQ(nextRecHdl, 0u); |
| 611 | hdr = reinterpret_cast<pldm_pdr_hdr*>(outData); |
| 612 | EXPECT_EQ(hdr->version, 1u); |
| 613 | EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET); |
| 614 | EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set))); |
| 615 | EXPECT_EQ(hdr->record_handle, htole32(2)); |
| 616 | fru = reinterpret_cast<pldm_pdr_fru_record_set*>(outData + |
| 617 | sizeof(pldm_pdr_hdr)); |
| 618 | EXPECT_EQ(fru->terminus_handle, htole16(2)); |
| 619 | EXPECT_EQ(fru->fru_rsi, htole16(11)); |
| 620 | EXPECT_EQ(fru->entity_type, htole16(2)); |
| 621 | EXPECT_EQ(fru->entity_instance_num, htole16(1)); |
| 622 | EXPECT_EQ(fru->container_id, htole16(101)); |
| 623 | outData = nullptr; |
| 624 | |
| 625 | hdl = pldm_pdr_find_record(repo, 1, &outData, &size, &nextRecHdl); |
| 626 | EXPECT_NE(hdl, nullptr); |
| 627 | EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set)); |
| 628 | EXPECT_EQ(nextRecHdl, 2u); |
| 629 | hdr = reinterpret_cast<pldm_pdr_hdr*>(outData); |
| 630 | EXPECT_EQ(hdr->version, 1u); |
| 631 | EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET); |
| 632 | EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set))); |
| 633 | EXPECT_EQ(hdr->record_handle, htole32(1)); |
| 634 | fru = reinterpret_cast<pldm_pdr_fru_record_set*>(outData + |
| 635 | sizeof(pldm_pdr_hdr)); |
| 636 | EXPECT_EQ(fru->terminus_handle, htole16(1)); |
| 637 | EXPECT_EQ(fru->fru_rsi, htole16(10)); |
| 638 | EXPECT_EQ(fru->entity_type, htole16(1)); |
| 639 | EXPECT_EQ(fru->entity_instance_num, htole16(0)); |
| 640 | EXPECT_EQ(fru->container_id, htole16(100)); |
| 641 | outData = nullptr; |
| 642 | |
| 643 | pldm_pdr_destroy(repo); |
| 644 | } |
| 645 | |
| 646 | TEST(PDRUpdate, tesFindtFruRecordSet) |
| 647 | { |
| 648 | auto repo = pldm_pdr_init(); |
| 649 | |
| 650 | uint16_t terminusHdl{}; |
| 651 | uint16_t entityType{}; |
| 652 | uint16_t entityInstanceNum{}; |
| 653 | uint16_t containerId{}; |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 654 | uint32_t first = 1; |
| 655 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check(repo, 1, 1, 1, 0, 100, &first), |
| 656 | 0); |
| 657 | uint32_t second = 2; |
| 658 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check(repo, 1, 2, 1, 1, 100, &second), |
| 659 | 0); |
| 660 | uint32_t third = 3; |
| 661 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check(repo, 1, 3, 1, 2, 100, &third), |
| 662 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 663 | EXPECT_EQ(first, pldm_pdr_get_record_handle( |
| 664 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 665 | repo, 1, &terminusHdl, &entityType, |
| 666 | &entityInstanceNum, &containerId))); |
| 667 | EXPECT_EQ(second, pldm_pdr_get_record_handle( |
| 668 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 669 | repo, 2, &terminusHdl, &entityType, |
| 670 | &entityInstanceNum, &containerId))); |
| 671 | EXPECT_EQ(third, pldm_pdr_get_record_handle( |
| 672 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 673 | repo, 3, &terminusHdl, &entityType, |
| 674 | &entityInstanceNum, &containerId))); |
| 675 | EXPECT_EQ(terminusHdl, 1u); |
| 676 | EXPECT_EQ(entityType, 1u); |
| 677 | EXPECT_EQ(entityInstanceNum, 2u); |
| 678 | EXPECT_EQ(containerId, 100u); |
| 679 | EXPECT_EQ(nullptr, pldm_pdr_fru_record_set_find_by_rsi( |
| 680 | repo, 4, &terminusHdl, &entityType, |
| 681 | &entityInstanceNum, &containerId)); |
| 682 | |
| 683 | pldm_pdr_destroy(repo); |
| 684 | } |
| 685 | |
Pavithra Barithaya | 4d69434 | 2023-05-19 08:04:41 -0500 | [diff] [blame] | 686 | #ifdef LIBPLDM_API_TESTING |
| 687 | TEST(PDRUpdate, testFindLastInRange) |
| 688 | { |
| 689 | auto repo = pldm_pdr_init(); |
| 690 | |
| 691 | std::array<uint8_t, 10> data{}; |
Andrew Jeffery | c79a5df | 2023-07-17 15:09:21 +0930 | [diff] [blame] | 692 | uint32_t handle1 = 0; |
| 693 | EXPECT_EQ( |
| 694 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &handle1), |
| 695 | 0); |
| 696 | uint32_t handle2 = 23; |
| 697 | EXPECT_EQ( |
| 698 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &handle2), |
| 699 | 0); |
| 700 | uint32_t handle3 = 77; |
| 701 | EXPECT_EQ( |
| 702 | pldm_pdr_add_check(repo, data.data(), data.size(), false, 1, &handle3), |
| 703 | 0); |
| 704 | uint32_t handle4 = 16777325; |
| 705 | EXPECT_EQ( |
| 706 | pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, &handle4), |
| 707 | 0); |
| 708 | uint32_t handle5 = 16777344; |
| 709 | EXPECT_EQ( |
| 710 | pldm_pdr_add_check(repo, data.data(), data.size(), true, 1, &handle5), |
| 711 | 0); |
Pavithra Barithaya | 4d69434 | 2023-05-19 08:04:41 -0500 | [diff] [blame] | 712 | |
| 713 | auto rec1 = pldm_pdr_find_last_in_range(repo, 0, 100); |
| 714 | auto rec2 = pldm_pdr_find_last_in_range(repo, 16777300, 33554431); |
| 715 | EXPECT_NE(rec1, nullptr); |
| 716 | EXPECT_NE(rec2, nullptr); |
| 717 | EXPECT_NE(handle1, pldm_pdr_get_record_handle(repo, rec1)); |
| 718 | EXPECT_NE(handle2, pldm_pdr_get_record_handle(repo, rec1)); |
| 719 | EXPECT_EQ(handle3, pldm_pdr_get_record_handle(repo, rec1)); |
| 720 | EXPECT_NE(handle4, pldm_pdr_get_record_handle(repo, rec2)); |
| 721 | EXPECT_EQ(handle5, pldm_pdr_get_record_handle(repo, rec2)); |
| 722 | |
| 723 | pldm_pdr_destroy(repo); |
| 724 | } |
| 725 | #endif |
| 726 | |
Pavithra Barithaya | 274732f | 2024-07-05 16:03:01 +0530 | [diff] [blame] | 727 | #ifdef LIBPLDM_API_TESTING |
| 728 | TEST(PDRAccess, testGetTerminusHandle) |
| 729 | { |
| 730 | |
| 731 | auto repo = pldm_pdr_init(); |
| 732 | |
| 733 | pldm_pdr_hdr hdr; |
| 734 | |
| 735 | hdr.type = 1; |
| 736 | uint16_t firstTerminusHandle = 1; |
| 737 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<const uint8_t*>(&hdr), |
| 738 | sizeof(hdr), false, firstTerminusHandle, NULL), |
| 739 | 0); |
| 740 | |
| 741 | hdr.type = 2; |
| 742 | uint16_t secondTerminusHandle = 2; |
| 743 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<const uint8_t*>(&hdr), |
| 744 | sizeof(hdr), true, secondTerminusHandle, NULL), |
| 745 | 0); |
| 746 | |
| 747 | hdr.type = 3; |
| 748 | uint16_t thirdTerminusHandle = 3; |
| 749 | EXPECT_EQ(pldm_pdr_add_check(repo, reinterpret_cast<const uint8_t*>(&hdr), |
| 750 | sizeof(hdr), true, thirdTerminusHandle, NULL), |
| 751 | 0); |
| 752 | |
| 753 | uint8_t* outData = nullptr; |
| 754 | uint32_t size{}; |
| 755 | |
| 756 | auto firstRec = |
| 757 | pldm_pdr_find_record_by_type(repo, 1, nullptr, &outData, &size); |
| 758 | EXPECT_EQ(pldm_pdr_get_terminus_handle(repo, firstRec), |
| 759 | firstTerminusHandle); |
| 760 | outData = nullptr; |
| 761 | |
| 762 | auto secondRec = |
| 763 | pldm_pdr_find_record_by_type(repo, 2, nullptr, &outData, &size); |
| 764 | EXPECT_EQ(pldm_pdr_get_terminus_handle(repo, secondRec), |
| 765 | secondTerminusHandle); |
| 766 | outData = nullptr; |
| 767 | |
| 768 | auto thirdRec = |
| 769 | pldm_pdr_find_record_by_type(repo, 3, nullptr, &outData, &size); |
| 770 | EXPECT_EQ(pldm_pdr_get_terminus_handle(repo, thirdRec), |
| 771 | thirdTerminusHandle); |
| 772 | outData = nullptr; |
| 773 | |
| 774 | pldm_pdr_destroy(repo); |
| 775 | } |
| 776 | #endif |
| 777 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 778 | TEST(EntityAssociationPDR, testInit) |
| 779 | { |
| 780 | auto tree = pldm_entity_association_tree_init(); |
| 781 | EXPECT_NE(tree, nullptr); |
| 782 | pldm_entity_association_tree_destroy(tree); |
| 783 | } |
| 784 | |
| 785 | TEST(EntityAssociationPDR, testBuild) |
| 786 | { |
| 787 | // 1 |
| 788 | // | |
| 789 | // 2--3--4 |
| 790 | // | |
| 791 | // 5--6--7 |
| 792 | // | | |
| 793 | // 9 8 |
| 794 | |
| 795 | pldm_entity entities[9]{}; |
| 796 | |
| 797 | entities[0].entity_type = 1; |
| 798 | entities[1].entity_type = 2; |
| 799 | entities[2].entity_type = 2; |
| 800 | entities[3].entity_type = 3; |
| 801 | entities[4].entity_type = 4; |
| 802 | entities[5].entity_type = 5; |
| 803 | entities[6].entity_type = 5; |
| 804 | entities[7].entity_type = 6; |
| 805 | entities[8].entity_type = 7; |
| 806 | |
| 807 | auto tree = pldm_entity_association_tree_init(); |
| 808 | |
| 809 | auto l1 = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 810 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 811 | EXPECT_NE(l1, nullptr); |
| 812 | auto l2a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 813 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 814 | EXPECT_NE(l2a, nullptr); |
| 815 | auto l2b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 816 | tree, &entities[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 817 | EXPECT_NE(l2b, nullptr); |
| 818 | auto l2c = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 819 | tree, &entities[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 820 | EXPECT_NE(l2c, nullptr); |
| 821 | auto l3a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 822 | tree, &entities[4], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 823 | EXPECT_NE(l3a, nullptr); |
| 824 | auto l3b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 825 | tree, &entities[5], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 826 | EXPECT_NE(l3b, nullptr); |
| 827 | auto l3c = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 828 | tree, &entities[6], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 829 | EXPECT_NE(l3b, nullptr); |
| 830 | auto l4a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 831 | tree, &entities[7], 0xffff, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 832 | EXPECT_NE(l4a, nullptr); |
| 833 | auto l4b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 834 | tree, &entities[8], 0xffff, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 835 | EXPECT_NE(l4b, nullptr); |
| 836 | |
| 837 | EXPECT_EQ(pldm_entity_is_node_parent(l1), true); |
| 838 | EXPECT_EQ(pldm_entity_is_node_parent(l2a), true); |
| 839 | EXPECT_EQ(pldm_entity_is_node_parent(l3a), true); |
| 840 | EXPECT_EQ(pldm_entity_is_node_parent(l3b), true); |
| 841 | |
| 842 | EXPECT_EQ(pldm_entity_is_node_parent(l2b), false); |
| 843 | EXPECT_EQ(pldm_entity_is_node_parent(l2c), false); |
| 844 | EXPECT_EQ(pldm_entity_is_node_parent(l3c), false); |
| 845 | EXPECT_EQ(pldm_entity_is_node_parent(l4a), false); |
| 846 | EXPECT_EQ(pldm_entity_is_node_parent(l4b), false); |
| 847 | |
| 848 | EXPECT_EQ(pldm_entity_is_exist_parent(l1), false); |
| 849 | |
| 850 | pldm_entity nodeL1 = pldm_entity_extract(l1); |
| 851 | pldm_entity parentL2a = pldm_entity_get_parent(l2a); |
| 852 | pldm_entity parentL2b = pldm_entity_get_parent(l2b); |
| 853 | pldm_entity parentL2c = pldm_entity_get_parent(l2c); |
| 854 | EXPECT_EQ(pldm_entity_is_exist_parent(l2a), true); |
| 855 | EXPECT_EQ(pldm_entity_is_exist_parent(l2b), true); |
| 856 | EXPECT_EQ(pldm_entity_is_exist_parent(l2c), true); |
| 857 | EXPECT_EQ(parentL2a.entity_type, nodeL1.entity_type); |
| 858 | EXPECT_EQ(parentL2a.entity_instance_num, nodeL1.entity_instance_num); |
| 859 | EXPECT_EQ(parentL2a.entity_container_id, nodeL1.entity_container_id); |
| 860 | EXPECT_EQ(parentL2b.entity_type, nodeL1.entity_type); |
| 861 | EXPECT_EQ(parentL2b.entity_instance_num, nodeL1.entity_instance_num); |
| 862 | EXPECT_EQ(parentL2b.entity_container_id, nodeL1.entity_container_id); |
| 863 | EXPECT_EQ(parentL2c.entity_type, nodeL1.entity_type); |
| 864 | EXPECT_EQ(parentL2c.entity_instance_num, nodeL1.entity_instance_num); |
| 865 | EXPECT_EQ(parentL2c.entity_container_id, nodeL1.entity_container_id); |
| 866 | |
| 867 | pldm_entity nodeL2a = pldm_entity_extract(l2a); |
| 868 | pldm_entity parentL3a = pldm_entity_get_parent(l3a); |
| 869 | pldm_entity parentL3b = pldm_entity_get_parent(l3b); |
| 870 | pldm_entity parentL3c = pldm_entity_get_parent(l3c); |
| 871 | EXPECT_EQ(pldm_entity_is_exist_parent(l3a), true); |
| 872 | EXPECT_EQ(pldm_entity_is_exist_parent(l3b), true); |
| 873 | EXPECT_EQ(pldm_entity_is_exist_parent(l3c), true); |
| 874 | EXPECT_EQ(parentL3a.entity_type, nodeL2a.entity_type); |
| 875 | EXPECT_EQ(parentL3a.entity_instance_num, nodeL2a.entity_instance_num); |
| 876 | EXPECT_EQ(parentL3a.entity_container_id, nodeL2a.entity_container_id); |
| 877 | EXPECT_EQ(parentL3b.entity_type, nodeL2a.entity_type); |
| 878 | EXPECT_EQ(parentL3b.entity_instance_num, nodeL2a.entity_instance_num); |
| 879 | EXPECT_EQ(parentL3b.entity_container_id, nodeL2a.entity_container_id); |
| 880 | EXPECT_EQ(parentL3c.entity_type, nodeL2a.entity_type); |
| 881 | EXPECT_EQ(parentL3c.entity_instance_num, nodeL2a.entity_instance_num); |
| 882 | EXPECT_EQ(parentL3c.entity_container_id, nodeL2a.entity_container_id); |
| 883 | |
| 884 | pldm_entity nodeL3a = pldm_entity_extract(l3a); |
| 885 | pldm_entity parentL4a = pldm_entity_get_parent(l4a); |
| 886 | EXPECT_EQ(pldm_entity_is_exist_parent(l4a), true); |
| 887 | EXPECT_EQ(parentL4a.entity_type, nodeL3a.entity_type); |
| 888 | EXPECT_EQ(parentL4a.entity_instance_num, nodeL3a.entity_instance_num); |
| 889 | EXPECT_EQ(parentL4a.entity_container_id, nodeL3a.entity_container_id); |
| 890 | |
| 891 | pldm_entity nodeL3b = pldm_entity_extract(l3b); |
| 892 | pldm_entity parentL4b = pldm_entity_get_parent(l4b); |
| 893 | EXPECT_EQ(pldm_entity_is_exist_parent(l4b), true); |
| 894 | EXPECT_EQ(parentL4b.entity_type, nodeL3b.entity_type); |
| 895 | EXPECT_EQ(parentL4b.entity_instance_num, nodeL3b.entity_instance_num); |
| 896 | EXPECT_EQ(parentL4b.entity_container_id, nodeL3b.entity_container_id); |
| 897 | |
| 898 | size_t num{}; |
| 899 | pldm_entity* out = nullptr; |
| 900 | pldm_entity_association_tree_visit(tree, &out, &num); |
| 901 | EXPECT_EQ(num, 9u); |
| 902 | |
| 903 | EXPECT_EQ(out[0].entity_type, 1u); |
| 904 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 905 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 906 | |
| 907 | EXPECT_EQ(out[1].entity_type, 2u); |
| 908 | EXPECT_EQ(out[1].entity_instance_num, 1u); |
| 909 | EXPECT_EQ(out[1].entity_container_id, 1u); |
| 910 | EXPECT_EQ(out[2].entity_type, 2u); |
| 911 | EXPECT_EQ(out[2].entity_instance_num, 2u); |
| 912 | EXPECT_EQ(out[2].entity_container_id, 1u); |
| 913 | EXPECT_EQ(out[3].entity_type, 3u); |
| 914 | EXPECT_EQ(out[3].entity_instance_num, 1u); |
| 915 | EXPECT_EQ(out[3].entity_container_id, 1u); |
| 916 | |
| 917 | EXPECT_EQ(out[4].entity_type, 4u); |
| 918 | EXPECT_EQ(out[4].entity_instance_num, 1u); |
| 919 | EXPECT_EQ(out[4].entity_container_id, 2u); |
| 920 | EXPECT_EQ(out[5].entity_type, 5u); |
| 921 | EXPECT_EQ(out[5].entity_instance_num, 1u); |
| 922 | EXPECT_EQ(out[5].entity_container_id, 2u); |
| 923 | EXPECT_EQ(out[6].entity_type, 5u); |
| 924 | EXPECT_EQ(out[6].entity_instance_num, 2u); |
| 925 | EXPECT_EQ(out[6].entity_container_id, 2u); |
| 926 | |
| 927 | EXPECT_EQ(out[7].entity_type, 7u); |
| 928 | EXPECT_EQ(out[7].entity_instance_num, 1u); |
| 929 | EXPECT_EQ(out[7].entity_container_id, 4u); |
| 930 | EXPECT_EQ(out[8].entity_type, 6u); |
| 931 | EXPECT_EQ(out[8].entity_instance_num, 1u); |
| 932 | EXPECT_EQ(out[8].entity_container_id, 3u); |
| 933 | |
| 934 | free(out); |
| 935 | |
| 936 | pldm_entity p1 = pldm_entity_extract(l1); |
| 937 | EXPECT_EQ(p1.entity_type, 1u); |
| 938 | EXPECT_EQ(p1.entity_instance_num, 1u); |
| 939 | EXPECT_EQ(p1.entity_container_id, 0u); |
| 940 | |
| 941 | pldm_entity p2a = pldm_entity_extract(l2a); |
| 942 | EXPECT_EQ(p2a.entity_type, 2u); |
| 943 | EXPECT_EQ(p2a.entity_instance_num, 1u); |
| 944 | EXPECT_EQ(p2a.entity_container_id, 1u); |
| 945 | pldm_entity p2b = pldm_entity_extract(l2b); |
| 946 | EXPECT_EQ(p2b.entity_type, 2u); |
| 947 | EXPECT_EQ(p2b.entity_instance_num, 2u); |
| 948 | EXPECT_EQ(p2b.entity_container_id, 1u); |
| 949 | pldm_entity p2c = pldm_entity_extract(l2c); |
| 950 | EXPECT_EQ(p2c.entity_type, 3u); |
| 951 | EXPECT_EQ(p2c.entity_instance_num, 1u); |
| 952 | EXPECT_EQ(p2c.entity_container_id, 1u); |
| 953 | |
| 954 | pldm_entity p3a = pldm_entity_extract(l3a); |
| 955 | EXPECT_EQ(p3a.entity_type, 4u); |
| 956 | EXPECT_EQ(p3a.entity_instance_num, 1u); |
| 957 | EXPECT_EQ(p3a.entity_container_id, 2u); |
| 958 | pldm_entity p3b = pldm_entity_extract(l3b); |
| 959 | EXPECT_EQ(p3b.entity_type, 5u); |
| 960 | EXPECT_EQ(p3b.entity_instance_num, 1u); |
| 961 | EXPECT_EQ(p3b.entity_container_id, 2u); |
| 962 | pldm_entity p3c = pldm_entity_extract(l3c); |
| 963 | EXPECT_EQ(p3c.entity_type, 5u); |
| 964 | EXPECT_EQ(p3c.entity_instance_num, 2u); |
| 965 | EXPECT_EQ(p3c.entity_container_id, 2u); |
| 966 | |
| 967 | pldm_entity p4a = pldm_entity_extract(l4a); |
| 968 | EXPECT_EQ(p4a.entity_type, 6u); |
| 969 | EXPECT_EQ(p4a.entity_instance_num, 1u); |
| 970 | EXPECT_EQ(p4a.entity_container_id, 3u); |
| 971 | pldm_entity p4b = pldm_entity_extract(l4b); |
| 972 | EXPECT_EQ(p4b.entity_type, 7u); |
| 973 | EXPECT_EQ(p4b.entity_instance_num, 1u); |
| 974 | EXPECT_EQ(p4b.entity_container_id, 4u); |
| 975 | |
| 976 | pldm_entity_association_tree_destroy(tree); |
| 977 | } |
| 978 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 979 | #if LIBPLDM_API_TESTING |
| 980 | TEST(EntityAssociationPDR, findAndAddRemotePDR) |
| 981 | { |
| 982 | // Tree - 1 |
| 983 | // |
| 984 | // 11521(1,0) |
| 985 | // | |
| 986 | // 45 (1,1) |
| 987 | // | |
| 988 | // 64 (1,2) |
| 989 | // | |
| 990 | // ------------------ |
| 991 | // | | |
| 992 | // 67(0,3) 67(1,3) |
| 993 | // | | |
| 994 | // 135(0,4) 135(0,5) |
| 995 | // | | |
| 996 | // 32903(0,6) 32903(0,7) |
| 997 | |
| 998 | pldm_entity entities[9]{}; |
| 999 | entities[0].entity_type = 11521; |
| 1000 | entities[1].entity_type = 45; |
| 1001 | entities[2].entity_type = 64; |
| 1002 | entities[3].entity_type = 67; |
| 1003 | entities[4].entity_type = 67; |
| 1004 | entities[5].entity_type = 135; |
| 1005 | entities[5].entity_container_id = 2; |
| 1006 | entities[6].entity_type = 135; |
| 1007 | entities[6].entity_container_id = 3; |
| 1008 | entities[7].entity_type = 32903; |
| 1009 | entities[8].entity_type = 32903; |
| 1010 | auto tree = pldm_entity_association_tree_init(); |
| 1011 | auto l1 = pldm_entity_association_tree_add_entity( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1012 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_LOGICAL, |
| 1013 | false, true, 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1014 | EXPECT_NE(l1, nullptr); |
| 1015 | auto l2 = pldm_entity_association_tree_add_entity( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1016 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
| 1017 | false, 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1018 | EXPECT_NE(l2, nullptr); |
| 1019 | auto l3 = pldm_entity_association_tree_add_entity( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1020 | tree, &entities[2], 0xffff, l2, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
| 1021 | true, 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1022 | EXPECT_NE(l3, nullptr); |
| 1023 | auto l4a = pldm_entity_association_tree_add_entity( |
| 1024 | tree, &entities[3], 0, l3, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1025 | false, 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1026 | EXPECT_NE(l4a, nullptr); |
| 1027 | auto l4b = pldm_entity_association_tree_add_entity( |
| 1028 | tree, &entities[4], 1, l3, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true, |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1029 | 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1030 | EXPECT_NE(l4b, nullptr); |
| 1031 | auto l5a = pldm_entity_association_tree_add_entity( |
| 1032 | tree, &entities[5], 0, l4a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1033 | false, 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1034 | EXPECT_NE(l5a, nullptr); |
| 1035 | auto l5b = pldm_entity_association_tree_add_entity( |
| 1036 | tree, &entities[6], 0, l4b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1037 | false, 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1038 | EXPECT_NE(l5b, nullptr); |
| 1039 | pldm_entity entity{}; |
| 1040 | entity.entity_type = 135; |
| 1041 | entity.entity_instance_num = 0; |
| 1042 | entity.entity_container_id = 2; |
| 1043 | auto result1 = pldm_entity_association_tree_find(tree, &entity); |
| 1044 | EXPECT_EQ(result1, l5a); |
| 1045 | EXPECT_EQ(entities[5].entity_container_id, 2); |
| 1046 | auto l6a = pldm_entity_association_tree_add_entity( |
| 1047 | tree, &entities[7], 0, result1, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1048 | false, 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1049 | EXPECT_NE(l6a, nullptr); |
| 1050 | entity.entity_type = 135; |
| 1051 | entity.entity_instance_num = 0; |
| 1052 | entity.entity_container_id = 3; |
| 1053 | auto result2 = pldm_entity_association_tree_find(tree, &entity); |
| 1054 | EXPECT_NE(result2, l5b); |
| 1055 | EXPECT_EQ(entities[6].entity_container_id, 3); |
| 1056 | auto l7a = pldm_entity_association_tree_add_entity( |
| 1057 | tree, &entities[8], 0, result2, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1058 | false, 0xffff); |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 1059 | EXPECT_EQ(l7a, nullptr); |
| 1060 | pldm_entity_association_tree_destroy(tree); |
| 1061 | } |
| 1062 | #endif |
| 1063 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1064 | TEST(EntityAssociationPDR, testSpecialTrees) |
| 1065 | { |
| 1066 | pldm_entity entities[3]{}; |
| 1067 | |
| 1068 | entities[0].entity_type = 1; |
| 1069 | entities[1].entity_type = 2; |
| 1070 | entities[2].entity_type = 1; |
| 1071 | |
| 1072 | // A |
| 1073 | auto tree = pldm_entity_association_tree_init(); |
| 1074 | auto node = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1075 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1076 | EXPECT_NE(node, nullptr); |
| 1077 | size_t num{}; |
| 1078 | pldm_entity* out = nullptr; |
| 1079 | pldm_entity_association_tree_visit(tree, &out, &num); |
| 1080 | EXPECT_EQ(num, 1u); |
| 1081 | EXPECT_EQ(out[0].entity_type, 1u); |
| 1082 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 1083 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 1084 | free(out); |
| 1085 | pldm_entity_association_tree_destroy(tree); |
| 1086 | |
| 1087 | // A-A-A |
| 1088 | tree = pldm_entity_association_tree_init(); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1089 | node = pldm_entity_association_tree_add(tree, &entities[0], 0xffff, nullptr, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1090 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1091 | EXPECT_NE(node, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1092 | node = pldm_entity_association_tree_add(tree, &entities[1], 0xffff, nullptr, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1093 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1094 | EXPECT_NE(node, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1095 | node = pldm_entity_association_tree_add(tree, &entities[2], 0xffff, nullptr, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1096 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1097 | EXPECT_NE(node, nullptr); |
| 1098 | pldm_entity_association_tree_visit(tree, &out, &num); |
| 1099 | EXPECT_EQ(num, 3u); |
| 1100 | EXPECT_EQ(out[0].entity_type, 1u); |
| 1101 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 1102 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 1103 | EXPECT_EQ(out[1].entity_type, 1u); |
| 1104 | EXPECT_EQ(out[1].entity_instance_num, 2u); |
| 1105 | EXPECT_EQ(out[1].entity_container_id, 0u); |
| 1106 | EXPECT_EQ(out[2].entity_type, 2u); |
| 1107 | EXPECT_EQ(out[2].entity_instance_num, 1u); |
| 1108 | EXPECT_EQ(out[2].entity_container_id, 0u); |
| 1109 | free(out); |
| 1110 | pldm_entity_association_tree_destroy(tree); |
| 1111 | |
| 1112 | // A |
| 1113 | // | |
| 1114 | // A |
| 1115 | // | |
| 1116 | // A |
| 1117 | tree = pldm_entity_association_tree_init(); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1118 | node = pldm_entity_association_tree_add(tree, &entities[0], 0xffff, nullptr, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1119 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1120 | EXPECT_NE(node, nullptr); |
| 1121 | auto node1 = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1122 | tree, &entities[1], 0xffff, node, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1123 | EXPECT_NE(node1, nullptr); |
| 1124 | auto node2 = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1125 | tree, &entities[2], 0xffff, node1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1126 | EXPECT_NE(node2, nullptr); |
| 1127 | pldm_entity_association_tree_visit(tree, &out, &num); |
| 1128 | EXPECT_EQ(num, 3u); |
| 1129 | EXPECT_EQ(out[0].entity_type, 1u); |
| 1130 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 1131 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 1132 | EXPECT_EQ(out[1].entity_type, 2u); |
| 1133 | EXPECT_EQ(out[1].entity_instance_num, 1u); |
| 1134 | EXPECT_EQ(out[1].entity_container_id, 1u); |
| 1135 | EXPECT_EQ(out[2].entity_type, 1u); |
| 1136 | EXPECT_EQ(out[2].entity_instance_num, 1u); |
| 1137 | EXPECT_EQ(out[2].entity_container_id, 2u); |
| 1138 | free(out); |
| 1139 | pldm_entity_association_tree_destroy(tree); |
| 1140 | |
| 1141 | // A-A |
| 1142 | // | |
| 1143 | // A-A |
| 1144 | tree = pldm_entity_association_tree_init(); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1145 | node = pldm_entity_association_tree_add(tree, &entities[0], 0xffff, nullptr, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1146 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1147 | EXPECT_NE(node, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1148 | node = pldm_entity_association_tree_add(tree, &entities[0], 0xffff, nullptr, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1149 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1150 | EXPECT_NE(node, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1151 | node1 = pldm_entity_association_tree_add(tree, &entities[1], 0xffff, node, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1152 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1153 | EXPECT_NE(node1, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1154 | node2 = pldm_entity_association_tree_add(tree, &entities[2], 0xffff, node, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1155 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1156 | EXPECT_NE(node2, nullptr); |
| 1157 | pldm_entity_association_tree_visit(tree, &out, &num); |
| 1158 | EXPECT_EQ(num, 4u); |
| 1159 | EXPECT_EQ(out[0].entity_type, 1u); |
| 1160 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 1161 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 1162 | EXPECT_EQ(out[1].entity_type, 1u); |
| 1163 | EXPECT_EQ(out[1].entity_instance_num, 2u); |
| 1164 | EXPECT_EQ(out[1].entity_container_id, 0u); |
| 1165 | EXPECT_EQ(out[2].entity_type, 2u); |
| 1166 | EXPECT_EQ(out[2].entity_instance_num, 1u); |
| 1167 | EXPECT_EQ(out[2].entity_container_id, 1u); |
| 1168 | EXPECT_EQ(out[3].entity_type, 1u); |
| 1169 | EXPECT_EQ(out[3].entity_instance_num, 1u); |
| 1170 | EXPECT_EQ(out[3].entity_container_id, 1u); |
| 1171 | free(out); |
| 1172 | pldm_entity_association_tree_destroy(tree); |
| 1173 | } |
| 1174 | |
| 1175 | TEST(EntityAssociationPDR, testPDR) |
| 1176 | { |
| 1177 | // e = entity type, c = container id, i = instance num |
| 1178 | |
| 1179 | // INPUT |
| 1180 | // 1(e=1)--1a(e=2) |
| 1181 | // | |
| 1182 | // 2(e=2)--3(e=2)--4(e=2)--5(e=3) |
| 1183 | // | |
| 1184 | // 6(e=4)--7(e=5)--8(e=5)--9(e=5) |
| 1185 | // | | |
| 1186 | // 11(e=6) 10(e=7) |
| 1187 | |
| 1188 | // Expected OUTPUT |
| 1189 | // 1(e=1,c=0,i=1) |
| 1190 | // | |
| 1191 | // 2(e=2,c=1,i=1)--3(e=2,c=1,i=2)--4(e=3,c=1,i=1)--5(e=3,c=1,i=2) |
| 1192 | // | |
| 1193 | // 6(e=4,c=2,i=1)--7(e=5,c=2,i=1)--8(e=5,c=2,i=2)--9(e=5,c=2,i=3) |
| 1194 | // | | |
| 1195 | // 10(e=6,c=3,i=1) 11(e=7,c=4,i=1) |
| 1196 | pldm_entity entities[11]{}; |
| 1197 | |
| 1198 | entities[0].entity_type = 1; |
| 1199 | entities[1].entity_type = 2; |
| 1200 | entities[2].entity_type = 3; |
| 1201 | entities[3].entity_type = 2; |
| 1202 | entities[4].entity_type = 3; |
| 1203 | entities[5].entity_type = 4; |
| 1204 | entities[6].entity_type = 5; |
| 1205 | entities[7].entity_type = 5; |
| 1206 | entities[8].entity_type = 5; |
| 1207 | entities[9].entity_type = 6; |
| 1208 | entities[10].entity_type = 7; |
| 1209 | |
| 1210 | auto tree = pldm_entity_association_tree_init(); |
| 1211 | |
| 1212 | auto l1 = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1213 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1214 | EXPECT_NE(l1, nullptr); |
| 1215 | auto l1a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1216 | tree, &entities[1], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1217 | EXPECT_NE(l1a, nullptr); |
| 1218 | |
| 1219 | auto l2a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1220 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1221 | EXPECT_NE(l2a, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1222 | auto l2b = pldm_entity_association_tree_add(tree, &entities[2], 0xffff, l1, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1223 | PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 1224 | EXPECT_NE(l2b, nullptr); |
| 1225 | auto l2c = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1226 | tree, &entities[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1227 | EXPECT_NE(l2c, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1228 | auto l2d = pldm_entity_association_tree_add(tree, &entities[4], 0xffff, l1, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1229 | PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 1230 | EXPECT_NE(l2d, nullptr); |
| 1231 | |
| 1232 | auto l3a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1233 | tree, &entities[5], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1234 | EXPECT_NE(l3a, nullptr); |
| 1235 | auto l3b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1236 | tree, &entities[6], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1237 | EXPECT_NE(l3b, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1238 | auto l3c = pldm_entity_association_tree_add(tree, &entities[7], 0xffff, l2a, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1239 | PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 1240 | EXPECT_NE(l3c, nullptr); |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1241 | auto l3d = pldm_entity_association_tree_add(tree, &entities[8], 0xffff, l2a, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1242 | PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 1243 | EXPECT_NE(l3d, nullptr); |
| 1244 | |
| 1245 | auto l4a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1246 | tree, &entities[9], 0xffff, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1247 | EXPECT_NE(l4a, nullptr); |
| 1248 | auto l4b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1249 | tree, &entities[10], 0xffff, l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1250 | EXPECT_NE(l4b, nullptr); |
| 1251 | |
| 1252 | EXPECT_EQ(pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL), |
| 1253 | 2); |
| 1254 | EXPECT_EQ(pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_LOGICAL), |
| 1255 | 2); |
| 1256 | EXPECT_EQ( |
| 1257 | pldm_entity_get_num_children(l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL), 2); |
| 1258 | EXPECT_EQ( |
| 1259 | pldm_entity_get_num_children(l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL), 0); |
| 1260 | EXPECT_EQ(pldm_entity_get_num_children(l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL), |
| 1261 | 1); |
| 1262 | |
| 1263 | auto repo = pldm_pdr_init(); |
Andrew Jeffery | 255f654 | 2023-08-10 15:46:54 +0930 | [diff] [blame] | 1264 | int rc = pldm_entity_association_pdr_add_check(tree, repo, false, 1); |
| 1265 | ASSERT_EQ(rc, 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1266 | |
| 1267 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 6u); |
| 1268 | |
| 1269 | uint32_t currRecHandle{}; |
| 1270 | uint32_t nextRecHandle{}; |
| 1271 | uint8_t* data = nullptr; |
| 1272 | uint32_t size{}; |
| 1273 | uint32_t commonSize = sizeof(struct pldm_pdr_hdr) + sizeof(uint16_t) + |
| 1274 | sizeof(uint8_t) + sizeof(pldm_entity) + |
| 1275 | sizeof(uint8_t); |
| 1276 | |
| 1277 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 1278 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 1279 | l1, PLDM_ENTITY_ASSOCIAION_LOGICAL) * |
| 1280 | sizeof(pldm_entity))); |
| 1281 | uint8_t* start = data; |
| 1282 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
| 1283 | EXPECT_EQ(le32toh(hdr->record_handle), 1u); |
| 1284 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
| 1285 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
| 1286 | start += sizeof(pldm_pdr_hdr); |
| 1287 | uint16_t* containerId = reinterpret_cast<uint16_t*>(start); |
| 1288 | EXPECT_EQ(le16toh(*containerId), 1u); |
| 1289 | start += sizeof(uint16_t); |
| 1290 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 1291 | start += sizeof(uint8_t); |
| 1292 | pldm_entity* entity = reinterpret_cast<pldm_entity*>(start); |
| 1293 | EXPECT_EQ(le16toh(entity->entity_type), 1u); |
| 1294 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1295 | EXPECT_EQ(le16toh(entity->entity_container_id), 0u); |
| 1296 | start += sizeof(pldm_entity); |
| 1297 | EXPECT_EQ(*start, |
| 1298 | pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_LOGICAL)); |
| 1299 | start += sizeof(uint8_t); |
| 1300 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1301 | EXPECT_EQ(le16toh(entity->entity_type), 3u); |
| 1302 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1303 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
| 1304 | start += sizeof(pldm_entity); |
| 1305 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1306 | EXPECT_EQ(le16toh(entity->entity_type), 3u); |
| 1307 | EXPECT_EQ(le16toh(entity->entity_instance_num), 2u); |
| 1308 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1309 | |
| 1310 | currRecHandle = nextRecHandle; |
| 1311 | |
| 1312 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 1313 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 1314 | l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL) * |
| 1315 | sizeof(pldm_entity))); |
| 1316 | start = data; |
| 1317 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
| 1318 | EXPECT_EQ(le32toh(hdr->record_handle), 2u); |
| 1319 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
| 1320 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
| 1321 | start += sizeof(pldm_pdr_hdr); |
| 1322 | containerId = reinterpret_cast<uint16_t*>(start); |
| 1323 | EXPECT_EQ(le16toh(*containerId), 1u); |
| 1324 | start += sizeof(uint16_t); |
| 1325 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1326 | start += sizeof(uint8_t); |
| 1327 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1328 | EXPECT_EQ(le16toh(entity->entity_type), 1u); |
| 1329 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1330 | EXPECT_EQ(le16toh(entity->entity_container_id), 0u); |
| 1331 | start += sizeof(pldm_entity); |
| 1332 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 1333 | l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL)); |
| 1334 | start += sizeof(uint8_t); |
| 1335 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1336 | EXPECT_EQ(le16toh(entity->entity_type), 2u); |
| 1337 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1338 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
| 1339 | start += sizeof(pldm_entity); |
| 1340 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1341 | EXPECT_EQ(le16toh(entity->entity_type), 2u); |
| 1342 | EXPECT_EQ(le16toh(entity->entity_instance_num), 2u); |
| 1343 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1344 | |
| 1345 | currRecHandle = nextRecHandle; |
| 1346 | |
| 1347 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 1348 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 1349 | l2a, PLDM_ENTITY_ASSOCIAION_LOGICAL) * |
| 1350 | sizeof(pldm_entity))); |
| 1351 | start = data; |
| 1352 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
| 1353 | EXPECT_EQ(le32toh(hdr->record_handle), 3u); |
| 1354 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
| 1355 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
| 1356 | start += sizeof(pldm_pdr_hdr); |
| 1357 | containerId = reinterpret_cast<uint16_t*>(start); |
| 1358 | EXPECT_EQ(le16toh(*containerId), 2u); |
| 1359 | start += sizeof(uint16_t); |
| 1360 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 1361 | start += sizeof(uint8_t); |
| 1362 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1363 | EXPECT_EQ(le16toh(entity->entity_type), 2u); |
| 1364 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1365 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
| 1366 | start += sizeof(pldm_entity); |
| 1367 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 1368 | l2a, PLDM_ENTITY_ASSOCIAION_LOGICAL)); |
| 1369 | start += sizeof(uint8_t); |
| 1370 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1371 | EXPECT_EQ(le16toh(entity->entity_type), 5); |
| 1372 | EXPECT_EQ(le16toh(entity->entity_instance_num), 2u); |
| 1373 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
| 1374 | start += sizeof(pldm_entity); |
| 1375 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1376 | EXPECT_EQ(le16toh(entity->entity_type), 5u); |
| 1377 | EXPECT_EQ(le16toh(entity->entity_instance_num), 3u); |
| 1378 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1379 | |
| 1380 | currRecHandle = nextRecHandle; |
| 1381 | |
| 1382 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 1383 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 1384 | l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL) * |
| 1385 | sizeof(pldm_entity))); |
| 1386 | start = data; |
| 1387 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
| 1388 | EXPECT_EQ(le32toh(hdr->record_handle), 4u); |
| 1389 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
| 1390 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
| 1391 | start += sizeof(pldm_pdr_hdr); |
| 1392 | containerId = reinterpret_cast<uint16_t*>(start); |
| 1393 | EXPECT_EQ(le16toh(*containerId), 2u); |
| 1394 | start += sizeof(uint16_t); |
| 1395 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1396 | start += sizeof(uint8_t); |
| 1397 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1398 | EXPECT_EQ(le16toh(entity->entity_type), 2u); |
| 1399 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1400 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
| 1401 | start += sizeof(pldm_entity); |
| 1402 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 1403 | l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL)); |
| 1404 | start += sizeof(uint8_t); |
| 1405 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1406 | EXPECT_EQ(le16toh(entity->entity_type), 4u); |
| 1407 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1408 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
| 1409 | start += sizeof(pldm_entity); |
| 1410 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1411 | EXPECT_EQ(le16toh(entity->entity_type), 5u); |
| 1412 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1413 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1414 | |
| 1415 | currRecHandle = nextRecHandle; |
| 1416 | |
| 1417 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 1418 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 1419 | l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL) * |
| 1420 | sizeof(pldm_entity))); |
| 1421 | start = data; |
| 1422 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
| 1423 | EXPECT_EQ(le32toh(hdr->record_handle), 5u); |
| 1424 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
| 1425 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
| 1426 | start += sizeof(pldm_pdr_hdr); |
| 1427 | containerId = reinterpret_cast<uint16_t*>(start); |
| 1428 | EXPECT_EQ(le16toh(*containerId), 3u); |
| 1429 | start += sizeof(uint16_t); |
| 1430 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1431 | start += sizeof(uint8_t); |
| 1432 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1433 | EXPECT_EQ(le16toh(entity->entity_type), 4u); |
| 1434 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1435 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
| 1436 | start += sizeof(pldm_entity); |
| 1437 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 1438 | l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL)); |
| 1439 | start += sizeof(uint8_t); |
| 1440 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1441 | EXPECT_EQ(le16toh(entity->entity_type), 6u); |
| 1442 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1443 | EXPECT_EQ(le16toh(entity->entity_container_id), 3u); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1444 | |
| 1445 | currRecHandle = nextRecHandle; |
| 1446 | |
| 1447 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 1448 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 1449 | l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL) * |
| 1450 | sizeof(pldm_entity))); |
| 1451 | start = data; |
| 1452 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
| 1453 | EXPECT_EQ(le32toh(hdr->record_handle), 6u); |
| 1454 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
| 1455 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
| 1456 | start += sizeof(pldm_pdr_hdr); |
| 1457 | containerId = reinterpret_cast<uint16_t*>(start); |
| 1458 | EXPECT_EQ(le16toh(*containerId), 4u); |
| 1459 | start += sizeof(uint16_t); |
| 1460 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 1461 | start += sizeof(uint8_t); |
| 1462 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1463 | EXPECT_EQ(le16toh(entity->entity_type), 5u); |
| 1464 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1465 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
| 1466 | start += sizeof(pldm_entity); |
| 1467 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 1468 | l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL)); |
| 1469 | start += sizeof(uint8_t); |
| 1470 | entity = reinterpret_cast<pldm_entity*>(start); |
| 1471 | EXPECT_EQ(le16toh(entity->entity_type), 7u); |
| 1472 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1473 | EXPECT_EQ(le16toh(entity->entity_container_id), 4u); |
| 1474 | |
| 1475 | EXPECT_EQ(nextRecHandle, 0u); |
| 1476 | |
| 1477 | pldm_pdr_destroy(repo); |
| 1478 | pldm_entity_association_tree_destroy(tree); |
| 1479 | } |
| 1480 | |
| 1481 | TEST(EntityAssociationPDR, testFind) |
| 1482 | { |
| 1483 | // 1 |
| 1484 | // | |
| 1485 | // 2--3--4 |
| 1486 | // | |
| 1487 | // 5--6--7 |
| 1488 | // | | |
| 1489 | // 8 9 |
| 1490 | |
| 1491 | pldm_entity entities[9]{}; |
| 1492 | |
| 1493 | entities[0].entity_type = 1; |
| 1494 | entities[1].entity_type = 2; |
| 1495 | entities[2].entity_type = 2; |
| 1496 | entities[3].entity_type = 3; |
| 1497 | entities[4].entity_type = 4; |
| 1498 | entities[5].entity_type = 5; |
| 1499 | entities[6].entity_type = 5; |
| 1500 | entities[7].entity_type = 6; |
| 1501 | entities[8].entity_type = 7; |
| 1502 | |
| 1503 | auto tree = pldm_entity_association_tree_init(); |
| 1504 | |
| 1505 | auto l1 = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1506 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1507 | EXPECT_NE(l1, nullptr); |
| 1508 | auto l2a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1509 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1510 | EXPECT_NE(l2a, nullptr); |
| 1511 | auto l2b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1512 | tree, &entities[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1513 | EXPECT_NE(l2b, nullptr); |
| 1514 | auto l2c = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1515 | tree, &entities[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1516 | EXPECT_NE(l2c, nullptr); |
| 1517 | auto l3a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1518 | tree, &entities[4], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1519 | EXPECT_NE(l3a, nullptr); |
| 1520 | auto l3b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1521 | tree, &entities[5], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1522 | EXPECT_NE(l3b, nullptr); |
| 1523 | auto l3c = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1524 | tree, &entities[6], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1525 | EXPECT_NE(l3c, nullptr); |
| 1526 | auto l4a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1527 | tree, &entities[7], 0xffff, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1528 | EXPECT_NE(l4a, nullptr); |
| 1529 | auto l4b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1530 | tree, &entities[8], 0xffff, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1531 | EXPECT_NE(l4b, nullptr); |
| 1532 | |
| 1533 | pldm_entity entity{}; |
| 1534 | |
| 1535 | entity.entity_type = 1; |
| 1536 | entity.entity_instance_num = 1; |
| 1537 | auto result = pldm_entity_association_tree_find(tree, &entity); |
| 1538 | EXPECT_EQ(result, l1); |
| 1539 | EXPECT_EQ(entity.entity_container_id, 0); |
| 1540 | |
| 1541 | entity.entity_type = 2; |
| 1542 | entity.entity_instance_num = 1; |
| 1543 | result = pldm_entity_association_tree_find(tree, &entity); |
| 1544 | EXPECT_EQ(result, l2a); |
| 1545 | EXPECT_EQ(entity.entity_container_id, 1); |
| 1546 | entity.entity_type = 2; |
| 1547 | entity.entity_instance_num = 2; |
| 1548 | result = pldm_entity_association_tree_find(tree, &entity); |
| 1549 | EXPECT_EQ(result, l2b); |
| 1550 | EXPECT_EQ(entity.entity_container_id, 1); |
| 1551 | entity.entity_type = 3; |
| 1552 | entity.entity_instance_num = 1; |
| 1553 | result = pldm_entity_association_tree_find(tree, &entity); |
| 1554 | EXPECT_EQ(result, l2c); |
| 1555 | EXPECT_EQ(entity.entity_container_id, 1); |
| 1556 | |
| 1557 | entity.entity_type = 7; |
| 1558 | entity.entity_instance_num = 1; |
| 1559 | result = pldm_entity_association_tree_find(tree, &entity); |
| 1560 | EXPECT_EQ(result, l4b); |
| 1561 | EXPECT_EQ(entity.entity_container_id, 4); |
| 1562 | |
| 1563 | pldm_entity_association_tree_destroy(tree); |
| 1564 | } |
| 1565 | |
| 1566 | TEST(EntityAssociationPDR, testCopyTree) |
| 1567 | { |
| 1568 | pldm_entity entities[4]{}; |
| 1569 | entities[0].entity_type = 1; |
| 1570 | entities[1].entity_type = 2; |
| 1571 | entities[2].entity_type = 2; |
| 1572 | entities[3].entity_type = 3; |
| 1573 | |
| 1574 | auto orgTree = pldm_entity_association_tree_init(); |
| 1575 | auto newTree = pldm_entity_association_tree_init(); |
| 1576 | auto l1 = |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1577 | pldm_entity_association_tree_add(orgTree, &entities[0], 0xffff, nullptr, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1578 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1579 | EXPECT_NE(l1, nullptr); |
| 1580 | auto l2a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1581 | orgTree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1582 | EXPECT_NE(l2a, nullptr); |
| 1583 | auto l2b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1584 | orgTree, &entities[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1585 | EXPECT_NE(l2b, nullptr); |
| 1586 | auto l2c = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1587 | orgTree, &entities[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1588 | EXPECT_NE(l2c, nullptr); |
| 1589 | size_t orgNum{}; |
| 1590 | pldm_entity* orgOut = nullptr; |
| 1591 | pldm_entity_association_tree_visit(orgTree, &orgOut, &orgNum); |
| 1592 | EXPECT_EQ(orgNum, 4u); |
| 1593 | |
| 1594 | pldm_entity_association_tree_copy_root(orgTree, newTree); |
| 1595 | size_t newNum{}; |
| 1596 | pldm_entity* newOut = nullptr; |
| 1597 | pldm_entity_association_tree_visit(newTree, &newOut, &newNum); |
| 1598 | EXPECT_EQ(newNum, orgNum); |
| 1599 | EXPECT_EQ(newOut[0].entity_type, 1u); |
| 1600 | EXPECT_EQ(newOut[0].entity_instance_num, 1u); |
| 1601 | EXPECT_EQ(newOut[0].entity_container_id, 0u); |
| 1602 | free(orgOut); |
| 1603 | free(newOut); |
| 1604 | pldm_entity_association_tree_destroy(orgTree); |
| 1605 | pldm_entity_association_tree_destroy(newTree); |
| 1606 | } |
| 1607 | |
| 1608 | TEST(EntityAssociationPDR, testExtract) |
| 1609 | { |
| 1610 | std::vector<uint8_t> pdr{}; |
| 1611 | pdr.resize(sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_entity_association) + |
| 1612 | sizeof(pldm_entity) * 4); |
| 1613 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(pdr.data()); |
| 1614 | hdr->type = PLDM_PDR_ENTITY_ASSOCIATION; |
| 1615 | hdr->length = |
| 1616 | htole16(sizeof(pldm_pdr_entity_association) + sizeof(pldm_entity) * 4); |
| 1617 | |
| 1618 | pldm_pdr_entity_association* e = |
| 1619 | reinterpret_cast<pldm_pdr_entity_association*>(pdr.data() + |
| 1620 | sizeof(pldm_pdr_hdr)); |
| 1621 | e->container_id = htole16(1); |
| 1622 | e->num_children = 5; |
| 1623 | e->container.entity_type = htole16(1); |
| 1624 | e->container.entity_instance_num = htole16(1); |
| 1625 | e->container.entity_container_id = htole16(0); |
| 1626 | |
| 1627 | pldm_entity* entity = e->children; |
| 1628 | entity->entity_type = htole16(2); |
| 1629 | entity->entity_instance_num = htole16(1); |
| 1630 | entity->entity_container_id = htole16(1); |
| 1631 | ++entity; |
| 1632 | entity->entity_type = htole16(3); |
| 1633 | entity->entity_instance_num = htole16(1); |
| 1634 | entity->entity_container_id = htole16(1); |
| 1635 | ++entity; |
| 1636 | entity->entity_type = htole16(4); |
| 1637 | entity->entity_instance_num = htole16(1); |
| 1638 | entity->entity_container_id = htole16(1); |
| 1639 | ++entity; |
| 1640 | entity->entity_type = htole16(5); |
| 1641 | entity->entity_instance_num = htole16(1); |
| 1642 | entity->entity_container_id = htole16(1); |
| 1643 | ++entity; |
| 1644 | entity->entity_type = htole16(6); |
| 1645 | entity->entity_instance_num = htole16(1); |
| 1646 | entity->entity_container_id = htole16(1); |
| 1647 | |
| 1648 | size_t num{}; |
| 1649 | pldm_entity* out = nullptr; |
| 1650 | pldm_entity_association_pdr_extract(pdr.data(), pdr.size(), &num, &out); |
| 1651 | EXPECT_EQ(num, (unsigned)e->num_children + 1); |
| 1652 | EXPECT_EQ(out[0].entity_type, 1u); |
| 1653 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 1654 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 1655 | EXPECT_EQ(out[1].entity_type, 2u); |
| 1656 | EXPECT_EQ(out[1].entity_instance_num, 1u); |
| 1657 | EXPECT_EQ(out[1].entity_container_id, 1u); |
| 1658 | EXPECT_EQ(out[2].entity_type, 3u); |
| 1659 | EXPECT_EQ(out[2].entity_instance_num, 1u); |
| 1660 | EXPECT_EQ(out[2].entity_container_id, 1u); |
| 1661 | EXPECT_EQ(out[3].entity_type, 4u); |
| 1662 | EXPECT_EQ(out[3].entity_instance_num, 1u); |
| 1663 | EXPECT_EQ(out[3].entity_container_id, 1u); |
| 1664 | EXPECT_EQ(out[4].entity_type, 5u); |
| 1665 | EXPECT_EQ(out[4].entity_instance_num, 1u); |
| 1666 | EXPECT_EQ(out[4].entity_container_id, 1u); |
| 1667 | EXPECT_EQ(out[5].entity_type, 6u); |
| 1668 | EXPECT_EQ(out[5].entity_instance_num, 1u); |
| 1669 | EXPECT_EQ(out[5].entity_container_id, 1u); |
| 1670 | |
| 1671 | free(out); |
| 1672 | } |
| 1673 | |
| 1674 | TEST(EntityAssociationPDR, testGetChildren) |
| 1675 | { |
| 1676 | pldm_entity entities[4]{}; |
| 1677 | entities[0].entity_type = 1; |
| 1678 | entities[1].entity_type = 2; |
| 1679 | entities[2].entity_type = 2; |
| 1680 | entities[3].entity_type = 3; |
| 1681 | |
| 1682 | auto tree = pldm_entity_association_tree_init(); |
| 1683 | auto l1 = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1684 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1685 | EXPECT_NE(l1, nullptr); |
| 1686 | auto l2a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1687 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1688 | EXPECT_NE(l2a, nullptr); |
| 1689 | auto l2b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1690 | tree, &entities[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1691 | EXPECT_NE(l2b, nullptr); |
| 1692 | auto l2c = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1693 | tree, &entities[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1694 | EXPECT_NE(l2c, nullptr); |
| 1695 | |
| 1696 | pldm_entity et1; |
| 1697 | et1.entity_type = 2; |
| 1698 | et1.entity_instance_num = 1; |
| 1699 | EXPECT_EQ(true, pldm_is_current_parent_child(l1, &et1)); |
| 1700 | |
| 1701 | pldm_entity et2; |
| 1702 | et2.entity_type = 2; |
| 1703 | et2.entity_instance_num = 2; |
| 1704 | EXPECT_EQ(true, pldm_is_current_parent_child(l1, &et2)); |
| 1705 | |
| 1706 | pldm_entity et3; |
| 1707 | et3.entity_type = 2; |
| 1708 | et3.entity_instance_num = 3; |
| 1709 | EXPECT_EQ(false, pldm_is_current_parent_child(l1, &et3)); |
| 1710 | |
| 1711 | pldm_entity_association_tree_destroy(tree); |
| 1712 | } |
| 1713 | |
| 1714 | TEST(EntityAssociationPDR, testEntityInstanceNumber) |
| 1715 | { |
| 1716 | pldm_entity entities[9]{}; |
| 1717 | |
| 1718 | entities[0].entity_type = 1; |
| 1719 | entities[1].entity_type = 2; |
| 1720 | entities[2].entity_type = 2; |
| 1721 | entities[3].entity_type = 2; |
| 1722 | entities[4].entity_type = 2; |
| 1723 | entities[5].entity_type = 2; |
| 1724 | entities[6].entity_type = 2; |
| 1725 | entities[7].entity_type = 3; |
| 1726 | entities[8].entity_type = 3; |
| 1727 | |
| 1728 | auto tree = pldm_entity_association_tree_init(); |
| 1729 | auto repo = pldm_pdr_init(); |
| 1730 | |
| 1731 | uint16_t terminusHdl{}; |
| 1732 | uint16_t entityType{}; |
| 1733 | uint16_t entityInstanceNum{}; |
| 1734 | uint16_t containerId{}; |
| 1735 | |
| 1736 | auto node = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1737 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1738 | EXPECT_NE(node, nullptr); |
| 1739 | |
| 1740 | auto l1 = pldm_entity_association_tree_add(tree, &entities[1], 63, node, |
| 1741 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 1742 | uint32_t first = 1; |
| 1743 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check( |
| 1744 | repo, 1, 1, entities[1].entity_type, |
| 1745 | entities[1].entity_instance_num, |
| 1746 | entities[1].entity_container_id, &first), |
| 1747 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1748 | EXPECT_NE(l1, nullptr); |
| 1749 | EXPECT_EQ(entities[1].entity_instance_num, 63); |
| 1750 | EXPECT_EQ(first, pldm_pdr_get_record_handle( |
| 1751 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1752 | repo, 1, &terminusHdl, &entityType, |
| 1753 | &entityInstanceNum, &containerId))); |
| 1754 | EXPECT_EQ(entityType, 2); |
| 1755 | EXPECT_EQ(entityInstanceNum, 63); |
| 1756 | |
| 1757 | auto l2 = pldm_entity_association_tree_add(tree, &entities[2], 37, node, |
| 1758 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 1759 | uint32_t second = 2; |
| 1760 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check( |
| 1761 | repo, 1, 2, entities[2].entity_type, |
| 1762 | entities[2].entity_instance_num, |
| 1763 | entities[2].entity_container_id, &second), |
| 1764 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1765 | EXPECT_NE(l2, nullptr); |
| 1766 | EXPECT_EQ(entities[2].entity_instance_num, 37); |
| 1767 | EXPECT_EQ(second, pldm_pdr_get_record_handle( |
| 1768 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1769 | repo, 2, &terminusHdl, &entityType, |
| 1770 | &entityInstanceNum, &containerId))); |
| 1771 | EXPECT_EQ(entityType, 2); |
| 1772 | EXPECT_EQ(entityInstanceNum, 37); |
| 1773 | |
| 1774 | auto l3 = pldm_entity_association_tree_add(tree, &entities[3], 44, node, |
| 1775 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 1776 | uint32_t third = 3; |
| 1777 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check( |
| 1778 | repo, 1, 3, entities[3].entity_type, |
| 1779 | entities[3].entity_instance_num, |
| 1780 | entities[3].entity_container_id, &third), |
| 1781 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1782 | EXPECT_NE(l3, nullptr); |
| 1783 | EXPECT_EQ(entities[3].entity_instance_num, 44); |
| 1784 | EXPECT_EQ(third, pldm_pdr_get_record_handle( |
| 1785 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1786 | repo, 3, &terminusHdl, &entityType, |
| 1787 | &entityInstanceNum, &containerId))); |
| 1788 | EXPECT_EQ(entityType, 2); |
| 1789 | EXPECT_EQ(entityInstanceNum, 44); |
| 1790 | |
| 1791 | auto l4 = pldm_entity_association_tree_add(tree, &entities[4], 89, node, |
| 1792 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 1793 | uint32_t fourth = 4; |
| 1794 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check( |
| 1795 | repo, 1, 4, entities[4].entity_type, |
| 1796 | entities[4].entity_instance_num, |
| 1797 | entities[4].entity_container_id, &fourth), |
| 1798 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1799 | EXPECT_NE(l4, nullptr); |
| 1800 | EXPECT_EQ(entities[4].entity_instance_num, 89); |
| 1801 | EXPECT_EQ(fourth, pldm_pdr_get_record_handle( |
| 1802 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1803 | repo, 4, &terminusHdl, &entityType, |
| 1804 | &entityInstanceNum, &containerId))); |
| 1805 | EXPECT_EQ(entityType, 2); |
| 1806 | EXPECT_EQ(entityInstanceNum, 89); |
| 1807 | |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1808 | auto l5 = pldm_entity_association_tree_add(tree, &entities[5], 0xffff, node, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1809 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 1810 | uint32_t fifth = 5; |
| 1811 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check( |
| 1812 | repo, 1, 5, entities[5].entity_type, |
| 1813 | entities[5].entity_instance_num, |
| 1814 | entities[5].entity_container_id, &fifth), |
| 1815 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1816 | EXPECT_NE(l5, nullptr); |
| 1817 | EXPECT_EQ(entities[5].entity_instance_num, 90); |
| 1818 | EXPECT_EQ(fifth, pldm_pdr_get_record_handle( |
| 1819 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1820 | repo, 5, &terminusHdl, &entityType, |
| 1821 | &entityInstanceNum, &containerId))); |
| 1822 | EXPECT_EQ(entityType, 2); |
| 1823 | EXPECT_EQ(entityInstanceNum, 90); |
| 1824 | |
| 1825 | auto l6 = pldm_entity_association_tree_add(tree, &entities[6], 90, node, |
| 1826 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1827 | EXPECT_EQ(l6, nullptr); |
| 1828 | |
| 1829 | auto l7 = pldm_entity_association_tree_add(tree, &entities[7], 100, l1, |
| 1830 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 1831 | uint32_t seventh = 7; |
| 1832 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check( |
| 1833 | repo, 1, 7, entities[7].entity_type, |
| 1834 | entities[7].entity_instance_num, |
| 1835 | entities[7].entity_container_id, &seventh), |
| 1836 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1837 | EXPECT_NE(l7, nullptr); |
| 1838 | EXPECT_EQ(entities[7].entity_instance_num, 100); |
| 1839 | EXPECT_EQ(seventh, pldm_pdr_get_record_handle( |
| 1840 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1841 | repo, 7, &terminusHdl, &entityType, |
| 1842 | &entityInstanceNum, &containerId))); |
| 1843 | EXPECT_EQ(entityType, 3); |
| 1844 | EXPECT_EQ(entityInstanceNum, 100); |
| 1845 | |
| 1846 | auto l8 = pldm_entity_association_tree_add(tree, &entities[8], 100, l2, |
| 1847 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Andrew Jeffery | 14d2984 | 2023-07-17 15:29:32 +0930 | [diff] [blame] | 1848 | uint32_t eighth = 8; |
| 1849 | EXPECT_EQ(pldm_pdr_add_fru_record_set_check( |
| 1850 | repo, 1, 8, entities[8].entity_type, |
| 1851 | entities[8].entity_instance_num, |
| 1852 | entities[8].entity_container_id, &eighth), |
| 1853 | 0); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1854 | EXPECT_NE(l8, nullptr); |
| 1855 | EXPECT_EQ(entities[8].entity_instance_num, 100); |
| 1856 | EXPECT_EQ(eighth, pldm_pdr_get_record_handle( |
| 1857 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1858 | repo, 8, &terminusHdl, &entityType, |
| 1859 | &entityInstanceNum, &containerId))); |
| 1860 | EXPECT_EQ(entityType, 3); |
| 1861 | EXPECT_EQ(entityInstanceNum, 100); |
| 1862 | |
| 1863 | pldm_pdr_destroy(repo); |
| 1864 | pldm_entity_association_tree_destroy(tree); |
| 1865 | } |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 1866 | |
Andrew Jeffery | 14a5fe8 | 2023-06-26 15:31:37 +0930 | [diff] [blame] | 1867 | #ifdef LIBPLDM_API_TESTING |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 1868 | TEST(EntityAssociationPDR, testFindChildContainerID) |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 1869 | { |
| 1870 | pldm_entity entities[3]{}; |
| 1871 | entities[0].entity_type = 1; |
| 1872 | entities[1].entity_type = 2; |
| 1873 | entities[2].entity_type = 3; |
| 1874 | entities[1].entity_container_id = 2; |
| 1875 | entities[1].entity_instance_num = 1; |
| 1876 | |
| 1877 | auto tree = pldm_entity_association_tree_init(); |
| 1878 | auto l1 = pldm_entity_association_tree_add_entity( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1879 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_LOGICAL, |
| 1880 | false, true, 0xffff); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 1881 | |
| 1882 | EXPECT_NE(l1, nullptr); |
| 1883 | auto l2 = pldm_entity_association_tree_add_entity( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1884 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
| 1885 | false, 0xffff); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 1886 | EXPECT_NE(l2, nullptr); |
| 1887 | auto l3 = pldm_entity_association_tree_add_entity( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1888 | tree, &entities[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false, |
| 1889 | true, 0xffff); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 1890 | EXPECT_NE(l3, nullptr); |
| 1891 | |
| 1892 | EXPECT_EQ(pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL), |
| 1893 | 2); |
| 1894 | |
| 1895 | auto repo = pldm_pdr_init(); |
Andrew Jeffery | 255f654 | 2023-08-10 15:46:54 +0930 | [diff] [blame] | 1896 | int rc = pldm_entity_association_pdr_add_check(tree, repo, false, 1); |
| 1897 | ASSERT_EQ(rc, 0); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 1898 | |
| 1899 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
| 1900 | |
| 1901 | uint16_t container_id{}; |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 1902 | pldm_pdr_find_child_container_id_index_range_exclude( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1903 | repo, 1, 1, 0, 0x01000000, 0x01ffffff, &container_id); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 1904 | EXPECT_EQ(container_id, 2); |
| 1905 | |
| 1906 | uint16_t container_id1{}; |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 1907 | pldm_pdr_find_child_container_id_index_range_exclude( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1908 | repo, 1, 1, 0, 0x00000001, 0x00ffffff, &container_id1); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 1909 | EXPECT_EQ(container_id1, 0); |
| 1910 | |
| 1911 | pldm_pdr_destroy(repo); |
| 1912 | pldm_entity_association_tree_destroy(tree); |
| 1913 | } |
Andrew Jeffery | 14a5fe8 | 2023-06-26 15:31:37 +0930 | [diff] [blame] | 1914 | #endif |
Pavithra Barithaya | 39eb322 | 2023-11-17 03:30:27 -0600 | [diff] [blame] | 1915 | |
| 1916 | TEST(EntityAssociationPDR, testNodeAddCheck) |
| 1917 | { |
| 1918 | // pldm_entity entities[4]{}; |
| 1919 | pldm_entity* entities = (pldm_entity*)malloc(sizeof(pldm_entity) * 4); |
| 1920 | entities[0].entity_type = 1; |
| 1921 | entities[1].entity_type = 2; |
| 1922 | entities[2].entity_type = 2; |
| 1923 | entities[3].entity_type = 3; |
| 1924 | |
| 1925 | auto tree = pldm_entity_association_tree_init(); |
| 1926 | |
| 1927 | auto l1 = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1928 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Pavithra Barithaya | 39eb322 | 2023-11-17 03:30:27 -0600 | [diff] [blame] | 1929 | EXPECT_NE(l1, nullptr); |
| 1930 | auto l2a = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1931 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Pavithra Barithaya | 39eb322 | 2023-11-17 03:30:27 -0600 | [diff] [blame] | 1932 | EXPECT_NE(l2a, nullptr); |
| 1933 | auto l2b = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1934 | tree, &entities[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Pavithra Barithaya | 39eb322 | 2023-11-17 03:30:27 -0600 | [diff] [blame] | 1935 | EXPECT_NE(l2b, nullptr); |
| 1936 | auto l2c = pldm_entity_association_tree_add( |
Pavithra Barithaya | dc7d3b5 | 2024-02-06 23:46:49 -0600 | [diff] [blame] | 1937 | tree, &entities[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Pavithra Barithaya | 39eb322 | 2023-11-17 03:30:27 -0600 | [diff] [blame] | 1938 | EXPECT_NE(l2c, nullptr); |
| 1939 | |
| 1940 | auto repo = pldm_pdr_init(); |
| 1941 | |
| 1942 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 1943 | l1, repo, &entities, 4, false, 1, 0), |
| 1944 | 0); |
| 1945 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 1946 | l1, repo, &entities, 4, false, 1, 2), |
| 1947 | 0); |
| 1948 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 1949 | l1, repo, &entities, 4, false, 1, 23), |
| 1950 | 0); |
| 1951 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 1952 | l1, repo, &entities, 4, false, 1, 34), |
| 1953 | 0); |
| 1954 | |
| 1955 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 1956 | |
| 1957 | uint8_t* outData = nullptr; |
| 1958 | uint32_t size{}; |
| 1959 | uint32_t nextRecHdl{}; |
| 1960 | auto hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 1961 | EXPECT_NE(hdl, nullptr); |
| 1962 | |
| 1963 | outData = nullptr; |
| 1964 | auto hdl1 = pldm_pdr_find_record(repo, 2, &outData, &size, &nextRecHdl); |
| 1965 | EXPECT_NE(hdl1, nullptr); |
| 1966 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(outData); |
| 1967 | EXPECT_EQ(hdr->record_handle, 2); |
| 1968 | |
| 1969 | outData = nullptr; |
| 1970 | auto hdl2 = pldm_pdr_find_record(repo, 23, &outData, &size, &nextRecHdl); |
| 1971 | EXPECT_NE(hdl2, nullptr); |
| 1972 | pldm_pdr_hdr* hdr1 = reinterpret_cast<pldm_pdr_hdr*>(outData); |
| 1973 | EXPECT_EQ(hdr1->record_handle, 23); |
| 1974 | |
| 1975 | outData = nullptr; |
| 1976 | auto hdl3 = pldm_pdr_find_record(repo, 3, &outData, &size, &nextRecHdl); |
| 1977 | EXPECT_EQ(hdl3, nullptr); |
| 1978 | |
| 1979 | free(entities); |
| 1980 | pldm_pdr_destroy(repo); |
| 1981 | pldm_entity_association_tree_destroy(tree); |
| 1982 | } |
Varsha Kaverappa | 37552b9 | 2024-02-12 05:06:06 -0600 | [diff] [blame] | 1983 | |
Andrew Jeffery | 1111a97 | 2024-06-03 13:39:18 +0930 | [diff] [blame] | 1984 | #ifdef LIBPLDM_API_TESTING |
Varsha Kaverappa | 37552b9 | 2024-02-12 05:06:06 -0600 | [diff] [blame] | 1985 | TEST(EntityAssociationPDR, testAddContainedEntityRemotePDR) |
| 1986 | { |
| 1987 | // pldm_entity entities[5]{}; |
| 1988 | pldm_entity* entities = (pldm_entity*)malloc(sizeof(pldm_entity) * 5); |
| 1989 | entities[0].entity_type = 1; |
| 1990 | entities[1].entity_type = 2; |
| 1991 | entities[2].entity_type = 3; |
| 1992 | entities[3].entity_type = 4; |
| 1993 | entities[4].entity_type = 5; |
| 1994 | |
| 1995 | auto tree = pldm_entity_association_tree_init(); |
| 1996 | auto l1 = pldm_entity_association_tree_add( |
| 1997 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1998 | EXPECT_NE(l1, nullptr); |
| 1999 | auto l2a = pldm_entity_association_tree_add( |
| 2000 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2001 | EXPECT_NE(l2a, nullptr); |
| 2002 | auto l2b = pldm_entity_association_tree_add( |
| 2003 | tree, &entities[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2004 | EXPECT_NE(l2b, nullptr); |
| 2005 | auto l2c = pldm_entity_association_tree_add( |
| 2006 | tree, &entities[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2007 | EXPECT_NE(l2c, nullptr); |
| 2008 | auto l3a = pldm_entity_association_tree_add( |
| 2009 | tree, &entities[4], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2010 | EXPECT_NE(l3a, nullptr); |
| 2011 | |
| 2012 | auto repo = pldm_pdr_init(); |
| 2013 | |
| 2014 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2015 | l1, repo, &entities, 5, false, 1, 0), |
| 2016 | 0); |
| 2017 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2018 | l1, repo, &entities, 5, false, 1, 2), |
| 2019 | 0); |
| 2020 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2021 | l1, repo, &entities, 5, false, 1, 23), |
| 2022 | 0); |
| 2023 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2024 | l1, repo, &entities, 5, false, 1, 34), |
| 2025 | 0); |
| 2026 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2027 | l2a, repo, &entities, 5, false, 1, 3), |
| 2028 | 0); |
| 2029 | |
| 2030 | pldm_entity entity1[1]; |
| 2031 | entity1[0].entity_type = 2; |
| 2032 | |
| 2033 | EXPECT_EQ(pldm_entity_association_pdr_add_contained_entity_to_remote_pdr( |
| 2034 | repo, &entity1[0], 2), |
| 2035 | 0); |
| 2036 | |
| 2037 | free(entities); |
| 2038 | pldm_pdr_destroy(repo); |
| 2039 | pldm_entity_association_tree_destroy(tree); |
| 2040 | } |
Andrew Jeffery | 1111a97 | 2024-06-03 13:39:18 +0930 | [diff] [blame] | 2041 | #endif |
Varsha Kaverappa | 37552b9 | 2024-02-12 05:06:06 -0600 | [diff] [blame] | 2042 | |
Andrew Jeffery | 1111a97 | 2024-06-03 13:39:18 +0930 | [diff] [blame] | 2043 | #ifdef LIBPLDM_API_TESTING |
Varsha Kaverappa | 37552b9 | 2024-02-12 05:06:06 -0600 | [diff] [blame] | 2044 | TEST(EntityAssociationPDR, testAddContainedEntityNew) |
| 2045 | { |
| 2046 | // pldm_entity entities[5]{}; |
| 2047 | pldm_entity* entities = (pldm_entity*)malloc(sizeof(pldm_entity) * 5); |
| 2048 | entities[0].entity_type = 1; |
| 2049 | entities[1].entity_type = 2; |
| 2050 | entities[2].entity_type = 3; |
| 2051 | entities[3].entity_type = 4; |
| 2052 | entities[4].entity_type = 5; |
| 2053 | |
| 2054 | auto tree = pldm_entity_association_tree_init(); |
| 2055 | auto l1 = pldm_entity_association_tree_add( |
| 2056 | tree, &entities[0], 0xffff, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2057 | EXPECT_NE(l1, nullptr); |
| 2058 | auto l2a = pldm_entity_association_tree_add( |
| 2059 | tree, &entities[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2060 | EXPECT_NE(l2a, nullptr); |
| 2061 | auto l2b = pldm_entity_association_tree_add( |
| 2062 | tree, &entities[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2063 | EXPECT_NE(l2b, nullptr); |
| 2064 | auto l2c = pldm_entity_association_tree_add( |
| 2065 | tree, &entities[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2066 | EXPECT_NE(l2c, nullptr); |
| 2067 | auto l3a = pldm_entity_association_tree_add( |
| 2068 | tree, &entities[4], 0xffff, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 2069 | EXPECT_NE(l3a, nullptr); |
| 2070 | |
| 2071 | auto repo = pldm_pdr_init(); |
| 2072 | |
| 2073 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2074 | l1, repo, &entities, 5, false, 1, 0), |
| 2075 | 0); |
| 2076 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2077 | l1, repo, &entities, 5, false, 1, 2), |
| 2078 | 0); |
| 2079 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2080 | l1, repo, &entities, 5, false, 1, 23), |
| 2081 | 0); |
| 2082 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2083 | l1, repo, &entities, 5, false, 1, 34), |
| 2084 | 0); |
| 2085 | EXPECT_EQ(pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 2086 | l2a, repo, &entities, 5, false, 1, 3), |
| 2087 | 0); |
| 2088 | |
| 2089 | uint32_t updated_record_handle = 0; |
| 2090 | |
| 2091 | pldm_entity entity2[1]{}; |
| 2092 | entity2[0].entity_type = 4; |
| 2093 | |
| 2094 | pldm_entity entity3[1]{}; |
| 2095 | entity3[0].entity_type = 4; |
| 2096 | |
| 2097 | EXPECT_EQ(pldm_entity_association_pdr_create_new( |
| 2098 | repo, 34, &entity2[0], &entity3[0], &updated_record_handle), |
| 2099 | 0); |
| 2100 | |
| 2101 | EXPECT_EQ(updated_record_handle, 35); |
| 2102 | |
| 2103 | free(entities); |
| 2104 | pldm_pdr_destroy(repo); |
| 2105 | pldm_entity_association_tree_destroy(tree); |
| 2106 | } |
Andrew Jeffery | 1111a97 | 2024-06-03 13:39:18 +0930 | [diff] [blame] | 2107 | #endif |