From 5d526d7620bf7b3bb1c96b19ad3c96cadc928b3c Mon Sep 17 00:00:00 2001 From: Salome Thirot Date: Mon, 20 Oct 2025 18:24:11 +0100 Subject: [PATCH] Add unit tests for xGetSAD functions Add unit tests for xGetSAD functions, for all block sizes. --- test/vvenc_unit_test/vvenc_unit_test.cpp | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/vvenc_unit_test/vvenc_unit_test.cpp b/test/vvenc_unit_test/vvenc_unit_test.cpp index 1b7828a9..d05a86aa 100644 --- a/test/vvenc_unit_test/vvenc_unit_test.cpp +++ b/test/vvenc_unit_test/vvenc_unit_test.cpp @@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. \brief This vvenclibtest.cpp file contains the main entry point of the test application. */ +#include #include #include #include @@ -1258,6 +1259,46 @@ static bool check_fixWeightedSSE( RdCost* ref, RdCost* opt, unsigned num_cases, return passed; } +static bool check_SAD( RdCost* ref, RdCost* opt, unsigned num_cases, int width, int height ) +{ + std::ostringstream sstm; + sstm << "RdCost::m_afpDistortFunc[0][DF_SAD" << width << "] " + << " w=" << width << " h=" << height; + printf( "Testing %s\n", sstm.str().c_str() ); + + DimensionGenerator rng; + InputGenerator g10{ 10, /*is_signed=*/false }; + + bool passed = true; + for( unsigned i = 0; i < num_cases; i++ ) + { + int org_stride = rng.get( width, g_fastUnitTest ? 256 : 1024 ); + int cur_stride = rng.get( width, g_fastUnitTest ? 256 : 1024 ); + std::vector orgBuf( org_stride * height ); + std::vector curBuf( cur_stride * height ); + + DistParam dtParam; + dtParam.org.buf = orgBuf.data(); + dtParam.org.stride = org_stride; + dtParam.cur.buf = curBuf.data(); + dtParam.cur.stride = cur_stride; + dtParam.org.width = width; + dtParam.org.height = height; + dtParam.bitDepth = 10; + dtParam.subShift = rng.get( 0, 1 ); + dtParam.applyWeight = 0; // applyWeight appears to be always zero. + + std::generate( orgBuf.begin(), orgBuf.end(), g10 ); + std::generate( curBuf.begin(), curBuf.end(), g10 ); + + const int index = DF_SAD + log2( width ); + Distortion sum_ref = ref->m_afpDistortFunc[0][index]( dtParam ); + Distortion sum_opt = opt->m_afpDistortFunc[0][index]( dtParam ); + passed = compare_value( sstm.str(), sum_ref, sum_opt ) && passed; + } + return passed; +} + static bool check_SADwMask( RdCost* ref, RdCost* opt, unsigned num_cases, int width, int height ) { std::ostringstream sstm; @@ -1323,6 +1364,7 @@ static bool test_RdCost() { passed = check_lumaWeightedSSE( &ref, &opt, num_cases, w, h ) && passed; passed = check_fixWeightedSSE( &ref, &opt, num_cases, w, h ) && passed; + passed = check_SAD( &ref, &opt, num_cases, w, h ) && passed; if (w >= 8 && h >= 8) {