Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 1 | #include <array> |
| 2 | |
| 3 | #include "libpldm/pdr.h" |
| 4 | #include "libpldm/platform.h" |
| 5 | |
| 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | TEST(PDRAccess, testInit) |
| 9 | { |
| 10 | auto repo = pldm_pdr_init(); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 11 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
| 12 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), 0u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 13 | pldm_pdr_destroy(repo); |
| 14 | } |
| 15 | |
| 16 | TEST(PDRUpdate, testAdd) |
| 17 | { |
| 18 | auto repo = pldm_pdr_init(); |
| 19 | |
| 20 | std::array<uint8_t, 10> data{}; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 21 | auto handle = pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 22 | EXPECT_EQ(handle, 1u); |
| 23 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 24 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), data.size()); |
| 25 | |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 26 | handle = pldm_pdr_add(repo, data.data(), data.size(), 0u, false); |
| 27 | EXPECT_EQ(handle, 2u); |
| 28 | handle = pldm_pdr_add(repo, data.data(), data.size(), 0u, false); |
| 29 | EXPECT_EQ(handle, 3u); |
| 30 | handle = pldm_pdr_add(repo, data.data(), data.size(), htole32(0xdeeddeedu), |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 31 | false); |
Lei YU | 90ff3ed | 2020-03-02 11:16:51 +0800 | [diff] [blame] | 32 | EXPECT_EQ(handle, htole32(0xdeeddeed)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 33 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
| 34 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), data.size() * 4u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 35 | |
| 36 | pldm_pdr_destroy(repo); |
| 37 | } |
| 38 | |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 39 | TEST(PDRUpdate, testRemove) |
| 40 | { |
| 41 | std::array<uint8_t, 10> data{}; |
| 42 | |
| 43 | auto repo = pldm_pdr_init(); |
| 44 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 45 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 46 | pldm_pdr_destroy(repo); |
| 47 | |
| 48 | repo = pldm_pdr_init(); |
| 49 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 50 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 51 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 52 | pldm_pdr_destroy(repo); |
| 53 | |
| 54 | repo = pldm_pdr_init(); |
| 55 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 56 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 57 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 58 | pldm_pdr_destroy(repo); |
| 59 | |
| 60 | repo = pldm_pdr_init(); |
| 61 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 62 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 63 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 64 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 65 | pldm_pdr_destroy(repo); |
| 66 | |
| 67 | repo = pldm_pdr_init(); |
| 68 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 69 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 70 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 71 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 72 | pldm_pdr_destroy(repo); |
| 73 | |
| 74 | repo = pldm_pdr_init(); |
| 75 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 76 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 77 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 78 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 79 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 80 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 81 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 82 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 83 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 84 | pldm_pdr_destroy(repo); |
| 85 | |
| 86 | repo = pldm_pdr_init(); |
| 87 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 88 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 89 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 90 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 91 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 92 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 93 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 94 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 95 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 6u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 96 | pldm_pdr_destroy(repo); |
| 97 | |
| 98 | repo = pldm_pdr_init(); |
| 99 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 100 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 101 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 102 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 103 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 104 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 105 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 106 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 107 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 108 | pldm_pdr_destroy(repo); |
| 109 | |
| 110 | repo = pldm_pdr_init(); |
| 111 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 112 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 113 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 114 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 115 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 116 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 117 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 118 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 119 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 120 | pldm_pdr_destroy(repo); |
| 121 | |
| 122 | repo = pldm_pdr_init(); |
| 123 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 124 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 125 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 126 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 127 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 128 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 129 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 130 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 131 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 132 | pldm_pdr_destroy(repo); |
| 133 | |
| 134 | repo = pldm_pdr_init(); |
| 135 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 136 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 137 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 138 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 139 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 140 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 141 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 142 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 143 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 144 | pldm_pdr_destroy(repo); |
| 145 | |
| 146 | repo = pldm_pdr_init(); |
| 147 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 148 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 149 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 150 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 151 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 152 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 153 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 154 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 155 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 156 | pldm_pdr_destroy(repo); |
| 157 | |
| 158 | repo = pldm_pdr_init(); |
| 159 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 160 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 161 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 162 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 163 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 164 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 165 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 166 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 167 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 168 | pldm_pdr_destroy(repo); |
| 169 | |
| 170 | repo = pldm_pdr_init(); |
| 171 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 172 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 173 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 174 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 175 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 176 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 177 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 178 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 179 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 180 | pldm_pdr_destroy(repo); |
| 181 | |
| 182 | repo = pldm_pdr_init(); |
| 183 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 184 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 185 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 186 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 187 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 188 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 189 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 190 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 191 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 192 | pldm_pdr_destroy(repo); |
| 193 | |
| 194 | repo = pldm_pdr_init(); |
| 195 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 196 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 197 | pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
| 198 | pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
| 199 | pldm_pdr_remove_remote_pdrs(repo); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 200 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 201 | auto handle = pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 202 | EXPECT_EQ(handle, 3u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 203 | handle = pldm_pdr_add(repo, data.data(), data.size(), 0, true); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 204 | EXPECT_EQ(handle, 4u); |
| 205 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 206 | pldm_pdr_destroy(repo); |
| 207 | } |
| 208 | |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 209 | TEST(PDRAccess, testGet) |
| 210 | { |
| 211 | auto repo = pldm_pdr_init(); |
| 212 | |
| 213 | std::array<uint32_t, 10> in{100, 345, 3, 6, 89, 0, 11, 45, 23434, 123123}; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 214 | pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in.data()), sizeof(in), 1, |
| 215 | false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 216 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 217 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in)); |
| 218 | uint32_t size{}; |
| 219 | uint32_t nextRecHdl{}; |
| 220 | uint8_t* outData = nullptr; |
| 221 | auto hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 222 | EXPECT_NE(hdl, nullptr); |
| 223 | EXPECT_EQ(size, sizeof(in)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 224 | EXPECT_EQ(nextRecHdl, 0u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 225 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 226 | outData = nullptr; |
| 227 | |
| 228 | auto hdl2 = pldm_pdr_find_record(repo, 1, &outData, &size, &nextRecHdl); |
| 229 | EXPECT_EQ(hdl, hdl2); |
| 230 | EXPECT_NE(hdl, nullptr); |
| 231 | EXPECT_EQ(size, sizeof(in)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 232 | EXPECT_EQ(nextRecHdl, 0u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 233 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 234 | outData = nullptr; |
| 235 | |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 236 | hdl = pldm_pdr_find_record(repo, htole32(0xdeaddead), &outData, &size, |
| 237 | &nextRecHdl); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 238 | EXPECT_EQ(hdl, nullptr); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 239 | EXPECT_EQ(size, 0u); |
| 240 | EXPECT_EQ(nextRecHdl, 0u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 241 | EXPECT_EQ(outData, nullptr); |
| 242 | outData = nullptr; |
| 243 | |
| 244 | std::array<uint32_t, 10> in2{1000, 3450, 30, 60, 890, |
| 245 | 0, 110, 450, 234034, 123123}; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 246 | pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 2, |
| 247 | false); |
| 248 | pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 3, |
| 249 | false); |
| 250 | pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 4, |
| 251 | true); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 252 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 253 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in2) * 4); |
| 254 | hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 255 | EXPECT_NE(hdl, nullptr); |
| 256 | EXPECT_EQ(size, sizeof(in)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 257 | EXPECT_EQ(nextRecHdl, 2u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 258 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 259 | outData = nullptr; |
| 260 | hdl2 = pldm_pdr_find_record(repo, 1, &outData, &size, &nextRecHdl); |
| 261 | EXPECT_EQ(hdl, hdl2); |
| 262 | EXPECT_NE(hdl, nullptr); |
| 263 | EXPECT_EQ(size, sizeof(in)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 264 | EXPECT_EQ(nextRecHdl, 2u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 265 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 266 | outData = nullptr; |
| 267 | hdl = pldm_pdr_find_record(repo, 2, &outData, &size, &nextRecHdl); |
| 268 | EXPECT_NE(hdl, nullptr); |
| 269 | EXPECT_EQ(size, sizeof(in2)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 270 | EXPECT_EQ(nextRecHdl, 3u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 271 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 272 | outData = nullptr; |
| 273 | hdl = pldm_pdr_find_record(repo, 3, &outData, &size, &nextRecHdl); |
| 274 | EXPECT_NE(hdl, nullptr); |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 275 | EXPECT_EQ(pldm_pdr_record_is_remote(hdl), false); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 276 | EXPECT_EQ(size, sizeof(in2)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 277 | EXPECT_EQ(nextRecHdl, 4u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 278 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 279 | outData = nullptr; |
| 280 | hdl = pldm_pdr_find_record(repo, 4, &outData, &size, &nextRecHdl); |
| 281 | EXPECT_NE(hdl, nullptr); |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 282 | EXPECT_EQ(pldm_pdr_record_is_remote(hdl), true); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 283 | EXPECT_EQ(size, sizeof(in2)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 284 | EXPECT_EQ(nextRecHdl, 0u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 285 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 286 | outData = nullptr; |
| 287 | |
| 288 | pldm_pdr_destroy(repo); |
| 289 | } |
| 290 | |
| 291 | TEST(PDRAccess, testGetNext) |
| 292 | { |
| 293 | auto repo = pldm_pdr_init(); |
| 294 | |
| 295 | std::array<uint32_t, 10> in{100, 345, 3, 6, 89, 0, 11, 45, 23434, 123123}; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 296 | pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in.data()), sizeof(in), 1, |
| 297 | false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 298 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 299 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in)); |
| 300 | uint32_t size{}; |
| 301 | uint32_t nextRecHdl{}; |
| 302 | uint8_t* outData = nullptr; |
| 303 | auto hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 304 | EXPECT_NE(hdl, nullptr); |
| 305 | EXPECT_EQ(size, sizeof(in)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 306 | EXPECT_EQ(nextRecHdl, 0u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 307 | EXPECT_EQ(memcmp(outData, in.data(), sizeof(in)), 0); |
| 308 | outData = nullptr; |
| 309 | |
| 310 | std::array<uint32_t, 10> in2{1000, 3450, 30, 60, 890, |
| 311 | 0, 110, 450, 234034, 123123}; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 312 | pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 2, |
| 313 | false); |
| 314 | pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 3, |
| 315 | false); |
| 316 | pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 4, |
| 317 | false); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 318 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 319 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in2) * 4); |
| 320 | hdl = pldm_pdr_get_next_record(repo, hdl, &outData, &size, &nextRecHdl); |
| 321 | EXPECT_NE(hdl, nullptr); |
| 322 | EXPECT_EQ(size, sizeof(in2)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 323 | EXPECT_EQ(nextRecHdl, 3u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 324 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 325 | outData = nullptr; |
| 326 | hdl = pldm_pdr_get_next_record(repo, hdl, &outData, &size, &nextRecHdl); |
| 327 | EXPECT_NE(hdl, nullptr); |
| 328 | EXPECT_EQ(size, sizeof(in2)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 329 | EXPECT_EQ(nextRecHdl, 4u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 330 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 331 | outData = nullptr; |
| 332 | hdl = pldm_pdr_get_next_record(repo, hdl, &outData, &size, &nextRecHdl); |
| 333 | EXPECT_NE(hdl, nullptr); |
| 334 | EXPECT_EQ(size, sizeof(in2)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 335 | EXPECT_EQ(nextRecHdl, 0u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 336 | EXPECT_EQ(memcmp(outData, in2.data(), sizeof(in2)), 0); |
| 337 | outData = nullptr; |
| 338 | |
| 339 | pldm_pdr_destroy(repo); |
| 340 | } |
| 341 | |
| 342 | TEST(PDRAccess, testFindByType) |
| 343 | { |
| 344 | auto repo = pldm_pdr_init(); |
| 345 | |
| 346 | std::array<uint8_t, sizeof(pldm_pdr_hdr)> data{}; |
| 347 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(data.data()); |
| 348 | hdr->type = 1; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 349 | auto first = pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 350 | hdr->type = 2; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 351 | auto second = pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 352 | hdr->type = 3; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 353 | auto third = pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 354 | hdr->type = 4; |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 355 | auto fourth = pldm_pdr_add(repo, data.data(), data.size(), 0, false); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 356 | |
| 357 | uint8_t* outData = nullptr; |
| 358 | uint32_t size{}; |
| 359 | auto firstRec = |
| 360 | pldm_pdr_find_record_by_type(repo, 1, nullptr, &outData, &size); |
| 361 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, firstRec), first); |
| 362 | outData = nullptr; |
| 363 | auto secondRec = |
| 364 | pldm_pdr_find_record_by_type(repo, 2, nullptr, &outData, &size); |
| 365 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, secondRec), second); |
| 366 | outData = nullptr; |
| 367 | auto thirdRec = |
| 368 | pldm_pdr_find_record_by_type(repo, 3, nullptr, &outData, &size); |
| 369 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, thirdRec), third); |
| 370 | outData = nullptr; |
| 371 | auto fourthRec = |
| 372 | pldm_pdr_find_record_by_type(repo, 4, nullptr, &outData, &size); |
| 373 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, fourthRec), fourth); |
| 374 | outData = nullptr; |
| 375 | auto fifthRec = |
| 376 | pldm_pdr_find_record_by_type(repo, 5, nullptr, &outData, &size); |
| 377 | EXPECT_EQ(fifthRec, nullptr); |
| 378 | EXPECT_EQ(outData, nullptr); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 379 | EXPECT_EQ(size, 0u); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 380 | |
| 381 | auto rec = |
| 382 | pldm_pdr_find_record_by_type(repo, 3, secondRec, &outData, &size); |
| 383 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, rec), third); |
| 384 | outData = nullptr; |
| 385 | rec = pldm_pdr_find_record_by_type(repo, 4, secondRec, &outData, &size); |
| 386 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, rec), fourth); |
| 387 | outData = nullptr; |
| 388 | rec = pldm_pdr_find_record_by_type(repo, 2, firstRec, &outData, &size); |
| 389 | EXPECT_EQ(pldm_pdr_get_record_handle(repo, rec), second); |
| 390 | outData = nullptr; |
| 391 | |
| 392 | pldm_pdr_destroy(repo); |
| 393 | } |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 394 | |
| 395 | TEST(PDRUpdate, testAddFruRecordSet) |
| 396 | { |
| 397 | auto repo = pldm_pdr_init(); |
| 398 | |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 399 | auto handle = pldm_pdr_add_fru_record_set(repo, 1, 10, 1, 0, 100, 0); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 400 | EXPECT_EQ(handle, 1u); |
| 401 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 402 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), |
| 403 | sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set)); |
| 404 | uint32_t size{}; |
| 405 | uint32_t nextRecHdl{}; |
| 406 | uint8_t* outData = nullptr; |
| 407 | auto hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl); |
| 408 | EXPECT_NE(hdl, nullptr); |
| 409 | EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 410 | EXPECT_EQ(nextRecHdl, 0u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 411 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(outData); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 412 | EXPECT_EQ(hdr->version, 1u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 413 | EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 414 | EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set))); |
| 415 | EXPECT_EQ(hdr->record_handle, htole32(1)); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 416 | pldm_pdr_fru_record_set* fru = reinterpret_cast<pldm_pdr_fru_record_set*>( |
| 417 | outData + sizeof(pldm_pdr_hdr)); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 418 | EXPECT_EQ(fru->terminus_handle, htole16(1)); |
| 419 | EXPECT_EQ(fru->fru_rsi, htole16(10)); |
| 420 | EXPECT_EQ(fru->entity_type, htole16(1)); |
| 421 | EXPECT_EQ(fru->entity_instance_num, htole16(0)); |
| 422 | EXPECT_EQ(fru->container_id, htole16(100)); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 423 | outData = nullptr; |
| 424 | |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 425 | handle = pldm_pdr_add_fru_record_set(repo, 2, 11, 2, 1, 101, 0); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 426 | EXPECT_EQ(handle, 2u); |
| 427 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 428 | EXPECT_EQ(pldm_pdr_get_repo_size(repo), |
| 429 | 2 * (sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set))); |
| 430 | hdl = pldm_pdr_find_record(repo, 2, &outData, &size, &nextRecHdl); |
| 431 | EXPECT_NE(hdl, nullptr); |
| 432 | EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 433 | EXPECT_EQ(nextRecHdl, 0u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 434 | hdr = reinterpret_cast<pldm_pdr_hdr*>(outData); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 435 | EXPECT_EQ(hdr->version, 1u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 436 | EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 437 | EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set))); |
| 438 | EXPECT_EQ(hdr->record_handle, htole32(2)); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 439 | fru = reinterpret_cast<pldm_pdr_fru_record_set*>(outData + |
| 440 | sizeof(pldm_pdr_hdr)); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 441 | EXPECT_EQ(fru->terminus_handle, htole16(2)); |
| 442 | EXPECT_EQ(fru->fru_rsi, htole16(11)); |
| 443 | EXPECT_EQ(fru->entity_type, htole16(2)); |
| 444 | EXPECT_EQ(fru->entity_instance_num, htole16(1)); |
| 445 | EXPECT_EQ(fru->container_id, htole16(101)); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 446 | outData = nullptr; |
| 447 | |
| 448 | hdl = pldm_pdr_find_record(repo, 1, &outData, &size, &nextRecHdl); |
| 449 | EXPECT_NE(hdl, nullptr); |
| 450 | EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set)); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 451 | EXPECT_EQ(nextRecHdl, 2u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 452 | hdr = reinterpret_cast<pldm_pdr_hdr*>(outData); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 453 | EXPECT_EQ(hdr->version, 1u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 454 | EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 455 | EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set))); |
| 456 | EXPECT_EQ(hdr->record_handle, htole32(1)); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 457 | fru = reinterpret_cast<pldm_pdr_fru_record_set*>(outData + |
| 458 | sizeof(pldm_pdr_hdr)); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 459 | EXPECT_EQ(fru->terminus_handle, htole16(1)); |
| 460 | EXPECT_EQ(fru->fru_rsi, htole16(10)); |
| 461 | EXPECT_EQ(fru->entity_type, htole16(1)); |
| 462 | EXPECT_EQ(fru->entity_instance_num, htole16(0)); |
| 463 | EXPECT_EQ(fru->container_id, htole16(100)); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 464 | outData = nullptr; |
| 465 | |
| 466 | pldm_pdr_destroy(repo); |
| 467 | } |
| 468 | |
| 469 | TEST(PDRUpdate, tesFindtFruRecordSet) |
| 470 | { |
| 471 | auto repo = pldm_pdr_init(); |
| 472 | |
| 473 | uint16_t terminusHdl{}; |
| 474 | uint16_t entityType{}; |
| 475 | uint16_t entityInstanceNum{}; |
| 476 | uint16_t containerId{}; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 477 | auto first = pldm_pdr_add_fru_record_set(repo, 1, 1, 1, 0, 100, 1); |
| 478 | auto second = pldm_pdr_add_fru_record_set(repo, 1, 2, 1, 1, 100, 2); |
| 479 | auto third = pldm_pdr_add_fru_record_set(repo, 1, 3, 1, 2, 100, 3); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 480 | EXPECT_EQ(first, pldm_pdr_get_record_handle( |
| 481 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 482 | repo, 1, &terminusHdl, &entityType, |
| 483 | &entityInstanceNum, &containerId))); |
| 484 | EXPECT_EQ(second, pldm_pdr_get_record_handle( |
| 485 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 486 | repo, 2, &terminusHdl, &entityType, |
| 487 | &entityInstanceNum, &containerId))); |
| 488 | EXPECT_EQ(third, pldm_pdr_get_record_handle( |
| 489 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 490 | repo, 3, &terminusHdl, &entityType, |
| 491 | &entityInstanceNum, &containerId))); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 492 | EXPECT_EQ(terminusHdl, 1u); |
| 493 | EXPECT_EQ(entityType, 1u); |
| 494 | EXPECT_EQ(entityInstanceNum, 2u); |
| 495 | EXPECT_EQ(containerId, 100u); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 496 | EXPECT_EQ(nullptr, pldm_pdr_fru_record_set_find_by_rsi( |
| 497 | repo, 4, &terminusHdl, &entityType, |
| 498 | &entityInstanceNum, &containerId)); |
| 499 | |
| 500 | pldm_pdr_destroy(repo); |
| 501 | } |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 502 | |
| 503 | TEST(EntityAssociationPDR, testInit) |
| 504 | { |
| 505 | auto tree = pldm_entity_association_tree_init(); |
| 506 | EXPECT_NE(tree, nullptr); |
| 507 | pldm_entity_association_tree_destroy(tree); |
| 508 | } |
| 509 | |
| 510 | TEST(EntityAssociationPDR, testBuild) |
| 511 | { |
| 512 | // 1 |
| 513 | // | |
| 514 | // 2--3--4 |
| 515 | // | |
| 516 | // 5--6--7 |
| 517 | // | | |
| 518 | // 9 8 |
| 519 | |
| 520 | pldm_entity entities[9]{}; |
| 521 | |
| 522 | entities[0].entity_type = 1; |
| 523 | entities[1].entity_type = 2; |
| 524 | entities[2].entity_type = 2; |
| 525 | entities[3].entity_type = 3; |
| 526 | entities[4].entity_type = 4; |
| 527 | entities[5].entity_type = 5; |
| 528 | entities[6].entity_type = 5; |
| 529 | entities[7].entity_type = 6; |
| 530 | entities[8].entity_type = 7; |
| 531 | |
| 532 | auto tree = pldm_entity_association_tree_init(); |
| 533 | |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 534 | auto l1 = pldm_entity_association_tree_add( |
| 535 | tree, &entities[0], 0xFFFF, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 536 | EXPECT_NE(l1, nullptr); |
| 537 | auto l2a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 538 | tree, &entities[1], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 539 | EXPECT_NE(l2a, nullptr); |
| 540 | auto l2b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 541 | tree, &entities[2], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 542 | EXPECT_NE(l2b, nullptr); |
| 543 | auto l2c = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 544 | tree, &entities[3], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 545 | EXPECT_NE(l2c, nullptr); |
| 546 | auto l3a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 547 | tree, &entities[4], 0xFFFF, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 548 | EXPECT_NE(l3a, nullptr); |
| 549 | auto l3b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 550 | tree, &entities[5], 0xFFFF, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 551 | EXPECT_NE(l3b, nullptr); |
| 552 | auto l3c = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 553 | tree, &entities[6], 0xFFFF, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 554 | EXPECT_NE(l3b, nullptr); |
| 555 | auto l4a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 556 | tree, &entities[7], 0xFFFF, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 557 | EXPECT_NE(l4a, nullptr); |
| 558 | auto l4b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 559 | tree, &entities[8], 0xFFFF, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 560 | EXPECT_NE(l4b, nullptr); |
| 561 | |
| 562 | EXPECT_EQ(pldm_entity_is_node_parent(l1), true); |
| 563 | EXPECT_EQ(pldm_entity_is_node_parent(l2a), true); |
| 564 | EXPECT_EQ(pldm_entity_is_node_parent(l3a), true); |
| 565 | EXPECT_EQ(pldm_entity_is_node_parent(l3b), true); |
| 566 | |
| 567 | EXPECT_EQ(pldm_entity_is_node_parent(l2b), false); |
| 568 | EXPECT_EQ(pldm_entity_is_node_parent(l2c), false); |
| 569 | EXPECT_EQ(pldm_entity_is_node_parent(l3c), false); |
| 570 | EXPECT_EQ(pldm_entity_is_node_parent(l4a), false); |
| 571 | EXPECT_EQ(pldm_entity_is_node_parent(l4b), false); |
| 572 | |
George Liu | fe77eea | 2021-04-28 15:08:07 +0800 | [diff] [blame] | 573 | EXPECT_EQ(pldm_entity_get_parent(l1), nullptr); |
| 574 | |
| 575 | EXPECT_EQ(pldm_entity_get_parent(l2a), l1); |
| 576 | EXPECT_EQ(pldm_entity_get_parent(l2b), l1); |
| 577 | EXPECT_EQ(pldm_entity_get_parent(l2c), l1); |
| 578 | |
| 579 | EXPECT_EQ(pldm_entity_get_parent(l3a), l2a); |
| 580 | EXPECT_EQ(pldm_entity_get_parent(l3b), l2a); |
| 581 | EXPECT_EQ(pldm_entity_get_parent(l3c), l2a); |
| 582 | |
| 583 | EXPECT_EQ(pldm_entity_get_parent(l4a), l3a); |
| 584 | |
| 585 | EXPECT_EQ(pldm_entity_get_parent(l4b), l3b); |
| 586 | |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 587 | size_t num{}; |
| 588 | pldm_entity* out = nullptr; |
| 589 | pldm_entity_association_tree_visit(tree, &out, &num); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 590 | EXPECT_EQ(num, 9u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 591 | |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 592 | EXPECT_EQ(out[0].entity_type, 1u); |
| 593 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 594 | EXPECT_EQ(out[0].entity_container_id, 0u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 595 | |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 596 | EXPECT_EQ(out[1].entity_type, 2u); |
| 597 | EXPECT_EQ(out[1].entity_instance_num, 1u); |
| 598 | EXPECT_EQ(out[1].entity_container_id, 1u); |
| 599 | EXPECT_EQ(out[2].entity_type, 2u); |
| 600 | EXPECT_EQ(out[2].entity_instance_num, 2u); |
| 601 | EXPECT_EQ(out[2].entity_container_id, 1u); |
| 602 | EXPECT_EQ(out[3].entity_type, 3u); |
| 603 | EXPECT_EQ(out[3].entity_instance_num, 1u); |
| 604 | EXPECT_EQ(out[3].entity_container_id, 1u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 605 | |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 606 | EXPECT_EQ(out[4].entity_type, 4u); |
| 607 | EXPECT_EQ(out[4].entity_instance_num, 1u); |
| 608 | EXPECT_EQ(out[4].entity_container_id, 2u); |
| 609 | EXPECT_EQ(out[5].entity_type, 5u); |
| 610 | EXPECT_EQ(out[5].entity_instance_num, 1u); |
| 611 | EXPECT_EQ(out[5].entity_container_id, 2u); |
| 612 | EXPECT_EQ(out[6].entity_type, 5u); |
| 613 | EXPECT_EQ(out[6].entity_instance_num, 2u); |
| 614 | EXPECT_EQ(out[6].entity_container_id, 2u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 615 | |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 616 | EXPECT_EQ(out[7].entity_type, 7u); |
| 617 | EXPECT_EQ(out[7].entity_instance_num, 1u); |
| 618 | EXPECT_EQ(out[7].entity_container_id, 4u); |
| 619 | EXPECT_EQ(out[8].entity_type, 6u); |
| 620 | EXPECT_EQ(out[8].entity_instance_num, 1u); |
| 621 | EXPECT_EQ(out[8].entity_container_id, 3u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 622 | |
| 623 | free(out); |
George Liu | d9855ab | 2021-05-13 09:41:31 +0800 | [diff] [blame] | 624 | |
| 625 | pldm_entity p1 = pldm_entity_extract(l1); |
| 626 | EXPECT_EQ(p1.entity_type, 1u); |
| 627 | EXPECT_EQ(p1.entity_instance_num, 1u); |
| 628 | EXPECT_EQ(p1.entity_container_id, 0u); |
| 629 | |
| 630 | pldm_entity p2a = pldm_entity_extract(l2a); |
| 631 | EXPECT_EQ(p2a.entity_type, 2u); |
| 632 | EXPECT_EQ(p2a.entity_instance_num, 1u); |
| 633 | EXPECT_EQ(p2a.entity_container_id, 1u); |
| 634 | pldm_entity p2b = pldm_entity_extract(l2b); |
| 635 | EXPECT_EQ(p2b.entity_type, 2u); |
| 636 | EXPECT_EQ(p2b.entity_instance_num, 2u); |
| 637 | EXPECT_EQ(p2b.entity_container_id, 1u); |
| 638 | pldm_entity p2c = pldm_entity_extract(l2c); |
| 639 | EXPECT_EQ(p2c.entity_type, 3u); |
| 640 | EXPECT_EQ(p2c.entity_instance_num, 1u); |
| 641 | EXPECT_EQ(p2c.entity_container_id, 1u); |
| 642 | |
| 643 | pldm_entity p3a = pldm_entity_extract(l3a); |
| 644 | EXPECT_EQ(p3a.entity_type, 4u); |
| 645 | EXPECT_EQ(p3a.entity_instance_num, 1u); |
| 646 | EXPECT_EQ(p3a.entity_container_id, 2u); |
| 647 | pldm_entity p3b = pldm_entity_extract(l3b); |
| 648 | EXPECT_EQ(p3b.entity_type, 5u); |
| 649 | EXPECT_EQ(p3b.entity_instance_num, 1u); |
| 650 | EXPECT_EQ(p3b.entity_container_id, 2u); |
| 651 | pldm_entity p3c = pldm_entity_extract(l3c); |
| 652 | EXPECT_EQ(p3c.entity_type, 5u); |
| 653 | EXPECT_EQ(p3c.entity_instance_num, 2u); |
| 654 | EXPECT_EQ(p3c.entity_container_id, 2u); |
| 655 | |
| 656 | pldm_entity p4a = pldm_entity_extract(l4a); |
| 657 | EXPECT_EQ(p4a.entity_type, 6u); |
| 658 | EXPECT_EQ(p4a.entity_instance_num, 1u); |
| 659 | EXPECT_EQ(p4a.entity_container_id, 3u); |
| 660 | pldm_entity p4b = pldm_entity_extract(l4b); |
| 661 | EXPECT_EQ(p4b.entity_type, 7u); |
| 662 | EXPECT_EQ(p4b.entity_instance_num, 1u); |
| 663 | EXPECT_EQ(p4b.entity_container_id, 4u); |
| 664 | |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 665 | pldm_entity_association_tree_destroy(tree); |
| 666 | } |
| 667 | |
| 668 | TEST(EntityAssociationPDR, testSpecialTrees) |
| 669 | { |
| 670 | pldm_entity entities[3]{}; |
| 671 | |
| 672 | entities[0].entity_type = 1; |
| 673 | entities[1].entity_type = 2; |
| 674 | entities[2].entity_type = 1; |
| 675 | |
| 676 | // A |
| 677 | auto tree = pldm_entity_association_tree_init(); |
| 678 | auto node = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 679 | tree, &entities[0], 0xFFFF, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 680 | EXPECT_NE(node, nullptr); |
| 681 | size_t num{}; |
| 682 | pldm_entity* out = nullptr; |
| 683 | pldm_entity_association_tree_visit(tree, &out, &num); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 684 | EXPECT_EQ(num, 1u); |
| 685 | EXPECT_EQ(out[0].entity_type, 1u); |
| 686 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 687 | EXPECT_EQ(out[0].entity_container_id, 0u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 688 | free(out); |
| 689 | pldm_entity_association_tree_destroy(tree); |
| 690 | |
| 691 | // A-A-A |
| 692 | tree = pldm_entity_association_tree_init(); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 693 | node = pldm_entity_association_tree_add(tree, &entities[0], 0xFFFF, nullptr, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 694 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 695 | EXPECT_NE(node, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 696 | node = pldm_entity_association_tree_add(tree, &entities[1], 0xFFFF, nullptr, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 697 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 698 | EXPECT_NE(node, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 699 | node = pldm_entity_association_tree_add(tree, &entities[2], 0xFFFF, nullptr, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 700 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 701 | EXPECT_NE(node, nullptr); |
| 702 | pldm_entity_association_tree_visit(tree, &out, &num); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 703 | EXPECT_EQ(num, 3u); |
| 704 | EXPECT_EQ(out[0].entity_type, 1u); |
| 705 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 706 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 707 | EXPECT_EQ(out[1].entity_type, 1u); |
| 708 | EXPECT_EQ(out[1].entity_instance_num, 2u); |
| 709 | EXPECT_EQ(out[1].entity_container_id, 0u); |
| 710 | EXPECT_EQ(out[2].entity_type, 2u); |
| 711 | EXPECT_EQ(out[2].entity_instance_num, 1u); |
| 712 | EXPECT_EQ(out[2].entity_container_id, 0u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 713 | free(out); |
| 714 | pldm_entity_association_tree_destroy(tree); |
| 715 | |
| 716 | // A |
| 717 | // | |
| 718 | // A |
| 719 | // | |
| 720 | // A |
| 721 | tree = pldm_entity_association_tree_init(); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 722 | node = pldm_entity_association_tree_add(tree, &entities[0], 0xFFFF, nullptr, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 723 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 724 | EXPECT_NE(node, nullptr); |
| 725 | auto node1 = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 726 | tree, &entities[1], 0xFFFF, node, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 727 | EXPECT_NE(node1, nullptr); |
| 728 | auto node2 = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 729 | tree, &entities[2], 0xFFFF, node1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 730 | EXPECT_NE(node2, nullptr); |
| 731 | pldm_entity_association_tree_visit(tree, &out, &num); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 732 | EXPECT_EQ(num, 3u); |
| 733 | EXPECT_EQ(out[0].entity_type, 1u); |
| 734 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 735 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 736 | EXPECT_EQ(out[1].entity_type, 2u); |
| 737 | EXPECT_EQ(out[1].entity_instance_num, 1u); |
| 738 | EXPECT_EQ(out[1].entity_container_id, 1u); |
| 739 | EXPECT_EQ(out[2].entity_type, 1u); |
| 740 | EXPECT_EQ(out[2].entity_instance_num, 1u); |
| 741 | EXPECT_EQ(out[2].entity_container_id, 2u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 742 | free(out); |
| 743 | pldm_entity_association_tree_destroy(tree); |
| 744 | |
| 745 | // A-A |
| 746 | // | |
| 747 | // A-A |
| 748 | tree = pldm_entity_association_tree_init(); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 749 | node = pldm_entity_association_tree_add(tree, &entities[0], 0xFFFF, nullptr, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 750 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 751 | EXPECT_NE(node, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 752 | node = pldm_entity_association_tree_add(tree, &entities[0], 0xFFFF, nullptr, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 753 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 754 | EXPECT_NE(node, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 755 | node1 = pldm_entity_association_tree_add(tree, &entities[1], 0xFFFF, node, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 756 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 757 | EXPECT_NE(node1, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 758 | node2 = pldm_entity_association_tree_add(tree, &entities[2], 0xFFFF, node, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 759 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 760 | EXPECT_NE(node2, nullptr); |
| 761 | pldm_entity_association_tree_visit(tree, &out, &num); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 762 | EXPECT_EQ(num, 4u); |
| 763 | EXPECT_EQ(out[0].entity_type, 1u); |
| 764 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 765 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 766 | EXPECT_EQ(out[1].entity_type, 1u); |
| 767 | EXPECT_EQ(out[1].entity_instance_num, 2u); |
| 768 | EXPECT_EQ(out[1].entity_container_id, 0u); |
| 769 | EXPECT_EQ(out[2].entity_type, 2u); |
| 770 | EXPECT_EQ(out[2].entity_instance_num, 1u); |
| 771 | EXPECT_EQ(out[2].entity_container_id, 1u); |
| 772 | EXPECT_EQ(out[3].entity_type, 1u); |
| 773 | EXPECT_EQ(out[3].entity_instance_num, 1u); |
| 774 | EXPECT_EQ(out[3].entity_container_id, 1u); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 775 | free(out); |
| 776 | pldm_entity_association_tree_destroy(tree); |
| 777 | } |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 778 | |
| 779 | TEST(EntityAssociationPDR, testPDR) |
| 780 | { |
| 781 | // e = entity type, c = container id, i = instance num |
| 782 | |
| 783 | // INPUT |
| 784 | // 1(e=1)--1a(e=2) |
| 785 | // | |
| 786 | // 2(e=2)--3(e=2)--4(e=2)--5(e=3) |
| 787 | // | |
| 788 | // 6(e=4)--7(e=5)--8(e=5)--9(e=5) |
| 789 | // | | |
| 790 | // 11(e=6) 10(e=7) |
| 791 | |
| 792 | // Expected OUTPUT |
| 793 | // 1(e=1,c=0,i=1) |
| 794 | // | |
| 795 | // 2(e=2,c=1,i=1)--3(e=2,c=1,i=2)--4(e=3,c=1,i=1)--5(e=3,c=1,i=2) |
| 796 | // | |
| 797 | // 6(e=4,c=2,i=1)--7(e=5,c=2,i=1)--8(e=5,c=2,i=2)--9(e=5,c=2,i=3) |
| 798 | // | | |
| 799 | // 10(e=6,c=3,i=1) 11(e=7,c=4,i=1) |
| 800 | pldm_entity entities[11]{}; |
| 801 | |
| 802 | entities[0].entity_type = 1; |
| 803 | entities[1].entity_type = 2; |
| 804 | entities[2].entity_type = 3; |
| 805 | entities[3].entity_type = 2; |
| 806 | entities[4].entity_type = 3; |
| 807 | entities[5].entity_type = 4; |
| 808 | entities[6].entity_type = 5; |
| 809 | entities[7].entity_type = 5; |
| 810 | entities[8].entity_type = 5; |
| 811 | entities[9].entity_type = 6; |
| 812 | entities[10].entity_type = 7; |
| 813 | |
| 814 | auto tree = pldm_entity_association_tree_init(); |
| 815 | |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 816 | auto l1 = pldm_entity_association_tree_add( |
| 817 | tree, &entities[0], 0xFFFF, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 818 | EXPECT_NE(l1, nullptr); |
| 819 | auto l1a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 820 | tree, &entities[1], 0xFFFF, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 821 | EXPECT_NE(l1a, nullptr); |
| 822 | |
| 823 | auto l2a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 824 | tree, &entities[1], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 825 | EXPECT_NE(l2a, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 826 | auto l2b = pldm_entity_association_tree_add(tree, &entities[2], 0xFFFF, l1, |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 827 | PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 828 | EXPECT_NE(l2b, nullptr); |
| 829 | auto l2c = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 830 | tree, &entities[3], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 831 | EXPECT_NE(l2c, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 832 | auto l2d = pldm_entity_association_tree_add(tree, &entities[4], 0xFFFF, l1, |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 833 | PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 834 | EXPECT_NE(l2d, nullptr); |
| 835 | |
| 836 | auto l3a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 837 | tree, &entities[5], 0xFFFF, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 838 | EXPECT_NE(l3a, nullptr); |
| 839 | auto l3b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 840 | tree, &entities[6], 0xFFFF, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 841 | EXPECT_NE(l3b, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 842 | auto l3c = pldm_entity_association_tree_add(tree, &entities[7], 0xFFFF, l2a, |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 843 | PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 844 | EXPECT_NE(l3c, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 845 | auto l3d = pldm_entity_association_tree_add(tree, &entities[8], 0xFFFF, l2a, |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 846 | PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 847 | EXPECT_NE(l3d, nullptr); |
| 848 | |
| 849 | auto l4a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 850 | tree, &entities[9], 0xFFFF, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 851 | EXPECT_NE(l4a, nullptr); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 852 | auto l4b = pldm_entity_association_tree_add( |
| 853 | tree, &entities[10], 0xFFFF, l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 854 | EXPECT_NE(l4b, nullptr); |
| 855 | |
| 856 | EXPECT_EQ(pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL), |
| 857 | 2); |
| 858 | EXPECT_EQ(pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_LOGICAL), |
| 859 | 2); |
| 860 | EXPECT_EQ( |
| 861 | pldm_entity_get_num_children(l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL), 2); |
| 862 | EXPECT_EQ( |
| 863 | pldm_entity_get_num_children(l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL), 0); |
| 864 | EXPECT_EQ(pldm_entity_get_num_children(l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL), |
| 865 | 1); |
| 866 | |
| 867 | auto repo = pldm_pdr_init(); |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 868 | pldm_entity_association_pdr_add(tree, repo, false); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 869 | |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 870 | EXPECT_EQ(pldm_pdr_get_record_count(repo), 6u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 871 | |
| 872 | uint32_t currRecHandle{}; |
| 873 | uint32_t nextRecHandle{}; |
| 874 | uint8_t* data = nullptr; |
| 875 | uint32_t size{}; |
| 876 | uint32_t commonSize = sizeof(struct pldm_pdr_hdr) + sizeof(uint16_t) + |
| 877 | sizeof(uint8_t) + sizeof(pldm_entity) + |
| 878 | sizeof(uint8_t); |
| 879 | |
| 880 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 881 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 882 | l1, PLDM_ENTITY_ASSOCIAION_LOGICAL) * |
| 883 | sizeof(pldm_entity))); |
| 884 | uint8_t* start = data; |
| 885 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 886 | EXPECT_EQ(le32toh(hdr->record_handle), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 887 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 888 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 889 | start += sizeof(pldm_pdr_hdr); |
| 890 | uint16_t* containerId = reinterpret_cast<uint16_t*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 891 | EXPECT_EQ(le16toh(*containerId), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 892 | start += sizeof(uint16_t); |
| 893 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 894 | start += sizeof(uint8_t); |
| 895 | pldm_entity* entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 896 | EXPECT_EQ(le16toh(entity->entity_type), 1u); |
| 897 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 898 | EXPECT_EQ(le16toh(entity->entity_container_id), 0u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 899 | start += sizeof(pldm_entity); |
| 900 | EXPECT_EQ(*start, |
| 901 | pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_LOGICAL)); |
| 902 | start += sizeof(uint8_t); |
| 903 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 904 | EXPECT_EQ(le16toh(entity->entity_type), 3u); |
| 905 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 906 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 907 | start += sizeof(pldm_entity); |
| 908 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 909 | EXPECT_EQ(le16toh(entity->entity_type), 3u); |
| 910 | EXPECT_EQ(le16toh(entity->entity_instance_num), 2u); |
| 911 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 912 | start += sizeof(pldm_entity); |
| 913 | |
| 914 | currRecHandle = nextRecHandle; |
| 915 | |
| 916 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 917 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 918 | l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL) * |
| 919 | sizeof(pldm_entity))); |
| 920 | start = data; |
| 921 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 922 | EXPECT_EQ(le32toh(hdr->record_handle), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 923 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 924 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 925 | start += sizeof(pldm_pdr_hdr); |
| 926 | containerId = reinterpret_cast<uint16_t*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 927 | EXPECT_EQ(le16toh(*containerId), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 928 | start += sizeof(uint16_t); |
| 929 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 930 | start += sizeof(uint8_t); |
| 931 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 932 | EXPECT_EQ(le16toh(entity->entity_type), 1u); |
| 933 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 934 | EXPECT_EQ(le16toh(entity->entity_container_id), 0u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 935 | start += sizeof(pldm_entity); |
| 936 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 937 | l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL)); |
| 938 | start += sizeof(uint8_t); |
| 939 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 940 | EXPECT_EQ(le16toh(entity->entity_type), 2u); |
| 941 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 942 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 943 | start += sizeof(pldm_entity); |
| 944 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 945 | EXPECT_EQ(le16toh(entity->entity_type), 2u); |
| 946 | EXPECT_EQ(le16toh(entity->entity_instance_num), 2u); |
| 947 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 948 | start += sizeof(pldm_entity); |
| 949 | |
| 950 | currRecHandle = nextRecHandle; |
| 951 | |
| 952 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 953 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 954 | l2a, PLDM_ENTITY_ASSOCIAION_LOGICAL) * |
| 955 | sizeof(pldm_entity))); |
| 956 | start = data; |
| 957 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 958 | EXPECT_EQ(le32toh(hdr->record_handle), 3u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 959 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 960 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 961 | start += sizeof(pldm_pdr_hdr); |
| 962 | containerId = reinterpret_cast<uint16_t*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 963 | EXPECT_EQ(le16toh(*containerId), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 964 | start += sizeof(uint16_t); |
| 965 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 966 | start += sizeof(uint8_t); |
| 967 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 968 | EXPECT_EQ(le16toh(entity->entity_type), 2u); |
| 969 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 970 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 971 | start += sizeof(pldm_entity); |
| 972 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 973 | l2a, PLDM_ENTITY_ASSOCIAION_LOGICAL)); |
| 974 | start += sizeof(uint8_t); |
| 975 | entity = reinterpret_cast<pldm_entity*>(start); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 976 | EXPECT_EQ(le16toh(entity->entity_type), 5); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 977 | EXPECT_EQ(le16toh(entity->entity_instance_num), 2u); |
| 978 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 979 | start += sizeof(pldm_entity); |
| 980 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 981 | EXPECT_EQ(le16toh(entity->entity_type), 5u); |
| 982 | EXPECT_EQ(le16toh(entity->entity_instance_num), 3u); |
| 983 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 984 | start += sizeof(pldm_entity); |
| 985 | |
| 986 | currRecHandle = nextRecHandle; |
| 987 | |
| 988 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 989 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 990 | l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL) * |
| 991 | sizeof(pldm_entity))); |
| 992 | start = data; |
| 993 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 994 | EXPECT_EQ(le32toh(hdr->record_handle), 4u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 995 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 996 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 997 | start += sizeof(pldm_pdr_hdr); |
| 998 | containerId = reinterpret_cast<uint16_t*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 999 | EXPECT_EQ(le16toh(*containerId), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1000 | start += sizeof(uint16_t); |
| 1001 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1002 | start += sizeof(uint8_t); |
| 1003 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1004 | EXPECT_EQ(le16toh(entity->entity_type), 2u); |
| 1005 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1006 | EXPECT_EQ(le16toh(entity->entity_container_id), 1u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1007 | start += sizeof(pldm_entity); |
| 1008 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 1009 | l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL)); |
| 1010 | start += sizeof(uint8_t); |
| 1011 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1012 | EXPECT_EQ(le16toh(entity->entity_type), 4u); |
| 1013 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1014 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1015 | start += sizeof(pldm_entity); |
| 1016 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1017 | EXPECT_EQ(le16toh(entity->entity_type), 5u); |
| 1018 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1019 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1020 | start += sizeof(pldm_entity); |
| 1021 | |
| 1022 | currRecHandle = nextRecHandle; |
| 1023 | |
| 1024 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 1025 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 1026 | l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL) * |
| 1027 | sizeof(pldm_entity))); |
| 1028 | start = data; |
| 1029 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1030 | EXPECT_EQ(le32toh(hdr->record_handle), 5u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1031 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 1032 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1033 | start += sizeof(pldm_pdr_hdr); |
| 1034 | containerId = reinterpret_cast<uint16_t*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1035 | EXPECT_EQ(le16toh(*containerId), 3u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1036 | start += sizeof(uint16_t); |
| 1037 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1038 | start += sizeof(uint8_t); |
| 1039 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1040 | EXPECT_EQ(le16toh(entity->entity_type), 4u); |
| 1041 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1042 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1043 | start += sizeof(pldm_entity); |
| 1044 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 1045 | l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL)); |
| 1046 | start += sizeof(uint8_t); |
| 1047 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1048 | EXPECT_EQ(le16toh(entity->entity_type), 6u); |
| 1049 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1050 | EXPECT_EQ(le16toh(entity->entity_container_id), 3u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1051 | start += sizeof(pldm_entity); |
| 1052 | |
| 1053 | currRecHandle = nextRecHandle; |
| 1054 | |
| 1055 | pldm_pdr_find_record(repo, currRecHandle, &data, &size, &nextRecHandle); |
| 1056 | EXPECT_EQ(size, commonSize + (pldm_entity_get_num_children( |
| 1057 | l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL) * |
| 1058 | sizeof(pldm_entity))); |
| 1059 | start = data; |
| 1060 | hdr = reinterpret_cast<pldm_pdr_hdr*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1061 | EXPECT_EQ(le32toh(hdr->record_handle), 6u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1062 | EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION); |
Deepak Kodihalli | fb4dd7b | 2020-03-17 03:27:22 -0500 | [diff] [blame] | 1063 | EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr)); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1064 | start += sizeof(pldm_pdr_hdr); |
| 1065 | containerId = reinterpret_cast<uint16_t*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1066 | EXPECT_EQ(le16toh(*containerId), 4u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1067 | start += sizeof(uint16_t); |
| 1068 | EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL); |
| 1069 | start += sizeof(uint8_t); |
| 1070 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1071 | EXPECT_EQ(le16toh(entity->entity_type), 5u); |
| 1072 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1073 | EXPECT_EQ(le16toh(entity->entity_container_id), 2u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1074 | start += sizeof(pldm_entity); |
| 1075 | EXPECT_EQ(*start, pldm_entity_get_num_children( |
| 1076 | l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL)); |
| 1077 | start += sizeof(uint8_t); |
| 1078 | entity = reinterpret_cast<pldm_entity*>(start); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1079 | EXPECT_EQ(le16toh(entity->entity_type), 7u); |
| 1080 | EXPECT_EQ(le16toh(entity->entity_instance_num), 1u); |
| 1081 | EXPECT_EQ(le16toh(entity->entity_container_id), 4u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1082 | |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1083 | EXPECT_EQ(nextRecHandle, 0u); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 1084 | |
| 1085 | pldm_pdr_destroy(repo); |
| 1086 | pldm_entity_association_tree_destroy(tree); |
| 1087 | } |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1088 | |
| 1089 | TEST(EntityAssociationPDR, testFind) |
| 1090 | { |
| 1091 | // 1 |
| 1092 | // | |
| 1093 | // 2--3--4 |
| 1094 | // | |
| 1095 | // 5--6--7 |
| 1096 | // | | |
| 1097 | // 8 9 |
| 1098 | |
| 1099 | pldm_entity entities[9]{}; |
| 1100 | |
| 1101 | entities[0].entity_type = 1; |
| 1102 | entities[1].entity_type = 2; |
| 1103 | entities[2].entity_type = 2; |
| 1104 | entities[3].entity_type = 3; |
| 1105 | entities[4].entity_type = 4; |
| 1106 | entities[5].entity_type = 5; |
| 1107 | entities[6].entity_type = 5; |
| 1108 | entities[7].entity_type = 6; |
| 1109 | entities[8].entity_type = 7; |
| 1110 | |
| 1111 | auto tree = pldm_entity_association_tree_init(); |
| 1112 | |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1113 | auto l1 = pldm_entity_association_tree_add( |
| 1114 | tree, &entities[0], 0xFFFF, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1115 | EXPECT_NE(l1, nullptr); |
| 1116 | auto l2a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1117 | tree, &entities[1], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1118 | EXPECT_NE(l2a, nullptr); |
| 1119 | auto l2b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1120 | tree, &entities[2], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1121 | EXPECT_NE(l2b, nullptr); |
| 1122 | auto l2c = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1123 | tree, &entities[3], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1124 | EXPECT_NE(l2c, nullptr); |
| 1125 | auto l3a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1126 | tree, &entities[4], 0xFFFF, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1127 | EXPECT_NE(l3a, nullptr); |
| 1128 | auto l3b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1129 | tree, &entities[5], 0xFFFF, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1130 | EXPECT_NE(l3b, nullptr); |
| 1131 | auto l3c = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1132 | tree, &entities[6], 0xFFFF, l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1133 | EXPECT_NE(l3c, nullptr); |
| 1134 | auto l4a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1135 | tree, &entities[7], 0xFFFF, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1136 | EXPECT_NE(l4a, nullptr); |
| 1137 | auto l4b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1138 | tree, &entities[8], 0xFFFF, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1139 | EXPECT_NE(l4b, nullptr); |
| 1140 | |
| 1141 | pldm_entity entity{}; |
| 1142 | |
| 1143 | entity.entity_type = 1; |
| 1144 | entity.entity_instance_num = 1; |
| 1145 | auto result = pldm_entity_association_tree_find(tree, &entity); |
| 1146 | EXPECT_EQ(result, l1); |
| 1147 | EXPECT_EQ(entity.entity_container_id, 0); |
| 1148 | |
| 1149 | entity.entity_type = 2; |
| 1150 | entity.entity_instance_num = 1; |
| 1151 | result = pldm_entity_association_tree_find(tree, &entity); |
| 1152 | EXPECT_EQ(result, l2a); |
| 1153 | EXPECT_EQ(entity.entity_container_id, 1); |
| 1154 | entity.entity_type = 2; |
| 1155 | entity.entity_instance_num = 2; |
| 1156 | result = pldm_entity_association_tree_find(tree, &entity); |
| 1157 | EXPECT_EQ(result, l2b); |
| 1158 | EXPECT_EQ(entity.entity_container_id, 1); |
| 1159 | entity.entity_type = 3; |
| 1160 | entity.entity_instance_num = 1; |
| 1161 | result = pldm_entity_association_tree_find(tree, &entity); |
| 1162 | EXPECT_EQ(result, l2c); |
| 1163 | EXPECT_EQ(entity.entity_container_id, 1); |
| 1164 | |
| 1165 | entity.entity_type = 7; |
| 1166 | entity.entity_instance_num = 1; |
| 1167 | result = pldm_entity_association_tree_find(tree, &entity); |
| 1168 | EXPECT_EQ(result, l4b); |
| 1169 | EXPECT_EQ(entity.entity_container_id, 4); |
| 1170 | |
| 1171 | pldm_entity_association_tree_destroy(tree); |
| 1172 | } |
| 1173 | |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 1174 | TEST(EntityAssociationPDR, testCopyTree) |
| 1175 | { |
| 1176 | pldm_entity entities[4]{}; |
| 1177 | entities[0].entity_type = 1; |
| 1178 | entities[1].entity_type = 2; |
| 1179 | entities[2].entity_type = 2; |
| 1180 | entities[3].entity_type = 3; |
| 1181 | |
| 1182 | auto orgTree = pldm_entity_association_tree_init(); |
| 1183 | auto newTree = pldm_entity_association_tree_init(); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1184 | auto l1 = |
| 1185 | pldm_entity_association_tree_add(orgTree, &entities[0], 0xFFFF, nullptr, |
| 1186 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 1187 | EXPECT_NE(l1, nullptr); |
| 1188 | auto l2a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1189 | orgTree, &entities[1], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 1190 | EXPECT_NE(l2a, nullptr); |
| 1191 | auto l2b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1192 | orgTree, &entities[2], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 1193 | EXPECT_NE(l2b, nullptr); |
| 1194 | auto l2c = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1195 | orgTree, &entities[3], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 1196 | EXPECT_NE(l2c, nullptr); |
| 1197 | size_t orgNum{}; |
| 1198 | pldm_entity* orgOut = nullptr; |
| 1199 | pldm_entity_association_tree_visit(orgTree, &orgOut, &orgNum); |
| 1200 | EXPECT_EQ(orgNum, 4u); |
| 1201 | |
| 1202 | pldm_entity_association_tree_copy_root(orgTree, newTree); |
| 1203 | size_t newNum{}; |
| 1204 | pldm_entity* newOut = nullptr; |
| 1205 | pldm_entity_association_tree_visit(newTree, &newOut, &newNum); |
| 1206 | EXPECT_EQ(newNum, orgNum); |
| 1207 | EXPECT_EQ(newOut[0].entity_type, 1u); |
| 1208 | EXPECT_EQ(newOut[0].entity_instance_num, 1u); |
| 1209 | EXPECT_EQ(newOut[0].entity_container_id, 0u); |
| 1210 | free(orgOut); |
| 1211 | free(newOut); |
| 1212 | pldm_entity_association_tree_destroy(orgTree); |
| 1213 | pldm_entity_association_tree_destroy(newTree); |
| 1214 | } |
| 1215 | |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1216 | TEST(EntityAssociationPDR, testExtract) |
| 1217 | { |
| 1218 | std::vector<uint8_t> pdr{}; |
| 1219 | pdr.resize(sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_entity_association) + |
| 1220 | sizeof(pldm_entity) * 4); |
| 1221 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(pdr.data()); |
| 1222 | hdr->type = PLDM_PDR_ENTITY_ASSOCIATION; |
| 1223 | hdr->length = |
| 1224 | htole16(sizeof(pldm_pdr_entity_association) + sizeof(pldm_entity) * 4); |
| 1225 | |
| 1226 | pldm_pdr_entity_association* e = |
| 1227 | reinterpret_cast<pldm_pdr_entity_association*>(pdr.data() + |
| 1228 | sizeof(pldm_pdr_hdr)); |
| 1229 | e->container_id = htole16(1); |
| 1230 | e->num_children = 5; |
| 1231 | e->container.entity_type = htole16(1); |
| 1232 | e->container.entity_instance_num = htole16(1); |
| 1233 | e->container.entity_container_id = htole16(0); |
| 1234 | |
| 1235 | pldm_entity* entity = e->children; |
| 1236 | entity->entity_type = htole16(2); |
| 1237 | entity->entity_instance_num = htole16(1); |
| 1238 | entity->entity_container_id = htole16(1); |
| 1239 | ++entity; |
| 1240 | entity->entity_type = htole16(3); |
| 1241 | entity->entity_instance_num = htole16(1); |
| 1242 | entity->entity_container_id = htole16(1); |
| 1243 | ++entity; |
| 1244 | entity->entity_type = htole16(4); |
| 1245 | entity->entity_instance_num = htole16(1); |
| 1246 | entity->entity_container_id = htole16(1); |
| 1247 | ++entity; |
| 1248 | entity->entity_type = htole16(5); |
| 1249 | entity->entity_instance_num = htole16(1); |
| 1250 | entity->entity_container_id = htole16(1); |
| 1251 | ++entity; |
| 1252 | entity->entity_type = htole16(6); |
| 1253 | entity->entity_instance_num = htole16(1); |
| 1254 | entity->entity_container_id = htole16(1); |
| 1255 | |
| 1256 | size_t num{}; |
| 1257 | pldm_entity* out = nullptr; |
| 1258 | pldm_entity_association_pdr_extract(pdr.data(), pdr.size(), &num, &out); |
crgeddes | 2550cee | 2020-05-05 17:51:28 +0000 | [diff] [blame] | 1259 | EXPECT_EQ(num, (unsigned)e->num_children + 1); |
| 1260 | EXPECT_EQ(out[0].entity_type, 1u); |
| 1261 | EXPECT_EQ(out[0].entity_instance_num, 1u); |
| 1262 | EXPECT_EQ(out[0].entity_container_id, 0u); |
| 1263 | EXPECT_EQ(out[1].entity_type, 2u); |
| 1264 | EXPECT_EQ(out[1].entity_instance_num, 1u); |
| 1265 | EXPECT_EQ(out[1].entity_container_id, 1u); |
| 1266 | EXPECT_EQ(out[2].entity_type, 3u); |
| 1267 | EXPECT_EQ(out[2].entity_instance_num, 1u); |
| 1268 | EXPECT_EQ(out[2].entity_container_id, 1u); |
| 1269 | EXPECT_EQ(out[3].entity_type, 4u); |
| 1270 | EXPECT_EQ(out[3].entity_instance_num, 1u); |
| 1271 | EXPECT_EQ(out[3].entity_container_id, 1u); |
| 1272 | EXPECT_EQ(out[4].entity_type, 5u); |
| 1273 | EXPECT_EQ(out[4].entity_instance_num, 1u); |
| 1274 | EXPECT_EQ(out[4].entity_container_id, 1u); |
| 1275 | EXPECT_EQ(out[5].entity_type, 6u); |
| 1276 | EXPECT_EQ(out[5].entity_instance_num, 1u); |
| 1277 | EXPECT_EQ(out[5].entity_container_id, 1u); |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 1278 | |
| 1279 | free(out); |
| 1280 | } |
George Liu | 6a6c3ab | 2021-06-22 16:12:42 +0800 | [diff] [blame] | 1281 | |
| 1282 | TEST(EntityAssociationPDR, testGetChildren) |
| 1283 | { |
| 1284 | pldm_entity entities[4]{}; |
| 1285 | entities[0].entity_type = 1; |
| 1286 | entities[1].entity_type = 2; |
| 1287 | entities[2].entity_type = 2; |
| 1288 | entities[3].entity_type = 3; |
| 1289 | |
| 1290 | auto tree = pldm_entity_association_tree_init(); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1291 | auto l1 = pldm_entity_association_tree_add( |
| 1292 | tree, &entities[0], 0xFFFF, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
George Liu | 6a6c3ab | 2021-06-22 16:12:42 +0800 | [diff] [blame] | 1293 | EXPECT_NE(l1, nullptr); |
| 1294 | auto l2a = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1295 | tree, &entities[1], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
George Liu | 6a6c3ab | 2021-06-22 16:12:42 +0800 | [diff] [blame] | 1296 | EXPECT_NE(l2a, nullptr); |
| 1297 | auto l2b = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1298 | tree, &entities[2], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
George Liu | 6a6c3ab | 2021-06-22 16:12:42 +0800 | [diff] [blame] | 1299 | EXPECT_NE(l2b, nullptr); |
| 1300 | auto l2c = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1301 | tree, &entities[3], 0xFFFF, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
George Liu | 6a6c3ab | 2021-06-22 16:12:42 +0800 | [diff] [blame] | 1302 | EXPECT_NE(l2c, nullptr); |
| 1303 | |
| 1304 | pldm_entity et1; |
| 1305 | et1.entity_type = 2; |
| 1306 | et1.entity_instance_num = 1; |
| 1307 | EXPECT_EQ(true, pldm_is_current_parent_child(l1, &et1)); |
| 1308 | |
| 1309 | pldm_entity et2; |
| 1310 | et2.entity_type = 2; |
| 1311 | et2.entity_instance_num = 2; |
| 1312 | EXPECT_EQ(true, pldm_is_current_parent_child(l1, &et2)); |
| 1313 | |
| 1314 | pldm_entity et3; |
| 1315 | et3.entity_type = 2; |
| 1316 | et3.entity_instance_num = 3; |
| 1317 | EXPECT_EQ(false, pldm_is_current_parent_child(l1, &et3)); |
| 1318 | |
| 1319 | pldm_entity_association_tree_destroy(tree); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | TEST(EntityAssociationPDR, testEntityInstanceNumber) |
| 1323 | { |
| 1324 | pldm_entity entities[9]{}; |
| 1325 | |
| 1326 | entities[0].entity_type = 1; |
| 1327 | entities[1].entity_type = 2; |
| 1328 | entities[2].entity_type = 2; |
| 1329 | entities[3].entity_type = 2; |
| 1330 | entities[4].entity_type = 2; |
| 1331 | entities[5].entity_type = 2; |
| 1332 | entities[6].entity_type = 2; |
| 1333 | entities[7].entity_type = 3; |
| 1334 | entities[8].entity_type = 3; |
| 1335 | |
| 1336 | auto tree = pldm_entity_association_tree_init(); |
| 1337 | auto repo = pldm_pdr_init(); |
| 1338 | |
| 1339 | uint16_t terminusHdl{}; |
| 1340 | uint16_t entityType{}; |
| 1341 | uint16_t entityInstanceNum{}; |
| 1342 | uint16_t containerId{}; |
| 1343 | |
| 1344 | auto node = pldm_entity_association_tree_add( |
| 1345 | tree, &entities[0], 0xFFFF, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1346 | EXPECT_NE(node, nullptr); |
| 1347 | |
| 1348 | auto l1 = pldm_entity_association_tree_add(tree, &entities[1], 63, node, |
| 1349 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1350 | auto first = pldm_pdr_add_fru_record_set( |
| 1351 | repo, 1, 1, entities[1].entity_type, entities[1].entity_instance_num, |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 1352 | entities[1].entity_container_id, 1); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1353 | EXPECT_NE(l1, nullptr); |
| 1354 | EXPECT_EQ(entities[1].entity_instance_num, 63); |
| 1355 | EXPECT_EQ(first, pldm_pdr_get_record_handle( |
| 1356 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1357 | repo, 1, &terminusHdl, &entityType, |
| 1358 | &entityInstanceNum, &containerId))); |
| 1359 | EXPECT_EQ(entityType, 2); |
| 1360 | EXPECT_EQ(entityInstanceNum, 63); |
| 1361 | |
| 1362 | auto l2 = pldm_entity_association_tree_add(tree, &entities[2], 37, node, |
| 1363 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1364 | auto second = pldm_pdr_add_fru_record_set( |
| 1365 | repo, 1, 2, entities[2].entity_type, entities[2].entity_instance_num, |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 1366 | entities[2].entity_container_id, 2); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1367 | EXPECT_NE(l2, nullptr); |
| 1368 | EXPECT_EQ(entities[2].entity_instance_num, 37); |
| 1369 | EXPECT_EQ(second, pldm_pdr_get_record_handle( |
| 1370 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1371 | repo, 2, &terminusHdl, &entityType, |
| 1372 | &entityInstanceNum, &containerId))); |
| 1373 | EXPECT_EQ(entityType, 2); |
| 1374 | EXPECT_EQ(entityInstanceNum, 37); |
| 1375 | |
| 1376 | auto l3 = pldm_entity_association_tree_add(tree, &entities[3], 44, node, |
| 1377 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1378 | auto third = pldm_pdr_add_fru_record_set( |
| 1379 | repo, 1, 3, entities[3].entity_type, entities[3].entity_instance_num, |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 1380 | entities[3].entity_container_id, 3); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1381 | EXPECT_NE(l3, nullptr); |
| 1382 | EXPECT_EQ(entities[3].entity_instance_num, 44); |
| 1383 | EXPECT_EQ(third, pldm_pdr_get_record_handle( |
| 1384 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1385 | repo, 3, &terminusHdl, &entityType, |
| 1386 | &entityInstanceNum, &containerId))); |
| 1387 | EXPECT_EQ(entityType, 2); |
| 1388 | EXPECT_EQ(entityInstanceNum, 44); |
| 1389 | |
| 1390 | auto l4 = pldm_entity_association_tree_add(tree, &entities[4], 89, node, |
| 1391 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1392 | auto fourth = pldm_pdr_add_fru_record_set( |
| 1393 | repo, 1, 4, entities[4].entity_type, entities[4].entity_instance_num, |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 1394 | entities[4].entity_container_id, 4); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1395 | EXPECT_NE(l4, nullptr); |
| 1396 | EXPECT_EQ(entities[4].entity_instance_num, 89); |
| 1397 | EXPECT_EQ(fourth, pldm_pdr_get_record_handle( |
| 1398 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1399 | repo, 4, &terminusHdl, &entityType, |
| 1400 | &entityInstanceNum, &containerId))); |
| 1401 | EXPECT_EQ(entityType, 2); |
| 1402 | EXPECT_EQ(entityInstanceNum, 89); |
| 1403 | |
| 1404 | auto l5 = pldm_entity_association_tree_add(tree, &entities[5], 0xFFFF, node, |
| 1405 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1406 | auto fifth = pldm_pdr_add_fru_record_set( |
| 1407 | repo, 1, 5, entities[5].entity_type, entities[5].entity_instance_num, |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 1408 | entities[5].entity_container_id, 5); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1409 | EXPECT_NE(l5, nullptr); |
| 1410 | EXPECT_EQ(entities[5].entity_instance_num, 90); |
| 1411 | EXPECT_EQ(fifth, pldm_pdr_get_record_handle( |
| 1412 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1413 | repo, 5, &terminusHdl, &entityType, |
| 1414 | &entityInstanceNum, &containerId))); |
| 1415 | EXPECT_EQ(entityType, 2); |
| 1416 | EXPECT_EQ(entityInstanceNum, 90); |
| 1417 | |
| 1418 | auto l6 = pldm_entity_association_tree_add(tree, &entities[6], 90, node, |
| 1419 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1420 | EXPECT_EQ(l6, nullptr); |
| 1421 | |
| 1422 | auto l7 = pldm_entity_association_tree_add(tree, &entities[7], 100, l1, |
| 1423 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1424 | auto seventh = pldm_pdr_add_fru_record_set( |
| 1425 | repo, 1, 7, entities[7].entity_type, entities[7].entity_instance_num, |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 1426 | entities[7].entity_container_id, 7); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1427 | EXPECT_NE(l7, nullptr); |
| 1428 | EXPECT_EQ(entities[7].entity_instance_num, 100); |
| 1429 | EXPECT_EQ(seventh, pldm_pdr_get_record_handle( |
| 1430 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1431 | repo, 7, &terminusHdl, &entityType, |
| 1432 | &entityInstanceNum, &containerId))); |
| 1433 | EXPECT_EQ(entityType, 3); |
| 1434 | EXPECT_EQ(entityInstanceNum, 100); |
| 1435 | |
| 1436 | auto l8 = pldm_entity_association_tree_add(tree, &entities[8], 100, l2, |
| 1437 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 1438 | auto eighth = pldm_pdr_add_fru_record_set( |
| 1439 | repo, 1, 8, entities[8].entity_type, entities[8].entity_instance_num, |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame^] | 1440 | entities[8].entity_container_id, 8); |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 1441 | EXPECT_NE(l8, nullptr); |
| 1442 | EXPECT_EQ(entities[8].entity_instance_num, 100); |
| 1443 | EXPECT_EQ(eighth, pldm_pdr_get_record_handle( |
| 1444 | repo, pldm_pdr_fru_record_set_find_by_rsi( |
| 1445 | repo, 8, &terminusHdl, &entityType, |
| 1446 | &entityInstanceNum, &containerId))); |
| 1447 | EXPECT_EQ(entityType, 3); |
| 1448 | EXPECT_EQ(entityInstanceNum, 100); |
| 1449 | |
| 1450 | pldm_pdr_destroy(repo); |
| 1451 | pldm_entity_association_tree_destroy(tree); |
| 1452 | } |