Skip to content

Commit

Permalink
Add a presubmit workflow that runs fuzztest tests (#2410)
Browse files Browse the repository at this point in the history
  • Loading branch information
maryla-uc authored Aug 27, 2024
1 parent fbf1cef commit a3647dc
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/actions/setup-common/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ runs:
with:
# Use the minimum required version of cmake.
cmake-version: '3.13.x'
- name: Set up CMake >= 3.21
- name: Set up CMake >= 3.25
if: ${{ runner.os == 'Linux' && inputs.recent-cmake == 'true' }}
uses: jwlawson/actions-setup-cmake@802fa1a2c4e212495c05bf94dba2704a92a472be # v2.0.2
with:
# Need cmake 3.21 to set CMAKE_C_STANDARD to 23 for [[nodiscard]].
cmake-version: '3.21.x'
# Need cmake 3.25 for fuzztest
cmake-version: '3.25.x'
- name: Print CMake version
run: cmake --version
shell: bash
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/ci-fuzztest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Builds libavif with local aom and dav1d and runs fuzztest tests
# (tests that have 'fuzztest' in their name).
# They are run in "unit test mode" (run with random inputs for a short period of time)
# see https://github.com/google/fuzztest/blob/main/doc/quickstart-cmake.md
# Runs on ubuntu only. libavif is built with clang.

name: CI Fuzztest
on: [push, pull_request]

permissions:
contents: read

# Cancel the workflow if a new one is triggered from the same PR, branch, or tag, except on main.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
build-shared-local:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04]
libyuv: [OFF, LOCAL]

name: build-shared-local-fuzztest

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ./.github/actions/setup-linux
id: setup
with:
codec-aom: 'LOCAL'
codec-dav1d: 'LOCAL'
libxml2: 'LOCAL'
libyuv: ${{ matrix.libyuv }}
recent-cmake: 'true'
- name: Build fuzztest
if: steps.setup.outputs.ext-cache-hit != 'true'
working-directory: ./ext
run: bash -e fuzztest.cmd

- name: Prepare libavif (cmake)
run: >
cmake -G Ninja -S . -B build
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
-DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_DAV1D=LOCAL
-DAVIF_LIBSHARPYUV=LOCAL -DAVIF_LIBXML2=LOCAL
-DAVIF_LIBYUV=${{ matrix.libyuv }}
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
-DAVIF_ENABLE_FUZZTEST=ON
-DAVIF_LOCAL_FUZZTEST=ON
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
-DAVIF_ENABLE_WERROR=ON
- name: Build libavif (ninja)
working-directory: ./build
run: ninja
- name: Run fuzztest AVIF Tests
working-directory: ./build
run: ctest -j $(getconf _NPROCESSORS_ONLN) --output-on-failure -R fuzztest
4 changes: 2 additions & 2 deletions ext/libargparse.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
: # If you're running this on Windows, be sure you've already run this (from your VC2019 install dir):
: # "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"

git clone --single-branch https://github.com/kmurray/libargparse.git
git clone https://github.com/maryla-uc/libargparse.git

cd libargparse
git checkout ee74d1b53bd680748af14e737378de57e2a0a954
git checkout 81998ffafb9c2ac8cf488d31e536a2e6fd6b3fdf

mkdir build
cd build
Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ enable_testing()
# C tests and tools

set(COVERAGE_TARGETS)

configure_file(${AVIF_SOURCE_DIR}/tests/CTestCustom.cmake ${CMAKE_BINARY_DIR})

# Macro to register a test for coverage. The first argument is the target name.
# Other arguments, like data path, can be added.
macro(register_test_for_coverage TEST_NAME)
Expand Down Expand Up @@ -205,6 +208,9 @@ if(AVIF_ENABLE_FUZZTEST)
if(CMAKE_VERSION VERSION_LESS 3.25.0)
message(FATAL_ERROR "CMake must be at least 3.25 to pass the SYSTEM argument to add_subdirectory(), bailing out")
endif()
# Add the fuzztest project. Note this may add some tests which may not be built because of EXCLUDE_FROM_ALL and will
# therefore fail. They can be ignored by adding them to CTestCustom.cmake
# See https://gitlab.kitware.com/cmake/cmake/-/issues/20212
add_subdirectory(${AVIF_SOURCE_DIR}/ext/fuzztest ${AVIF_SOURCE_DIR}/ext/fuzztest/build.libavif EXCLUDE_FROM_ALL SYSTEM)
else()
message(
Expand Down
4 changes: 4 additions & 0 deletions tests/CTestCustom.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CTEST_CUSTOM_TESTS_IGNORE
# Ignore failing tests brought by `add_subdirectory(${AVIF_SOURCE_DIR}/ext/fuzztest)` when AVIF_ENABLE_FUZZTEST is ON
antlr4_tests_NOT_BUILT
)

0 comments on commit a3647dc

Please sign in to comment.