libhevc-mirror/tests/common/ihevc_padding_test.cc
Harish Mahendrakar 89da890161
Some checks failed
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
Added benchmark tests for ihevc modules
2026-09-26 11:04:34 -07:00

176 lines
5.9 KiB
C++

/******************************************************************************
*
* Copyright (C) 2026 Ittiam Systems Pvt Ltd, Bangalore
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#include <gtest/gtest.h>
#include <algorithm>
#include <cstring>
#include <random>
#include <tuple>
#include <utility>
#include <vector>
// clang-format off
#include "func_selector.h"
#include "ihevc_typedefs.h"
#include "TestCommon.h"
// clang-format on
namespace {
// ---------------------------- Test Param -----------------------------------
using PaddingTestParam = std::tuple<std::pair<int, int>, int, IV_ARCH_T>;
std::string PrintPaddingTestParam(
const testing::TestParamInfo<PaddingTestParam>& info) {
int wd, ht, pad_size;
std::pair<int, int> block_size;
IV_ARCH_T arch;
std::tie(block_size, pad_size, arch) = info.param;
std::tie(wd, ht) = block_size;
return std::to_string(wd) + "x" + std::to_string(ht) + "_pad_" +
std::to_string(pad_size) + "_" + get_arch_str(arch);
}
// ---------------------------- Base Class -----------------------------------
template <int kComponents>
class PaddingTestBase : public ::testing::TestWithParam<PaddingTestParam> {
protected:
void SetUp() override {
std::pair<int, int> block_size;
std::tie(block_size, pad_size, arch) = GetParam();
std::tie(wd, ht) = block_size;
stride = kComponents * wd + 2 * pad_size + 16;
total_ht = ht + 2 * pad_size + 16;
buf_size = stride * total_ht;
buf_ref.resize(buf_size, 0xAA);
buf_tst.resize(buf_size, 0xAA);
src_offset = pad_size * stride + pad_size + 8;
ref = get_ref_func_ptr();
tst = get_tst_func_ptr(arch);
}
void InitializeBuffers() {
std::mt19937 rng(42);
std::uniform_int_distribution<uint8_t> dist(0, 255);
for (int r = 0; r < ht; r++) {
for (int c = 0; c < kComponents * wd; c++) {
uint8_t val = dist(rng);
buf_ref[src_offset + r * stride + c] = val;
buf_tst[src_offset + r * stride + c] = val;
}
}
}
int wd, ht, pad_size;
IV_ARCH_T arch;
int stride, total_ht, buf_size, src_offset;
std::vector<UWORD8> buf_ref;
std::vector<UWORD8> buf_tst;
const ihevc_func_selector_t* ref;
const ihevc_func_selector_t* tst;
};
using PaddingLumaTest = PaddingTestBase<1>;
using PaddingChromaTest = PaddingTestBase<2>;
// ---------------------------- Test cases -----------------------------------
class PaddingLeftLumaTest : public PaddingLumaTest {};
TEST_P(PaddingLeftLumaTest, Run) {
InitializeBuffers();
(ref->*(&ihevc_func_selector_t::ihevc_pad_left_luma_fptr))(
buf_ref.data() + src_offset, stride, ht, pad_size);
(tst->*(&ihevc_func_selector_t::ihevc_pad_left_luma_fptr))(
buf_tst.data() + src_offset, stride, ht, pad_size);
ASSERT_EQ(buf_ref, buf_tst);
}
class PaddingLeftChromaTest : public PaddingChromaTest {};
TEST_P(PaddingLeftChromaTest, Run) {
InitializeBuffers();
(ref->*(&ihevc_func_selector_t::ihevc_pad_left_chroma_fptr))(
buf_ref.data() + src_offset, stride, ht, pad_size);
(tst->*(&ihevc_func_selector_t::ihevc_pad_left_chroma_fptr))(
buf_tst.data() + src_offset, stride, ht, pad_size);
ASSERT_EQ(buf_ref, buf_tst);
}
class PaddingRightLumaTest : public PaddingLumaTest {};
TEST_P(PaddingRightLumaTest, Run) {
InitializeBuffers();
int pad_offset = wd;
(ref->*(&ihevc_func_selector_t::ihevc_pad_right_luma_fptr))(
buf_ref.data() + src_offset + pad_offset, stride, ht, pad_size);
(tst->*(&ihevc_func_selector_t::ihevc_pad_right_luma_fptr))(
buf_tst.data() + src_offset + pad_offset, stride, ht, pad_size);
ASSERT_EQ(buf_ref, buf_tst);
}
class PaddingRightChromaTest : public PaddingChromaTest {};
TEST_P(PaddingRightChromaTest, Run) {
InitializeBuffers();
int pad_offset = 2 * wd;
(ref->*(&ihevc_func_selector_t::ihevc_pad_right_chroma_fptr))(
buf_ref.data() + src_offset + pad_offset, stride, ht, pad_size);
(tst->*(&ihevc_func_selector_t::ihevc_pad_right_chroma_fptr))(
buf_tst.data() + src_offset + pad_offset, stride, ht, pad_size);
ASSERT_EQ(buf_ref, buf_tst);
}
// ---------------------------- Instantiation --------------------------------
auto kLumaPaddingParams = ::testing::Combine(
::testing::ValuesIn(getLumaPUBlockSizes()), ::testing::Values(80),
::testing::ValuesIn(getTstArch()));
const std::vector<std::pair<int, int>>& getChromaPaddingBlockSizes() {
static const std::vector<std::pair<int, int>> kChromaPaddingBlockSizes =
[]() {
std::vector<std::pair<int, int>> ret;
for (const auto& size : getChromaPUBlockSizes()) {
if (size.second % 4 == 0) {
ret.push_back(size);
}
}
return ret;
}();
return kChromaPaddingBlockSizes;
}
auto kChromaPaddingParams = ::testing::Combine(
::testing::ValuesIn(getChromaPaddingBlockSizes()), ::testing::Values(80),
::testing::ValuesIn(getTstArch()));
INSTANTIATE_TEST_SUITE_P(Padding, PaddingLeftLumaTest, kLumaPaddingParams,
PrintPaddingTestParam);
INSTANTIATE_TEST_SUITE_P(Padding, PaddingRightLumaTest, kLumaPaddingParams,
PrintPaddingTestParam);
INSTANTIATE_TEST_SUITE_P(Padding, PaddingLeftChromaTest, kChromaPaddingParams,
PrintPaddingTestParam);
INSTANTIATE_TEST_SUITE_P(Padding, PaddingRightChromaTest, kChromaPaddingParams,
PrintPaddingTestParam);
} // namespace