Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 1 | #include "common/utils.hpp" |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 2 | #include "mocked_utils.hpp" |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 3 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 4 | #include <libpldm/platform.h> |
| 5 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | using namespace pldm::utils; |
| 9 | |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 10 | TEST(GetInventoryObjects, testForEmptyObject) |
| 11 | { |
| 12 | ObjectValueTree result = |
| 13 | DBusHandler::getInventoryObjects<GetManagedEmptyObject>(); |
| 14 | EXPECT_TRUE(result.empty()); |
| 15 | } |
| 16 | |
| 17 | TEST(GetInventoryObjects, testForObject) |
| 18 | { |
| 19 | std::string path = "/foo/bar"; |
| 20 | std::string service = "foo.bar"; |
| 21 | auto result = DBusHandler::getInventoryObjects<GetManagedObject>(); |
| 22 | EXPECT_EQ(result[path].begin()->first, service); |
| 23 | auto function = |
| 24 | std::get<bool>(result[path][service][std::string("Functional")]); |
| 25 | auto model = |
| 26 | std::get<std::string>(result[path][service][std::string("Model")]); |
| 27 | EXPECT_FALSE(result.empty()); |
| 28 | EXPECT_TRUE(function); |
| 29 | EXPECT_EQ(model, std::string("1234 - 00Z")); |
| 30 | } |
| 31 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 32 | TEST(decodeDate, testGooduintToDate) |
| 33 | { |
| 34 | uint64_t data = 20191212115959; |
| 35 | uint16_t year = 2019; |
| 36 | uint8_t month = 12; |
| 37 | uint8_t day = 12; |
| 38 | uint8_t hours = 11; |
| 39 | uint8_t minutes = 59; |
| 40 | uint8_t seconds = 59; |
| 41 | |
| 42 | uint16_t retyear = 0; |
| 43 | uint8_t retmonth = 0; |
| 44 | uint8_t retday = 0; |
| 45 | uint8_t rethours = 0; |
| 46 | uint8_t retminutes = 0; |
| 47 | uint8_t retseconds = 0; |
| 48 | |
| 49 | auto ret = uintToDate(data, &retyear, &retmonth, &retday, &rethours, |
| 50 | &retminutes, &retseconds); |
| 51 | |
| 52 | EXPECT_EQ(ret, true); |
| 53 | EXPECT_EQ(year, retyear); |
| 54 | EXPECT_EQ(month, retmonth); |
| 55 | EXPECT_EQ(day, retday); |
| 56 | EXPECT_EQ(hours, rethours); |
| 57 | EXPECT_EQ(minutes, retminutes); |
| 58 | EXPECT_EQ(seconds, retseconds); |
| 59 | } |
| 60 | |
| 61 | TEST(decodeDate, testBaduintToDate) |
| 62 | { |
| 63 | uint64_t data = 10191212115959; |
| 64 | |
| 65 | uint16_t retyear = 0; |
| 66 | uint8_t retmonth = 0; |
| 67 | uint8_t retday = 0; |
| 68 | uint8_t rethours = 0; |
| 69 | uint8_t retminutes = 0; |
| 70 | uint8_t retseconds = 0; |
| 71 | |
| 72 | auto ret = uintToDate(data, &retyear, &retmonth, &retday, &rethours, |
| 73 | &retminutes, &retseconds); |
| 74 | |
| 75 | EXPECT_EQ(ret, false); |
| 76 | } |
| 77 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 78 | TEST(parseEffecterData, testGoodDecodeEffecterData) |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 79 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 80 | std::vector<uint8_t> effecterData = {1, 1, 0, 1}; |
| 81 | uint8_t effecterCount = 2; |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 82 | set_effecter_state_field stateField0 = {1, 1}; |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 83 | set_effecter_state_field stateField1 = {0, 1}; |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 84 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 85 | auto effecterField = parseEffecterData(effecterData, effecterCount); |
| 86 | EXPECT_NE(effecterField, std::nullopt); |
| 87 | EXPECT_EQ(effecterCount, effecterField->size()); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 88 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 89 | std::vector<set_effecter_state_field> stateField = effecterField.value(); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 90 | EXPECT_EQ(stateField[0].set_request, stateField0.set_request); |
| 91 | EXPECT_EQ(stateField[0].effecter_state, stateField0.effecter_state); |
| 92 | EXPECT_EQ(stateField[1].set_request, stateField1.set_request); |
| 93 | EXPECT_EQ(stateField[1].effecter_state, stateField1.effecter_state); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 94 | } |
| 95 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 96 | TEST(parseEffecterData, testBadDecodeEffecterData) |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 97 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 98 | std::vector<uint8_t> effecterData = {0, 1, 0, 1, 0, 1}; |
| 99 | uint8_t effecterCount = 2; |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 100 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 101 | auto effecterField = parseEffecterData(effecterData, effecterCount); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 102 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 103 | EXPECT_EQ(effecterField, std::nullopt); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 104 | } |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 105 | |
| 106 | TEST(FindStateEffecterPDR, testOneMatch) |
| 107 | { |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 108 | auto repo = pldm_pdr_init(); |
| 109 | uint8_t tid = 1; |
| 110 | uint16_t entityID = 33; |
| 111 | uint16_t stateSetId = 196; |
| 112 | |
| 113 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 114 | sizeof(uint8_t) + |
| 115 | sizeof(struct state_effecter_possible_states)); |
| 116 | |
| 117 | auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data()); |
| 118 | |
| 119 | auto state = |
| 120 | reinterpret_cast<state_effecter_possible_states*>(rec->possible_states); |
| 121 | |
| 122 | rec->hdr.type = 11; |
| 123 | rec->hdr.record_handle = 1; |
| 124 | rec->entity_type = 33; |
| 125 | rec->container_id = 0; |
| 126 | rec->composite_effecter_count = 1; |
| 127 | state->state_set_id = 196; |
| 128 | state->possible_states_size = 1; |
| 129 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 130 | uint32_t handle = 0; |
| 131 | ASSERT_EQ( |
| 132 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 133 | |
| 134 | auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo); |
| 135 | |
| 136 | EXPECT_EQ(pdr, record[0]); |
| 137 | |
| 138 | pldm_pdr_destroy(repo); |
| 139 | } |
| 140 | |
| 141 | TEST(FindStateEffecterPDR, testNoMatch) |
| 142 | { |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 143 | auto repo = pldm_pdr_init(); |
| 144 | uint8_t tid = 1; |
| 145 | uint16_t entityID = 44; |
| 146 | uint16_t stateSetId = 196; |
| 147 | |
| 148 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 149 | sizeof(uint8_t) + |
| 150 | sizeof(struct state_effecter_possible_states)); |
| 151 | |
| 152 | auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data()); |
| 153 | |
| 154 | auto state = |
| 155 | reinterpret_cast<state_effecter_possible_states*>(rec->possible_states); |
| 156 | |
| 157 | rec->hdr.type = 11; |
| 158 | rec->hdr.record_handle = 1; |
| 159 | rec->entity_type = 33; |
| 160 | rec->container_id = 0; |
| 161 | rec->composite_effecter_count = 1; |
| 162 | state->state_set_id = 196; |
| 163 | state->possible_states_size = 1; |
| 164 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 165 | uint32_t handle = 0; |
| 166 | ASSERT_EQ( |
| 167 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 168 | |
| 169 | auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo); |
| 170 | |
| 171 | EXPECT_EQ(record.empty(), true); |
| 172 | |
| 173 | pldm_pdr_destroy(repo); |
| 174 | } |
| 175 | |
| 176 | TEST(FindStateEffecterPDR, testEmptyRepo) |
| 177 | { |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 178 | auto repo = pldm_pdr_init(); |
| 179 | uint8_t tid = 1; |
| 180 | uint16_t entityID = 33; |
| 181 | uint16_t stateSetId = 196; |
| 182 | |
| 183 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 184 | sizeof(uint8_t) + |
| 185 | sizeof(struct state_effecter_possible_states)); |
| 186 | |
| 187 | auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo); |
| 188 | |
| 189 | EXPECT_EQ(record.empty(), true); |
| 190 | |
| 191 | pldm_pdr_destroy(repo); |
| 192 | } |
| 193 | |
| 194 | TEST(FindStateEffecterPDR, testMoreMatch) |
| 195 | { |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 196 | auto repo = pldm_pdr_init(); |
| 197 | uint8_t tid = 1; |
| 198 | |
| 199 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 200 | sizeof(uint8_t) + |
| 201 | sizeof(struct state_effecter_possible_states)); |
| 202 | |
| 203 | auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data()); |
| 204 | |
| 205 | auto state = |
| 206 | reinterpret_cast<state_effecter_possible_states*>(rec->possible_states); |
| 207 | |
| 208 | rec->hdr.type = 11; |
| 209 | rec->hdr.record_handle = 1; |
| 210 | rec->entity_type = 31; |
| 211 | rec->container_id = 0; |
| 212 | rec->composite_effecter_count = 1; |
| 213 | state->state_set_id = 129; |
| 214 | state->possible_states_size = 1; |
| 215 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 216 | uint32_t handle = 0; |
| 217 | ASSERT_EQ( |
| 218 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 219 | |
| 220 | std::vector<uint8_t> pdr_second( |
| 221 | sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) + |
| 222 | sizeof(struct state_effecter_possible_states)); |
| 223 | |
| 224 | auto rec_second = |
| 225 | reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data()); |
| 226 | |
| 227 | auto state_second = reinterpret_cast<state_effecter_possible_states*>( |
| 228 | rec_second->possible_states); |
| 229 | |
| 230 | rec_second->hdr.type = 11; |
| 231 | rec_second->hdr.record_handle = 2; |
| 232 | rec_second->entity_type = 31; |
| 233 | rec_second->container_id = 0; |
| 234 | rec_second->composite_effecter_count = 1; |
| 235 | state_second->state_set_id = 129; |
| 236 | state_second->possible_states_size = 1; |
| 237 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 238 | handle = 0; |
| 239 | ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(), |
| 240 | false, 1, &handle), |
| 241 | 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 242 | |
| 243 | uint16_t entityID_ = 31; |
| 244 | uint16_t stateSetId_ = 129; |
| 245 | |
| 246 | auto record = findStateEffecterPDR(tid, entityID_, stateSetId_, repo); |
| 247 | |
| 248 | EXPECT_EQ(pdr, record[0]); |
| 249 | EXPECT_EQ(pdr_second, record[1]); |
| 250 | |
| 251 | pldm_pdr_destroy(repo); |
| 252 | } |
| 253 | |
| 254 | TEST(FindStateEffecterPDR, testManyNoMatch) |
| 255 | { |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 256 | auto repo = pldm_pdr_init(); |
| 257 | uint8_t tid = 1; |
| 258 | uint16_t entityID = 33; |
| 259 | uint16_t stateSetId = 196; |
| 260 | |
| 261 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 262 | sizeof(uint8_t) + |
| 263 | sizeof(struct state_effecter_possible_states)); |
| 264 | |
| 265 | auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data()); |
| 266 | |
| 267 | auto state = |
| 268 | reinterpret_cast<state_effecter_possible_states*>(rec->possible_states); |
| 269 | |
| 270 | rec->hdr.type = 11; |
| 271 | rec->hdr.record_handle = 1; |
| 272 | rec->entity_type = 34; |
| 273 | rec->container_id = 0; |
| 274 | rec->composite_effecter_count = 1; |
| 275 | state->state_set_id = 198; |
| 276 | state->possible_states_size = 1; |
| 277 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 278 | uint32_t handle = 0; |
| 279 | ASSERT_EQ( |
| 280 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 281 | |
| 282 | std::vector<uint8_t> pdr_second( |
| 283 | sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) + |
| 284 | sizeof(struct state_effecter_possible_states)); |
| 285 | |
| 286 | auto rec_second = |
| 287 | reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data()); |
| 288 | |
| 289 | auto state_second = reinterpret_cast<state_effecter_possible_states*>( |
| 290 | rec_second->possible_states); |
| 291 | |
| 292 | rec_second->hdr.type = 11; |
| 293 | rec_second->hdr.record_handle = 2; |
| 294 | rec_second->entity_type = 39; |
| 295 | rec_second->container_id = 0; |
| 296 | rec_second->composite_effecter_count = 1; |
| 297 | state_second->state_set_id = 169; |
| 298 | state_second->possible_states_size = 1; |
| 299 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 300 | handle = 0; |
| 301 | ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(), |
| 302 | false, 1, &handle), |
| 303 | 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 304 | |
| 305 | auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo); |
| 306 | |
| 307 | EXPECT_EQ(record.empty(), true); |
| 308 | |
| 309 | pldm_pdr_destroy(repo); |
| 310 | } |
| 311 | |
| 312 | TEST(FindStateEffecterPDR, testOneMatchOneNoMatch) |
| 313 | { |
| 314 | auto repo = pldm_pdr_init(); |
| 315 | uint8_t tid = 1; |
| 316 | uint16_t entityID = 67; |
| 317 | uint16_t stateSetId = 192; |
| 318 | |
| 319 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 320 | sizeof(uint8_t) + |
| 321 | sizeof(struct state_effecter_possible_states)); |
| 322 | |
| 323 | auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data()); |
| 324 | |
| 325 | auto state = |
| 326 | reinterpret_cast<state_effecter_possible_states*>(rec->possible_states); |
| 327 | |
| 328 | rec->hdr.type = 11; |
| 329 | rec->hdr.record_handle = 1; |
| 330 | rec->entity_type = 32; |
| 331 | rec->container_id = 0; |
| 332 | rec->composite_effecter_count = 1; |
| 333 | state->state_set_id = 198; |
| 334 | state->possible_states_size = 1; |
| 335 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 336 | uint32_t handle = 0; |
| 337 | ASSERT_EQ( |
| 338 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 339 | |
| 340 | std::vector<uint8_t> pdr_second( |
| 341 | sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) + |
| 342 | sizeof(struct state_effecter_possible_states)); |
| 343 | |
| 344 | auto rec_second = |
| 345 | reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data()); |
| 346 | |
| 347 | auto state_second = reinterpret_cast<state_effecter_possible_states*>( |
| 348 | rec_second->possible_states); |
| 349 | |
| 350 | rec_second->hdr.type = 11; |
| 351 | rec_second->hdr.record_handle = 2; |
| 352 | rec_second->entity_type = 67; |
| 353 | rec_second->container_id = 0; |
| 354 | rec_second->composite_effecter_count = 1; |
| 355 | state_second->state_set_id = 192; |
| 356 | state_second->possible_states_size = 1; |
| 357 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 358 | handle = 0; |
| 359 | ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(), |
| 360 | false, 1, &handle), |
| 361 | 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 362 | |
| 363 | auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo); |
| 364 | |
| 365 | EXPECT_EQ(pdr_second, record[0]); |
| 366 | EXPECT_EQ(record.size(), 1); |
| 367 | |
| 368 | pldm_pdr_destroy(repo); |
| 369 | } |
| 370 | |
| 371 | TEST(FindStateEffecterPDR, testOneMatchManyNoMatch) |
| 372 | { |
| 373 | auto repo = pldm_pdr_init(); |
| 374 | uint8_t tid = 1; |
| 375 | uint16_t entityID = 67; |
| 376 | uint16_t stateSetId = 192; |
| 377 | |
| 378 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 379 | sizeof(uint8_t) + |
| 380 | sizeof(struct state_effecter_possible_states)); |
| 381 | |
| 382 | auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data()); |
| 383 | |
| 384 | auto state = |
| 385 | reinterpret_cast<state_effecter_possible_states*>(rec->possible_states); |
| 386 | |
| 387 | rec->hdr.type = 11; |
| 388 | rec->hdr.record_handle = 1; |
| 389 | rec->entity_type = 32; |
| 390 | rec->container_id = 0; |
| 391 | rec->composite_effecter_count = 1; |
| 392 | state->state_set_id = 198; |
| 393 | state->possible_states_size = 1; |
| 394 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 395 | uint32_t handle = 0; |
| 396 | ASSERT_EQ( |
| 397 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 398 | |
| 399 | std::vector<uint8_t> pdr_second( |
| 400 | sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) + |
| 401 | sizeof(struct state_effecter_possible_states)); |
| 402 | |
| 403 | auto rec_second = |
| 404 | reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data()); |
| 405 | |
| 406 | auto state_second = reinterpret_cast<state_effecter_possible_states*>( |
| 407 | rec_second->possible_states); |
| 408 | |
| 409 | rec_second->hdr.type = 11; |
| 410 | rec_second->hdr.record_handle = 2; |
| 411 | rec_second->entity_type = 67; |
| 412 | rec_second->container_id = 0; |
| 413 | rec_second->composite_effecter_count = 1; |
| 414 | state_second->state_set_id = 192; |
| 415 | state_second->possible_states_size = 1; |
| 416 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 417 | handle = 0; |
| 418 | ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(), |
| 419 | false, 1, &handle), |
| 420 | 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 421 | |
| 422 | std::vector<uint8_t> pdr_third( |
| 423 | sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) + |
| 424 | sizeof(struct state_effecter_possible_states)); |
| 425 | |
| 426 | auto rec_third = |
| 427 | reinterpret_cast<pldm_state_effecter_pdr*>(pdr_third.data()); |
| 428 | |
| 429 | auto state_third = reinterpret_cast<state_effecter_possible_states*>( |
| 430 | rec_third->possible_states); |
| 431 | |
| 432 | rec_third->hdr.type = 11; |
| 433 | rec_third->hdr.record_handle = 3; |
| 434 | rec_third->entity_type = 69; |
| 435 | rec_third->container_id = 0; |
| 436 | rec_third->composite_effecter_count = 1; |
| 437 | state_third->state_set_id = 199; |
| 438 | state_third->possible_states_size = 1; |
| 439 | |
| 440 | auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo); |
| 441 | |
| 442 | EXPECT_EQ(pdr_second, record[0]); |
| 443 | EXPECT_EQ(record.size(), 1); |
| 444 | |
| 445 | pldm_pdr_destroy(repo); |
| 446 | } |
| 447 | |
| 448 | TEST(FindStateEffecterPDR, testCompositeEffecter) |
| 449 | { |
| 450 | auto repo = pldm_pdr_init(); |
| 451 | uint8_t tid = 1; |
| 452 | uint16_t entityID = 67; |
| 453 | uint16_t stateSetId = 192; |
| 454 | |
| 455 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 456 | sizeof(uint8_t) + |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 457 | sizeof(struct state_effecter_possible_states) * 3); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 458 | |
| 459 | auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data()); |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 460 | auto state_start = rec->possible_states; |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 461 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 462 | auto state = reinterpret_cast<state_effecter_possible_states*>(state_start); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 463 | |
| 464 | rec->hdr.type = 11; |
| 465 | rec->hdr.record_handle = 1; |
| 466 | rec->entity_type = 67; |
| 467 | rec->container_id = 0; |
| 468 | rec->composite_effecter_count = 3; |
| 469 | state->state_set_id = 198; |
| 470 | state->possible_states_size = 1; |
| 471 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 472 | state_start += state->possible_states_size + sizeof(state->state_set_id) + |
| 473 | sizeof(state->possible_states_size); |
| 474 | state = reinterpret_cast<state_effecter_possible_states*>(state_start); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 475 | state->state_set_id = 193; |
| 476 | state->possible_states_size = 1; |
| 477 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 478 | state_start += state->possible_states_size + sizeof(state->state_set_id) + |
| 479 | sizeof(state->possible_states_size); |
| 480 | state = reinterpret_cast<state_effecter_possible_states*>(state_start); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 481 | state->state_set_id = 192; |
| 482 | state->possible_states_size = 1; |
| 483 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 484 | uint32_t handle = 0; |
| 485 | ASSERT_EQ( |
| 486 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 487 | |
| 488 | auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo); |
| 489 | |
| 490 | EXPECT_EQ(pdr, record[0]); |
| 491 | |
| 492 | pldm_pdr_destroy(repo); |
| 493 | } |
| 494 | |
| 495 | TEST(FindStateEffecterPDR, testNoMatchCompositeEffecter) |
| 496 | { |
| 497 | auto repo = pldm_pdr_init(); |
| 498 | uint8_t tid = 1; |
| 499 | uint16_t entityID = 67; |
| 500 | uint16_t stateSetId = 192; |
| 501 | |
| 502 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_effecter_pdr) - |
| 503 | sizeof(uint8_t) + |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 504 | sizeof(struct state_effecter_possible_states) * 3); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 505 | |
| 506 | auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data()); |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 507 | auto state_start = rec->possible_states; |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 508 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 509 | auto state = reinterpret_cast<state_effecter_possible_states*>(state_start); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 510 | |
| 511 | rec->hdr.type = 11; |
| 512 | rec->hdr.record_handle = 1; |
| 513 | rec->entity_type = 34; |
| 514 | rec->container_id = 0; |
| 515 | rec->composite_effecter_count = 3; |
| 516 | state->state_set_id = 198; |
| 517 | state->possible_states_size = 1; |
| 518 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 519 | state_start += state->possible_states_size + sizeof(state->state_set_id) + |
| 520 | sizeof(state->possible_states_size); |
| 521 | state = reinterpret_cast<state_effecter_possible_states*>(state_start); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 522 | state->state_set_id = 193; |
| 523 | state->possible_states_size = 1; |
| 524 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 525 | state_start += state->possible_states_size + sizeof(state->state_set_id) + |
| 526 | sizeof(state->possible_states_size); |
| 527 | state = reinterpret_cast<state_effecter_possible_states*>(state_start); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 528 | state->state_set_id = 123; |
| 529 | state->possible_states_size = 1; |
| 530 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 531 | uint32_t handle = 0; |
| 532 | ASSERT_EQ( |
| 533 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Pavithra Barithaya | 0f74c98 | 2020-04-27 02:17:10 -0500 | [diff] [blame] | 534 | |
| 535 | auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo); |
| 536 | |
| 537 | EXPECT_EQ(record.empty(), true); |
| 538 | |
| 539 | pldm_pdr_destroy(repo); |
| 540 | } |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 541 | |
| 542 | TEST(FindStateSensorPDR, testOneMatch) |
| 543 | { |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 544 | auto repo = pldm_pdr_init(); |
| 545 | uint8_t tid = 1; |
| 546 | uint16_t entityID = 5; |
| 547 | uint16_t stateSetId = 1; |
| 548 | |
| 549 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 550 | sizeof(uint8_t) + |
| 551 | sizeof(struct state_sensor_possible_states)); |
| 552 | |
| 553 | auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data()); |
| 554 | |
| 555 | auto state = |
| 556 | reinterpret_cast<state_sensor_possible_states*>(rec->possible_states); |
| 557 | |
| 558 | rec->hdr.type = 4; |
| 559 | rec->hdr.record_handle = 1; |
| 560 | rec->entity_type = 5; |
| 561 | rec->container_id = 0; |
| 562 | rec->composite_sensor_count = 1; |
| 563 | state->state_set_id = 1; |
| 564 | state->possible_states_size = 1; |
| 565 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 566 | uint32_t handle = 0; |
| 567 | ASSERT_EQ( |
| 568 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 569 | |
| 570 | auto record = findStateSensorPDR(tid, entityID, stateSetId, repo); |
| 571 | |
| 572 | EXPECT_EQ(pdr, record[0]); |
| 573 | |
| 574 | pldm_pdr_destroy(repo); |
| 575 | } |
| 576 | |
| 577 | TEST(FindStateSensorPDR, testNoMatch) |
| 578 | { |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 579 | auto repo = pldm_pdr_init(); |
| 580 | uint8_t tid = 1; |
| 581 | uint16_t entityID = 5; |
| 582 | uint16_t stateSetId = 1; |
| 583 | |
| 584 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 585 | sizeof(uint8_t) + |
| 586 | sizeof(struct state_sensor_possible_states)); |
| 587 | |
| 588 | auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data()); |
| 589 | |
| 590 | auto state = |
| 591 | reinterpret_cast<state_sensor_possible_states*>(rec->possible_states); |
| 592 | |
| 593 | rec->hdr.type = 4; |
| 594 | rec->hdr.record_handle = 1; |
| 595 | rec->entity_type = 55; |
| 596 | rec->container_id = 0; |
| 597 | rec->composite_sensor_count = 1; |
| 598 | state->state_set_id = 1; |
| 599 | state->possible_states_size = 1; |
| 600 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 601 | uint32_t handle = 0; |
| 602 | ASSERT_EQ( |
| 603 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 604 | |
| 605 | auto record = findStateSensorPDR(tid, entityID, stateSetId, repo); |
| 606 | |
| 607 | EXPECT_EQ(record.empty(), true); |
| 608 | |
| 609 | pldm_pdr_destroy(repo); |
| 610 | } |
| 611 | |
| 612 | TEST(FindStateSensorPDR, testEmptyRepo) |
| 613 | { |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 614 | auto repo = pldm_pdr_init(); |
| 615 | uint8_t tid = 1; |
| 616 | uint16_t entityID = 5; |
| 617 | uint16_t stateSetId = 1; |
| 618 | |
| 619 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 620 | sizeof(uint8_t) + |
| 621 | sizeof(struct state_sensor_possible_states)); |
| 622 | |
| 623 | auto record = findStateSensorPDR(tid, entityID, stateSetId, repo); |
| 624 | |
| 625 | EXPECT_EQ(record.empty(), true); |
| 626 | |
| 627 | pldm_pdr_destroy(repo); |
| 628 | } |
| 629 | |
| 630 | TEST(FindStateSensorPDR, testMoreMatch) |
| 631 | { |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 632 | auto repo = pldm_pdr_init(); |
| 633 | uint8_t tid = 1; |
| 634 | |
| 635 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 636 | sizeof(uint8_t) + |
| 637 | sizeof(struct state_sensor_possible_states)); |
| 638 | |
| 639 | auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data()); |
| 640 | |
| 641 | auto state = |
| 642 | reinterpret_cast<state_sensor_possible_states*>(rec->possible_states); |
| 643 | |
| 644 | rec->hdr.type = 4; |
| 645 | rec->hdr.record_handle = 1; |
| 646 | rec->entity_type = 5; |
| 647 | rec->container_id = 0; |
| 648 | rec->composite_sensor_count = 1; |
| 649 | state->state_set_id = 1; |
| 650 | state->possible_states_size = 1; |
| 651 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 652 | uint32_t handle = 0; |
| 653 | ASSERT_EQ( |
| 654 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 655 | |
| 656 | std::vector<uint8_t> pdr_second( |
| 657 | sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) + |
| 658 | sizeof(struct state_sensor_possible_states)); |
| 659 | |
| 660 | auto rec_second = |
| 661 | reinterpret_cast<pldm_state_sensor_pdr*>(pdr_second.data()); |
| 662 | |
| 663 | auto state_second = reinterpret_cast<state_sensor_possible_states*>( |
| 664 | rec_second->possible_states); |
| 665 | |
| 666 | rec_second->hdr.type = 4; |
| 667 | rec_second->hdr.record_handle = 2; |
| 668 | rec_second->entity_type = 5; |
| 669 | rec_second->container_id = 0; |
| 670 | rec_second->composite_sensor_count = 1; |
| 671 | state_second->state_set_id = 1; |
| 672 | state_second->possible_states_size = 1; |
| 673 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 674 | handle = 0; |
| 675 | ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(), |
| 676 | false, 1, &handle), |
| 677 | 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 678 | |
| 679 | uint16_t entityID_ = 5; |
| 680 | uint16_t stateSetId_ = 1; |
| 681 | |
| 682 | auto record = findStateSensorPDR(tid, entityID_, stateSetId_, repo); |
| 683 | |
| 684 | EXPECT_EQ(pdr, record[0]); |
| 685 | EXPECT_EQ(pdr_second, record[1]); |
| 686 | |
| 687 | pldm_pdr_destroy(repo); |
| 688 | } |
| 689 | |
| 690 | TEST(FindStateSensorPDR, testManyNoMatch) |
| 691 | { |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 692 | auto repo = pldm_pdr_init(); |
| 693 | uint8_t tid = 1; |
| 694 | uint16_t entityID = 5; |
| 695 | uint16_t stateSetId = 1; |
| 696 | |
| 697 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 698 | sizeof(uint8_t) + |
| 699 | sizeof(struct state_sensor_possible_states)); |
| 700 | |
| 701 | auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data()); |
| 702 | |
| 703 | auto state = |
| 704 | reinterpret_cast<state_sensor_possible_states*>(rec->possible_states); |
| 705 | |
| 706 | rec->hdr.type = 4; |
| 707 | rec->hdr.record_handle = 1; |
| 708 | rec->entity_type = 56; |
| 709 | rec->container_id = 0; |
| 710 | rec->composite_sensor_count = 1; |
| 711 | state->state_set_id = 2; |
| 712 | state->possible_states_size = 1; |
| 713 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 714 | uint32_t handle = 0; |
| 715 | ASSERT_EQ( |
| 716 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 717 | |
| 718 | std::vector<uint8_t> pdr_second( |
| 719 | sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) + |
| 720 | sizeof(struct state_sensor_possible_states)); |
| 721 | |
| 722 | auto rec_second = |
| 723 | reinterpret_cast<pldm_state_sensor_pdr*>(pdr_second.data()); |
| 724 | |
| 725 | auto state_second = reinterpret_cast<state_sensor_possible_states*>( |
| 726 | rec_second->possible_states); |
| 727 | |
| 728 | rec_second->hdr.type = 4; |
| 729 | rec_second->hdr.record_handle = 2; |
| 730 | rec_second->entity_type = 66; |
| 731 | rec_second->container_id = 0; |
| 732 | rec_second->composite_sensor_count = 1; |
| 733 | state_second->state_set_id = 3; |
| 734 | state_second->possible_states_size = 1; |
| 735 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 736 | handle = 0; |
| 737 | ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(), |
| 738 | false, 1, &handle), |
| 739 | 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 740 | |
| 741 | auto record = findStateSensorPDR(tid, entityID, stateSetId, repo); |
| 742 | |
| 743 | EXPECT_EQ(record.empty(), true); |
| 744 | |
| 745 | pldm_pdr_destroy(repo); |
| 746 | } |
| 747 | |
| 748 | TEST(FindStateSensorPDR, testOneMatchOneNoMatch) |
| 749 | { |
| 750 | auto repo = pldm_pdr_init(); |
| 751 | uint8_t tid = 1; |
| 752 | uint16_t entityID = 5; |
| 753 | uint16_t stateSetId = 1; |
| 754 | |
| 755 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 756 | sizeof(uint8_t) + |
| 757 | sizeof(struct state_sensor_possible_states)); |
| 758 | |
| 759 | auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data()); |
| 760 | |
| 761 | auto state = |
| 762 | reinterpret_cast<state_sensor_possible_states*>(rec->possible_states); |
| 763 | |
| 764 | rec->hdr.type = 4; |
| 765 | rec->hdr.record_handle = 1; |
| 766 | rec->entity_type = 10; |
| 767 | rec->container_id = 0; |
| 768 | rec->composite_sensor_count = 1; |
| 769 | state->state_set_id = 20; |
| 770 | state->possible_states_size = 1; |
| 771 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 772 | uint32_t handle = 0; |
| 773 | ASSERT_EQ( |
| 774 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 775 | |
| 776 | std::vector<uint8_t> pdr_second( |
| 777 | sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) + |
| 778 | sizeof(struct state_sensor_possible_states)); |
| 779 | |
| 780 | auto rec_second = |
| 781 | reinterpret_cast<pldm_state_sensor_pdr*>(pdr_second.data()); |
| 782 | |
| 783 | auto state_second = reinterpret_cast<state_sensor_possible_states*>( |
| 784 | rec_second->possible_states); |
| 785 | |
| 786 | rec_second->hdr.type = 4; |
| 787 | rec_second->hdr.record_handle = 2; |
| 788 | rec_second->entity_type = 5; |
| 789 | rec_second->container_id = 0; |
| 790 | rec_second->composite_sensor_count = 1; |
| 791 | state_second->state_set_id = 1; |
| 792 | state_second->possible_states_size = 1; |
| 793 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 794 | handle = 0; |
| 795 | ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(), |
| 796 | false, 1, &handle), |
| 797 | 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 798 | |
| 799 | auto record = findStateSensorPDR(tid, entityID, stateSetId, repo); |
| 800 | |
| 801 | EXPECT_EQ(pdr_second, record[0]); |
| 802 | EXPECT_EQ(record.size(), 1); |
| 803 | |
| 804 | pldm_pdr_destroy(repo); |
| 805 | } |
| 806 | |
| 807 | TEST(FindStateSensorPDR, testOneMatchManyNoMatch) |
| 808 | { |
| 809 | auto repo = pldm_pdr_init(); |
| 810 | uint8_t tid = 1; |
| 811 | uint16_t entityID = 5; |
| 812 | uint16_t stateSetId = 1; |
| 813 | |
| 814 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 815 | sizeof(uint8_t) + |
| 816 | sizeof(struct state_sensor_possible_states)); |
| 817 | |
| 818 | auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data()); |
| 819 | |
| 820 | auto state = |
| 821 | reinterpret_cast<state_sensor_possible_states*>(rec->possible_states); |
| 822 | |
| 823 | rec->hdr.type = 4; |
| 824 | rec->hdr.record_handle = 1; |
| 825 | rec->entity_type = 6; |
| 826 | rec->container_id = 0; |
| 827 | rec->composite_sensor_count = 1; |
| 828 | state->state_set_id = 9; |
| 829 | state->possible_states_size = 1; |
| 830 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 831 | uint32_t handle = 0; |
| 832 | ASSERT_EQ( |
| 833 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 834 | |
| 835 | std::vector<uint8_t> pdr_second( |
| 836 | sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) + |
| 837 | sizeof(struct state_sensor_possible_states)); |
| 838 | |
| 839 | auto rec_second = |
| 840 | reinterpret_cast<pldm_state_sensor_pdr*>(pdr_second.data()); |
| 841 | |
| 842 | auto state_second = reinterpret_cast<state_sensor_possible_states*>( |
| 843 | rec_second->possible_states); |
| 844 | |
| 845 | rec_second->hdr.type = 4; |
| 846 | rec_second->hdr.record_handle = 2; |
| 847 | rec_second->entity_type = 5; |
| 848 | rec_second->container_id = 0; |
| 849 | rec_second->composite_sensor_count = 1; |
| 850 | state_second->state_set_id = 1; |
| 851 | state_second->possible_states_size = 1; |
| 852 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 853 | handle = 0; |
| 854 | ASSERT_EQ(pldm_pdr_add_check(repo, pdr_second.data(), pdr_second.size(), |
| 855 | false, 1, &handle), |
| 856 | 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 857 | |
| 858 | std::vector<uint8_t> pdr_third(sizeof(struct pldm_state_sensor_pdr) - |
| 859 | sizeof(uint8_t) + |
| 860 | sizeof(struct state_sensor_possible_states)); |
| 861 | |
| 862 | auto rec_third = reinterpret_cast<pldm_state_sensor_pdr*>(pdr_third.data()); |
| 863 | |
| 864 | auto state_third = reinterpret_cast<state_sensor_possible_states*>( |
| 865 | rec_third->possible_states); |
| 866 | |
| 867 | rec_third->hdr.type = 4; |
| 868 | rec_third->hdr.record_handle = 3; |
| 869 | rec_third->entity_type = 7; |
| 870 | rec_third->container_id = 0; |
| 871 | rec_third->composite_sensor_count = 1; |
| 872 | state_third->state_set_id = 12; |
| 873 | state_third->possible_states_size = 1; |
| 874 | |
| 875 | auto record = findStateSensorPDR(tid, entityID, stateSetId, repo); |
| 876 | |
| 877 | EXPECT_EQ(pdr_second, record[0]); |
| 878 | EXPECT_EQ(record.size(), 1); |
| 879 | |
| 880 | pldm_pdr_destroy(repo); |
| 881 | } |
| 882 | |
| 883 | TEST(FindStateSensorPDR, testCompositeSensor) |
| 884 | { |
| 885 | auto repo = pldm_pdr_init(); |
| 886 | uint8_t tid = 1; |
| 887 | uint16_t entityID = 5; |
| 888 | uint16_t stateSetId = 1; |
| 889 | |
| 890 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 891 | sizeof(uint8_t) + |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 892 | sizeof(struct state_sensor_possible_states) * 3); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 893 | |
| 894 | auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data()); |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 895 | auto state_start = rec->possible_states; |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 896 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 897 | auto state = reinterpret_cast<state_sensor_possible_states*>(state_start); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 898 | |
| 899 | rec->hdr.type = 4; |
| 900 | rec->hdr.record_handle = 1; |
| 901 | rec->entity_type = 5; |
| 902 | rec->container_id = 0; |
| 903 | rec->composite_sensor_count = 3; |
| 904 | state->state_set_id = 2; |
| 905 | state->possible_states_size = 1; |
| 906 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 907 | state_start += state->possible_states_size + sizeof(state->state_set_id) + |
| 908 | sizeof(state->possible_states_size); |
| 909 | state = reinterpret_cast<state_sensor_possible_states*>(state_start); |
| 910 | |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 911 | state->state_set_id = 7; |
| 912 | state->possible_states_size = 1; |
| 913 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 914 | state_start += state->possible_states_size + sizeof(state->state_set_id) + |
| 915 | sizeof(state->possible_states_size); |
| 916 | state = reinterpret_cast<state_sensor_possible_states*>(state_start); |
| 917 | |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 918 | state->state_set_id = 1; |
| 919 | state->possible_states_size = 1; |
| 920 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 921 | uint32_t handle = 0; |
| 922 | ASSERT_EQ( |
| 923 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 924 | |
| 925 | auto record = findStateSensorPDR(tid, entityID, stateSetId, repo); |
| 926 | |
| 927 | EXPECT_EQ(pdr, record[0]); |
| 928 | |
| 929 | pldm_pdr_destroy(repo); |
| 930 | } |
| 931 | |
| 932 | TEST(FindStateSensorPDR, testNoMatchCompositeSensor) |
| 933 | { |
| 934 | auto repo = pldm_pdr_init(); |
| 935 | uint8_t tid = 1; |
| 936 | uint16_t entityID = 5; |
| 937 | uint16_t stateSetId = 1; |
| 938 | |
| 939 | std::vector<uint8_t> pdr(sizeof(struct pldm_state_sensor_pdr) - |
| 940 | sizeof(uint8_t) + |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 941 | sizeof(struct state_sensor_possible_states) * 3); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 942 | |
| 943 | auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data()); |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 944 | auto state_start = rec->possible_states; |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 945 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 946 | auto state = reinterpret_cast<state_sensor_possible_states*>(state_start); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 947 | |
| 948 | rec->hdr.type = 4; |
| 949 | rec->hdr.record_handle = 1; |
| 950 | rec->entity_type = 21; |
| 951 | rec->container_id = 0; |
| 952 | rec->composite_sensor_count = 3; |
| 953 | state->state_set_id = 15; |
| 954 | state->possible_states_size = 1; |
| 955 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 956 | state_start += state->possible_states_size + sizeof(state->state_set_id) + |
| 957 | sizeof(state->possible_states_size); |
| 958 | state = reinterpret_cast<state_sensor_possible_states*>(state_start); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 959 | state->state_set_id = 19; |
| 960 | state->possible_states_size = 1; |
| 961 | |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 962 | state_start += state->possible_states_size + sizeof(state->state_set_id) + |
| 963 | sizeof(state->possible_states_size); |
| 964 | state = reinterpret_cast<state_sensor_possible_states*>(state_start); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 965 | state->state_set_id = 39; |
| 966 | state->possible_states_size = 1; |
| 967 | |
Andrew Jeffery | 64f37fe | 2023-07-03 15:41:13 +0930 | [diff] [blame] | 968 | uint32_t handle = 0; |
| 969 | ASSERT_EQ( |
| 970 | pldm_pdr_add_check(repo, pdr.data(), pdr.size(), false, 1, &handle), 0); |
Chicago Duan | 738e4d8 | 2020-05-28 16:39:19 +0800 | [diff] [blame] | 971 | |
| 972 | auto record = findStateSensorPDR(tid, entityID, stateSetId, repo); |
| 973 | |
| 974 | EXPECT_EQ(record.empty(), true); |
| 975 | |
| 976 | pldm_pdr_destroy(repo); |
Chicago Duan | a7aacc3 | 2020-06-10 18:03:38 +0800 | [diff] [blame] | 977 | } |
Tom Joseph | 5492207 | 2021-06-19 02:45:46 -0700 | [diff] [blame] | 978 | |
| 979 | TEST(toString, allTestCases) |
| 980 | { |
| 981 | variable_field buffer{}; |
| 982 | constexpr std::string_view str1{}; |
| 983 | auto returnStr1 = toString(buffer); |
| 984 | EXPECT_EQ(returnStr1, str1); |
| 985 | |
| 986 | constexpr std::string_view str2{"0penBmc"}; |
| 987 | constexpr std::array<uint8_t, 7> bufferArr1{0x30, 0x70, 0x65, 0x6e, |
| 988 | 0x42, 0x6d, 0x63}; |
| 989 | buffer.ptr = bufferArr1.data(); |
| 990 | buffer.length = bufferArr1.size(); |
| 991 | auto returnStr2 = toString(buffer); |
| 992 | EXPECT_EQ(returnStr2, str2); |
| 993 | |
| 994 | constexpr std::string_view str3{"0pen mc"}; |
| 995 | // \xa0 - the non-breaking space in ISO-8859-1 |
| 996 | constexpr std::array<uint8_t, 7> bufferArr2{0x30, 0x70, 0x65, 0x6e, |
| 997 | 0xa0, 0x6d, 0x63}; |
| 998 | buffer.ptr = bufferArr2.data(); |
| 999 | buffer.length = bufferArr2.size(); |
| 1000 | auto returnStr3 = toString(buffer); |
| 1001 | EXPECT_EQ(returnStr3, str3); |
George Liu | 872f0f6 | 2021-11-25 16:26:16 +0800 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | TEST(Split, allTestCases) |
| 1005 | { |
| 1006 | std::string s1 = "aa,bb,cc,dd"; |
| 1007 | auto results1 = split(s1, ","); |
| 1008 | EXPECT_EQ(results1[0], "aa"); |
| 1009 | EXPECT_EQ(results1[1], "bb"); |
| 1010 | EXPECT_EQ(results1[2], "cc"); |
| 1011 | EXPECT_EQ(results1[3], "dd"); |
| 1012 | |
| 1013 | std::string s2 = "aa||bb||cc||dd"; |
| 1014 | auto results2 = split(s2, "||"); |
| 1015 | EXPECT_EQ(results2[0], "aa"); |
| 1016 | EXPECT_EQ(results2[1], "bb"); |
| 1017 | EXPECT_EQ(results2[2], "cc"); |
| 1018 | EXPECT_EQ(results2[3], "dd"); |
| 1019 | |
| 1020 | std::string s3 = " aa || bb||cc|| dd"; |
| 1021 | auto results3 = split(s3, "||", " "); |
| 1022 | EXPECT_EQ(results3[0], "aa"); |
| 1023 | EXPECT_EQ(results3[1], "bb"); |
| 1024 | EXPECT_EQ(results3[2], "cc"); |
| 1025 | EXPECT_EQ(results3[3], "dd"); |
| 1026 | |
| 1027 | std::string s4 = "aa\\\\bb\\cc\\dd"; |
| 1028 | auto results4 = split(s4, "\\"); |
| 1029 | EXPECT_EQ(results4[0], "aa"); |
| 1030 | EXPECT_EQ(results4[1], "bb"); |
| 1031 | EXPECT_EQ(results4[2], "cc"); |
| 1032 | EXPECT_EQ(results4[3], "dd"); |
| 1033 | |
| 1034 | std::string s5 = "aa\\"; |
| 1035 | auto results5 = split(s5, "\\"); |
| 1036 | EXPECT_EQ(results5[0], "aa"); |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 1037 | } |