xref: /openbmc/phosphor-host-ipmid/test/message/pack.cpp (revision ebe8e90639e3ce11193c9c823662b1ad8280b6f2)
1*ebe8e906SVernon Mauery /**
2*ebe8e906SVernon Mauery  * Copyright © 2018 Intel Corporation
3*ebe8e906SVernon Mauery  *
4*ebe8e906SVernon Mauery  * Licensed under the Apache License, Version 2.0 (the "License");
5*ebe8e906SVernon Mauery  * you may not use this file except in compliance with the License.
6*ebe8e906SVernon Mauery  * You may obtain a copy of the License at
7*ebe8e906SVernon Mauery  *
8*ebe8e906SVernon Mauery  *     http://www.apache.org/licenses/LICENSE-2.0
9*ebe8e906SVernon Mauery  *
10*ebe8e906SVernon Mauery  * Unless required by applicable law or agreed to in writing, software
11*ebe8e906SVernon Mauery  * distributed under the License is distributed on an "AS IS" BASIS,
12*ebe8e906SVernon Mauery  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*ebe8e906SVernon Mauery  * See the License for the specific language governing permissions and
14*ebe8e906SVernon Mauery  * limitations under the License.
15*ebe8e906SVernon Mauery  */
16*ebe8e906SVernon Mauery #include <ipmid/api.hpp>
17*ebe8e906SVernon Mauery #include <ipmid/message.hpp>
18*ebe8e906SVernon Mauery 
19*ebe8e906SVernon Mauery #include <gtest/gtest.h>
20*ebe8e906SVernon Mauery 
21*ebe8e906SVernon Mauery // TODO: Add testing of Payload response API
22*ebe8e906SVernon Mauery 
23*ebe8e906SVernon Mauery TEST(PackBasics, Uint8)
24*ebe8e906SVernon Mauery {
25*ebe8e906SVernon Mauery     ipmi::message::Payload p;
26*ebe8e906SVernon Mauery     uint8_t v = 4;
27*ebe8e906SVernon Mauery     p.pack(v);
28*ebe8e906SVernon Mauery     // check that the number of bytes matches
29*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(v));
30*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
31*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x04};
32*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
33*ebe8e906SVernon Mauery }
34*ebe8e906SVernon Mauery 
35*ebe8e906SVernon Mauery TEST(PackBasics, Uint16)
36*ebe8e906SVernon Mauery {
37*ebe8e906SVernon Mauery     ipmi::message::Payload p;
38*ebe8e906SVernon Mauery     uint16_t v = 0x8604;
39*ebe8e906SVernon Mauery     p.pack(v);
40*ebe8e906SVernon Mauery     // check that the number of bytes matches
41*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(v));
42*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
43*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x04, 0x86};
44*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
45*ebe8e906SVernon Mauery }
46*ebe8e906SVernon Mauery 
47*ebe8e906SVernon Mauery TEST(PackBasics, Uint32)
48*ebe8e906SVernon Mauery {
49*ebe8e906SVernon Mauery     ipmi::message::Payload p;
50*ebe8e906SVernon Mauery     uint32_t v = 0x02008604;
51*ebe8e906SVernon Mauery     p.pack(v);
52*ebe8e906SVernon Mauery     // check that the number of bytes matches
53*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(v));
54*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
55*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x04, 0x86, 0x00, 0x02};
56*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
57*ebe8e906SVernon Mauery }
58*ebe8e906SVernon Mauery 
59*ebe8e906SVernon Mauery TEST(PackBasics, Uint64)
60*ebe8e906SVernon Mauery {
61*ebe8e906SVernon Mauery     ipmi::message::Payload p;
62*ebe8e906SVernon Mauery     uint64_t v = 0x1122334402008604ull;
63*ebe8e906SVernon Mauery     p.pack(v);
64*ebe8e906SVernon Mauery     // check that the number of bytes matches
65*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(v));
66*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
67*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x04, 0x86, 0x00, 0x02, 0x44, 0x33, 0x22, 0x11};
68*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
69*ebe8e906SVernon Mauery }
70*ebe8e906SVernon Mauery 
71*ebe8e906SVernon Mauery TEST(PackBasics, Uint24)
72*ebe8e906SVernon Mauery {
73*ebe8e906SVernon Mauery     ipmi::message::Payload p;
74*ebe8e906SVernon Mauery     uint24_t v = 0x112358;
75*ebe8e906SVernon Mauery     p.pack(v);
76*ebe8e906SVernon Mauery     // check that the number of bytes matches
77*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), types::nrFixedBits<decltype(v)> / CHAR_BIT);
78*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
79*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x58, 0x23, 0x11};
80*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
81*ebe8e906SVernon Mauery }
82*ebe8e906SVernon Mauery 
83*ebe8e906SVernon Mauery TEST(PackBasics, Uint3Uint5)
84*ebe8e906SVernon Mauery {
85*ebe8e906SVernon Mauery     // individual bytes are packed low-order-bits first
86*ebe8e906SVernon Mauery     // v1 will occupy [2:0], v2 will occupy [7:3]
87*ebe8e906SVernon Mauery     ipmi::message::Payload p;
88*ebe8e906SVernon Mauery     uint3_t v1 = 0x1;
89*ebe8e906SVernon Mauery     uint5_t v2 = 0x19;
90*ebe8e906SVernon Mauery     p.pack(v1, v2);
91*ebe8e906SVernon Mauery     // check that the number of bytes matches
92*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), (types::nrFixedBits<decltype(v1)> +
93*ebe8e906SVernon Mauery                          types::nrFixedBits<decltype(v2)>) /
94*ebe8e906SVernon Mauery                             CHAR_BIT);
95*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
96*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0xc9};
97*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
98*ebe8e906SVernon Mauery }
99*ebe8e906SVernon Mauery 
100*ebe8e906SVernon Mauery TEST(PackBasics, Boolx8)
101*ebe8e906SVernon Mauery {
102*ebe8e906SVernon Mauery     // individual bytes are packed low-order-bits first
103*ebe8e906SVernon Mauery     // [v8, v7, v6, v5, v4, v3, v2, v1]
104*ebe8e906SVernon Mauery     ipmi::message::Payload p;
105*ebe8e906SVernon Mauery     bool v8 = true, v7 = true, v6 = false, v5 = false;
106*ebe8e906SVernon Mauery     bool v4 = true, v3 = false, v2 = false, v1 = true;
107*ebe8e906SVernon Mauery     p.pack(v1, v2, v3, v4, v5, v6, v7, v8);
108*ebe8e906SVernon Mauery     // check that the number of bytes matches
109*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(uint8_t));
110*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
111*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0xc9};
112*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
113*ebe8e906SVernon Mauery }
114*ebe8e906SVernon Mauery 
115*ebe8e906SVernon Mauery TEST(PackBasics, Bitset8)
116*ebe8e906SVernon Mauery {
117*ebe8e906SVernon Mauery     // individual bytes are packed low-order-bits first
118*ebe8e906SVernon Mauery     // a bitset for 8 bits fills the full byte
119*ebe8e906SVernon Mauery     ipmi::message::Payload p;
120*ebe8e906SVernon Mauery     std::bitset<8> v(0xc9);
121*ebe8e906SVernon Mauery     p.pack(v);
122*ebe8e906SVernon Mauery     // check that the number of bytes matches
123*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), v.size() / CHAR_BIT);
124*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
125*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0xc9};
126*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
127*ebe8e906SVernon Mauery }
128*ebe8e906SVernon Mauery 
129*ebe8e906SVernon Mauery TEST(PackBasics, Bitset3Bitset5)
130*ebe8e906SVernon Mauery {
131*ebe8e906SVernon Mauery     // individual bytes are packed low-order-bits first
132*ebe8e906SVernon Mauery     // v1 will occupy [2:0], v2 will occupy [7:3]
133*ebe8e906SVernon Mauery     ipmi::message::Payload p;
134*ebe8e906SVernon Mauery     std::bitset<3> v1(0x1);
135*ebe8e906SVernon Mauery     std::bitset<5> v2(0x19);
136*ebe8e906SVernon Mauery     p.pack(v1, v2);
137*ebe8e906SVernon Mauery     // check that the number of bytes matches
138*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), (v1.size() + v2.size()) / CHAR_BIT);
139*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
140*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0xc9};
141*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
142*ebe8e906SVernon Mauery }
143*ebe8e906SVernon Mauery 
144*ebe8e906SVernon Mauery TEST(PackBasics, Bitset32)
145*ebe8e906SVernon Mauery {
146*ebe8e906SVernon Mauery     // individual bytes are packed low-order-bits first
147*ebe8e906SVernon Mauery     // v1 will occupy 4 bytes, but in LSByte first order
148*ebe8e906SVernon Mauery     // v1[7:0] v1[15:9] v1[23:16] v1[31:24]
149*ebe8e906SVernon Mauery     ipmi::message::Payload p;
150*ebe8e906SVernon Mauery     std::bitset<32> v(0x02008604);
151*ebe8e906SVernon Mauery     p.pack(v);
152*ebe8e906SVernon Mauery     // check that the number of bytes matches
153*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), v.size() / CHAR_BIT);
154*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
155*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x04, 0x86, 0x00, 0x02};
156*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
157*ebe8e906SVernon Mauery }
158*ebe8e906SVernon Mauery 
159*ebe8e906SVernon Mauery TEST(PackBasics, Array4xUint8)
160*ebe8e906SVernon Mauery {
161*ebe8e906SVernon Mauery     // an array of bytes will be output verbatim, low-order element first
162*ebe8e906SVernon Mauery     ipmi::message::Payload p;
163*ebe8e906SVernon Mauery     std::array<uint8_t, 4> v = {{0x02, 0x00, 0x86, 0x04}};
164*ebe8e906SVernon Mauery     p.pack(v);
165*ebe8e906SVernon Mauery     // check that the number of bytes matches
166*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), v.size() * sizeof(v[0]));
167*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (in byte order)
168*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x02, 0x00, 0x86, 0x04};
169*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
170*ebe8e906SVernon Mauery }
171*ebe8e906SVernon Mauery 
172*ebe8e906SVernon Mauery TEST(PackBasics, Array4xUint32)
173*ebe8e906SVernon Mauery {
174*ebe8e906SVernon Mauery     // an array of multi-byte values will be output in order low-order
175*ebe8e906SVernon Mauery     // element first, each multi-byte element in LSByte order
176*ebe8e906SVernon Mauery     // v[0][7:0] v[0][15:9] v[0][23:16] v[0][31:24]
177*ebe8e906SVernon Mauery     // v[1][7:0] v[1][15:9] v[1][23:16] v[1][31:24]
178*ebe8e906SVernon Mauery     // v[2][7:0] v[2][15:9] v[2][23:16] v[2][31:24]
179*ebe8e906SVernon Mauery     // v[3][7:0] v[3][15:9] v[3][23:16] v[3][31:24]
180*ebe8e906SVernon Mauery     ipmi::message::Payload p;
181*ebe8e906SVernon Mauery     std::array<uint32_t, 4> v = {
182*ebe8e906SVernon Mauery         {0x11223344, 0x22446688, 0x33557799, 0x12345678}};
183*ebe8e906SVernon Mauery     p.pack(v);
184*ebe8e906SVernon Mauery     // check that the number of bytes matches
185*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), v.size() * sizeof(v[0]));
186*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (in byte order)
187*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
188*ebe8e906SVernon Mauery                               0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
189*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
190*ebe8e906SVernon Mauery }
191*ebe8e906SVernon Mauery 
192*ebe8e906SVernon Mauery TEST(PackBasics, VectorUint32)
193*ebe8e906SVernon Mauery {
194*ebe8e906SVernon Mauery     // a vector of multi-byte values will be output in order low-order
195*ebe8e906SVernon Mauery     // element first, each multi-byte element in LSByte order
196*ebe8e906SVernon Mauery     // v[0][7:0] v[0][15:9] v[0][23:16] v[0][31:24]
197*ebe8e906SVernon Mauery     // v[1][7:0] v[1][15:9] v[1][23:16] v[1][31:24]
198*ebe8e906SVernon Mauery     // v[2][7:0] v[2][15:9] v[2][23:16] v[2][31:24]
199*ebe8e906SVernon Mauery     // v[3][7:0] v[3][15:9] v[3][23:16] v[3][31:24]
200*ebe8e906SVernon Mauery     ipmi::message::Payload p;
201*ebe8e906SVernon Mauery     std::vector<uint32_t> v = {
202*ebe8e906SVernon Mauery         {0x11223344, 0x22446688, 0x33557799, 0x12345678}};
203*ebe8e906SVernon Mauery     p.pack(v);
204*ebe8e906SVernon Mauery     // check that the number of bytes matches
205*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), v.size() * sizeof(v[0]));
206*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (in byte order)
207*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
208*ebe8e906SVernon Mauery                               0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
209*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
210*ebe8e906SVernon Mauery }
211*ebe8e906SVernon Mauery 
212*ebe8e906SVernon Mauery TEST(PackBasics, VectorUint8)
213*ebe8e906SVernon Mauery {
214*ebe8e906SVernon Mauery     // a vector of bytes will be output verbatim, low-order element first
215*ebe8e906SVernon Mauery     ipmi::message::Payload p;
216*ebe8e906SVernon Mauery     std::vector<uint8_t> v = {0x02, 0x00, 0x86, 0x04};
217*ebe8e906SVernon Mauery     p.pack(v);
218*ebe8e906SVernon Mauery     // check that the number of bytes matches
219*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), v.size() * sizeof(v[0]));
220*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (in byte order)
221*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x02, 0x00, 0x86, 0x04};
222*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
223*ebe8e906SVernon Mauery }
224*ebe8e906SVernon Mauery 
225*ebe8e906SVernon Mauery TEST(PackAdvanced, Uints)
226*ebe8e906SVernon Mauery {
227*ebe8e906SVernon Mauery     // all elements will be processed in order, with each multi-byte
228*ebe8e906SVernon Mauery     // element being processed LSByte first
229*ebe8e906SVernon Mauery     // v1[7:0] v2[7:0] v2[15:8] v3[7:0] v3[15:8] v3[23:16] v3[31:24]
230*ebe8e906SVernon Mauery     // v4[7:0] v4[15:8] v4[23:16] v4[31:24]
231*ebe8e906SVernon Mauery     // v4[39:25] v4[47:40] v4[55:48] v4[63:56]
232*ebe8e906SVernon Mauery     ipmi::message::Payload p;
233*ebe8e906SVernon Mauery     uint8_t v1 = 0x02;
234*ebe8e906SVernon Mauery     uint16_t v2 = 0x0604;
235*ebe8e906SVernon Mauery     uint32_t v3 = 0x44332211;
236*ebe8e906SVernon Mauery     uint64_t v4 = 0xccbbaa9988776655ull;
237*ebe8e906SVernon Mauery     p.pack(v1, v2, v3, v4);
238*ebe8e906SVernon Mauery     // check that the number of bytes matches
239*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(v1) + sizeof(v2) + sizeof(v3) + sizeof(v4));
240*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
241*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
242*ebe8e906SVernon Mauery                               0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
243*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
244*ebe8e906SVernon Mauery }
245*ebe8e906SVernon Mauery 
246*ebe8e906SVernon Mauery TEST(PackAdvanced, TupleInts)
247*ebe8e906SVernon Mauery {
248*ebe8e906SVernon Mauery     // all elements will be processed in order, with each multi-byte
249*ebe8e906SVernon Mauery     // element being processed LSByte first
250*ebe8e906SVernon Mauery     // v1[7:0] v2[7:0] v2[15:8] v3[7:0] v3[15:8] v3[23:16] v3[31:24]
251*ebe8e906SVernon Mauery     // v4[7:0] v4[15:8] v4[23:16] v4[31:24]
252*ebe8e906SVernon Mauery     // v4[39:25] v4[47:40] v4[55:48] v4[63:56]
253*ebe8e906SVernon Mauery     ipmi::message::Payload p;
254*ebe8e906SVernon Mauery     uint8_t v1 = 0x02;
255*ebe8e906SVernon Mauery     uint16_t v2 = 0x0604;
256*ebe8e906SVernon Mauery     uint32_t v3 = 0x44332211;
257*ebe8e906SVernon Mauery     uint64_t v4 = 0xccbbaa9988776655ull;
258*ebe8e906SVernon Mauery     auto v = std::make_tuple(v1, v2, v3, v4);
259*ebe8e906SVernon Mauery     p.pack(v);
260*ebe8e906SVernon Mauery     // check that the number of bytes matches
261*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(v1) + sizeof(v2) + sizeof(v3) + sizeof(v4));
262*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
263*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
264*ebe8e906SVernon Mauery                               0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
265*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
266*ebe8e906SVernon Mauery }
267*ebe8e906SVernon Mauery 
268*ebe8e906SVernon Mauery TEST(PackAdvanced, BoolsnBitfieldsnFixedIntsOhMy)
269*ebe8e906SVernon Mauery {
270*ebe8e906SVernon Mauery     // each element will be added, filling the low-order bits first
271*ebe8e906SVernon Mauery     // with multi-byte values getting added LSByte first
272*ebe8e906SVernon Mauery     // v1 will occupy k[0][1:0]
273*ebe8e906SVernon Mauery     // v2 will occupy k[0][2]
274*ebe8e906SVernon Mauery     // v3[4:0] will occupy k[0][7:3], v3[6:5] will occupy k[1][1:0]
275*ebe8e906SVernon Mauery     // v4 will occupy k[1][2]
276*ebe8e906SVernon Mauery     // v5 will occupy k[1][7:3]
277*ebe8e906SVernon Mauery     ipmi::message::Payload p;
278*ebe8e906SVernon Mauery     uint2_t v1 = 2;          // binary 0b10
279*ebe8e906SVernon Mauery     bool v2 = true;          // binary 0b1
280*ebe8e906SVernon Mauery     std::bitset<7> v3(0x73); // binary 0b1110011
281*ebe8e906SVernon Mauery     bool v4 = false;         // binary 0b0
282*ebe8e906SVernon Mauery     uint5_t v5 = 27;         // binary 0b11011
283*ebe8e906SVernon Mauery     // concat binary: 0b1101101110011110 -> 0xdb9e -> 0x9e 0xdb (LSByte first)
284*ebe8e906SVernon Mauery     p.pack(v1, v2, v3, v4, v5);
285*ebe8e906SVernon Mauery     // check that the number of bytes matches
286*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(uint16_t));
287*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
288*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x9e, 0xdb};
289*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
290*ebe8e906SVernon Mauery }
291*ebe8e906SVernon Mauery 
292*ebe8e906SVernon Mauery TEST(PackAdvanced, UnalignedBitPacking)
293*ebe8e906SVernon Mauery {
294*ebe8e906SVernon Mauery     // unaligned multi-byte values will be packed the same as
295*ebe8e906SVernon Mauery     // other bits, effectively building up a large value, low-order
296*ebe8e906SVernon Mauery     // bits first, then outputting a stream of LSByte values
297*ebe8e906SVernon Mauery     // v1 will occupy k[0][1:0]
298*ebe8e906SVernon Mauery     // v2[5:0] will occupy k[0][7:2], v2[7:6] will occupy k[1][1:0]
299*ebe8e906SVernon Mauery     // v3 will occupy k[1][2]
300*ebe8e906SVernon Mauery     // v4[4:0] will occupy k[1][7:3] v4[12:5] will occupy k[2][7:0]
301*ebe8e906SVernon Mauery     // v4[15:13] will occupy k[3][2:0]
302*ebe8e906SVernon Mauery     // v5 will occupy k[3][3]
303*ebe8e906SVernon Mauery     // v6[3:0] will occupy k[3][7:0] v6[11:4] will occupy k[4][7:0]
304*ebe8e906SVernon Mauery     // v6[19:12] will occupy k[5][7:0] v6[27:20] will occupy k[6][7:0]
305*ebe8e906SVernon Mauery     // v6[31:28] will occupy k[7][3:0]
306*ebe8e906SVernon Mauery     // v7 will occupy k[7][7:4]
307*ebe8e906SVernon Mauery     ipmi::message::Payload p;
308*ebe8e906SVernon Mauery     uint2_t v1 = 2;           // binary 0b10
309*ebe8e906SVernon Mauery     uint8_t v2 = 0xa5;        // binary 0b10100101
310*ebe8e906SVernon Mauery     bool v3 = false;          // binary 0b0
311*ebe8e906SVernon Mauery     uint16_t v4 = 0xa55a;     // binary 0b1010010101011010
312*ebe8e906SVernon Mauery     bool v5 = true;           // binary 0b1
313*ebe8e906SVernon Mauery     uint32_t v6 = 0xdbc3bd3c; // binary 0b11011011110000111011110100111100
314*ebe8e906SVernon Mauery     uint4_t v7 = 9;           // binary 0b1001
315*ebe8e906SVernon Mauery     // concat binary:
316*ebe8e906SVernon Mauery     //   0b1001110110111100001110111101001111001101001010101101001010010110
317*ebe8e906SVernon Mauery     //   -> 0x9dbc3bd3cd2ad296 -> 0x96 0xd2 0x2a 0xcd 0xd3 0x3b 0xbc 0x9d
318*ebe8e906SVernon Mauery     p.pack(v1, v2, v3, v4, v5, v6, v7);
319*ebe8e906SVernon Mauery     // check that the number of bytes matches
320*ebe8e906SVernon Mauery     ASSERT_EQ(p.size(), sizeof(uint64_t));
321*ebe8e906SVernon Mauery     // check that the bytes were correctly packed (LSB first)
322*ebe8e906SVernon Mauery     std::vector<uint8_t> k = {0x96, 0xd2, 0x2a, 0xcd, 0xd3, 0x3b, 0xbc, 0x9d};
323*ebe8e906SVernon Mauery     ASSERT_EQ(p.raw, k);
324*ebe8e906SVernon Mauery }
325