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