Skip to content

Commit

Permalink
Fixes #13, regards #12:
Browse files Browse the repository at this point in the history
* Updated the compiler directives for suppressing relevant warnings to also properly work with NVCC.
* Test suite "replicated" for CUDA host-side compilation (by including the `.cpp` file from the `.cu` file)
* `CMakeLists.txt` for the tests reworked to support CUDA targets, architecture auto-detection, etc.
  • Loading branch information
Eyal Rozenberg committed Jul 6, 2021
1 parent 6344c04 commit 5965fd4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 25 deletions.
73 changes: 54 additions & 19 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.18)

enable_language(CXX)

add_executable(test_suite "test_suite.cpp")

set_target_properties(
test_suite
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)

option(BUILD_CUDA_TESTS "Include tests for use of the printf library with CUDA host-side and device-side code" OFF)
option(TEST_BROKEN_FORMATS "Include tests using non-standard-compliant format strings?" ON)
# ... don't worry, we'll suppress the compiler warnings for those.
if (TEST_BROKEN_FORMATS)
target_compile_definitions(test_suite PRIVATE TEST_WITH_NON_STANDARD_FORMAT_STRINGS)

set(cuda_tests)
if(BUILD_CUDA_TESTS)
enable_language(CUDA)
list(APPEND CMAKE_CUDA_FLAGS "--extended-lambda --expt-relaxed-constexpr -Xcudafe --display_error_number")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
cmake_policy(SET CMP0104 OLD)
endif()
include(FindCUDA/select_compute_arch)
list(APPEND cuda_tests cuda_test_suite_host)
if((NOT DEFINED CUDA_ARCH_FLAGS) OR ("${CUDA_ARCH_FLAGS}" STREQUAL ""))
cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS_1 Auto)
set(CUDA_ARCH_FLAGS ${CUDA_ARCH_FLAGS} CACHE STRING "CUDA -gencode parameters")
string(REPLACE ";" " " CUDA_ARCH_FLAGS_STR "${CUDA_ARCH_FLAGS}")
else()
set(CUDA_ARCH_FLAGS_STR "${CUDA_ARCH_FLAGS}")
endif()
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CUDA_ARCH_FLAGS_STR}")
endif()

target_link_libraries(test_suite PRIVATE mpaland-printf)
foreach(tgt ${cuda_tests})
add_executable(${tgt} "${tgt}.cu")
set_target_properties(
${tgt}
PROPERTIES
CUDA_STANDARD 11
CUDA_STANDARD_REQUIRED YES
CUDA_EXTENSIONS NO
)
endforeach()

set(tests test_suite ${cuda_tests})

add_executable(test_suite "test_suite.cpp")

foreach(tgt ${tests})
set_target_properties(
${tgt}
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
if (TEST_BROKEN_FORMATS)
# ... don't worry, we'll suppress the compiler warnings for those.
target_compile_definitions(${tgt} PRIVATE TEST_WITH_NON_STANDARD_FORMAT_STRINGS)
endif()

target_link_libraries(test_suite PRIVATE mpaland-printf)
add_test(
NAME ${PROJECT_NAME}.${tgt}
COMMAND ${tgt} # ${TEST_RUNNER_PARAMS}
)
endforeach()

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(test_suite PRIVATE /W4)
Expand Down Expand Up @@ -53,9 +92,5 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
endif()
endif()

add_test(
NAME ${PROJECT_NAME}.test_suite
COMMAND test_suite # ${TEST_RUNNER_PARAMS}
)


1 change: 1 addition & 0 deletions test/cuda_test_suite_host.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "test_suite.cpp"
23 changes: 17 additions & 6 deletions test/test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,35 @@ namespace test {
#define DISABLE_WARNING(warningNumber) __pragma(warning( disable : warningNumber ))

// TODO: find the right warning number for this
#define DISABLE_WARNING_PRINTF_FORMAT
#define DISABLE_WARNING_PRINTF_FORMAT_EXTRA_ARGS
#define DISABLE_WARNING_PRINTF_FORMAT
#define DISABLE_WARNING_PRINTF_FORMAT_EXTRA_ARGS
#define DISABLE_WARNING_PRINTF_FORMAT_OVERFLOW

#elif defined(__NVCC__)
#define DO_PRAGMA(X) _Pragma(#X)
#define DISABLE_WARNING_PUSH DO_PRAGMA(push)
#define DISABLE_WARNING_POP DO_PRAGMA(pop)
#define DISABLE_WARNING(warning_code) DO_PRAGMA(diag_suppress warning_code)

#define DISABLE_WARNING_PRINTF_FORMAT DISABLE_WARNING(bad_printf_format_string)
#define DISABLE_WARNING_PRINTF_FORMAT_EXTRA_ARGS
#define DISABLE_WARNING_PRINTF_FORMAT_OVERFLOW

#elif defined(__GNUC__) || defined(__clang__)
#define DO_PRAGMA(X) _Pragma(#X)
#define DISABLE_WARNING_PUSH DO_PRAGMA(GCC diagnostic push)
#define DISABLE_WARNING_POP DO_PRAGMA(GCC diagnostic pop)
#define DISABLE_WARNING(warningName) DO_PRAGMA(GCC diagnostic ignored #warningName)

#define DISABLE_WARNING_PRINTF_FORMAT DISABLE_WARNING(-Wformat)
#define DISABLE_WARNING_PRINTF_FORMAT_EXTRA_ARGS DISABLE_WARNING(-Wformat-extra-args)
#define DISABLE_WARNING_PRINTF_FORMAT_OVERFLOW DISABLE_WARNING(-Wformat-overflow)

#define DISABLE_WARNING_PRINTF_FORMAT DISABLE_WARNING(-Wformat)
#define DISABLE_WARNING_PRINTF_FORMAT_EXTRA_ARGS DISABLE_WARNING(-Wformat-extra-args)
#define DISABLE_WARNING_PRINTF_FORMAT_OVERFLOW DISABLE_WARNING(-Wformat-overflow)
#else
#define DISABLE_WARNING_PUSH
#define DISABLE_WARNING_POP
#define DISABLE_WARNING_PRINTF_FORMAT
#define DISABLE_WARNING_PRINTF_FORMAT_EXTRA_ARGS
#define DISABLE_WARNING_PRINTF_FORMAT_OVERFLOW
#endif

#ifdef TEST_WITH_NON_STANDARD_FORMAT_STRINGS
Expand Down

0 comments on commit 5965fd4

Please sign in to comment.