summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathis Rosenhauer <rosenhauer@dkrz.de>2017-06-29 15:59:14 (GMT)
committerMathis Rosenhauer <rosenhauer@dkrz.de>2017-06-30 15:06:09 (GMT)
commit8cd1a00dcbc58d69b5bff2ed93a2f42d491e54cf (patch)
tree0006e9fbbdebb7b174951b3182d1ac26078029c4
parentd5a9a756ef5dff1f747b2692cdc0e1a31a69e39f (diff)
downloadlibaec-8cd1a00dcbc58d69b5bff2ed93a2f42d491e54cf.zip
libaec-8cd1a00dcbc58d69b5bff2ed93a2f42d491e54cf.tar.gz
libaec-8cd1a00dcbc58d69b5bff2ed93a2f42d491e54cf.tar.bz2
cmake: fuzzing
-rw-r--r--CMakeLists.txt126
-rw-r--r--cmake/macros.cmake84
-rw-r--r--fuzz/CMakeLists.txt17
-rw-r--r--src/CMakeLists.txt72
-rw-r--r--tests/CMakeLists.txt37
5 files changed, 174 insertions, 162 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ed1b3df..7d109bc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,72 +1,78 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6)
-INCLUDE(CheckIncludeFiles)
-INCLUDE(TestBigEndian)
-INCLUDE(CheckCSourceCompiles)
-INCLUDE(cmake/macros.cmake)
-PROJECT(libaec)
-SET(libaec_VERSION_MAJOR 1)
-SET(libaec_VERSION_MINOR 0)
-SET(libaec_VERSION_PATCH 0)
-SET(CMAKE_BUILD_TYPE Release)
-ENABLE_TESTING()
+cmake_minimum_required(VERSION 2.8.6)
+include(CheckIncludeFiles)
+include(TestBigEndian)
+include(CheckCSourceCompiles)
+include(cmake/macros.cmake)
+project(libaec)
+set(libaec_VERSION_MAJOR 1)
+set(libaec_VERSION_MINOR 0)
+set(libaec_VERSION_PATCH 0)
+set(CMAKE_BUILD_TYPE Release)
+enable_testing()
-CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H)
-CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
-TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
-CHECK_CLZLL(HAVE_DECL___BUILTIN_CLZLL)
-IF(NOT HAVE_DECL___BUILTIN_CLZLL)
- CHECK_BSR64(HAVE_BSR64)
-ENDIF(NOT HAVE_DECL___BUILTIN_CLZLL)
-FIND_INLINE_KEYWORD()
-FIND_RESTRICT_KEYWORD()
+check_include_files(malloc.h HAVE_MALLOC_H)
+check_include_files(stdint.h HAVE_STDINT_H)
+test_big_endian(WORDS_BIGENDIAN)
+check_clzll(HAVE_DECL___BUILTIN_CLZLL)
+if(NOT HAVE_DECL___BUILTIN_CLZLL)
+ check_bsr64(HAVE_BSR64)
+endif(NOT HAVE_DECL___BUILTIN_CLZLL)
+find_inline_keyword()
+find_restrict_keyword()
-CONFIGURE_FILE(
+configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
- ${CMAKE_CURRENT_BINARY_DIR}/config.h
- )
-ADD_DEFINITIONS("-DHAVE_CONFIG_H")
+ ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+add_definitions("-DHAVE_CONFIG_H")
-# Allow the developer to select if Dynamic or Static libraries are built
-OPTION(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
-IF(BUILD_SHARED_LIBS)
- SET (LIB_TYPE SHARED)
-ELSE(BUILD_SHARED_LIBS)
- IF(WIN32)
- MESSAGE(WARNING "You will have to modify libaec.h for static libs.")
- ENDIF(WIN32)
- SET(LIB_TYPE STATIC)
-ENDIF(BUILD_SHARED_LIBS)
+option(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
+if(BUILD_SHARED_LIBS)
+ set (LIB_TYPE SHARED)
+else(BUILD_SHARED_LIBS)
+ if(WIN32)
+ message(WARNING "You will have to modify libaec.h for static libs.")
+ endif(WIN32)
+ set(LIB_TYPE STATIC)
+endif(BUILD_SHARED_LIBS)
-INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
-INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}/src")
-INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src")
+set(libaec_SRCS
+ ${PROJECT_SOURCE_DIR}/src/encode.c
+ ${PROJECT_SOURCE_DIR}/src/encode_accessors.c
+ ${PROJECT_SOURCE_DIR}/src/decode.c)
-ADD_SUBDIRECTORY(src)
-# EXCLUDE_FROM_ALL doesn't seem to be working in VS
-ADD_SUBDIRECTORY(tests)
+include_directories("${PROJECT_BINARY_DIR}")
+include_directories("${PROJECT_SOURCE_DIR}/src")
-SET(CPACK_PACKAGE_NAME "libaec")
-SET(CPACK_PACKAGE_VENDOR "Deutsches Klimarechenzentrum GmbH")
-SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
+add_subdirectory(src)
+add_subdirectory(tests)
+
+option(AEC_FUZZING "Enable build of fuzzing targets" OFF)
+if(AEC_FUZZING)
+ add_subdirectory(fuzz)
+endif()
+
+set(CPACK_PACKAGE_NAME "libaec")
+set(CPACK_PACKAGE_VENDOR "Deutsches Klimarechenzentrum GmbH")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"libaec - Adaptive Entropy Coding library")
-SET(CPACK_PACKAGE_VERSION_MAJOR "${libaec_VERSION_MAJOR}")
-SET(CPACK_PACKAGE_VERSION_MINOR "${libaec_VERSION_MINOR}")
-SET(CPACK_PACKAGE_VERSION_PATCH "${libaec_VERSION_PATCH}")
-SET(CPACK_PACKAGE_INSTALL_DIRECTORY "libaec")
-SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/Copyright.txt")
+set(CPACK_PACKAGE_VERSION_MAJOR "${libaec_VERSION_MAJOR}")
+set(CPACK_PACKAGE_VERSION_MINOR "${libaec_VERSION_MINOR}")
+set(CPACK_PACKAGE_VERSION_PATCH "${libaec_VERSION_PATCH}")
+set(CPACK_PACKAGE_INSTALL_DIRECTORY "libaec")
+set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/Copyright.txt")
-IF(WIN32)
- SET(CPACK_GENERATOR "WIX")
- SET(CPACK_WIX_UPGRADE_GUID "E58A21F6-BB99-46B5-8AD8-6114E4CCA0A6")
- IF(CMAKE_CL_64)
- SET(CPACK_INSTALL_DIRECTORY "$PROGRAMFILES64")
- SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
+if(WIN32)
+ set(CPACK_GENERATOR "WIX")
+ set(CPACK_WIX_UPGRADE_GUID "E58A21F6-BB99-46B5-8AD8-6114E4CCA0A6")
+ if(CMAKE_CL_64)
+ set(CPACK_INSTALL_DIRECTORY "$PROGRAMFILES64")
+ set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION} (Win64)")
- ELSE(CMAKE_CL_64)
- SET(CPACK_INSTALL_DIRECTORY "$PROGRAMFILES")
- SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
+ else(CMAKE_CL_64)
+ set(CPACK_INSTALL_DIRECTORY "$PROGRAMFILES")
+ set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
- ENDIF(CMAKE_CL_64)
-ENDIF(WIN32)
+ endif(CMAKE_CL_64)
+endif(WIN32)
-INCLUDE(CPack)
+include(CPack)
diff --git a/cmake/macros.cmake b/cmake/macros.cmake
index 39bca9a..a568b15 100644
--- a/cmake/macros.cmake
+++ b/cmake/macros.cmake
@@ -1,77 +1,77 @@
-MACRO(CHECK_CLZLL VARIABLE)
- CHECK_C_SOURCE_COMPILES(
+macro(check_clzll VARIABLE)
+ check_c_source_compiles(
"int main(int argc, char *argv[])
{return __builtin_clzll(1LL);}"
${VARIABLE}
)
-ENDMACRO()
+endmacro()
-MACRO(CHECK_BSR64 VARIABLE)
- CHECK_C_SOURCE_COMPILES(
+macro(check_bsr64 VARIABLE)
+ check_c_source_compiles(
"int main(int argc, char *argv[])
{unsigned long foo; unsigned __int64 bar=1LL;
return _BitScanReverse64(&foo, bar);}"
${VARIABLE}
)
-ENDMACRO()
+endmacro()
-MACRO(FIND_INLINE_KEYWORD)
+macro(find_inline_keyword)
#Inspired from http://www.cmake.org/Wiki/CMakeTestInline
- SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
+ set(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
static inline int static_foo(){return 0\;}
int main(int argc, char *argv[]){return 0\;}
")
- FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
${INLINE_TEST_SRC})
- FOREACH(KEYWORD "inline" "__inline__" "__inline")
- IF(NOT DEFINED C_INLINE)
- TRY_COMPILE(C_HAS_${KEYWORD}
+ foreach(KEYWORD "inline" "__inline__" "__inline")
+ if(NOT DEFINED C_INLINE)
+ try_compile(C_HAS_${KEYWORD}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
COMPILE_DEFINITIONS "-Dinline=${KEYWORD}"
)
- IF(C_HAS_${KEYWORD})
- SET(C_INLINE TRUE)
- ADD_DEFINITIONS("-Dinline=${KEYWORD}")
- MESSAGE(STATUS "Inline keyword found - ${KEYWORD}")
- ENDIF(C_HAS_${KEYWORD})
- ENDIF(NOT DEFINED C_INLINE)
- ENDFOREACH(KEYWORD)
+ if(C_HAS_${KEYWORD})
+ set(C_INLINE TRUE)
+ add_definitions("-Dinline=${KEYWORD}")
+ message(STATUS "Inline keyword found - ${KEYWORD}")
+ endif(C_HAS_${KEYWORD})
+ endif(NOT DEFINED C_INLINE)
+ endforeach(KEYWORD)
- IF(NOT DEFINED C_INLINE)
- ADD_DEFINITIONS("-Dinline=")
- MESSAGE(STATUS "Inline keyword - not found")
- ENDIF(NOT DEFINED C_INLINE)
-ENDMACRO(FIND_INLINE_KEYWORD)
+ if(NOT DEFINED C_INLINE)
+ add_definitions("-Dinline=")
+ message(STATUS "Inline keyword - not found")
+ endif(NOT DEFINED C_INLINE)
+endmacro(find_inline_keyword)
-MACRO(FIND_RESTRICT_KEYWORD)
- SET(RESTRICT_TEST_SRC "/* Inspired by autoconf's c.m4 */
+macro(find_restrict_keyword)
+ set(RESTRICT_TEST_SRC "/* Inspired by autoconf's c.m4 */
int foo (int * restrict ip){return ip[0]\;}
int main(int argc, char *argv[]){int s[1]\;
int * restrict t = s\; t[0] = 0\; return foo(t)\;}
")
- FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
${RESTRICT_TEST_SRC})
- FOREACH(KEYWORD "restrict" "__restrict" "__restrict__" "_Restrict")
- IF(NOT DEFINED C_RESTRICT)
- TRY_COMPILE(C_HAS_${KEYWORD}
+ foreach(KEYWORD "restrict" "__restrict" "__restrict__" "_Restrict")
+ if(NOT DEFINED C_RESTRICT)
+ try_compile(C_HAS_${KEYWORD}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
COMPILE_DEFINITIONS "-Drestrict=${KEYWORD}"
)
- IF(C_HAS_${KEYWORD})
- SET(C_RESTRICT TRUE)
- ADD_DEFINITIONS("-Drestrict=${KEYWORD}")
- MESSAGE(STATUS "Restrict keyword found - ${KEYWORD}")
- ENDIF(C_HAS_${KEYWORD})
- ENDIF(NOT DEFINED C_RESTRICT)
- ENDFOREACH(KEYWORD)
+ if(C_HAS_${KEYWORD})
+ set(C_RESTRICT TRUE)
+ add_definitions("-Drestrict=${KEYWORD}")
+ message(STATUS "Restrict keyword found - ${KEYWORD}")
+ endif(C_HAS_${KEYWORD})
+ endif(NOT DEFINED C_RESTRICT)
+ endforeach(KEYWORD)
- IF(NOT DEFINED C_RESTRICT)
- ADD_DEFINITIONS("-Drestrict=")
- MESSAGE(STATUS "Restrict keyword - not found")
- ENDIF(NOT DEFINED C_RESTRICT)
-ENDMACRO(FIND_RESTRICT_KEYWORD)
+ if(NOT DEFINED C_RESTRICT)
+ add_definitions("-Drestrict=")
+ message(STATUS "Restrict keyword - not found")
+ endif(NOT DEFINED C_RESTRICT)
+endmacro(find_restrict_keyword)
diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt
new file mode 100644
index 0000000..b57e642
--- /dev/null
+++ b/fuzz/CMakeLists.txt
@@ -0,0 +1,17 @@
+if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
+endif()
+
+add_library(aec_fuzz STATIC ${libaec_SRCS})
+add_executable(fuzz_target fuzz_target.cc)
+
+set(FUZZ_TARGET_LINK_FLAGS "-fsanitize=address")
+set(FUZZ_TARGET_COMPILE_FLAGS
+ "-g"
+ "-fsanitize=address"
+ "-fsanitize-coverage=trace-pc-guard,indirect-calls,edge")
+set_target_properties(fuzz_target aec_fuzz PROPERTIES
+ LINK_FLAGS ${FUZZ_TARGET_LINK_FLAGS}
+ COMPILE_OPTIONS "${FUZZ_TARGET_COMPILE_FLAGS}")
+
+target_link_libraries(fuzz_target aec_fuzz Fuzzer)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2198cce..6ddf029 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,59 +1,49 @@
-SET(libaec_SRCS encode.c encode_accessors.c decode.c)
-ADD_LIBRARY(aec ${LIB_TYPE} ${libaec_SRCS})
-SET_TARGET_PROPERTIES(aec PROPERTIES
- VERSION 0.0.6 SOVERSION 0
- )
-ADD_LIBRARY(sz ${LIB_TYPE} sz_compat.c)
-SET_TARGET_PROPERTIES(sz PROPERTIES
- VERSION 2.0.1 SOVERSION 2
- )
+add_library(aec ${LIB_TYPE} ${libaec_SRCS})
+set_target_properties(aec PROPERTIES VERSION 0.0.6 SOVERSION 0)
+add_library(sz ${LIB_TYPE} sz_compat.c)
+set_target_properties(sz PROPERTIES VERSION 2.0.1 SOVERSION 2)
-TARGET_LINK_LIBRARIES(sz aec)
-IF(WIN32 AND BUILD_SHARED_LIBS)
- SET_TARGET_PROPERTIES (aec PROPERTIES DEFINE_SYMBOL "BUILDING_LIBAEC")
- SET_TARGET_PROPERTIES (sz PROPERTIES DEFINE_SYMBOL "BUILDING_LIBAEC")
- SET_TARGET_PROPERTIES(sz PROPERTIES OUTPUT_NAME "szip")
-ENDIF(WIN32 AND BUILD_SHARED_LIBS)
+target_link_libraries(sz aec)
+if(WIN32 AND BUILD_SHARED_LIBS)
+ set_target_properties (aec PROPERTIES DEFINE_SYMBOL "BUILDING_LIBAEC")
+ set_target_properties (sz PROPERTIES DEFINE_SYMBOL "BUILDING_LIBAEC")
+ set_target_properties(sz PROPERTIES OUTPUT_NAME "szip")
+endif(WIN32 AND BUILD_SHARED_LIBS)
-ADD_EXECUTABLE(aec_client aec.c)
-SET_TARGET_PROPERTIES(aec_client PROPERTIES OUTPUT_NAME "aec")
-TARGET_LINK_LIBRARIES(aec_client aec)
+add_executable(aec_client aec.c)
+set_target_properties(aec_client PROPERTIES OUTPUT_NAME "aec")
+target_link_libraries(aec_client aec)
-IF(UNIX)
- ADD_EXECUTABLE(utime EXCLUDE_FROM_ALL utime.c)
- ADD_CUSTOM_TARGET(bench
+if(UNIX)
+ add_executable(utime EXCLUDE_FROM_ALL utime.c)
+ add_custom_target(bench
COMMAND ${CMAKE_SOURCE_DIR}/src/benc.sh ${CMAKE_SOURCE_DIR}/data/typical.rz
COMMAND ${CMAKE_SOURCE_DIR}/src/bdec.sh
- DEPENDS aec_client utime
- )
-ENDIF(UNIX)
+ DEPENDS aec_client utime)
+endif(UNIX)
-INCLUDE(GNUInstallDirs)
-IF(WIN32)
- INSTALL(TARGETS aec sz
+include(GNUInstallDirs)
+if(WIN32)
+ install(TARGETS aec sz
RUNTIME
DESTINATION bin
ARCHIVE
DESTINATION lib
- COMPONENT libraries
- )
-ELSE(WIN32)
- INSTALL(TARGETS aec sz
+ COMPONENT libraries)
+else(WIN32)
+ install(TARGETS aec sz
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
- COMPONENT libraries
- )
-ENDIF(WIN32)
-INSTALL(FILES libaec.h szlib.h
+ COMPONENT libraries)
+endif(WIN32)
+install(FILES libaec.h szlib.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
- COMPONENT headers
- )
-INSTALL(TARGETS aec_client
+ COMPONENT headers)
+install(TARGETS aec_client
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
- COMPONENT applications
- )
+ COMPONENT applications)
-SET(CPACK_COMPONENTS_ALL applications libraries headers)
+set(CPACK_COMPONENTS_ALL applications libraries headers)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e4bcd78..3553ff5 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,23 +1,22 @@
-ADD_LIBRARY(check_aec STATIC check_aec.c)
+add_library(check_aec STATIC check_aec.c)
-ADD_EXECUTABLE(check_code_options check_code_options.c)
-TARGET_LINK_LIBRARIES(check_code_options check_aec aec)
-ADD_TEST(NAME check_code_options COMMAND check_code_options)
-ADD_EXECUTABLE(check_buffer_sizes check_buffer_sizes.c)
-TARGET_LINK_LIBRARIES(check_buffer_sizes check_aec aec)
-ADD_TEST(NAME check_buffer_sizes COMMAND check_buffer_sizes)
-ADD_EXECUTABLE(check_long_fs check_long_fs.c)
-TARGET_LINK_LIBRARIES(check_long_fs check_aec aec)
-ADD_TEST(NAME check_long_fs COMMAND check_long_fs)
-ADD_EXECUTABLE(check_szcomp check_szcomp.c)
-TARGET_LINK_LIBRARIES(check_szcomp check_aec sz)
-ADD_TEST(NAME check_szcomp
- COMMAND check_szcomp ${CMAKE_CURRENT_SOURCE_DIR}/../data/121B2TestData/ExtendedParameters/sar32bit.dat)
+add_executable(check_code_options check_code_options.c)
+target_link_libraries(check_code_options check_aec aec)
+add_test(NAME check_code_options COMMAND check_code_options)
+add_executable(check_buffer_sizes check_buffer_sizes.c)
+target_link_libraries(check_buffer_sizes check_aec aec)
+add_test(NAME check_buffer_sizes COMMAND check_buffer_sizes)
+add_executable(check_long_fs check_long_fs.c)
+target_link_libraries(check_long_fs check_aec aec)
+add_test(NAME check_long_fs COMMAND check_long_fs)
+add_executable(check_szcomp check_szcomp.c)
+target_link_libraries(check_szcomp check_aec sz)
+add_test(NAME check_szcomp
+ COMMAND check_szcomp ${PROJECT_SOURCE_DIR}/data/121B2TestData/ExtendedParameters/sar32bit.dat)
-IF(UNIX)
- ADD_TEST(
+if(UNIX)
+ add_test(
NAME sampledata.sh
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/sampledata.sh ${CMAKE_CURRENT_SOURCE_DIR}
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- )
-ENDIF(UNIX)
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+endif(UNIX)