Skip to content

Commit

Permalink
Work for test refactoring.
Browse files Browse the repository at this point in the history
There are a few major areas in this change.

* CMake options are now located in a common cmake/NNGOptions.cmake
  file.  This should make it easier for folks to figure out what
  the options are, and how they are used.

* Tests are now scoped with their directory name, which should
  avoid possible name collisions with test names.

* A number of tests have been either moved or incorporated into
  the newer testutil/acutest framework.  We are moving away from
  my old c-convey framework to something easier to debug.

* We use CMake directories a bit more extensively leading to a much
  cleaner CMake structure.  It's not complete, but a big step in the
  right direction, and a preview of future work.

* Tests are now run with verbose flags, so we get more test results
  in the CI/CD logs.
  • Loading branch information
gdamore committed Nov 19, 2020
1 parent cda4885 commit b826bfc
Show file tree
Hide file tree
Showing 42 changed files with 1,450 additions and 1,200 deletions.
47 changes: 9 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ cmake_minimum_required(VERSION 3.13)

project(nng C)
include(CheckCCompilerFlag)
include(CMakeDependentOption)
include(GNUInstallDirs)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

include(NNGHelpers)
include(NNGOptions)

set(CMAKE_C_STANDARD 99)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
Expand Down Expand Up @@ -66,22 +66,9 @@ message(STATUS "Configuring for NNG version ${NNG_ABI_VERSION}")

# User-defined options.

option(BUILD_SHARED_LIBS "Build shared library" ${BUILD_SHARED_LIBS})

if (CMAKE_CROSSCOMPILING)
set(NNG_NATIVE_BUILD OFF)
else ()
set(NNG_NATIVE_BUILD ON)
endif ()

# We only build command line tools and tests if we are not in a
# cross-compile situation. Cross-compiling users who still want to
# build these must enable them explicitly. Some of these switches
# must be enabled rather early as we use their values later.
option(NNG_TESTS "Build and run tests." ${NNG_NATIVE_BUILD})
option(NNG_TOOLS "Build extra tools." ${NNG_NATIVE_BUILD})
option(NNG_ENABLE_NNGCAT "Enable building nngcat utility." ${NNG_TOOLS})
option(NNG_ENABLE_COVERAGE "Enable coverage reporting." OFF)
# This prefix is appended to by subdirectories, so that each test
# gets named based on where it is in the tree.
set(NNG_TEST_PREFIX nng)

# Enable access to private APIs for our own use.
add_definitions(-DNNG_PRIVATE)
Expand All @@ -108,16 +95,6 @@ target_compile_definitions(nng_testing PUBLIC NNG_STATIC_LIB NNG_TEST_LIB NNG_PR
add_library(nng_private INTERFACE)
target_compile_definitions(nng_private INTERFACE NNG_PRIVATE)

# Eliding deprecated functionality can be used to build a slimmed down
# version of the library, or alternatively to test for application
# preparedness for expected feature removals (in the next major release.)
# Applications can also set the NNG_ELIDE_DEPRECATED preprocessor symbol
# before including <nng/nng.h> -- this will prevent declarations from
# being exposed to applications, but it will not affect their ABI
# availability for existing compiled applications.
# Note: Currently this breaks the test suite, so we only do it
# for the public library.
option(NNG_ELIDE_DEPRECATED "Elide deprecated functionality." OFF)
if (NNG_ELIDE_DEPRECATED)
target_compile_definitions(nng, NNG_ELIDE_DEPRECATED)
endif()
Expand All @@ -137,11 +114,7 @@ if (NOT WIN32)
mark_as_advanced(NNG_SETSTACKSIZE)
endif ()

option(NNG_ENABLE_STATS "Enable statistics" ON)
if (NNG_ENABLE_STATS)
add_definitions(-DNNG_ENABLE_STATS)
endif ()
mark_as_advanced(NNG_ENABLE_STATS)
nng_defines_if(NNG_ENABLE_STATS NNG_ENABLE_STATS)

if (NNG_RESOLV_CONCURRENCY)
add_definitions(-DNNG_RESOLV_CONCURRENCY=${NNG_RESOLV_CONCURRENCY})
Expand Down Expand Up @@ -269,6 +242,10 @@ else ()
set(NNG_PLATFORM_POSIX ON)
endif ()

if (NNG_ENABLE_TLS)
add_definitions(-DNNG_SUPP_TLS)
endif ()

if (NNG_TESTS)
enable_testing()
set(all_tests, "")
Expand All @@ -287,12 +264,6 @@ if (NNG_ENABLE_NNGCAT)
add_subdirectory(tools/nngcat)
endif ()

option(NNG_ENABLE_TLS "Enable TLS protocol" OFF)
if (NNG_ENABLE_TLS)
add_definitions(-DNNG_SUPP_TLS)
set(NNG_SUPP_TLS ON)
endif ()

add_subdirectory(docs/man)

set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
Expand Down
12 changes: 8 additions & 4 deletions cmake/NNGHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function(nng_test NAME)
${PROJECT_SOURCE_DIR}/tests
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/include)
add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} -t)
set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT 180)
add_test(NAME ${NNG_TEST_PREFIX}.${NAME} COMMAND ${NAME} -t -v)
set_tests_properties(${NNG_TEST_PREFIX}.${NAME} PROPERTIES TIMEOUT 180)
endif ()
endfunction()

Expand All @@ -111,8 +111,8 @@ function(nng_test_if COND NAME)
${PROJECT_SOURCE_DIR}/tests
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/include)
add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} -t)
set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT 180)
add_test(NAME ${NNG_TEST_PREFIX}.${NAME} COMMAND ${NAME} -t -v)
set_tests_properties(${NNG_TEST_PREFIX}.${NAME} PROPERTIES TIMEOUT 180)
endif ()
endfunction()

Expand Down Expand Up @@ -153,3 +153,7 @@ function(nng_check_struct_member STR MEM HDR DEF)
target_compile_definitions(nng_private INTERFACE ${DEF}=1)
endif ()
endfunction(nng_check_struct_member)

macro(nng_directory DIR)
set(NNG_TEST_PREFIX ${NNG_TEST_PREFIX}.${DIR})
endmacro(nng_directory)
140 changes: 140 additions & 0 deletions cmake/NNGOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#
# Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
#
# This software is supplied under the terms of the MIT License, a
# copy of which should be located in the distribution where this
# file was obtained (LICENSE.txt). A copy of the license may also be
# found online at https://opensource.org/licenses/MIT.
#

# NNG Options. These are user configurable knobs.

include(CMakeDependentOption)

if (CMAKE_CROSSCOMPILING)
set(NNG_NATIVE_BUILD OFF)
else ()
set(NNG_NATIVE_BUILD ON)
endif ()

# Global options.
option(BUILD_SHARED_LIBS "Build shared library" ${BUILD_SHARED_LIBS})

# We only build command line tools and tests if we are not in a
# cross-compile situation. Cross-compiling users who still want to
# build these must enable them explicitly. Some of these switches
# must be enabled rather early as we use their values later.
option(NNG_TESTS "Build and run tests." ${NNG_NATIVE_BUILD})
option(NNG_TOOLS "Build extra tools." ${NNG_NATIVE_BUILD})
option(NNG_ENABLE_NNGCAT "Enable building nngcat utility." ${NNG_TOOLS})
option(NNG_ENABLE_COVERAGE "Enable coverage reporting." OFF)
# Eliding deprecated functionality can be used to build a slimmed down
# version of the library, or alternatively to test for application
# preparedness for expected feature removals (in the next major release.)
# Applications can also set the NNG_ELIDE_DEPRECATED preprocessor symbol
# before including <nng/nng.h> -- this will prevent declarations from
# being exposed to applications, but it will not affect their ABI
# availability for existing compiled applications.
# Note: Currently this breaks the test suite, so we only do it
# for the public library.
option(NNG_ELIDE_DEPRECATED "Elide deprecated functionality." OFF)

option(NNG_ENABLE_STATS "Enable statistics." ON)
mark_as_advanced(NNG_ENABLE_STATS)

# Protocols.
option (NNG_PROTO_BUS0 "Enable BUSv0 protocol." ON)
mark_as_advanced(NNG_PROTO_BUS0)

option (NNG_PROTO_PAIR0 "Enable PAIRv0 protocol." ON)
mark_as_advanced(NNG_PROTO_PAIR0)

option (NNG_PROTO_PAIR1 "Enable PAIRv1 protocol." ON)
mark_as_advanced(NNG_PROTO_PAIR1)

option (NNG_PROTO_PUSH0 "Enable PUSHv0 protocol." ON)
mark_as_advanced(NNG_PROTO_PUSH0)

option (NNG_PROTO_PULL0 "Enable PULLv0 protocol." ON)
mark_as_advanced(NNG_PROTO_PULL0)

option (NNG_PROTO_PUB0 "Enable PUBv0 protocol." ON)
mark_as_advanced(NNG_PROTO_PUB0)

option (NNG_PROTO_SUB0 "Enable SUBv0 protocol." ON)
mark_as_advanced(NNG_PROTO_SUB0)

option(NNG_PROTO_REQ0 "Enable REQv0 protocol." ON)
mark_as_advanced(NNG_PROTO_REQ0)

option(NNG_PROTO_REP0 "Enable REPv0 protocol." ON)
mark_as_advanced(NNG_PROTO_REP0)

option (NNG_PROTO_RESPONDENT0 "Enable RESPONDENTv0 protocol." ON)
mark_as_advanced(NNG_PROTO_RESPONDENT0)

option (NNG_PROTO_SURVEYOR0 "Enable SURVEYORv0 protocol." ON)
mark_as_advanced(NNG_PROTO_SURVEYOR0)

# TLS support.

# Enabling TLS is required to enable support for the TLS transport
# and WSS. It does require a 3rd party TLS engine to be selected.
option(NNG_ENABLE_TLS "Enable TLS support." OFF)
if (NNG_ENABLE_TLS)
set(NNG_SUPP_TLS ON)
endif ()

if (NNG_ENABLE_TLS)
set(NNG_TLS_ENGINES mbed wolf none)
# We assume Mbed for now. (Someday replaced perhaps with Bear.)
set(NNG_TLS_ENGINE mbed CACHE STRING "TLS engine to use.")
set_property(CACHE NNG_TLS_ENGINE PROPERTY STRINGS ${NNG_TLS_ENGINES})
else ()
set(NNG_TLS_ENGINE none)
endif ()

# HTTP API support.
option (NNG_ENABLE_HTTP "Enable HTTP API." ON)
if (NNG_ENABLE_HTTP)
set(NNG_SUPP_HTTP ON)
endif()
mark_as_advanced(NNG_ENABLE_HTTP)

#
# Transport Options.
#

option (NNG_TRANSPORT_INPROC "Enable inproc transport." ON)
mark_as_advanced(NNG_TRANSPORT_INPROC)

option (NNG_TRANSPORT_IPC "Enable IPC transport." ON)
mark_as_advanced(NNG_TRANSPORT_IPC)

# TCP transport
option (NNG_TRANSPORT_TCP "Enable TCP transport." ON)
mark_as_advanced(NNG_TRANSPORT_TCP)

# TLS transport
option (NNG_TRANSPORT_TLS "Enable TLS transport." ON)
mark_as_advanced(NNG_TRANSPORT_TLS)

# WebSocket
option (NNG_TRANSPORT_WS "Enable WebSocket transport." ON)
mark_as_advanced(NNG_TRANSPORT_WS)

CMAKE_DEPENDENT_OPTION(NNG_TRANSPORT_WSS "Enable WSS transport." ON
"NNG_ENABLE_TLS" OFF)
mark_as_advanced(NNG_TRANSPORT_WSS)

# ZeroTier
option (NNG_TRANSPORT_ZEROTIER "Enable ZeroTier transport (requires libzerotiercore)." OFF)
mark_as_advanced(NNG_TRANSPORT_ZEROTIER)

if (NNG_TRANSPORT_WS OR NNG_TRANSPORT_WSS)
# Make sure things we *MUST* have are enabled.
set(NNG_SUPP_WEBSOCKET ON)
set(NNG_SUPP_HTTP ON)
set(NNG_SUPP_BASE64 ON)
set(NNG_SUPP_SHA1 ON)
endif()
20 changes: 3 additions & 17 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,16 @@
nng_sources(nng.c nng_legacy.c)
nng_headers(nng/nng.h)


target_include_directories(nng PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_include_directories(nng_testing PRIVATE ${PROJECT_SOURCE_DIR}/src)

add_subdirectory(core)

add_subdirectory(platform/windows)
add_subdirectory(platform/posix)
add_subdirectory(platform)
add_subdirectory(compat/nanomsg)

add_subdirectory(protocol/bus0)
add_subdirectory(protocol/pair0)
add_subdirectory(protocol/pair1)
add_subdirectory(protocol/pipeline0)
add_subdirectory(protocol/pubsub0)
add_subdirectory(protocol/reqrep0)
add_subdirectory(protocol/survey0)

add_subdirectory(transport/inproc)
add_subdirectory(transport/ipc)
add_subdirectory(transport/tcp)
add_subdirectory(transport/tls)
add_subdirectory(transport/ws)
add_subdirectory(transport/zerotier)
add_subdirectory(protocol)
add_subdirectory(transport)

add_subdirectory(supplemental/base64)
add_subdirectory(supplemental/http)
Expand Down
2 changes: 2 additions & 0 deletions src/compat/nanomsg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@

nng_sources(nn.c)

set(NNG_TEST_PREFIX ${NNG_TEST_PREFIX}.compat.nanomsg)

nng_test(compat_tcp_test)
9 changes: 9 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

# Core.
nng_directory(core)

nng_check_sym(strlcpy string.h NNG_HAVE_STRLCPY)
nng_check_sym(strnlen string.h NNG_HAVE_STRNLEN)
Expand Down Expand Up @@ -75,3 +76,11 @@ nng_sources(
url.c
url.h
)

nng_test(aio_test)
nng_test(buf_size_test)
nng_test(errors_test)
nng_test(id_test)
nng_test(reconnect_test)
nng_test(sock_test)
nng_test(url_test)
Loading

0 comments on commit b826bfc

Please sign in to comment.