Skip to content

Commit

Permalink
Now use AVIF_FUZZTEST with OFF/LOCAL possibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
vrabaud committed Jan 2, 2025
1 parent 12a84de commit ccd0037
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-fuzztest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
-DAVIF_LOCAL_FUZZTEST=ON
-DAVIF_FUZZTEST=LOCAL
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
-DAVIF_ENABLE_WERROR=ON
- name: Build libavif (ninja)
Expand Down
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ option(
"Build tests that compare encoding outputs to golden files. Needs AVIF_BUILD_APPS=ON and AVIF_BUILD_TESTS=ON, and depends on MP4box which can be built with ext/mp4box.sh"
OFF
)
option(
AVIF_LOCAL_FUZZTEST
"Build the Google FuzzTest framework by providing your own copy of the repo in ext/fuzztest (see Local Builds in README). CMake must be at least 3.25."
OFF
set_local_or_system_option(
"AVIF_FUZZTEST" OFF "Build the Google FuzzTest framework. Only OFF and LOCAL are supported. CMake must be at least 3.25."
)

# Whether the libavif library uses c++ indirectly (e.g. through linking to libyuv).
Expand Down Expand Up @@ -575,7 +573,7 @@ if(NOT AVIF_CODEC_AOM_ENABLED
message(WARNING "libavif: No decoding library is enabled.")
endif()

if(AVIF_LIB_USE_CXX OR AVIF_BUILD_APPS OR (AVIF_BUILD_TESTS AND (AVIF_LOCAL_FUZZTEST OR AVIF_GTEST)))
if(AVIF_LIB_USE_CXX OR AVIF_BUILD_APPS OR (AVIF_BUILD_TESTS AND (AVIF_FUZZTEST OR AVIF_GTEST)))
enable_language(CXX)
if(AVIF_ENABLE_NODISCARD)
# [[nodiscard]] requires C++17.
Expand Down Expand Up @@ -652,7 +650,7 @@ if(NOT SKIP_INSTALL_ALL)
include(GNUInstallDirs)
endif()

if(AVIF_BUILD_APPS OR (AVIF_BUILD_TESTS AND (AVIF_LOCAL_FUZZTEST OR AVIF_GTEST)))
if(AVIF_BUILD_APPS OR (AVIF_BUILD_TESTS AND (AVIF_FUZZTEST OR AVIF_GTEST)))
if(AVIF_ZLIBPNG STREQUAL "OFF")
message(FATAL_ERROR "libavif: AVIF_ZLIBPNG cannot be OFF when AVIF_BUILD_APPS or AVIF_BUILD_TESTS is ON")
elseif(AVIF_ZLIBPNG STREQUAL "SYSTEM")
Expand Down
10 changes: 5 additions & 5 deletions cmake/Modules/LocalFuzztest.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
set(AVIF_LOCAL_FUZZTEST_TAG "078ea0871cc96d3a69bad406577f176a4fa14ae9")
set(AVIF_FUZZTEST_TAG "078ea0871cc96d3a69bad406577f176a4fa14ae9")

set(FUZZTEST_SOURCE_DIR "${AVIF_SOURCE_DIR}/ext/fuzztest")

if(EXISTS "${FUZZTEST_SOURCE_DIR}")
message(STATUS "libavif(AVIF_LOCAL_FUZZTEST=ON): folder found at ${FUZZTEST_SOURCE_DIR}")
message(STATUS "libavif(AVIF_FUZZTEST=LOCAL): folder found at ${FUZZTEST_SOURCE_DIR}")
set(FUZZTEST_BINARY_DIR "${FUZZTEST_SOURCE_DIR}/build.libavif")
else()
message(STATUS "libavif(AVIF_LIBYUV=LOCAL): compiled library not found at ${LIB_FILENAME}; using FetchContent")
message(STATUS "libavif(AVIF_FUZZTEST=LOCAL): compiled library not found at ${LIB_FILENAME}; using FetchContent")

message(CHECK_START "libavif(AVIF_LOCAL_FUZZTEST=ON): configuring fuzztest")
message(CHECK_START "libavif(AVIF_FUZZTEST=LOCAL): configuring fuzztest")

set(FUZZTEST_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/fuzztest-src")
set(FUZZTEST_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/fuzztest-build")
FetchContent_Declare(
fuzztest
GIT_REPOSITORY "https://github.com/google/fuzztest.git"
BINARY_DIR "${FUZZTEST_BINARY_DIR}"
GIT_TAG "${AVIF_LOCAL_FUZZTEST_TAG}"
GIT_TAG "${AVIF_FUZZTEST_TAG}"
# Fixes for https://github.com/google/fuzztest/issues/1124
PATCH_COMMAND
sed -i.bak -e "s/-fsanitize=address//g" cmake/FuzzTestFlagSetup.cmake && sed -i.bak -e "s/-DADDRESS_SANITIZER//g"
Expand Down
9 changes: 6 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ foreach(AVIFYUV_MODE limited rgb) # Modes drift and premultiply take more than 2
add_test(NAME avifyuv_${AVIFYUV_MODE} COMMAND avifyuv -m ${AVIFYUV_MODE})
endforeach()

if(AVIF_LOCAL_FUZZTEST OR AVIF_GTEST OR AVIF_BUILD_APPS)
if(AVIF_FUZZTEST OR AVIF_GTEST OR AVIF_BUILD_APPS)
add_library(aviftest_helpers OBJECT gtest/aviftest_helpers.cc)
target_link_libraries(aviftest_helpers PUBLIC avif_apps avif)
target_link_libraries(aviftest_helpers PRIVATE avif_enable_warnings)
Expand Down Expand Up @@ -170,7 +170,7 @@ endif()
################################################################################
# Experimental FuzzTest support (Linux only)

if(AVIF_LOCAL_FUZZTEST)
if(AVIF_FUZZTEST)
# Adds a fuzztest from file TEST_NAME.cc located in the gtest folder. Extra arguments
# are considered as extra source files.
macro(add_avif_fuzztest TEST_NAME)
Expand All @@ -194,6 +194,9 @@ if(AVIF_LOCAL_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()
if(AVIF_FUZZTEST STREQUAL "SYSTEM")
message(FATAL_ERROR "SYSTEM is not supported for AVIF_FUZZTEST")
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
Expand All @@ -215,7 +218,7 @@ if(AVIF_LOCAL_FUZZTEST)
add_avif_fuzztest(avif_fuzztest_read_image)
add_avif_fuzztest(avif_fuzztest_yuvrgb)
else()
message(STATUS "FuzzTest targets are disabled because AVIF_LOCAL_FUZZTEST is OFF.")
message(STATUS "FuzzTest targets are disabled because AVIF_FUZZTEST is OFF.")
endif()

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion tests/CTestCustom.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(CTEST_CUSTOM_TESTS_IGNORE
# Ignore failing tests brought by `add_subdirectory(${AVIF_SOURCE_DIR}/ext/fuzztest)` when AVIF_LOCAL_FUZZTEST is ON
# Ignore failing tests brought by `add_subdirectory(${AVIF_SOURCE_DIR}/ext/fuzztest)` when AVIF_FUZZTEST is not OFF
antlr4_tests_NOT_BUILT
)
2 changes: 1 addition & 1 deletion tests/oss-fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This document provides links and knowledge about fuzzing libavif on oss-fuzz.
You need to build with the following CMake flags:

```sh
-DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_AOM_DECODE=ON -DAVIF_CODEC_AOM_ENCODE=ON -DAVIF_CODEC_DAV1D=LOCAL -DAVIF_LIBYUV=LOCAL -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL -DAVIF_LOCAL_FUZZTEST=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DAVIF_ENABLE_WERROR=OFF
-DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_AOM_DECODE=ON -DAVIF_CODEC_AOM_ENCODE=ON -DAVIF_CODEC_DAV1D=LOCAL -DAVIF_LIBYUV=LOCAL -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL -DAVIF_FUZZTEST=LOCAL -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DAVIF_ENABLE_WERROR=OFF
```

You can then run your tests as normal:
Expand Down
2 changes: 1 addition & 1 deletion tests/oss-fuzz/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if [[ "$FUZZING_ENGINE" == "libfuzzer" ]]; then
fi
cmake .. -G Ninja -DBUILD_SHARED_LIBS=OFF -DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_DAV1D=LOCAL \
-DAVIF_CODEC_AOM_DECODE=ON -DAVIF_CODEC_AOM_ENCODE=ON \
-DAVIF_LOCAL_FUZZTEST=ON \
-DAVIF_FUZZTEST=LOCAL \
-DAVIF_JPEG=LOCAL -DAVIF_LIBSHARPYUV=LOCAL \
-DAVIF_LIBYUV=LOCAL -DAVIF_ZLIBPNG=LOCAL \
-DAVIF_BUILD_TESTS=ON -DAVIF_GTEST=OFF -DAVIF_ENABLE_WERROR=ON \
Expand Down

0 comments on commit ccd0037

Please sign in to comment.