From 502b16925ec7c706db3f3aeb0b8a1e7351539ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20Aam=C3=A5s?= <saamas@cisco.com> Date: Tue, 19 Apr 2016 16:37:02 +0200 Subject: [PATCH] [UT] Add tests for CavlcParamCal_c and CavlcParamCal_sse2 --- codec/encoder/core/inc/set_mb_syn_cavlc.h | 2 + .../win32/codec_ut/codec_unittest.vcproj | 4 + test/encoder/EncUT_Cavlc.cpp | 83 +++++++++++++++++++ test/encoder/targets.mk | 1 + 4 files changed, 90 insertions(+) create mode 100644 test/encoder/EncUT_Cavlc.cpp diff --git a/codec/encoder/core/inc/set_mb_syn_cavlc.h b/codec/encoder/core/inc/set_mb_syn_cavlc.h index d7ffa22e..4faffc2d 100644 --- a/codec/encoder/core/inc/set_mb_syn_cavlc.h +++ b/codec/encoder/core/inc/set_mb_syn_cavlc.h @@ -75,6 +75,8 @@ int32_t WriteBlockResidualCavlc (SWelsFuncPtrList* pFuncList, int16_t* pCoffLev extern "C" { #endif//__cplusplus +int32_t CavlcParamCal_c (int16_t* pCoffLevel, uint8_t* pRun, int16_t* pLevel, int32_t* pTotalCoeffs , + int32_t iEndIdx); #ifdef X86_ASM int32_t CavlcParamCal_sse2 (int16_t* pCoffLevel, uint8_t* pRun, int16_t* pLevel, int32_t* pTotalCoeffs , int32_t iEndIdx); diff --git a/test/build/win32/codec_ut/codec_unittest.vcproj b/test/build/win32/codec_ut/codec_unittest.vcproj index 52cc0178..8d04bf14 100644 --- a/test/build/win32/codec_ut/codec_unittest.vcproj +++ b/test/build/win32/codec_ut/codec_unittest.vcproj @@ -390,6 +390,10 @@ <Filter Name="encoder" > + <File + RelativePath="..\..\..\encoder\EncUT_Cavlc.cpp" + > + </File> <File RelativePath="..\..\..\encoder\EncUT_DecodeMbAux.cpp" > diff --git a/test/encoder/EncUT_Cavlc.cpp b/test/encoder/EncUT_Cavlc.cpp new file mode 100644 index 00000000..04837d7f --- /dev/null +++ b/test/encoder/EncUT_Cavlc.cpp @@ -0,0 +1,83 @@ +#include "cpu.h" +#include "macros.h" +#include "set_mb_syn_cavlc.h" +#include <gtest/gtest.h> +#include <cmath> +#include <cstddef> + +using namespace WelsEnc; + +namespace { + +int32_t CavlcParamCal_ref (int16_t* pCoffLevel, uint8_t* pRun, int16_t* pLevel, int32_t* pTotalCoeff, + int32_t iLastIndex) { + int32_t iTotalZeros = 0; + int32_t iTotalCoeffs = 0; + + while (iLastIndex >= 0 && pCoffLevel[iLastIndex] == 0) { + -- iLastIndex; + } + + while (iLastIndex >= 0) { + int32_t iCountZero = 0; + pLevel[iTotalCoeffs] = pCoffLevel[iLastIndex--]; + + while (iLastIndex >= 0 && pCoffLevel[iLastIndex] == 0) { + ++ iCountZero; + -- iLastIndex; + } + iTotalZeros += iCountZero; + pRun[iTotalCoeffs++] = iCountZero; + } + *pTotalCoeff = iTotalCoeffs; + return iTotalZeros; +} + +void TestCavlcParamCalWithEndIdx (PCavlcParamCalFunc func, int endIdx, bool allZero, bool allNonZero) { + ENFORCE_STACK_ALIGN_1D(int16_t, coeffLevel, 16, 16); + ENFORCE_STACK_ALIGN_1D(int16_t, level, 16, 16); + ENFORCE_STACK_ALIGN_1D(uint8_t, run, 16, 16); + uint8_t run_ref[16]; + int16_t level_ref[16]; + int32_t totalCoeffs = 0; + int32_t totalCoeffs_ref = 0; + for (int i = 0; i < 16; i++) { + const int r = std::rand(); + if (allZero || (i > endIdx && endIdx > 7)) + coeffLevel[i] = 0; + else if (allNonZero) + coeffLevel[i] = r % 0xFFFF - 0x8000 ? r % 0xFFFF - 0x8000 : 0x7FFF; + else + coeffLevel[i] = (r >> 16 & 1) * ((r & 0xFFFF) - 0x8000); + } + const int32_t totalZeros_ref = CavlcParamCal_ref (coeffLevel, run_ref, level_ref, &totalCoeffs_ref, endIdx); + const int32_t totalZeros = func (coeffLevel, run, level, &totalCoeffs, endIdx); + ASSERT_EQ (totalCoeffs, totalCoeffs_ref); + if (totalCoeffs > 0) + ASSERT_EQ (totalZeros, totalZeros_ref); + for (int i = 0; i < totalCoeffs_ref; i++) + ASSERT_EQ (level[i], level_ref[i]); + for (int i = 0; i < totalCoeffs_ref - 1; i++) + ASSERT_EQ (run[i], run_ref[i]); +} + +void TestCavlcParamCal (PCavlcParamCalFunc func) { + const int endIdxes[] = { 3, 14, 15 }; + const int num_test_repetitions = 10000; + for (std::size_t i = 0; i < sizeof endIdxes / sizeof *endIdxes; i++) { + for (int count = 0; count < num_test_repetitions; count++) + TestCavlcParamCalWithEndIdx (func, endIdxes[i], count == 0, count == 1); + } +} + +} // anon ns. + +TEST (CavlcTest, CavlcParamCal_c) { + TestCavlcParamCal (CavlcParamCal_c); +} + +#ifdef X86_32_ASM +TEST (CavlcTest, CavlcParamCal_sse2) { + TestCavlcParamCal (CavlcParamCal_sse2); +} +#endif diff --git a/test/encoder/targets.mk b/test/encoder/targets.mk index 40cab065..49787cae 100644 --- a/test/encoder/targets.mk +++ b/test/encoder/targets.mk @@ -1,5 +1,6 @@ ENCODER_UNITTEST_SRCDIR=test/encoder ENCODER_UNITTEST_CPP_SRCS=\ + $(ENCODER_UNITTEST_SRCDIR)/EncUT_Cavlc.cpp\ $(ENCODER_UNITTEST_SRCDIR)/EncUT_DecodeMbAux.cpp\ $(ENCODER_UNITTEST_SRCDIR)/EncUT_EncoderExt.cpp\ $(ENCODER_UNITTEST_SRCDIR)/EncUT_EncoderMb.cpp\