Add a presubmit workflow that runs fuzztest tests (#2410)

diff --git a/.github/actions/setup-common/action.yml b/.github/actions/setup-common/action.yml
index c19b571..94b708a 100644
--- a/.github/actions/setup-common/action.yml
+++ b/.github/actions/setup-common/action.yml
@@ -26,12 +26,13 @@
       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
diff --git a/.github/workflows/ci-fuzztest.yml b/.github/workflows/ci-fuzztest.yml
new file mode 100644
index 0000000..2e620dd
--- /dev/null
+++ b/.github/workflows/ci-fuzztest.yml
@@ -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
diff --git a/ext/libargparse.cmd b/ext/libargparse.cmd
index 509c7b0..d04045c 100755
--- a/ext/libargparse.cmd
+++ b/ext/libargparse.cmd
@@ -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
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index da71adb..90c9aac 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -9,6 +9,9 @@
 # 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)
@@ -205,6 +208,9 @@
         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(
diff --git a/tests/CTestCustom.cmake b/tests/CTestCustom.cmake
new file mode 100644
index 0000000..2873481
--- /dev/null
+++ b/tests/CTestCustom.cmake
@@ -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
+)