Commit 86ecd6008da3b0b0baa0833fd8932e91994a9f9b

Patrick Steinhardt 2019-06-28T15:11:27

fuzzers: provide test targets Instead of having to find the fuzzer executables in our Azure test scripts, provide test targets for each of our fuzzers that will run them with the correct paths.

diff --git a/ci/test.sh b/ci/test.sh
index 9e12f53..cbc3925 100755
--- a/ci/test.sh
+++ b/ci/test.sh
@@ -256,9 +256,7 @@ if [ -z "$SKIP_FUZZERS" ]; then
 	echo "## Running fuzzers"
 	echo "##############################################################################"
 
-	for fuzzer in fuzzers/*_fuzzer; do
-		"${fuzzer}" "${SOURCE_DIR}/fuzzers/corpora/$(basename "${fuzzer%_fuzzer}")" || failure
-	done
+	ctest -V -R 'fuzzer'
 fi
 
 cleanup
diff --git a/fuzzers/CMakeLists.txt b/fuzzers/CMakeLists.txt
index 1c03aa9..59eca24 100644
--- a/fuzzers/CMakeLists.txt
+++ b/fuzzers/CMakeLists.txt
@@ -9,6 +9,8 @@ ENDIF ()
 FILE(GLOB SRC_FUZZ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c)
 FOREACH(fuzz_target_src ${SRC_FUZZ})
 	STRING(REPLACE ".c" "" fuzz_target_name ${fuzz_target_src})
+	STRING(REPLACE "_fuzzer" "" fuzz_name ${fuzz_target_name})
+
 	SET(${fuzz_target_name}_SOURCES ${fuzz_target_src} ${LIBGIT2_OBJECTS})
 	IF(USE_STANDALONE_FUZZERS)
 		LIST(APPEND ${fuzz_target_name}_SOURCES "standalone_driver.c")
@@ -16,4 +18,6 @@ FOREACH(fuzz_target_src ${SRC_FUZZ})
 	ADD_EXECUTABLE(${fuzz_target_name} ${${fuzz_target_name}_SOURCES})
 	SET_TARGET_PROPERTIES(${fuzz_target_name} PROPERTIES C_STANDARD 90)
 	TARGET_LINK_LIBRARIES(${fuzz_target_name} ${LIBGIT2_LIBS})
+
+	ADD_TEST(${fuzz_target_name} "${CMAKE_CURRENT_BINARY_DIR}/${fuzz_target_name}" "${CMAKE_CURRENT_SOURCE_DIR}/corpora/${fuzz_name}")
 ENDFOREACH()