Skip to content

Commit 314bbe0

Browse files
committed
lib: packing: add additional KUnit tests
JIRA: https://issues.redhat.com/browse/RHEL-92666 Upstream commit(s): commit fcd6dd9 Author: Jacob Keller <jacob.e.keller@intel.com> Date: Wed Oct 2 14:51:56 2024 -0700 lib: packing: add additional KUnit tests While reviewing the initial KUnit tests for lib/packing, Przemek pointed out that the test values have duplicate bytes in the input sequence. In addition, I noticed that the unit tests pack and unpack on a byte boundary, instead of crossing bytes. Thus, we lack good coverage of the corner cases of the API. Add additional unit tests to cover packing and unpacking byte buffers which do not have duplicate bytes in the unpacked value, and which pack and unpack to an unaligned offset. A careful reviewer may note the lack tests for QUIRK_MSB_ON_THE_RIGHT. This is because I found issues with that quirk during test implementation. This quirk will be fixed and the tests will be included in a future change. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Link: https://patch.msgid.link/20241002-packing-kunit-tests-and-split-pack-unpack-v2-7-8373e551eae3@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Petr Oros <poros@redhat.com>
1 parent b9d8a19 commit 314bbe0

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

lib/packing_test.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,88 @@ static const struct packing_test_case cases[] = {
210210
.end_bit = 32,
211211
.quirks = QUIRK_LSW32_IS_FIRST | QUIRK_LITTLE_ENDIAN,
212212
},
213+
/* These tests pack and unpack a magic 64-bit value
214+
* (0x1122334455667788) at an odd starting bit (43) within an
215+
* otherwise zero array of 128 bits (16 bytes). They test all possible
216+
* bit layouts of the 128 bit buffer.
217+
*/
218+
{
219+
.desc = "no quirks, 16 bytes, non-aligned",
220+
PBUF(0x00, 0x00, 0x00, 0x89, 0x11, 0x9a, 0x22, 0xab,
221+
0x33, 0xbc, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00),
222+
.uval = 0x1122334455667788,
223+
.start_bit = 106,
224+
.end_bit = 43,
225+
.quirks = NO_QUIRKS,
226+
},
227+
{
228+
.desc = "lsw32 first, 16 bytes, non-aligned",
229+
PBUF(0x00, 0x00, 0x00, 0x00, 0x33, 0xbc, 0x40, 0x00,
230+
0x11, 0x9a, 0x22, 0xab, 0x00, 0x00, 0x00, 0x89),
231+
.uval = 0x1122334455667788,
232+
.start_bit = 106,
233+
.end_bit = 43,
234+
.quirks = QUIRK_LSW32_IS_FIRST,
235+
},
236+
{
237+
.desc = "little endian words, 16 bytes, non-aligned",
238+
PBUF(0x89, 0x00, 0x00, 0x00, 0xab, 0x22, 0x9a, 0x11,
239+
0x00, 0x40, 0xbc, 0x33, 0x00, 0x00, 0x00, 0x00),
240+
.uval = 0x1122334455667788,
241+
.start_bit = 106,
242+
.end_bit = 43,
243+
.quirks = QUIRK_LITTLE_ENDIAN,
244+
},
245+
{
246+
.desc = "lsw32 first + little endian words, 16 bytes, non-aligned",
247+
PBUF(0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xbc, 0x33,
248+
0xab, 0x22, 0x9a, 0x11, 0x89, 0x00, 0x00, 0x00),
249+
.uval = 0x1122334455667788,
250+
.start_bit = 106,
251+
.end_bit = 43,
252+
.quirks = QUIRK_LSW32_IS_FIRST | QUIRK_LITTLE_ENDIAN,
253+
},
254+
/* These tests pack and unpack a u64 with all bits set
255+
* (0xffffffffffffffff) at an odd starting bit (43) within an
256+
* otherwise zero array of 128 bits (16 bytes). They test all possible
257+
* bit layouts of the 128 bit buffer.
258+
*/
259+
{
260+
.desc = "no quirks, 16 bytes, non-aligned, 0xff",
261+
PBUF(0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
262+
0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00),
263+
.uval = 0xffffffffffffffff,
264+
.start_bit = 106,
265+
.end_bit = 43,
266+
.quirks = NO_QUIRKS,
267+
},
268+
{
269+
.desc = "lsw32 first, 16 bytes, non-aligned, 0xff",
270+
PBUF(0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x00,
271+
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x07, 0xff),
272+
.uval = 0xffffffffffffffff,
273+
.start_bit = 106,
274+
.end_bit = 43,
275+
.quirks = QUIRK_LSW32_IS_FIRST,
276+
},
277+
{
278+
.desc = "little endian words, 16 bytes, non-aligned, 0xff",
279+
PBUF(0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
280+
0x00, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00),
281+
.uval = 0xffffffffffffffff,
282+
.start_bit = 106,
283+
.end_bit = 43,
284+
.quirks = QUIRK_LITTLE_ENDIAN,
285+
},
286+
{
287+
.desc = "lsw32 first + little endian words, 16 bytes, non-aligned, 0xff",
288+
PBUF(0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff,
289+
0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00),
290+
.uval = 0xffffffffffffffff,
291+
.start_bit = 106,
292+
.end_bit = 43,
293+
.quirks = QUIRK_LSW32_IS_FIRST | QUIRK_LITTLE_ENDIAN,
294+
},
213295
};
214296

215297
KUNIT_ARRAY_PARAM_DESC(packing, cases, desc);

0 commit comments

Comments
 (0)