Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if(ENABLE_COVERAGE)
add_compile_options(-O0 -g)
endif()
option(ENABLE_TESTS "Enables gtest based unit tests" ON)
option(ENABLE_BENCHMARKS "Enables google benchmark based performance tests" ON)


if(POLICY CMP0135)
Expand Down Expand Up @@ -62,6 +63,9 @@ libhevc_add_compile_options()
if(ENABLE_TESTS)
libhevc_add_gtest()
endif()
if(ENABLE_BENCHMARKS)
libhevc_add_benchmark()
endif()
libhevc_add_definitions()
libhevc_set_link_libraries()

Expand All @@ -75,6 +79,6 @@ include("${HEVC_ROOT}/examples/encoder/hevcenc.cmake")
include("${HEVC_ROOT}/fuzzer/hevc_dec_fuzzer.cmake")
include("${HEVC_ROOT}/fuzzer/hevc_enc_fuzzer.cmake")

if(ENABLE_TESTS)
if(ENABLE_TESTS OR ENABLE_BENCHMARKS)
include("${HEVC_ROOT}/tests/common/common.cmake")
endif()
36 changes: 33 additions & 3 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,39 @@ function(libhevc_add_gtest_executable NAME)
cmake_parse_arguments(ARG "" "" "${multi_value_args}" ${ARGN})

libhevc_add_executable(
${NAME} libhevcdec
SOURCES ${HEVC_ROOT}/tests/common/func_selector.cc
${HEVC_ROOT}/tests/common/TestCommon.cc ${ARG_SOURCES}
${NAME} libhevc_dsp_test_utils
SOURCES ${ARG_SOURCES}
LIBS GTest::gtest_main)
add_test(NAME ${NAME} COMMAND ${NAME})
endfunction()

# Adds Google Benchmark dependency
function(libhevc_add_benchmark)
include(FetchContent)
FetchContent_Declare(
benchmark
URL https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip
)
# Disable benchmark's internal test suite
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(benchmark)
endfunction()

# cmake-format: off
# Adds a target for a benchmark executable
#
# Arguments:
# NAME: Name of the executable
#
# Optional Arguments:
# SOURCES: Additional source files
# cmake-format: on
function(libhevc_add_benchmark_executable NAME)
set(multi_value_args SOURCES)
cmake_parse_arguments(ARG "" "" "${multi_value_args}" ${ARGN})

libhevc_add_executable(
${NAME} libhevc_dsp_test_utils
SOURCES ${HEVC_ROOT}/tests/common/BenchmarkCommon.cc ${ARG_SOURCES}
LIBS benchmark::benchmark)
endfunction()
2 changes: 1 addition & 1 deletion fuzzer/ossfuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rm -rf ${build_dir}
mkdir -p ${build_dir}

pushd ${build_dir}
cmake ${SRC}/libhevc -DENABLE_TESTS=0
cmake ${SRC}/libhevc -DENABLE_TESTS=0 -DENABLE_BENCHMARKS=0
make -j$(nproc) hevc_dec_fuzzer hevc_enc_fuzzer
cp ${build_dir}/hevc_dec_fuzzer $OUT/
cp ${build_dir}/hevc_enc_fuzzer $OUT/
Expand Down
135 changes: 135 additions & 0 deletions tests/common/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ cc_library_static {
srcs: [
"TestCommon.cc",
"func_selector.cc",
"ihevc_deblk_utils.cc",
"ihevc_inter_pred_utils.cc",
"ihevc_intra_pred_utils.cc",
"ihevc_itrans_utils.cc",
"ihevc_sao_utils.cc",
"BitsBuf.cpp",
"RawBuf.cpp",
"Md5Wrapper.cpp",
Expand All @@ -57,6 +62,16 @@ cc_library_static {
],
}

cc_defaults {
name: "libhevc_benchmarks_defaults",
defaults: ["libhevc_tests_defaults"],
srcs: ["BenchmarkCommon.cc"],
static_libs: [
"libhevc_tests_common",
"libhevccommon",
],
}

cc_test {
name: "ihevc_luma_inter_pred_test",
defaults: ["libhevc_tests_defaults"],
Expand Down Expand Up @@ -206,3 +221,123 @@ cc_test {
"libhevccommon",
],
}

cc_benchmark {
name: "ihevc_itrans_recon_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_itrans_recon_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_itrans_res_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_itrans_res_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_deblk_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_deblk_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_hbd_deblk_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_hbd_deblk_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_hbd_itrans_recon_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_hbd_itrans_recon_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_sao_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_sao_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_hbd_sao_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_hbd_sao_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_luma_intra_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_luma_intra_pred_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_hbd_luma_intra_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_hbd_luma_intra_pred_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_chroma_intra_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_chroma_intra_pred_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_hbd_chroma_intra_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_hbd_chroma_intra_pred_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_luma_inter_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_luma_inter_pred_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_chroma_inter_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_chroma_inter_pred_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_hbd_luma_inter_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_hbd_luma_inter_pred_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_hbd_chroma_inter_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_hbd_chroma_inter_pred_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_chroma_itrans_recon_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_chroma_itrans_recon_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_chroma_recon_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_chroma_recon_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_recon_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_recon_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_padding_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_padding_benchmark.cc"],
}

cc_benchmark {
name: "ihevc_weighted_pred_benchmark",
defaults: ["libhevc_benchmarks_defaults"],
srcs: ["ihevc_weighted_pred_benchmark.cc"],
}
54 changes: 54 additions & 0 deletions tests/common/BenchmarkCommon.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/******************************************************************************
*
* 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 "BenchmarkCommon.h"

#include <benchmark/benchmark.h>

const std::vector<IV_ARCH_T>& GetBenchmarkArchitectures() {
static const std::vector<IV_ARCH_T> kArches = []() {
std::vector<IV_ARCH_T> arches = {ARCH_NA};
for (auto a : getTstArch()) {
arches.push_back(a);
}
return arches;
}();
return kArches;
}

const std::vector<std::pair<int, int>>& GetBenchmarkLumaPUSizes() {
static const std::vector<std::pair<int, int>> kSizes = {
{8, 8}, {16, 16}, {32, 32}, {64, 64}, {16, 8}, {32, 16}, {64, 32},
};
return kSizes;
}

const std::vector<std::pair<int, int>>& GetBenchmarkChromaPUSizes() {
static const std::vector<std::pair<int, int>> kSizes = {
{4, 4}, {8, 8}, {16, 16}, {32, 32}, {8, 4}, {16, 8}, {32, 16},
};
return kSizes;
}

int main(int argc, char** argv) {
RegisterAllBenchmarks();
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
return 0;
}
47 changes: 47 additions & 0 deletions tests/common/BenchmarkCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/******************************************************************************
*
* 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.
*
******************************************************************************/

#pragma once

#include <string>
#include <utility>
#include <vector>

// clang-format off
#include "ihevc_typedefs.h"
#include "iv.h"
// clang-format on

#include "TestCommon.h"

// Returns human-readable architecture name ("C", "SSSE3", "SSE42", "ARMV8", etc.)
inline std::string GetArchName(IV_ARCH_T arch) { return get_arch_str(arch); }

// Returns the list of architectures to benchmark, starting with ARCH_NA
// (generic C), followed by all supported target architectures returned by
// getTstArch().
const std::vector<IV_ARCH_T>& GetBenchmarkArchitectures();

// Common representative PU block sizes for Luma benchmarks
const std::vector<std::pair<int, int>>& GetBenchmarkLumaPUSizes();

// Common representative PU block sizes for Chroma benchmarks
const std::vector<std::pair<int, int>>& GetBenchmarkChromaPUSizes();

// Implemented by each benchmark executable to register its benchmark suite
void RegisterAllBenchmarks();
7 changes: 4 additions & 3 deletions tests/common/TestCommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ const std::vector<std::pair<int, int>>& getChromaPUBlockSizes() {
const std::vector<UWORD8>& getSrc8Buf() {
static const std::vector<UWORD8> g_src8_buf = []() {
std::vector<UWORD8> buf(kMaxSize * kMaxHeight * 4);
std::mt19937 rng(12345);
std::uniform_int_distribution<int> dist(0, 255);
for (auto& v : buf) v = static_cast<UWORD8>(dist(rng));
FillRandom(buf, static_cast<UWORD8>(0), static_cast<UWORD8>(255), 12345);
return buf;
}();
return g_src8_buf;
Expand All @@ -72,6 +70,9 @@ const std::vector<UWORD8>& getSrc8Buf() {
std::string get_arch_str(IV_ARCH_T arch) {
std::string arch_str;
switch (arch) {
case ARCH_NA:
arch_str = "C";
break;
case ARCH_X86_GENERIC:
arch_str = "GENERIC";
break;
Expand Down
Loading
Loading