Skip to content

Commit

Permalink
Don't link test cases twice
Browse files Browse the repository at this point in the history
Before we were building and running each test program twice: once via
static linking, and once via shared library linking.  We now use the
Travis build matrix for that (to still verify that we test both kinds of
linking for each new feature), instead of testing both every time you
run `make test`.
  • Loading branch information
dcreager committed Jun 7, 2018
1 parent b2ae1e7 commit 2c10646
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 41 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Expand Up @@ -3,12 +3,12 @@ compiler:
- clang
- gcc
env:
- ARCH=i386 ENABLE_SHARED_EXECUTABLES=YES FALLBACK_U128=NO
- ARCH=amd64 ENABLE_SHARED_EXECUTABLES=YES FALLBACK_U128=NO
- ARCH=i386 ENABLE_SHARED_EXECUTABLES=NO FALLBACK_U128=NO
- ARCH=amd64 ENABLE_SHARED_EXECUTABLES=NO FALLBACK_U128=NO
- ARCH=i386 ENABLE_SHARED_EXECUTABLES=NO FALLBACK_U128=YES
- ARCH=amd64 ENABLE_SHARED_EXECUTABLES=NO FALLBACK_U128=YES
- ARCH=i386
- ARCH=amd64
- ARCH=i386 ENABLE_SHARED_TESTS=YES
- ARCH=amd64 ENABLE_SHARED_TESTS=YES
- ARCH=i386 FALLBACK_U128=YES
- ARCH=amd64 FALLBACK_U128=YES
os:
- linux
# TODO(dcreager): Reenable this once the Travis Mac backlog isn't quite so
Expand Down
7 changes: 5 additions & 2 deletions .travis/test
@@ -1,10 +1,13 @@
#!/bin/sh
#!/bin/bash

set -e

mkdir .build
cd .build

: ${ENABLE_SHARED_TESTS:=NO}
: ${FALLBACK_U128:=NO}

if [ "$TRAVIS_OS_NAME" = linux ]; then
if [ "$ARCH" = i386 ]; then
ARCH_FLAGS="-m32"
Expand All @@ -28,6 +31,6 @@ fi
cmake .. \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-g -O3 $ARCH_FLAGS $EXTRA_FLAGS" \
-DENABLE_SHARED_EXECUTABLES="${ENABLE_SHARED_EXECUTABLES}"
-DENABLE_SHARED_TESTS="${ENABLE_SHARED_TESTS}"
make
make test
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -74,6 +74,8 @@ endif(NOT CMAKE_BUILD_TYPE)
set(ENABLE_SHARED YES CACHE BOOL "Whether to build a shared library")
set(ENABLE_SHARED_EXECUTABLES NO CACHE BOOL
"Whether to link executables using shared libraries")
set(ENABLE_SHARED_TESTS NO CACHE BOOL
"Whether to link test cases using shared libraries")
set(ENABLE_STATIC YES CACHE BOOL "Whether to build a static library")

if(NOT CMAKE_INSTALL_LIBDIR)
Expand Down
8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Expand Up @@ -70,17 +70,17 @@ add_c_library(
threads
)

if (ENABLE_SHARED OR ENABLE_SHARED_EXECUTABLES)
if (ENABLE_SHARED OR ENABLE_SHARED_EXECUTABLES OR ENABLE_SHARED_TESTS)
set_target_properties(libcork-shared PROPERTIES
COMPILE_DEFINITIONS CORK_API=CORK_EXPORT
)
endif (ENABLE_SHARED OR ENABLE_SHARED_EXECUTABLES)
endif (ENABLE_SHARED OR ENABLE_SHARED_EXECUTABLES OR ENABLE_SHARED_TESTS)

if (ENABLE_STATIC OR NOT ENABLE_SHARED_EXECUTABLES)
if (ENABLE_STATIC OR NOT ENABLE_SHARED_EXECUTABLES OR NOT ENABLE_SHARED_TESTS)
set_target_properties(libcork-static PROPERTIES
COMPILE_DEFINITIONS CORK_API=CORK_LOCAL
)
endif (ENABLE_STATIC OR NOT ENABLE_SHARED_EXECUTABLES)
endif (ENABLE_STATIC OR NOT ENABLE_SHARED_EXECUTABLES OR NOT ENABLE_SHARED_TESTS)


#-----------------------------------------------------------------------
Expand Down
37 changes: 9 additions & 28 deletions tests/CMakeLists.txt
Expand Up @@ -17,29 +17,15 @@ find_package(PythonInterp)
#-----------------------------------------------------------------------
# Build the test cases

# For each test cases, we create two executables: one that links with a
# shared libcork, and the other that simulates embedding libcork into
# another project. For the embedded version, we need to know which of
# the libcork submodules should be included when compiling the test
# case. These are provided as additional parameters to the make_test
# macro.

macro(make_test test_name)
if (ENABLE_SHARED OR ENABLE_SHARED_EXECUTABLES)
add_executable(shared-${test_name} ${test_name}.c)
target_link_libraries(shared-${test_name} ${CHECK_LIBRARIES}
libcork-shared)
add_test(shared-${test_name} shared-${test_name})
endif (ENABLE_SHARED OR ENABLE_SHARED_EXECUTABLES)

if (ENABLE_STATIC OR NOT ENABLE_SHARED_EXECUTABLES)
add_executable(embedded-${test_name} ${test_name}.c)
set_target_properties(embedded-${test_name} PROPERTIES
COMPILE_DEFINITIONS CORK_EMBEDDED_TEST=1)
target_link_libraries(embedded-${test_name} ${CHECK_LIBRARIES}
libcork-static)
add_test(embedded-${test_name} embedded-${test_name})
endif (ENABLE_STATIC OR NOT ENABLE_SHARED_EXECUTABLES)
add_executable(${test_name} ${test_name}.c)
add_test(${test_name} ${test_name})
if (ENABLE_SHARED_TESTS)
target_link_libraries(${test_name} ${CHECK_LIBRARIES} libcork-shared)
else (ENABLE_SHARED_TESTS)
set_target_properties(${test_name} PROPERTIES COMPILE_DEFINITIONS CORK_EMBEDDED_TEST=1)
target_link_libraries(${test_name} ${CHECK_LIBRARIES} libcork-static)
endif (ENABLE_SHARED_TESTS)
endmacro(make_test)

make_test(test-array)
Expand All @@ -65,12 +51,7 @@ make_test(test-u128)
# arithmetic functions.

add_custom_target(u128-test-suite)
if (ENABLE_SHARED OR ENABLE_SHARED_EXECUTABLES)
add_dependencies(shared-test-u128 u128-test-suite)
endif (ENABLE_SHARED OR ENABLE_SHARED_EXECUTABLES)
if (ENABLE_STATIC OR NOT ENABLE_SHARED_EXECUTABLES)
add_dependencies(embedded-test-u128 u128-test-suite)
endif (ENABLE_STATIC OR NOT ENABLE_SHARED_EXECUTABLES)
add_dependencies(test-u128 u128-test-suite)

macro(make_u128_suite op)
set(generator "${CMAKE_CURRENT_SOURCE_DIR}/create-u128-test-cases.py")
Expand Down
2 changes: 1 addition & 1 deletion tests/test-files.c
Expand Up @@ -365,7 +365,7 @@ test_file_exists(const char *filename, bool expected)
START_TEST(test_file_exists_01)
{
DESCRIBE_TEST;
test_file_exists("embedded-test-files", true);
test_file_exists("test-files", true);
test_file_exists("test-nonexistent", false);
}
END_TEST
Expand Down

0 comments on commit 2c10646

Please sign in to comment.