From 9061e960b2e4c4c8b10af54e37e35f07dc7bc501 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 22 Oct 2022 10:28:47 -0400 Subject: [PATCH] asahi: Add group tests Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/tests/test-packing.cpp | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/asahi/lib/tests/test-packing.cpp b/src/asahi/lib/tests/test-packing.cpp index 4bd634c6952..0c41f03ffee 100644 --- a/src/asahi/lib/tests/test-packing.cpp +++ b/src/asahi/lib/tests/test-packing.cpp @@ -45,6 +45,27 @@ const struct { { INFINITY, 0x380, true }, }; +const struct { + uint32_t group_size; + uint32_t length; + uint32_t value; + uint32_t encoded; +} group_cases[] = { + /* Groups of 16 in a 4-bit word */ + { 16, 4, 0, 0x1 }, + { 16, 4, 1, 0x1 }, + { 16, 4, 16, 0x1 }, + { 16, 4, 17, 0x2 }, + { 16, 4, 31, 0x2 }, + { 16, 4, 32, 0x2 }, + { 16, 4, 33, 0x3 }, + { 16, 4, 239, 0xF }, + { 16, 4, 240, 0xF }, + { 16, 4, 241, 0x0 }, + { 16, 4, 255, 0x0 }, + { 16, 4, 256, 0x0 }, +}; + TEST(LODClamp, Encode) { for (unsigned i = 0; i < ARRAY_SIZE(lod_cases); ++i) @@ -63,3 +84,30 @@ TEST(LODClamp, Decode) ASSERT_EQ(__gen_unpack_lod(cl, 0, 10), lod_cases[i].f); } } + +TEST(Groups, Encode) +{ + for (unsigned i = 0; i < ARRAY_SIZE(group_cases); ++i) { + ASSERT_EQ(__gen_to_groups(group_cases[i].value, + group_cases[i].group_size, + group_cases[i].length), + group_cases[i].encoded); + } +} + +TEST(Groups, Decode) +{ + for (unsigned i = 0; i < ARRAY_SIZE(group_cases); ++i) { + unsigned expected = ALIGN_POT(group_cases[i].value, + group_cases[i].group_size); + + /* Clamp to minimum encodable */ + if (group_cases[i].value == 0) + expected = group_cases[i].group_size; + + ASSERT_EQ(__gen_from_groups(group_cases[i].encoded, + group_cases[i].group_size, + group_cases[i].length), + expected); + } +}