asahi: Add group tests

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18813>
This commit is contained in:
Alyssa Rosenzweig 2022-10-22 10:28:47 -04:00
parent 8b464f4c59
commit 9061e960b2

View file

@ -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);
}
}