Skip to content

Commit

Permalink
Merge 'build: do not always build seastar as a static library' from K…
Browse files Browse the repository at this point in the history
…efu Chai

* tests/unit: include unit_test.hpp instead of included/unit_test.hpp
* build: do not always build seastar as a static library
* build: build seastar as a shared library in 'debug' or 'dev' mode

Signed-off-by: Kefu Chai <[email protected]>

Closes scylladb#1484

* github.com:scylladb/seastar:
  build: build seastar as a shared library in 'debug' or 'dev' mode
  build: do not always build seastar as a static library
  build: populate env vars using "env"
  tests/unit: link tests to libboost_unit_test_framework.so
  • Loading branch information
avikivity committed Feb 10, 2023
2 parents 97bc034 + afa523c commit f9574eb
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 31 deletions.
35 changes: 27 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,29 +311,46 @@ set (Seastar_TEST_TIMEOUT
STRING
"Maximum allowed time for a test to run, in seconds.")

option (BUILD_SHARED_LIBS
"Build seastar library as shared libraries instead of static"
OFF)
# We set the following environment variables
# * ASAN_OPTIONS=disable_coredump=0:abort_on_error=1:detect_stack_use_after_return=1
# * ASAN_OPTIONS=disable_coredump=0:abort_on_error=1:detect_stack_use_after_return=1:verify_asan_link_order=0
# By default asan disables core dumps because they used to be
# huge. This is no longer the case since the shadow memory is
# excluded, so it is safe to enable them.
# Also, by default, to make sure it works as expected, asan
# verifies if the asan dynamic runtime is the first DSO in the
# initial library list by calling dl_iterate_phdr(3). But
# Seastar provides this symbol, and its implementation references
# some static variables. So if Seastar is built as a shared
# library, this causes a chicken and egg problem. On one hard,
# ASan tries to reference a symbol which is in turn provided by
# yet another shared library which is not necessariy ready its
# static variables yet. And this leads leads to a segfault. So,
# we have to disable this check when "BUILD_SHARED_LIBS" is
# enabled.
# * UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1
# Fail the test if any undefined behavior is found and use abort
# instead of exit. Using abort is what causes core dumps to be
# produced.
# * BOOST_TEST_CATCH_SYSTEM_ERRORS=no
# Normally the boost test library handles SIGABRT and prevents core
# dumps from being produced.

# This works great with clang and gcc 10.2, but unfortunately not any
# previous gcc.
set (Seastar_USE_AFTER_RETURN "")
set (Seastar_ASAN_OPTIONS "disable_coredump=0:abort_on_error=1")
if ((NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) OR
(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2))
set (Seastar_USE_AFTER_RETURN ":detect_stack_use_after_return=1")
string (APPEND Seastar_ASAN_OPTIONS ":detect_stack_use_after_return=1")
endif ()
if (BUILD_SHARED_LIBS)
string (APPEND Seastar_ASAN_OPTIONS ":verify_asan_link_order=0")
endif ()


set (Seastar_TEST_ENVIRONMENT
"ASAN_OPTIONS=disable_coredump=0:abort_on_error=1${Seastar_USE_AFTER_RETURN};UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1;BOOST_TEST_CATCH_SYSTEM_ERRORS=no"
"ASAN_OPTIONS=${Seastar_ASAN_OPTIONS};UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1;BOOST_TEST_CATCH_SYSTEM_ERRORS=no"
CACHE
STRING
"Environment variables for running tests")
Expand Down Expand Up @@ -453,7 +470,7 @@ if (Seastar_DPDK)
set (seastar_dpdk_obj seastar-dpdk.o)
endif ()

add_library (seastar STATIC
add_library (seastar
${http_chunk_parsers_file}
${http_request_parser_file}
${seastar_dpdk_obj}
Expand Down Expand Up @@ -741,12 +758,14 @@ target_include_directories (seastar
${CMAKE_CURRENT_SOURCE_DIR}/src)

set (Seastar_PRIVATE_CXX_FLAGS
-fvisibility=hidden
-UNDEBUG
-Wall
-Werror
-Wno-array-bounds # Disabled because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93437
-Wno-error=deprecated-declarations)
if (NOT BUILD_SHARED_LIBS)
list (APPEND Seastar_PRIVATE_CXX_FLAGS -fvisibility=hidden)
endif ()

if (Seastar_COMPRESS_DEBUG)
# -gz doesn't imply -g, so it is safe to add it regardless of debug
Expand Down Expand Up @@ -1071,7 +1090,6 @@ if (Seastar_INSTALL OR Seastar_TESTING)
add_library (Seastar::seastar_testing ALIAS seastar_testing)

target_compile_definitions (seastar_testing
PUBLIC BOOST_TEST_DYN_LINK
PRIVATE ${Seastar_PRIVATE_COMPILE_DEFINITIONS})

target_compile_options (seastar_testing
Expand All @@ -1080,6 +1098,7 @@ if (Seastar_INSTALL OR Seastar_TESTING)
target_link_libraries (seastar_testing
PUBLIC
Boost::unit_test_framework
Boost::dynamic_linking
seastar)

add_library(seastar_perf_testing
Expand Down
1 change: 1 addition & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def configure_mode(mode):
'-DCMAKE_CXX_STANDARD={}'.format(args.cpp_standard),
'-DCMAKE_INSTALL_PREFIX={}'.format(args.install_prefix),
'-DCMAKE_EXPORT_COMPILE_COMMANDS={}'.format('yes' if args.cc_json else 'no'),
'-DBUILD_SHARED_LIBS={}'.format('yes' if mode in ('debug', 'dev') else 'no'),
'-DSeastar_API_LEVEL={}'.format(args.api_level),
'-DSeastar_SCHEDULING_GROUPS_COUNT={}'.format(args.scheduling_groups_count),
tr(args.exclude_tests, 'EXCLUDE_TESTS_FROM_ALL'),
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function (seastar_add_test name)
elseif (parsed_args_KIND STREQUAL "BOOST")
list (APPEND libraries
Boost::unit_test_framework
Boost::dynamic_linking
seastar_private)

if (NOT (Seastar_JENKINS STREQUAL ""))
Expand Down Expand Up @@ -141,13 +142,13 @@ function (seastar_add_test name)
OUTPUT_NAME ${name}_test)

add_dependencies (unit_tests ${executable_target})
set (forwarded_args COMMAND ${executable_target} ${args})
set (forwarded_args COMMAND ${CMAKE_COMMAND} -E env "${Seastar_TEST_ENVIRONMENT}" $<TARGET_FILE:${executable_target}> ${args})
else ()
if (NOT (parsed_args_KIND STREQUAL "CUSTOM"))
message (FATAL_ERROR "SOURCES are required for ${parsed_args_KIND} tests")
endif ()

set (forwarded_args COMMAND ${parsed_args_RUN_ARGS})
set (forwarded_args COMMAND ${CMAKE_COMMAND} -E env "${Seastar_TEST_ENVIRONMENT}" ${parsed_args_RUN_ARGS})
endif ()

#
Expand All @@ -174,8 +175,7 @@ function (seastar_add_test name)

set_tests_properties (Seastar.unit.${name}
PROPERTIES
TIMEOUT ${Seastar_TEST_TIMEOUT}
ENVIRONMENT "${Seastar_TEST_ENVIRONMENT}")
TIMEOUT ${Seastar_TEST_TIMEOUT})
endfunction ()

#
Expand Down Expand Up @@ -250,15 +250,18 @@ seastar_add_test (checked_ptr
SOURCES checked_ptr_test.cc)

seastar_add_test (chunked_fifo
KIND BOOST
SOURCES chunked_fifo_test.cc)

seastar_add_test (chunk_parsers
SOURCES chunk_parsers_test.cc)

seastar_add_test (circular_buffer
KIND BOOST
SOURCES circular_buffer_test.cc)

seastar_add_test (circular_buffer_fixed_capacity
KIND BOOST
SOURCES circular_buffer_fixed_capacity_test.cc)

seastar_add_test (condition_variable
Expand All @@ -274,9 +277,11 @@ seastar_add_test (coroutines
SOURCES coroutines_test.cc)

seastar_add_test (defer
KIND BOOST
SOURCES defer_test.cc)

seastar_add_test (deleter
KIND BOOST
SOURCES deleter_test.cc)

seastar_add_app_test (directory
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/checked_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/core/checked_ptr.hh>
#include <seastar/core/weak_ptr.hh>

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/chunked_fifo_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/core/chunked_fifo.hh>
#include <stdlib.h>
#include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/circular_buffer_fixed_capacity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <deque>
#include <random>
#include <seastar/core/circular_buffer_fixed_capacity.hh>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/circular_buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <stdlib.h>
#include <chrono>
#include <deque>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/defer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/util/defer.hh>

using namespace seastar;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/deleter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/core/deleter.hh>

using namespace seastar;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/exception_logging_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <exception>
#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/util/log.hh>
#include <seastar/util/backtrace.hh>
#include <ostream>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/net_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define BOOST_TEST_MODULE core

#include <seastar/net/config.hh>
#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <exception>
#include <sstream>

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/noncopyable_function_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/util/noncopyable_function.hh>

using namespace seastar;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/packet_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/net/packet.hh>
#include <array>

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/program_options_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <seastar/util/program-options.hh>

#include <boost/program_options.hpp>
#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>

#include <initializer_list>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/shared_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <set>
#include <unordered_map>
#include <seastar/core/sstring.hh>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/simple_stream_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define BOOST_TEST_MODULE simple_stream

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/core/simple-stream.hh>

using namespace seastar;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/source_location_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>

#include <seastar/util/std-compat.hh>

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/sstring_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/core/sstring.hh>
#include <list>

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tuple_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <seastar/util/tuple_utils.hh>

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>

#include <sstream>
#include <type_traits>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/uname_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/core/internal/uname.hh>

using namespace seastar::internal;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/unwind_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <pthread.h>
#include <seastar/core/posix.hh>
#include <seastar/util/backtrace.hh>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/weak_ptr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define BOOST_TEST_MODULE core

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <seastar/core/weak_ptr.hh>

using namespace seastar;
Expand Down

0 comments on commit f9574eb

Please sign in to comment.