Skip to content

[torchcodec] refactor test utils into its own library #135

[torchcodec] refactor test utils into its own library

[torchcodec] refactor test utils into its own library #135

Workflow file for this run

name: Unit Test
on:
push:
branches: [ main ]
pull_request:
concurrency:
group: unit-test${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash -l -eo pipefail {0}
jobs:
python:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.12']
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1']
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Setup conda env
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniconda-version: "latest"
activate-environment: test
python-version: ${{ matrix.python-version }}
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: |
python -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
- name: Build and install torchcodec
run: |
if command -v "ffmpeg" &> /dev/null
then
echo "ffmpeg is installed, but it shouldn't! Exiting!!"
exit 1
fi
# TODO: should we pass -DCMAKE_BUILD_TYPE=Debug here? That's what we
# do for the C++ tests.
BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 python -m pip install -e ".[dev]" --no-build-isolation -vvv
# list the built so files, for debugging.
find src | grep ".so"
- name: Install ffmpeg, post build
run: |
conda install "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" -c conda-forge
ffmpeg -version
- name: Smoke test
run: |
python test/decoders/manual_smoke_test.py
# TODO: diff the output frame with its expeceted value
- name: Run Python tests
run: |
pytest test
Cpp:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1']
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Setup conda env
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniconda-version: "latest"
activate-environment: test
python-version: '3.12'
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: |
python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu
- name: Install ffmpeg and pkg-config
run: |
conda install "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" pkg-config -c conda-forge
ffmpeg -version
- name: Build and run C++ tests
run: |
# Note: we're not setting BUILD_AGAINST_ALL_FFMPEG_FROM_S3 here, so
# we're building libtorchcodec against the installed FFmpeg version
# (from conda-forge) instead of building against our pre-built non-GPL
# FFmpeg libraries.
# The reason we need this is because the C++ tests decode x264 files.
# x264 support is not LGPL, os it is not supported by our
# pre-built non-GPL FFmpeg libraries. And if we were to build against
# those, this is also what the tests would be loading at run time,
# then failing when we try to decode x264.
# To remediate that, we build against the FFmpeg that we installed
# from conda-forge (which is able to decode x264), and that's also
# what gets loaded at run time.
# The Python tests are also decoding x264 files, and are built against
# our non-GPL FFmpeg. And yet they pass. This is because in Python
# we're able to distinguish between build-time (non-GPL FFmpeg) and
# run time (conda-forge FFmpeg).
#
# TODO: Ideally, we should find a way to make the same distinction
# between build time and run time for those C++ tests, and build them
# against our non-GPL FFmpeg libraries.
build_tests_dir="${PWD}/build_tests"
mkdir $build_tests_dir
pushd $build_tests_dir
TORCH_PATH=$(python -c "import pathlib, torch; print(pathlib.Path(torch.__path__[0]))")
Torch_DIR="${TORCH_PATH}/share/cmake/Torch"
cmake .. -DTorch_DIR=$Torch_DIR -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DCMAKE_VERBOSE_MAKEFILE=ON
cmake --build .
ctest
popd