Skip to content

Commit

Permalink
Split up the one integration test file
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Sep 26, 2024
1 parent ca2e6e6 commit b6c7757
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 240 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/BuildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
build:
strategy:
matrix:
config: [ {os: windows-latest, copyCommand: copy, artifactName: ffmpegTestWindows, buildPath: Release/, dummyLib: dummyLib.dll, ffmpegTest: ffmpegTest.exe},
{os: ubuntu-latest, copyCommand: cp, artifactName: ffmpegTestUbuntu, buildPath: , dummyLib: libdummyLib.so, ffmpegTest: ffmpegTest},
{os: macos-13, copyCommand: cp, artifactName: ffmpegTestMacIntel, buildPath: , dummyLib: libdummyLib.dylib, ffmpegTest: ffmpegTest},
{os: macos-14, copyCommand: cp, artifactName: ffmpegTestMacM1, buildPath: , dummyLib: libdummyLib.dylib, ffmpegTest: ffmpegTest} ]
config: [ {os: windows-latest, copyCommand: copy, artifactName: integrationTestWindows, buildPath: Release/, dummyLib: dummyLib.dll, integrationTest: integrationTest.exe},
{os: ubuntu-latest, copyCommand: cp, artifactName: integrationTestUbuntu, buildPath: , dummyLib: libdummyLib.so, integrationTest: integrationTest},
{os: macos-13, copyCommand: cp, artifactName: integrationTestMacIntel, buildPath: , dummyLib: libdummyLib.dylib, integrationTest: integrationTest},
{os: macos-14, copyCommand: cp, artifactName: integrationTestMacM1, buildPath: , dummyLib: libdummyLib.dylib, integrationTest: integrationTest} ]
runs-on: ${{ matrix.config.os }}

steps:
Expand All @@ -34,24 +34,24 @@ jobs:
- uses: actions/upload-artifact@master
with:
name: ${{ matrix.config.artifactName }}
path: ${{ github.workspace }}/build/test/ffmpegTest/${{ matrix.config.buildPath }}${{ matrix.config.ffmpegTest }}
path: ${{ github.workspace }}/build/test/integration/${{ matrix.config.buildPath }}${{ matrix.config.integrationTest }}

testFFmpegVersions:
needs: build
strategy:
matrix:
config: [ {os: windows-latest, artifactName: ffmpegTestWindows, azureFolder: windows, unzipCommand: 7z x },
{os: ubuntu-latest, artifactName: ffmpegTestUbuntu, azureFolder: ubuntu-22.04, unzipCommand: unzip },
{os: macos-13, artifactName: ffmpegTestMacIntel, azureFolder: macos-intel, unzipCommand: unzip },
{os: macos-14, artifactName: ffmpegTestMacM1, azureFolder: macos-m1, unzipCommand: unzip } ]
config: [ {os: windows-latest, artifactName: integrationTestWindows, azureFolder: windows, unzipCommand: 7z x },
{os: ubuntu-latest, artifactName: integrationTestUbuntu, azureFolder: ubuntu-22.04, unzipCommand: unzip },
{os: macos-13, artifactName: integrationTestMacIntel, azureFolder: macos-intel, unzipCommand: unzip },
{os: macos-14, artifactName: integrationTestMacM1, azureFolder: macos-m1, unzipCommand: unzip } ]
ffmpegVersions: ["2.8.22", "3.4.13", "4.4.4", "5.1.4", "6.1.1", "7.0"]
runs-on: ${{ matrix.config.os }}
steps:
- uses: actions/download-artifact@master
with:
name: ${{ matrix.config.artifactName }}

- name: Make ffmpegTest executable
- name: Make integrationTest executable
run: chmod a+x ffmpegTest
if: ${{ matrix.config.os }} != windows-latest

Expand All @@ -62,17 +62,17 @@ jobs:
${{ matrix.config.unzipCommand }} ffmpeg.zip
rm ffmpeg.zip
- name: runffmpegTest
run: ./ffmpegTest
- name: Run integration tests
run: ./integrationTest

testFFmpegNativeInstall:
needs: build
strategy:
matrix:
config: [ {os: windows-latest, artifactName: ffmpegTestWindows},
{os: ubuntu-latest, artifactName: ffmpegTestUbuntu},
{os: macos-13, artifactName: ffmpegTestMacIntel},
{os: macos-14, artifactName: ffmpegTestMacM1} ]
config: [ {os: windows-latest, artifactName: integrationTestWindows},
{os: ubuntu-latest, artifactName: integrationTestUbuntu},
{os: macos-13, artifactName: integrationTestMacIntel},
{os: macos-14, artifactName: integrationTestMacM1} ]
runs-on: ${{ matrix.config.os }}
steps:
- uses: actions/download-artifact@master
Expand All @@ -85,8 +85,8 @@ jobs:
apt: ffmpeg
choco: ffmpeg-shared

- name: Make ffmpegTest executable
run: chmod a+x ffmpegTest
- name: Make integrationTest executable
run: chmod a+x integrationTest
if: matrix.config.os != 'windows-latest'

- name: Add ffmpeg to path
Expand All @@ -96,5 +96,5 @@ jobs:
- name: Download Test files
run: curl -L "${{ secrets.AZURE_BLOB_ROOT_PATH }}bitstream-testfiles/TestFile_h264_aac_1s_320x240.mp4${{ secrets.AZURE_BLOB_TOKEN }}" -o TestFile_h264_aac_1s_320x240.mp4

- name: runffmpegTest
run: ./ffmpegTest
- name: Run integration tests
run: ./integrationTest
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ FetchContent_MakeAvailable(googletest)
add_subdirectory(common)
add_subdirectory(dummyLib)
add_subdirectory(unit)
add_subdirectory(ffmpegTest)
add_subdirectory(integration)
10 changes: 0 additions & 10 deletions test/ffmpegTest/CMakeLists.txt

This file was deleted.

10 changes: 10 additions & 0 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FILE(GLOB_RECURSE TEST_UNIT_SOURCE_FILES *.cpp)
FILE(GLOB_RECURSE TEST_UNIT_HEADER_FILES *.h)

add_executable(integrationTest ${TEST_UNIT_SOURCE_FILES} ${TEST_UNIT_HEADER_FILES})

target_include_directories(integrationTest PRIVATE ${CMAKE_SOURCE_DIR}/src/lib ${CMAKE_SOURCE_DIR}/test)
target_link_libraries(integrationTest gtest_main gmock_main libFFmpeg++ testCommon)

include(GoogleTest)
gtest_discover_tests(integrationTest)
128 changes: 128 additions & 0 deletions test/integration/DecodingTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/* Copyright (c) 2023 Christian Feldmann [[email protected]].
* All rights reserved.
* This work is licensed under the terms of the MIT license.
* For a copy, see <https://opensource.org/licenses/MIT>.
*/

#include <common/ComparisonFunctions.h>

#include "LibrariesWithLogging.h"

#include <gmock/gmock.h>
#include <gtest/gtest.h>

namespace libffmpeg::test::integration
{

using libffmpeg::avutil::PictureType;
using ::testing::Contains;

TEST(FFmpegTest, DecodingTest)
{
auto libsAndLogs = LibrariesWithLogging();

auto demuxer = libsAndLogs.openTestFileInDemuxer();
auto decoder = Decoder(libsAndLogs.libraries);

const auto streamToDecode = 1;
const auto stream = demuxer.getFormatContext()->getStream(streamToDecode);
const auto avcodecVersionMajor = libsAndLogs.libraries->getLibrariesVersion().avcodec.major;

// The amount of padding that FFmpeg uses depends on how it was compiled.
// Here, we use our own compiled versions. But in general this can not be predicted.
constexpr std::array<int, 2> EXPECTED_LINESIZE_LUMA = {320, 384};
constexpr std::array<int, 2> EXPECTED_LINESIZE_CHROMA = {160, 192};

ASSERT_TRUE(decoder.openForDecoding(stream));

auto totalFrameCounter = 0;

auto pullFramesFromDecoder = [&decoder,
&totalFrameCounter,
&EXPECTED_LINESIZE_LUMA,
&EXPECTED_LINESIZE_CHROMA,
&avcodecVersionMajor]()
{
int framesDecodedInLoop = 0;
while (const auto frame = decoder.decodeNextFrame())
{
EXPECT_TRUE(frame);

EXPECT_EQ(frame->getPixelFormatDescriptor().name, "yuv420p");

EXPECT_EQ(frame->getSize(), Size({320, 240}));
EXPECT_THAT(EXPECTED_LINESIZE_LUMA, Contains(frame->getLineSize(0)));
EXPECT_THAT(EXPECTED_LINESIZE_CHROMA, Contains(frame->getLineSize(1)));
EXPECT_THAT(EXPECTED_LINESIZE_CHROMA, Contains(frame->getLineSize(2)));
EXPECT_EQ(frame->getSampleAspectRatio(), Rational({1, 1}));

const auto absoluteFrameIndex = totalFrameCounter + framesDecodedInLoop;

constexpr std::array<PictureType, 25> expectedPictureTypes = {
PictureType::I, PictureType::B, PictureType::B, PictureType::B, PictureType::P,
PictureType::B, PictureType::B, PictureType::B, PictureType::P, PictureType::B,
PictureType::B, PictureType::B, PictureType::P, PictureType::B, PictureType::B,
PictureType::B, PictureType::P, PictureType::B, PictureType::B, PictureType::P,
PictureType::B, PictureType::B, PictureType::P, PictureType::P, PictureType::P};
EXPECT_EQ(frame->getPictType(), expectedPictureTypes.at(absoluteFrameIndex));

constexpr std::array<int64_t, 25> expectedPTSValues = {
0, 512, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 4608, 5120, 5632, 6144,
6656, 7168, 7680, 8192, 8704, 9216, 9728, 10240, 10752, 11264, 11776, 12288};
if (avcodecVersionMajor == 56)
EXPECT_FALSE(frame->getPTS());
else
EXPECT_EQ(frame->getPTS(), expectedPTSValues.at(absoluteFrameIndex));

constexpr std::array<std::int64_t, 25> expectedFrameHashes = {
-3007600926112186533, -3391200051889142087, -1160633604618185881, 4273627566792723166,
-4154039706688151037, -1301428058581480615, 7452780297656341798, 7600256964838247071,
-8499296325100989937, -8234365708930177171, -6091801175307918277, -6243952166556384038,
-1538307937175716804, -1214069488220656158, 221111691894747256, -6002299333845183392,
2227144204187938134, 6419852838956731569, -2032560420377261054, 84234931995669811,
-6767048039990945080, -8993409000448418032, -7272467650392102601, 3844105725739243304,
-2350406183677959349};
EXPECT_EQ(calculateFrameDataHash(*frame), expectedFrameHashes.at(absoluteFrameIndex));

++framesDecodedInLoop;
}
return framesDecodedInLoop;
};

while (const auto packet = demuxer.getNextPacket())
{
if (packet->getStreamIndex() != streamToDecode)
continue;

EXPECT_EQ(decoder.getDecoderState(), Decoder::State::NeedsMoreData);

auto result = decoder.sendPacket(*packet);
ASSERT_NE(result, Decoder::SendPacketResult::Error);

if (decoder.getDecoderState() == Decoder::State::RetrieveFrames)
{
const auto framesDecoded = pullFramesFromDecoder();
EXPECT_GT(framesDecoded, 0);
totalFrameCounter += framesDecoded;
EXPECT_EQ(decoder.getDecoderState(), Decoder::State::NeedsMoreData);
}

if (result == Decoder::SendPacketResult::NotSentPullFramesFirst)
{
result = decoder.sendPacket(*packet);
EXPECT_EQ(result, Decoder::SendPacketResult::Ok);
}
}

decoder.setFlushing();

EXPECT_EQ(decoder.getDecoderState(), Decoder::State::RetrieveFrames);
const auto framesDecoded = pullFramesFromDecoder();
EXPECT_GT(framesDecoded, 0);
totalFrameCounter += framesDecoded;
EXPECT_EQ(decoder.getDecoderState(), Decoder::State::EndOfBitstream);

EXPECT_EQ(totalFrameCounter, 25);
}

} // namespace libffmpeg::test::integration
Loading

0 comments on commit b6c7757

Please sign in to comment.