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