libhevc-mirror/tests/encoder/EncTests.cpp
Harish Mahendrakar 4a8c3163e3
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
Add initial tests for decoder and encoder
Encoder tests currently do not dump recon as ihevce_plugin doesn't yet support recon dump.
This will be enabled once the recon dump is supported.

Decoder tests currently validate just a few files from big buck bunny.

Use "ctest" run all the tests when using cmake.
This downloads the required media files and uses them in the tests.

If running the tests directly using the test binaries, then download the media files
and export HEVC_TEST_DIR to the extracted folder before running the binaries directly.
2026-07-27 13:15:45 -07:00

119 lines
3.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 <cstdlib>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "DecHelper.h"
#include "EncHelper.h"
#include "Md5Wrapper.h"
#include "TestCommon.h"
namespace libhevc {
namespace test {
struct EncodeStreamConfig {
std::string filename;
size_t width;
size_t height;
Format format;
};
void PrintTo(const EncodeStreamConfig& config, ::std::ostream* os) {
*os << config.filename;
}
// Class EncodeTestParams is no longer needed since we use std::tuple with
// Combine
// Helper to resolve absolute file path for test assets
static std::string getFullPath(const std::string& filename) {
if (const char* envPath = std::getenv("HEVC_TEST_DIR")) {
return std::string(envPath) + "/" + filename;
}
return filename;
}
class EncTestFixture
: public ::testing::TestWithParam<std::tuple<EncodeStreamConfig, size_t>> {
protected:
EncTestFixture() = default;
~EncTestFixture() override = default;
};
TEST_P(EncTestFixture, EncodeVerify) {
auto [config, cores] = GetParam();
std::string inputPath = getFullPath(config.filename);
std::string outBitstreamPath = "temp_output.hevc";
std::string reconMd5Path = "temp_recon_md5.txt";
// Check if input YUV file exists. If not, generate synthetic YUV file!
std::ifstream f(inputPath);
if (!f.good()) {
GTEST_FAIL() << "Input file not found: " << inputPath;
}
f.close();
// Clean up any stale outputs
std::remove(outBitstreamPath.c_str());
auto encBuilder = EncHelper::Builder()
.setInputFilePath(inputPath)
.setOutFilePath(outBitstreamPath)
.setOutputReconMd5Path(reconMd5Path)
.setFormat(config.format)
.setResolution(config.width, config.height)
.setFrameRate(30000, 1000)
.setCores(cores);
std::unique_ptr<EncHelper> helper = encBuilder.build();
ASSERT_NE(helper, nullptr)
<< "Failed to build EncHelper for input: " << inputPath;
EXPECT_TRUE(helper->encodeFile())
<< "Encoding failed for input: " << inputPath;
auto decBuilder = DecHelper::Builder()
.setInputFilePath(outBitstreamPath)
.setRefMd5Path(reconMd5Path)
.setFormat(libhevc::test::Format::yuv420sp_uv)
.setCores(cores);
std::unique_ptr<DecHelper> decHelper = decBuilder.build();
ASSERT_NE(decHelper, nullptr)
<< "Failed to build DecHelper for input: " << outBitstreamPath;
EXPECT_TRUE(decHelper->decodeFile())
<< "Decoding failed for input: " << outBitstreamPath;
// Clean up temporary outputs
// std::remove(outBitstreamPath.c_str());
}
static const std::vector<EncodeStreamConfig> kEncodeStreams = {
{"bbb_176x144_yuv420.yuv", 176, 144, Format::yuv420p}};
INSTANTIATE_TEST_SUITE_P(EncoderRegression, EncTestFixture,
::testing::Combine(::testing::ValuesIn(kEncodeStreams),
::testing::Values(1, 2, 3, 4)));
} // namespace test
} // namespace libhevc