The branch, master has been updated via c26835a gitlab-ci: Disable the FreeBSD runner via 7628650 gitlab-ci: Add helgrind tests via bee622b gitlab-ci: Add runners and toolchain files via ab9cf16 tests: Init in_addr only once in test_tcp_socket_overwrite via 35174c8 tests: Return an error if setenv() fails in test_max_sockets via b6f1a42 tests: Check the correct return code in test_thread_echo_tcp_write_read via d588231 tests: Check return code of connect in test_thread_echo_tcp_sendmsg_recvmsg via 7232dee tests: Check the return code of connect in test_echo_udp_sendmsg_recvmsg via 6e65180 tests: Check return code of connnect in test_echo_tcp_sendmsg_recvmsg via 545d0b7 echo_srv: Check for a valid pidfile pointer via 04091a9 echo_srv: Only use 128K as buffer size instead of 4MB via c49a629 torture: Wait longer for echo_srv startup via 9289145 echo_srv: Do not close bogus file descriptors via 326e9f8 swrap: Don't do a deep bind if we run with libasan via 370ece1 swrap: Add a mutex for resetting socket index via 0b1a43e swrap: Fix helgrind errors via a2a8a80 tests: Use assert_return_code() to get errno via 0983cd2 tests: Avoid -Wcast-align warning via 3d340c3 tests: Fix -Wformat gcc warning via 702f2fb cmake: Fix checking for required system libraries via 62080ac cmake: Use target_include_directories() via d3d419b cmake: Require modern cmake version via b976977 cmake: Update AddCMockaTest via b91dae5 cmake: Update cmocka requirement via 4adb5cf cmake: Support running the tests with AddressSanitizer via da17de1 cmake: Add CFLAGS for AddressSanitizer and UndefinedSanitizer via 402f548 cmake: Move Compiler flags to new file via 013687b cmake: Remove obsolete DefineCompilerFlags.cmake via aa9b0da cmake: Improve checks for compiler flags via 5672618 cmake: Update CMake defaults via a5df8fc cmake: Suppress helgrind race condition warning we created on purpose via da4b908 cmake: Create an error if helgrind finds a bug via f465bf4 cmake: Write helgrind logs to stderr so we can see them via 1ef1728 cmake: Don't misuse CMAKE_REQUIRED_LIBRARIES from 5bbd6ad tests: Update valgrind suppression file
https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit c26835ad5b0165efe51535b9e11c9d7282eca4b2 Author: Andreas Schneider <a...@samba.org> Date: Tue Oct 2 16:40:16 2018 +0200 gitlab-ci: Disable the FreeBSD runner There is a threading race condition in FreeBSD. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 76286508446f6c1b278021e1074b1c078ae0caf7 Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 27 21:10:45 2018 +0200 gitlab-ci: Add helgrind tests Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit bee622ba59ae933f219a2efba1c3f1a1d53a9783 Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 27 17:56:11 2018 +0200 gitlab-ci: Add runners and toolchain files Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit ab9cf16f48fd996e77117bd48eddecd869397ffa Author: Andreas Schneider <a...@samba.org> Date: Mon Oct 1 21:34:44 2018 +0200 tests: Init in_addr only once in test_tcp_socket_overwrite Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 35174c856c0c464e13f72c5e4b82a976d1c84c2a Author: Andreas Schneider <a...@samba.org> Date: Mon Oct 1 21:28:27 2018 +0200 tests: Return an error if setenv() fails in test_max_sockets Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit b6f1a42a7e88ff0376f92911813f3f0f56d8ccf9 Author: Andreas Schneider <a...@samba.org> Date: Mon Oct 1 21:28:06 2018 +0200 tests: Check the correct return code in test_thread_echo_tcp_write_read Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit d588231d05fa80bce1e860f9797d7a4a7624c670 Author: Andreas Schneider <a...@samba.org> Date: Mon Oct 1 21:27:40 2018 +0200 tests: Check return code of connect in test_thread_echo_tcp_sendmsg_recvmsg Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 7232dee952f4d4da4e670ff918589ec22a323631 Author: Andreas Schneider <a...@samba.org> Date: Mon Oct 1 21:31:19 2018 +0200 tests: Check the return code of connect in test_echo_udp_sendmsg_recvmsg Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 6e651805d42d808abb374f725dd5c5e25fe3ff1a Author: Andreas Schneider <a...@samba.org> Date: Mon Oct 1 21:27:14 2018 +0200 tests: Check return code of connnect in test_echo_tcp_sendmsg_recvmsg Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 545d0b77d3308fde3de50c446b02ef1571b5cfa6 Author: Andreas Schneider <a...@cryptomilk.org> Date: Mon Oct 1 21:23:31 2018 +0200 echo_srv: Check for a valid pidfile pointer Signed-off-by: Andreas Schneider <a...@cryptomilk.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 04091a9e1684970cca87a046f394addfb0c6664b Author: Andreas Schneider <a...@cryptomilk.org> Date: Mon Oct 1 10:54:53 2018 +0200 echo_srv: Only use 128K as buffer size instead of 4MB This produced errors built with clang. Signed-off-by: Andreas Schneider <a...@cryptomilk.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit c49a62956df63d8e2110de3a91bd69981a05a789 Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 27 18:19:42 2018 +0200 torture: Wait longer for echo_srv startup Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 92891453fb69adb66ea591ed1343c2da821b09d3 Author: Andreas Schneider <a...@samba.org> Date: Fri Sep 28 12:55:49 2018 +0200 echo_srv: Do not close bogus file descriptors ==1564== Warning: invalid file descriptor 1048564 in syscall close() ==1564== at 0x4D18534: close (in /lib64/libc-2.27.so) ==1564== by 0x4046A74: libc_close (socket_wrapper.c:760) ==1564== by 0x405105C: swrap_close (socket_wrapper.c:5933) ==1564== by 0x40511F5: close (socket_wrapper.c:5979) ==1564== by 0x401679: become_daemon (echo_srv.c:202) ==1564== by 0x402D44: main (echo_srv.c:896) ==1563== Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 326e9f8cd33aeac5d4010910cd32f98b7365bdb7 Author: Andreas Schneider <a...@samba.org> Date: Sat Sep 1 19:36:19 2018 +0200 swrap: Don't do a deep bind if we run with libasan Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 370ece1e1142be6ce0f153b12b0d8cda1dbcf100 Author: Andreas Schneider <a...@samba.org> Date: Fri Sep 28 12:46:30 2018 +0200 swrap: Add a mutex for resetting socket index Fixes a helgrind error. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 0b1a43e384e2173de0bafefd000127f3cef5b139 Author: Anoop C S <anoo...@redhat.com> Date: Wed Sep 19 13:41:49 2018 +0530 swrap: Fix helgrind errors Signed-off-by: Anoop C S <anoo...@redhat.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit a2a8a804405c439082af3083b2ec4c804ca71049 Author: Andreas Schneider <a...@samba.org> Date: Fri Sep 28 08:11:57 2018 +0200 tests: Use assert_return_code() to get errno Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 0983cd2fd88cf580f60fe0cf6b0ddcdfcd18d249 Author: Anoop C S <anoo...@redhat.com> Date: Thu Aug 30 04:48:30 2018 +0530 tests: Avoid -Wcast-align warning warning: cast from 'struct sockaddr *' to 'struct sockaddr_in *' increases required alignment from 2 to 4 [-Wcast-align] struct sockaddr_in *sinp = (struct sockaddr_in *)to; ^~~~~~~~~~~~~~~~~~~~~~~~ Above warning can be avoided by making use of sockaddr_in available within torture_address from the caller of echo_udp_recv_from_to(). Following that sa_socklen from torture_address can be used instead of passing sa_socklen explicitly to echo_udp_recv_from_to(). Signed-off-by: Anoop C S <anoo...@redhat.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 3d340c30517b90853318fe60ec239bf2bf789931 Author: Anoop C S <anoo...@redhat.com> Date: Tue Aug 28 22:11:31 2018 +0530 tests: Fix -Wformat gcc warning test_fork_thread_deadlock.c:48:25: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘pid_t {aka long int}’ [-Wformat=] Signed-off-by: Anoop C S <anoo...@redhat.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 702f2fb52f90273b86ef6d1f117814bd08fcc542 Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 27 18:31:26 2018 +0200 cmake: Fix checking for required system libraries Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 62080ac13dd2c5e38c49412bced652f1b314bda0 Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 27 17:52:19 2018 +0200 cmake: Use target_include_directories() Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit d3d419bd29c71cc5ea61ac0bdbf1736148a7cccc Author: Andreas Schneider <a...@samba.org> Date: Mon Sep 10 08:34:03 2018 +0200 cmake: Require modern cmake version Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit b976977a5355b67bd563e363abb3d2cb7fa6d3c9 Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 27 17:22:57 2018 +0200 cmake: Update AddCMockaTest Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit b91dae57e472cafe1c2014b84f79a9552d53579c Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 27 17:50:02 2018 +0200 cmake: Update cmocka requirement Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 4adb5cf4748feaf190e1da2444d1ed822314a2f0 Author: Andreas Schneider <a...@samba.org> Date: Sat Sep 1 20:46:52 2018 +0200 cmake: Support running the tests with AddressSanitizer Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit da17de1693abeb5f163ab6b6a85fcfceb1db68ce Author: Andreas Schneider <a...@samba.org> Date: Wed Sep 5 15:39:35 2018 +0200 cmake: Add CFLAGS for AddressSanitizer and UndefinedSanitizer Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 402f548051549edb764184f901e83ee7ece06b29 Author: Andreas Schneider <a...@samba.org> Date: Wed Sep 5 15:38:37 2018 +0200 cmake: Move Compiler flags to new file Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 013687b2ccd6c8436e552e6ada2e7f73b8dfd7cd Author: Andreas Schneider <a...@samba.org> Date: Sun Sep 2 11:18:45 2018 +0200 cmake: Remove obsolete DefineCompilerFlags.cmake Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit aa9b0da96927e957f6ed0b1b9d51b16db90ea2af Author: Andreas Schneider <a...@samba.org> Date: Sun Sep 2 11:18:09 2018 +0200 cmake: Improve checks for compiler flags Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 567261810523f2ab3af10268fc4a64d863ce2c93 Author: Andreas Schneider <a...@samba.org> Date: Tue Oct 2 16:37:43 2018 +0200 cmake: Update CMake defaults Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit a5df8fc8f5f22ba561a39b3eb752766cb62d7f71 Author: Andreas Schneider <a...@samba.org> Date: Fri Sep 28 11:01:15 2018 +0200 cmake: Suppress helgrind race condition warning we created on purpose Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit da4b908371ddc05a8402794b6929979449e4132a Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 27 21:08:23 2018 +0200 cmake: Create an error if helgrind finds a bug Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit f465bf4d82c1f995fd7629484f7acf21b1156df0 Author: Andreas Schneider <a...@samba.org> Date: Thu Sep 6 18:40:17 2018 +0200 cmake: Write helgrind logs to stderr so we can see them Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 1ef17288f30cc064c0099e0437f8fade4e739541 Author: Andreas Schneider <a...@samba.org> Date: Sat Sep 1 20:32:04 2018 +0200 cmake: Don't misuse CMAKE_REQUIRED_LIBRARIES Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> ----------------------------------------------------------------------- Summary of changes: .gitlab-ci.yml | 222 +++++++++++++++++++++++++++ CMakeLists.txt | 21 +-- CompilerChecks.cmake | 108 +++++++++++++ ConfigureChecks.cmake | 24 +-- DefineOptions.cmake | 1 + cmake/Modules/AddCCompilerFlag.cmake | 21 +++ cmake/Modules/AddCMockaTest.cmake | 125 +++++++++++++-- cmake/Modules/CheckCCompilerFlagSSP.cmake | 36 ++++- cmake/Modules/DefineCMakeDefaults.cmake | 15 +- cmake/Modules/DefineCompilerFlags.cmake | 99 +++++------- cmake/Toolchain-Debian-mips.cmake | 21 +++ src/CMakeLists.txt | 10 +- src/socket_wrapper.c | 76 ++++++++- tests/CMakeLists.txt | 71 +++++++-- tests/echo_srv.c | 56 +++---- tests/helgrind.supp | 11 ++ tests/test_echo_tcp_sendmsg_recvmsg.c | 3 + tests/test_echo_udp_sendmsg_recvmsg.c | 3 + tests/test_echo_udp_sendto_recvfrom.c | 16 +- tests/test_fork_thread_deadlock.c | 2 +- tests/test_max_sockets.c | 2 +- tests/test_tcp_socket_overwrite.c | 10 +- tests/test_thread_echo_tcp_sendmsg_recvmsg.c | 2 + tests/test_thread_echo_tcp_write_read.c | 2 +- tests/torture.c | 4 +- 25 files changed, 765 insertions(+), 196 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 CompilerChecks.cmake create mode 100644 cmake/Modules/AddCCompilerFlag.cmake create mode 100644 cmake/Toolchain-Debian-mips.cmake create mode 100644 tests/helgrind.supp Changeset truncated at 500 lines: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..1f9dab3 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,222 @@ +variables: + BUILD_IMAGES_PROJECT: cmocka/gitlab-build-images + FEDORA_BUILD: buildenv-fedora + CENTOS7_BUILD: buildenv-centos7 + TUMBLEWEED_BUILD: buildenv-tumbleweed + MINGW_BUILD: buildenv-mingw + DEBIAN_CROSS_BUILD: buildenv-debian-cross + +centos7/x86_64: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$CENTOS7_BUILD + script: + - mkdir -p obj && cd obj && cmake3 + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +fedora/x86_64: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +fedora/address-sanitizer: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=AddressSanitizer + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +fedora/undefined-sanitizer: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=UndefinedSanitizer + -DUNIT_TESTING=ON .. + && make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +# This runner is disabled because there is a threading race condition in +# FreeBSD. +# See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848 +.freebsd/x86_64: + image: + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make && ctest --output-on-failure + tags: + - freebsd + except: + - tags + only: + - branches@cwrap/socket_wrapper + - branches@cryptomilk/socket_wrapper + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +.Debian.cross.template: &Debian_cross_template + stage: test + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_CROSS_BUILD + script: + - build=$(dpkg-architecture -qDEB_HOST_GNU_TYPE) + - host="${CI_JOB_NAME#*.cross.}" + - mkdir -p obj && cd obj && cmake + -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Debian-mips.cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DUNIT_TESTING=ON .. && make -j$(nproc) && + ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +Debian.cross.mips-linux-gnu: + <<: *Debian_cross_template + +tumbleweed/x86_64/gcc: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/x86_64/gcc7: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/x86_64/clang: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + +tumbleweed/static-analysis: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - export CCC_CC=clang + - export CCC_CXX=clang++ + - mkdir -p obj && cd obj && scan-build cmake + -DCMAKE_BUILD_TYPE=Debug + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + scan-build --status-bugs -o scan make -j$(nproc) + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/scan + +tumbleweed/helgrind: + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_BUILD_TYPE=Debug + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON + -DHELGRIND_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ diff --git a/CMakeLists.txt b/CMakeLists.txt index efb30d8..35527f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,16 @@ # Required cmake version -cmake_minimum_required(VERSION 2.8.5) +cmake_minimum_required(VERSION 3.5.0) cmake_policy(SET CMP0048 NEW) +# Specify search path for CMake modules to be loaded by include() +# and find_package() +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") + +# Add defaults for cmake +# Those need to be set before the project() call. +include(DefineCMakeDefaults) +include(DefineCompilerFlags) + project(socket_wrapper VERSION 1.1.9 LANGUAGES C) # global needed variables @@ -17,18 +26,12 @@ set(APPLICATION_NAME ${PROJECT_NAME}) set(LIBRARY_VERSION "0.1.9") set(LIBRARY_SOVERSION "0") -# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked -set(CMAKE_MODULE_PATH - ${CMAKE_SOURCE_DIR}/cmake/Modules -) - # add definitions -include(DefineCMakeDefaults) include(DefinePlatformDefaults) -include(DefineCompilerFlags) include(DefineInstallationPaths) include(DefineOptions.cmake) include(CPackConfig.cmake) +include(CompilerChecks.cmake) # disallow in-source build include(MacroEnsureOutOfSourceBuild) @@ -46,7 +49,7 @@ configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) add_subdirectory(src) if (UNIT_TESTING) - find_package(cmocka 0.4.1 REQUIRED) + find_package(cmocka 1.1.0 REQUIRED) include(AddCMockaTest) add_subdirectory(tests) diff --git a/CompilerChecks.cmake b/CompilerChecks.cmake new file mode 100644 index 0000000..f5a3c7f --- /dev/null +++ b/CompilerChecks.cmake @@ -0,0 +1,108 @@ +include(AddCCompilerFlag) +include(CheckCCompilerFlagSSP) + +if (UNIX) + # + # Check for -Werror turned on if possible + # + # This will prevent that compiler flags are detected incorrectly. + # + check_c_compiler_flag("-Werror" REQUIRED_FLAGS_WERROR) + if (REQUIRED_FLAGS_WERROR) + set(CMAKE_REQUIRED_FLAGS "-Werror") + + if (PICKY_DEVELOPER) + list(APPEND SUPPORTED_COMPILER_FLAGS "-Werror") + endif() + endif() + + add_c_compiler_flag("-std=gnu99" SUPPORTED_COMPILER_FLAGS) + #add_c_compiler_flag("-Wpedantic" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wall" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wshadow" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wmissing-prototypes" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wcast-align" SUPPORTED_COMPILER_FLAGS) + #add_c_compiler_flag("-Wcast-qual" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=address" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wstrict-prototypes" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=strict-prototypes" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wwrite-strings" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=write-strings" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror-implicit-function-declaration" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wpointer-arith" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=pointer-arith" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wdeclaration-after-statement" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=declaration-after-statement" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wreturn-type" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=return-type" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wuninitialized" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=uninitialized" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wimplicit-fallthrough" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=strict-overflow" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wstrict-overflow=2" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wno-format-zero-length" SUPPORTED_COMPILER_FLAGS) + + check_c_compiler_flag("-Wformat" REQUIRED_FLAGS_WFORMAT) + if (REQUIRED_FLAGS_WFORMAT) + list(APPEND SUPPORTED_COMPILER_FLAGS "-Wformat") + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wformat") + endif() + add_c_compiler_flag("-Wformat-security" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Werror=format-security" SUPPORTED_COMPILER_FLAGS) + + # Allow zero for a variadic macro argument + string(TOLOWER "${CMAKE_C_COMPILER_ID}" _C_COMPILER_ID) + if ("${_C_COMPILER_ID}" STREQUAL "clang") + add_c_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments" SUPPORTED_COMPILER_FLAGS) + endif() + + add_c_compiler_flag("-fno-common" SUPPORTED_COMPILER_FLAGS) + + if (CMAKE_BUILD_TYPE) + string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) + if (CMAKE_BUILD_TYPE_LOWER MATCHES (release|relwithdebinfo|minsizerel)) + add_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" SUPPORTED_COMPILER_FLAGS) + endif() + endif() + + check_c_compiler_flag_ssp("-fstack-protector-strong" WITH_STACK_PROTECTOR_STRONG) + if (WITH_STACK_PROTECTOR_STRONG) + list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector-strong") + # This is needed as Solaris has a seperate libssp + if (SOLARIS) + list(APPEND SUPPORTED_LINKER_FLAGS "-fstack-protector-strong") + endif() + else (WITH_STACK_PROTECTOR_STRONG) + check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR) + if (WITH_STACK_PROTECTOR) + list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector") + # This is needed as Solaris has a seperate libssp + if (SOLARIS) + list(APPEND SUPPORTED_LINKER_FLAGS "-fstack-protector") + endif() + endif() + endif (WITH_STACK_PROTECTOR_STRONG) + + check_c_compiler_flag_ssp("-fstack-clash-protection" WITH_STACK_CLASH_PROTECTION) + if (WITH_STACK_CLASH_PROTECTION) + list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-clash-protection") + endif() + + if (PICKY_DEVELOPER) + add_c_compiler_flag("-Wno-error=deprecated-declarations" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("-Wno-error=tautological-compare" SUPPORTED_COMPILER_FLAGS) + endif() + + # Unset CMAKE_REQUIRED_FLAGS + unset(CMAKE_REQUIRED_FLAGS) +endif() + +if (MSVC) + add_c_compiler_flag("/D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("/D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("/D _CRT_NONSTDC_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) + add_c_compiler_flag("/D _CRT_SECURE_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) +endif() + +set(DEFAULT_C_COMPILE_FLAGS ${SUPPORTED_COMPILER_FLAGS} CACHE INTERNAL "Default C Compiler Flags" FORCE) +set(DEFAULT_LINK_FLAGS ${SUPPORTED_LINKER_FLAGS} CACHE INTERNAL "Default C Linker Flags" FORCE) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 8fdb7f4..cb5bf53 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -70,25 +70,33 @@ check_function_exists(pledge HAVE_PLEDGE) if (UNIX) + find_library(DLFCN_LIBRARY dl) + if (DLFCN_LIBRARY) + string(APPEND _REQUIRED_LIBRARIES ${DLFCN_LIBRARY}) + else() + check_function_exists(dlopen HAVE_DLOPEN) + if (NOT HAVE_DLOPEN) + message(FATAL_ERROR "FATAL: No dlopen() function detected") + endif() + endif() + if (NOT LINUX) # libsocket (Solaris) check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET) if (HAVE_LIBSOCKET) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket) + string(APPEND _REQUIRED_LIBRARIES socket) endif (HAVE_LIBSOCKET) # libnsl/inet_pton (Solaris) check_library_exists(nsl inet_pton "" HAVE_LIBNSL) if (HAVE_LIBNSL) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} nsl) + string(APPEND _REQUIRED_LIBRARIES nsl) endif (HAVE_LIBNSL) endif (NOT LINUX) check_function_exists(getaddrinfo HAVE_GETADDRINFO) endif (UNIX) -set(SWRAP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "socket_wrapper required system libraries") - # STRUCTS check_struct_has_member("struct in_pktinfo" ipi_addr "sys/types.h;sys/socket.h;netinet/in.h" HAVE_STRUCT_IN_PKTINFO) set(CMAKE_REQUIRED_FLAGS -D_GNU_SOURCE) @@ -250,12 +258,6 @@ int main(void) { unset(CMAKE_REQUIRED_FLAGS) ########################################################### -check_library_exists(dl dlopen "" HAVE_LIBDL) -if (HAVE_LIBDL) - find_library(DLFCN_LIBRARY dl) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${DLFCN_LIBRARY}) -endif (HAVE_LIBDL) - if (OSX) set(HAVE_APPLE 1) endif (OSX) @@ -267,4 +269,4 @@ endif (NOT WIN32) check_type_size(pid_t SIZEOF_PID_T) -set(SWRAP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "swrap required system libraries") +set(SWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL "socket_wrapper required system libraries") diff --git a/DefineOptions.cmake b/DefineOptions.cmake index 54e65e1..28152e3 100644 --- a/DefineOptions.cmake +++ b/DefineOptions.cmake @@ -1,2 +1,3 @@ option(UNIT_TESTING "Build with unit tests" OFF) option(HELGRIND_TESTING "Run threaded unit tests with helgrind" OFF) +option(PICKY_DEVELOPER "Build with picky developer flags" OFF) diff --git a/cmake/Modules/AddCCompilerFlag.cmake b/cmake/Modules/AddCCompilerFlag.cmake new file mode 100644 index 0000000..c24c215 --- /dev/null +++ b/cmake/Modules/AddCCompilerFlag.cmake @@ -0,0 +1,21 @@ +# +# add_c_compiler_flag("-Werror" SUPPORTED_CFLAGS) +# +# Copyright (c) 2018 Andreas Schneider <a...@cryptomilk.org> +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +include(CheckCCompilerFlag) + +macro(add_c_compiler_flag _COMPILER_FLAG _OUTPUT_VARIABLE) + string(TOUPPER ${_COMPILER_FLAG} _COMPILER_FLAG_NAME) + string(REGEX REPLACE "^-" "" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}") + string(REGEX REPLACE "(-|=|\ )" "_" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}") + + check_c_compiler_flag("${_COMPILER_FLAG}" WITH_${_COMPILER_FLAG_NAME}_FLAG) + if (WITH_${_COMPILER_FLAG_NAME}_FLAG) + #string(APPEND ${_OUTPUT_VARIABLE} "${_COMPILER_FLAG} ") + list(APPEND ${_OUTPUT_VARIABLE} ${_COMPILER_FLAG}) + endif() +endmacro() diff --git a/cmake/Modules/AddCMockaTest.cmake b/cmake/Modules/AddCMockaTest.cmake index b2d1ca8..2f45e1a 100644 --- a/cmake/Modules/AddCMockaTest.cmake +++ b/cmake/Modules/AddCMockaTest.cmake @@ -1,23 +1,120 @@ -# - ADD_CHECK_TEST(test_name test_source linklib1 ... linklibN) - +# # Copyright (c) 2007 Daniel Gollub <dgol...@suse.de> -# Copyright (c) 2007-2010 Andreas Schneider <a...@cynapses.org> +# Copyright (c) 2007-2018 Andreas Schneider <a...@cryptomilk.org> -- Socket Wrapper Repository