Skip to content

Commit

Permalink
add fuzz ci
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed May 25, 2024
1 parent 90dcf62 commit a28b2c3
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .github/setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function c4_show_info()
echo "PROJ_PFX_TARGET=$PROJ_PFX_TARGET"
echo "PROJ_PFX_CMAKE=$PROJ_PFX_CMAKE"
echo "CMAKE_FLAGS=$CMAKE_FLAGS"
echo "CMAKE_C_FLAGS=$CMAKE_C_FLAGS"
echo "CMAKE_CXX_FLAGS=$CMAKE_CXX_FLAGS"
echo "NUM_JOBS_BUILD=$NUM_JOBS_BUILD"
echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
pwd
Expand Down Expand Up @@ -304,7 +306,7 @@ function c4_cfg_test()
-G 'Visual Studio 17 2022' -A $(_c4vsarchtype $id) \
$(_c4_add_ehsc_to_vs_arm32 $id) \
-DCMAKE_BUILD_TYPE=$BT $CMFLAGS \
-DCMAKE_C_FLAGS=" $CFLAGS" -DCMAKE_CXX_FLAGS=" $CXXFLAGS"
-DCMAKE_C_FLAGS=" $CFLAGS $CMAKE_C_FLAGS" -DCMAKE_CXX_FLAGS=" $CXXFLAGS $CMAKE_CXX_FLAGS"
;;
vs2019)
cmake -S $PROJ_DIR -B $build_dir -DCMAKE_INSTALL_PREFIX="$install_dir" \
Expand Down
53 changes: 52 additions & 1 deletion .github/workflows/clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,58 @@ jobs:
- {std: 11, cxx: "4.0", bt: Release, vg: on, img: ubuntu18.04}
- {std: 11, cxx: "3.9", bt: Debug , vg: on, img: ubuntu18.04}
- {std: 11, cxx: "3.9", bt: Release, vg: on, img: ubuntu18.04}
env: {STD: "${{matrix.std}}", CXX_: "clang++-${{matrix.cxx}}", BT: "${{matrix.bt}}", BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"}
env: {
STD: "${{matrix.std}}", CXX_: "clang++-${{matrix.cxx}}", BT: "${{matrix.bt}}",
BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}",
SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"
}
steps:
- {name: checkout, uses: actions/checkout@v3, with: {submodules: recursive}}
- run: git config --system --add safe.directory '*' # needed for running in the docker image. see https://github.com/actions/checkout/issues/1169
- run: c4core-install $CXX_
- {name: show info, run: source .github/setenv.sh && c4_show_info}
- name: shared64-configure---------------------------------------------------
run: source .github/setenv.sh && c4_cfg_test shared64
- {name: shared64-build, run: source .github/setenv.sh && c4_build_test shared64}
- {name: shared64-run, run: source .github/setenv.sh && c4_run_test shared64}
- {name: shared64-pack, run: source .github/setenv.sh && c4_package shared64}
- name: static64-configure---------------------------------------------------
run: source .github/setenv.sh && c4_cfg_test static64
- {name: static64-build, run: source .github/setenv.sh && c4_build_test static64}
- {name: static64-run, run: source .github/setenv.sh && c4_run_test static64}
- {name: static64-pack, run: source .github/setenv.sh && c4_package static64}
- name: static32-configure---------------------------------------------------
run: source .github/setenv.sh && c4_cfg_test static32
- {name: static32-build, run: source .github/setenv.sh && c4_build_test static32}
- {name: static32-run, run: source .github/setenv.sh && c4_run_test static32}
- {name: static32-pack, run: source .github/setenv.sh && c4_package static32}
- name: shared32-configure---------------------------------------------------
run: source .github/setenv.sh && c4_cfg_test shared32
- {name: shared32-build, run: source .github/setenv.sh && c4_build_test shared32}
- {name: shared32-run, run: source .github/setenv.sh && c4_run_test shared32}
- {name: shared32-pack, run: source .github/setenv.sh && c4_package shared32}

#----------------------------------------------------------------------------
clang_fuzz:
name: clang_fuzz/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}}/vg${{matrix.vg}}
continue-on-error: true
if: always() # https://stackoverflow.com/questions/62045967/github-actions-is-there-a-way-to-continue-on-error-while-still-getting-correct
runs-on: ubuntu-latest
container: ghcr.io/biojppm/c4core/${{matrix.img}}:latest # use the docker image
strategy:
fail-fast: false
matrix:
include:
- {std: 11, cxx: "16" , bt: fuzz , vg: on, img: ubuntu18.04}
- {std: 11, cxx: "16" , bt: Debug , vg: on, img: ubuntu18.04}
- {std: 11, cxx: "16" , bt: Release, vg: on, img: ubuntu18.04}
env: {
CMAKE_CXX_FLAGS: "-g -O0 -fsanitize=address,undefined",
CMAKE_FLAGS: "-DRYML_TEST_FUZZ=ON -DRYML_FUZZ_LIBFUZZER_MERGE=ON",
STD: "${{matrix.std}}", CXX_: "clang++-${{matrix.cxx}}", BT: "${{matrix.bt}}",
BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}",xs SAN: "${{matrix.san}}",
LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"
}
steps:
- {name: checkout, uses: actions/checkout@v3, with: {submodules: recursive}}
- run: git config --system --add safe.directory '*' # needed for running in the docker image. see https://github.com/actions/checkout/issues/1169
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
env: {STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}",
BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}",
LINT: "${{matrix.lint}}", OS: "${{matrix.os}}",
CMAKE_FLAGS: "${{matrix.cmk}}",
CMAKE_FLAGS: "${{matrix.cmk}} -DRYML_TEST_FUZZ=ON",
CODECOV_TOKEN: "${{secrets.CODECOV_TOKEN}}",
COVERALLS_REPO_TOKEN: "${{secrets.COVERALLS_REPO_TOKEN}}",
# coveralls disabled: https://github.com/lemurheavy/coveralls-public/issues/1665
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ jobs:
- {std: 11, cxx: g++-5 , bt: Release, bitlinks: shared64 static32}
- {std: 11, cxx: g++-4.8, bt: Debug , bitlinks: shared64 static32}
- {std: 11, cxx: g++-4.8, bt: Release, bitlinks: shared64 static32}
env: {STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}", BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"}
env: {
STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}",
BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"
}
steps:
- {name: checkout, uses: actions/checkout@v3, with: {submodules: recursive}}
- run: git config --system --add safe.directory '*' # needed for running in the docker image. see https://github.com/actions/checkout/issues/1169
Expand Down Expand Up @@ -134,7 +137,13 @@ jobs:
- {std: 11, cxx: g++-7 , bt: Release, bitlinks: shared64 static32}
- {std: 20, cxx: g++-10 , bt: Debug , bitlinks: shared64 static32}
- {std: 20, cxx: g++-10 , bt: Release, bitlinks: shared64 static32}
env: {CXXFLAGS: "-fno-exceptions -fno-rtti", STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}", BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"}
env: {
CXXFLAGS: "-fno-exceptions -fno-rtti",
CMAKE_FLAGS: "-DRYML_TEST_FUZZ=ON",
STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}",
BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}",
SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"
}
steps:
- {name: checkout, uses: actions/checkout@v3, with: {submodules: recursive}}
- run: git config --system --add safe.directory '*' # needed for running in the docker image. see https://github.com/actions/checkout/issues/1169
Expand Down Expand Up @@ -200,7 +209,12 @@ jobs:
- {std: 11, cxx: g++-4.9, bt: Release, img: ubuntu18.04}
- {std: 11, cxx: g++-4.8, bt: Debug , img: ubuntu18.04}
- {std: 11, cxx: g++-4.8, bt: Release, img: ubuntu18.04}
env: {STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}", BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"}
env: {
CMAKE_FLAGS: "-DRYML_TEST_FUZZ=ON",
STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}",
BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}",
SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"
}
steps:
- {name: checkout, uses: actions/checkout@v3, with: {submodules: recursive}}
- run: git config --system --add safe.directory '*' # needed for running in the docker image. see https://github.com/actions/checkout/issues/1169
Expand Down
23 changes: 13 additions & 10 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ endif(RYML_TEST_SUITE)
#------------------------------------------------------------------------------

string(TOUPPER "${CMAKE_BUILD_TYPE}" upper_build_type)
if((upper_build_type STREQUAL FUZZ) OR (upper_build_type STREQUAL COVERAGE))
if(upper_build_type STREQUAL FUZZ)
option(RYML_TEST_FUZZ "Enable fuzz tests" ON)
else()
option(RYML_TEST_FUZZ "Enable fuzz tests" OFF)
endif()

if(RYML_TEST_FUZZ)
c4_download_remote_proj(rapidyaml-data rapidyaml_data_dir
GIT_REPOSITORY https://github.com/biojppm/rapidyaml-data
GIT_TAG master)
Expand All @@ -288,24 +294,21 @@ if((upper_build_type STREQUAL FUZZ) OR (upper_build_type STREQUAL COVERAGE))
function(ryml_add_fuzz_test name)
c4_add_executable(ryml-test-fuzz-${name}
SOURCES
test_fuzz/test_fuzz_common.hpp
test_fuzz/test_fuzz_${name}.cpp
test_fuzz/test_fuzz_main.cpp
test_fuzz/test_fuzz_common.hpp
test_fuzz/test_fuzz_${name}.cpp
test_fuzz/test_fuzz_main.cpp
${ARGN}
INC_DIRS ${CMAKE_CURRENT_LIST_DIR}
LIBS ryml c4fs
FOLDER test/fuzz)
function(ryml_add_fuzz_test_file name_ dir file)
string(REPLACE "/" "_" fuzz_name "${file}")
#add_test(NAME ryml-test-fuzz-${name_}-${fuzz_name}
# COMMAND $<TARGET_FILE:ryml-test-fuzz-${name_}> ${dir}/${file})
add_test(NAME ryml-test-fuzz-${name_}-${fuzz_name}
COMMAND $<TARGET_FILE:ryml-test-fuzz-${name_}> ${dir}/${file})
endfunction()
foreach(fuzz_file ${fuzz_files})
ryml_add_fuzz_test_file(${name} ${corpus_artifacts_dir} ${fuzz_file})
endforeach()
foreach(fuzz_file ${suite_files})
ryml_add_fuzz_test_file(${name} ${corpus_suite_dir} ${fuzz_file})
endforeach()
if(RYML_DBG)
target_compile_definitions(ryml-test-fuzz-${name} PUBLIC RYML_DBG)
endif()
Expand All @@ -329,7 +332,7 @@ if((upper_build_type STREQUAL FUZZ) OR (upper_build_type STREQUAL COVERAGE))
#
#
# libfuzzer: https://llvm.org/docs/LibFuzzer.html
if((upper_build_type STREQUAL FUZZ) AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
option(RYML_FUZZ_LIBFUZZER_MERGE OFF "merge fuzz corpus")
option(RYML_FUZZ_LIBFUZZER_MERGE_RESUME ON "resume merge")
option(RYML_FUZZ_LIBFUZZER_DICT ON "use a yaml dict")
Expand Down
2 changes: 1 addition & 1 deletion test/test_fuzz/test_fuzz_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ inline C4_NORETURN void errcallback(const char *msg, size_t msg_len, c4::yml::Lo
jmp_msg.assign(msg, msg_len);
std::longjmp(jmp_env, 1);
);
};
}

inline c4::yml::Callbacks create_custom_callbacks()
{
Expand Down
2 changes: 1 addition & 1 deletion test/test_fuzz/test_fuzz_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *str, size_t len)
{
static std::atomic_uint32_t case_number{0};
static std::atomic<uint32_t> case_number{0};
c4::csubstr src = {reinterpret_cast<const char*>(str), len};
return c4::yml::fuzztest_yaml_events(case_number++, src);
}
2 changes: 1 addition & 1 deletion test/test_fuzz/test_fuzz_parse_emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *str, size_t len)
{
static std::atomic_uint32_t case_number{0};
static std::atomic<uint32_t> case_number{0};
c4::csubstr src = {reinterpret_cast<const char*>(str), len};
return c4::yml::fuzztest_parse_emit(case_number++, src);
}

0 comments on commit a28b2c3

Please sign in to comment.