util: add unit tests for util/lut.h

Wasn't 100% sure about some of these derivations so let's add tests.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37200>
This commit is contained in:
Alyssa Rosenzweig
2025-09-10 17:11:00 -04:00
committed by Marge Bot
parent 95badb6b1d
commit a2d14208b0
2 changed files with 76 additions and 0 deletions
+1
View File
@@ -404,6 +404,7 @@ if with_tests
'tests/int_min_max.cpp',
'tests/linear_test.cpp',
'tests/list_test.cpp',
'tests/lut_test.cpp',
'tests/mesa-sha1_test.cpp',
'tests/os_mman_test.cpp',
'tests/perf/u_trace_test.cpp',
+75
View File
@@ -0,0 +1,75 @@
/*
* Copyright 2025 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#if !defined(_MSC_VER)
#include <gtest/gtest.h>
#include "util/lut.h"
#define EXPECT_LUT3(value, str) \
EXPECT_STREQ(util_lut3_to_str[value], str)
TEST(lut, build3)
{
EXPECT_LUT3(UTIL_LUT3(a), "a");
EXPECT_LUT3(UTIL_LUT3(b), "b");
EXPECT_LUT3(UTIL_LUT3(c), "c");
EXPECT_LUT3(UTIL_LUT3(a & b), "a & b");
EXPECT_LUT3(UTIL_LUT3(a ^ b ^ c), "a ^ b ^ c");
EXPECT_LUT3(UTIL_LUT3(~c ^ (~a) ^ ~b), "a ^ b ^ ~c");
}
TEST(lut, build2)
{
EXPECT_LUT3(UTIL_LUT2(a), "a & ~c");
EXPECT_LUT3(UTIL_LUT2(b), "b & ~c");
EXPECT_LUT3(UTIL_LUT2(a & b), "a & b & ~c");
EXPECT_LUT3(UTIL_LUT2(~b ^ (~a)), "(a ^ b) & ~c");
}
TEST(lut, invert2)
{
EXPECT_LUT3(util_lut2_invert(UTIL_LUT2(a & b)), "(~a | ~b) & ~c");
}
TEST(lut, invert3)
{
EXPECT_LUT3(util_lut3_invert(UTIL_LUT3(a ^ b ^ c)), "a ^ b ^ ~c");
}
TEST(lut, invert_source3)
{
EXPECT_LUT3(util_lut3_invert_source(UTIL_LUT3(a | b | c), 0), "~a | b | c");
EXPECT_LUT3(util_lut3_invert_source(UTIL_LUT3(a | b | c), 1), "a | ~b | c");
EXPECT_LUT3(util_lut3_invert_source(UTIL_LUT3(a | b | c), 2), "a | b | ~c");
EXPECT_LUT3(util_lut3_invert_source(UTIL_LUT3(a & b), 0), "~a & b");
EXPECT_LUT3(util_lut3_invert_source(UTIL_LUT3(a & b), 1), "a & ~b");
EXPECT_LUT3(util_lut3_invert_source(UTIL_LUT3(a & b), 2), "a & b");
}
TEST(lut, invert_source2)
{
EXPECT_LUT3(util_lut2_invert_source(UTIL_LUT2(a & b), 0), "~a & b & ~c");
EXPECT_LUT3(util_lut2_invert_source(UTIL_LUT2(a & b), 1), "a & ~b & ~c");
}
TEST(lut, swap_sources2)
{
EXPECT_LUT3(util_lut2_swap_sources(UTIL_LUT2(a & b)), "a & b & ~c");
EXPECT_LUT3(util_lut2_swap_sources(UTIL_LUT2(a & ~b)), "~a & b & ~c");
EXPECT_LUT3(util_lut2_swap_sources(UTIL_LUT2(~a & b)), "a & ~b & ~c");
EXPECT_LUT3(util_lut2_swap_sources(UTIL_LUT2(~a | b)), "(a | ~b) & ~c");
}
TEST(lut, swap_sources3)
{
EXPECT_LUT3(util_lut3_swap_sources(UTIL_LUT3(a & b & c), 0, 2), "a & b & c");
EXPECT_LUT3(util_lut3_swap_sources(UTIL_LUT3(~a & b & c), 0, 2), "a & b & ~c");
EXPECT_LUT3(util_lut3_swap_sources(UTIL_LUT3(a | ~b | c), 0, 1), "~a | b | c");
EXPECT_LUT3(util_lut3_swap_sources(UTIL_LUT3(a | ~b | c), 0, 2), "a | ~b | c");
EXPECT_LUT3(util_lut3_swap_sources(UTIL_LUT3(a | ~b | c), 1, 2), "a | b | ~c");
}
#endif