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