Skip to content

Commit

Permalink
Add ClusterFuzzLite
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaskosunen committed Jan 13, 2024
1 parent e29bd86 commit c1c9a17
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM gcr.io/oss-fuzz-base/base-builder

RUN echo "CXX=$CXX"
RUN echo "CXXFLAGS=$CXXFLAGS"

RUN apt update && \
apt install -y --no-install-recommends \
ninja-build cmake && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY . $SRC/scnlib
WORKDIR $SRC/scnlib
COPY ./.clusterfuzzlite/build.sh $SRC/
29 changes: 29 additions & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash -eu

mkdir build
cd build

cmake .. \
-G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=17 \
-DSCN_DISABLE_TOP_PROJECT=ON -DSCN_FUZZING=ON \
-DSCN_FUZZING_LDFLAGS="$LIB_FUZZING_ENGINE"

cmake --build .

# Binary targets
cp tests/fuzz/scn_fuzz_* "$OUT"

fuzz_src_dir="$(pwd)/../tests/fuzz"

# Dictionaries and seed corpora
copy_data() {
cp "$fuzz_src_dir/dictionaries/$1.txt" "$OUT/scn_fuzz_$2.dict"

zip "$OUT/scn_fuzz_$2_seed_corpus.zip" "$fuzz_src_dir"/seed-corpora/"$1"/*
}
copy_data float float
copy_data format format
copy_data int int
copy_data int roundtrip
copy_data string string
copy_data string string_impl
4 changes: 4 additions & 0 deletions .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
homepage: "https://github.com/eliaskosunen/scnlib"
language: c++
primary_contact: "[email protected]"
main_repo: "https://github.com/eliaskosunen/scnlib.git"
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build*/
cmake-build*/
docs/html/
41 changes: 40 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}-${{ github.event.schedule }}
cancel-in-progress: true

env:
APT_INSTALL: |
sudo apt-get install
-yq --no-install-suggests --no-install-recommends
--allow-unauthenticated --allow-downgrades --allow-change-held-packages
CCACHE_ABSSTDERR: true
CCACHE_COMPRESS: true
CCACHE_COMPRESSLEVEL: 6
CCACHE_DIR: "/tmp/ccache"
CCACHE_MAXSIZE: 100M
CCACHE_NOHASHDIR: true
CCACHE_SLOPPINESS: "pch_defines,time_macros"
CCACHE_UNIFY: true
DEBIAN_FRONTEND: noninteractive
CXX: g++-11
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache

jobs:
codecov:
runs-on: ubuntu-22.04
Expand All @@ -40,14 +58,31 @@ jobs:
sudo update-locale
sudo locale -a
sudo apt-get install -yq lcov
sudo apt-get install -yq lcov ccache
mkdir ${{ github.workspace }}/build
mkdir ${{ github.workspace }}/report
- name: Checkout
uses: actions/checkout@v4

- name: Load ccache
uses: actions/cache@v3
with:
path: ${{ env.CCACHE_DIR }}
key: coverage-${{ github.sha }}
restore-keys: |
coverage-${{ github.ref }}
coverage-${{ github.base_ref }}
coverage
- name: Setup ccache
run: |
ccache --version
ccache --zero-stats
ccache --show-stats
ccache --show-config
- name: Run CMake
working-directory: ${{ github.workspace }}/build
run: |
Expand All @@ -61,6 +96,10 @@ jobs:
run: |
cmake --build . -- -k 0
- name: Show ccache stats
run: |
ccache --show-stats
- name: Generate Coverage Report
working-directory: ${{ github.workspace }}/build
run: |
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/fuzz-batch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: ClusterFuzzLite batch fuzzing

on:
schedule:
- cron: '0 0/6 * * *' # Every 6th hour
push:
branches:
- master
- dev
paths:
- '.github/**'
- 'benchmark/**'
- 'cmake/**'
- 'examples/**'
- 'include/**'
- 'src/**'
- 'tests/**'
- '**/CMakeLists.txt'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}-${{ github.event.schedule }}
cancel-in-progress: true

jobs:
fuzz:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sanitizer:
- address
- undefined
- memory

steps:
- name: Build fuzzers
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
language: c++
sanitizer: ${{ matrix.sanitizer }}

- name: Run fuzzers
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 3600
mode: 'batch'
sanitizer: ${{ matrix.sanitizer }}
output-sarif: true
41 changes: 41 additions & 0 deletions .github/workflows/fuzz-continuous.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: ClusterFuzzLite PR fuzzing

on:
push:
branches:
- master
- dev
paths:
- '.github/**'
- 'benchmark/**'
- 'cmake/**'
- 'examples/**'
- 'include/**'
- 'src/**'
- 'tests/**'
- '**/CMakeLists.txt'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}-${{ github.event.schedule }}
cancel-in-progress: true

jobs:
fuzz:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sanitizer:
- address
- undefined
- memory

steps:
- name: Build fuzzers
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
language: c++
sanitizer: ${{ matrix.sanitizer }}
upload-build: true
50 changes: 50 additions & 0 deletions .github/workflows/fuzz-cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: ClusterFuzzLite cron-jobs

on:
schedule:
- cron: '0 0 * * *' # Once a day at midnight
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}-${{ github.event.schedule }}
cancel-in-progress: true

jobs:
fuzz-prune:
runs-on: ubuntu-latest

steps:
- name: Build fuzzers
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
language: c++

- name: Run fuzzers
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 600
mode: 'prune'
output-sarif: true

fuzz-coverage:
runs-on: ubuntu-latest

steps:
- name: Build fuzzers
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
language: c++
sanitizer: coverage

- name: Run fuzzers
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 600
mode: 'coverage'
sanitizer: 'coverage'
47 changes: 47 additions & 0 deletions .github/workflows/fuzz-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: ClusterFuzzLite PR fuzzing

on:
pull_request:
paths:
- '.github/**'
- 'benchmark/**'
- 'cmake/**'
- 'examples/**'
- 'include/**'
- 'src/**'
- 'tests/**'
- '**/CMakeLists.txt'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}-${{ github.event.schedule }}
cancel-in-progress: true

jobs:
fuzz:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sanitizer:
- address
- undefined
- memory

steps:
- name: Build fuzzers
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
language: c++
github-token: ${{ secrets.GITHUB_TOKEN }}
sanitizer: ${{ matrix.sanitizer }}

- name: Run fuzzers
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 600
mode: 'code-change'
sanitizer: ${{ matrix.sanitizer }}
1 change: 1 addition & 0 deletions .github/workflows/lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ jobs:
- name: Create Build Environment
run: |
mkdir ${{ github.workspace }}/build
brew install --overwrite ccache
- name: Load ccache
uses: actions/cache@v3
Expand Down
4 changes: 3 additions & 1 deletion cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ option(SCN_BENCHMARKS "Enable runtime benchmarks" ${SCN_ENABLE_EXTRAS})
option(SCN_BENCHMARKS_BUILDTIME "Enable buildtime benchmarks" ${SCN_ENABLE_EXTRAS})
option(SCN_BENCHMARKS_BINARYSIZE "Enable binary size benchmarks" ${SCN_ENABLE_EXTRAS})

option(SCN_FUZZING "Enable fuzz tests (clang only)" OFF)
option(SCN_COVERAGE "Enable coverage reporting" OFF)
option(SCN_TESTS_LOCALIZED "Enable localized tests (requires en_US.UTF-8 and fi_FI.UTF-8 locales)" OFF)

option(SCN_FUZZING "Enable fuzz tests (clang only)" OFF)
set(SCN_FUZZING_LDFLAGS "" CACHE STRING "")

option(SCN_PEDANTIC "Enable pedantic compilation flags" ${SCN_ENABLE_EXTRAS})
option(SCN_WERROR "Halt compilation in case of a warning" ${SCN_CI})

Expand Down
9 changes: 7 additions & 2 deletions tests/fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (NOT SCN_FUZZING)
return()
endif()
endif ()

add_library(scn_fuzz_base INTERFACE)
target_link_libraries(scn_fuzz_base INTERFACE scn scn_fuzzer simdutf::simdutf)
Expand All @@ -9,7 +9,12 @@ function(add_fuzzer name)
add_executable(scn_fuzz_${name}
fuzz.h
${name}_fuzz.cpp)
target_link_libraries(scn_fuzz_${name} PUBLIC scn_fuzz_base)
target_link_libraries(scn_fuzz_${name} PRIVATE scn simdutf::simdutf)
if (SCN_FUZZING_LDFLAGS)
target_link_libraries(scn_fuzz_${name} PRIVATE ${SCN_FUZZING_LDFLAGS})
else ()
target_link_libraries(scn_fuzz_${name} INTERFACE scn_fuzzer)
endif ()
endfunction()

add_fuzzer(int)
Expand Down

0 comments on commit c1c9a17

Please sign in to comment.