diff --git a/src/panfrost/genxml/meson.build b/src/panfrost/genxml/meson.build index b222e48b4c8..7a17f8bb38b 100644 --- a/src/panfrost/genxml/meson.build +++ b/src/panfrost/genxml/meson.build @@ -45,3 +45,19 @@ libpanfrost_decode = static_library( build_by_default : false, link_with: [libpanfrost_decode_per_arch], ) + +if with_tests + test('cs_builder_tests', + executable( + 'cs_builder_tests', + ['test/cs_builder.cpp'], + # Nothing arch-specific is tested currently, only compile v10. + cpp_args : [cpp_msvc_compat_args, no_override_init_args, '-DPAN_ARCH=10'], + gnu_symbol_visibility : 'hidden', + include_directories: [inc_include, inc_src, inc_panfrost], + dependencies: [idep_gtest, idep_pan_packers, idep_mesautil], + ), + suite: ['panfrost'], + protocol: 'gtest', + ) +endif diff --git a/src/panfrost/genxml/test/cs_builder.cpp b/src/panfrost/genxml/test/cs_builder.cpp new file mode 100644 index 00000000000..1c1f5852e43 --- /dev/null +++ b/src/panfrost/genxml/test/cs_builder.cpp @@ -0,0 +1,53 @@ +/* + * Copyright 2025 Collabora Ltd + * SPDX-License-Identifier: MIT + */ + +#include "cs_builder.h" + +#include +#include "mesa-gtest-extras.h" + +#define MAX_OUTPUT_SIZE 512 + +class CsBuilderTest : public ::testing::Test { +public: + CsBuilderTest(); + ~CsBuilderTest(); + + struct cs_builder b; + uint64_t *output; +}; + +CsBuilderTest::CsBuilderTest() +{ + output = new uint64_t[MAX_OUTPUT_SIZE]; + struct cs_builder_conf conf = { + .nr_registers = 96, + .nr_kernel_registers = 4, + }; + struct cs_buffer buffer = { + .cpu = output, + .gpu = 0x0, + .capacity = MAX_OUTPUT_SIZE, + }; + cs_builder_init(&b, &conf, buffer); +} + +CsBuilderTest::~CsBuilderTest() +{ + delete output; +} + +TEST_F(CsBuilderTest, basic) +{ + cs_move32_to(&b, cs_reg32(&b, 42), 0xdeadbeef); + cs_finish(&b); + + uint64_t expected[] = { + 0x022a0000deadbeef, /* MOVE32 r42, #0xdeadbeef */ + }; + + EXPECT_EQ(b.root_chunk.size, ARRAY_SIZE(expected)); + EXPECT_U64_ARRAY_EQUAL(output, expected, ARRAY_SIZE(expected)); +}