mirror of
https://github.com/tezc/sc.git
synced 2025-01-14 06:43:04 +08:00
Build test on debug only (#45)
* Build tests in debug mode only, fix gcc warnings * strncpy fix in thread err
This commit is contained in:
parent
ed5bcab2b9
commit
950d6f191b
@ -12,10 +12,15 @@ endif ()
|
||||
message(STATUS "Build type ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
option(SC_BUILD_TEST "Build tests" ON)
|
||||
if(NOT SC_BUILD_TEST)
|
||||
message(STATUS "Turned off building tests because SC is a subproject.")
|
||||
message(STATUS "Turned off coverage because SC is a subproject.")
|
||||
endif()
|
||||
if (NOT SC_BUILD_TEST)
|
||||
message(STATUS "Turned off building tests because SC is a subproject.")
|
||||
message(STATUS "Turned off coverage because SC is a subproject.")
|
||||
endif ()
|
||||
|
||||
if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug" AND NOT ${CMAKE_BUILD_TYPE} MATCHES "Coverage")
|
||||
SET(SC_BUILD_TEST OFF CACHE BOOL "Turn off sc_lib tests" FORCE)
|
||||
message(STATUS "Not building tests, SC tests are supported in Debug build only.")
|
||||
endif ()
|
||||
|
||||
add_subdirectory(array)
|
||||
add_subdirectory(buffer)
|
||||
@ -43,47 +48,47 @@ add_subdirectory(uri)
|
||||
# --------------------------------------------------------------------------- #
|
||||
# --------------------- Test Configuration Start ---------------------------- #
|
||||
# --------------------------------------------------------------------------- #
|
||||
if(SC_BUILD_TEST)
|
||||
# ----------------------- - Code Coverage Start ----------------------------- #
|
||||
if (SC_BUILD_TEST)
|
||||
# ----------------------- - Code Coverage Start ----------------------------- #
|
||||
|
||||
if (${CMAKE_BUILD_TYPE} MATCHES "Coverage")
|
||||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
||||
add_compile_options(--coverage)
|
||||
link_libraries(gcov)
|
||||
else()
|
||||
message(FATAL_ERROR "Only GCC is supported for coverage")
|
||||
endif()
|
||||
endif ()
|
||||
if (${CMAKE_BUILD_TYPE} MATCHES "Coverage")
|
||||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
||||
add_compile_options(--coverage)
|
||||
link_libraries(gcov)
|
||||
else ()
|
||||
message(FATAL_ERROR "Only GCC is supported for coverage")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
add_custom_target(coverage)
|
||||
add_custom_command(
|
||||
TARGET coverage
|
||||
COMMAND lcov --capture --directory .
|
||||
--output-file coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
||||
COMMAND lcov --remove coverage.info '/usr/*' '*example*' '*test*'
|
||||
--output-file coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
||||
COMMAND lcov --list coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
||||
)
|
||||
add_custom_target(coverage)
|
||||
add_custom_command(
|
||||
TARGET coverage
|
||||
COMMAND lcov --capture --directory .
|
||||
--output-file coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
||||
COMMAND lcov --remove coverage.info '/usr/*' '*example*' '*test*'
|
||||
--output-file coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
||||
COMMAND lcov --list coverage.info --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
|
||||
)
|
||||
|
||||
# -------------------------- Code Coverage End ------------------------------ #
|
||||
# -------------------------- Code Coverage End ------------------------------ #
|
||||
|
||||
SET(MEMORYCHECK_COMMAND_OPTIONS
|
||||
"-q --log-fd=2 --trace-children=yes --track-origins=yes \
|
||||
SET(MEMORYCHECK_COMMAND_OPTIONS
|
||||
"-q --log-fd=2 --trace-children=yes --track-origins=yes \
|
||||
--leak-check=full --show-leak-kinds=all \
|
||||
--error-exitcode=255")
|
||||
|
||||
add_custom_target(valgrind ${CMAKE_COMMAND}
|
||||
-E env CTEST_OUTPUT_ON_FAILURE=1
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIG>
|
||||
--overwrite MemoryCheckCommandOptions=${MEMORYCHECK_COMMAND_OPTIONS}
|
||||
--verbose -T memcheck WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
add_custom_target(valgrind ${CMAKE_COMMAND}
|
||||
-E env CTEST_OUTPUT_ON_FAILURE=1
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIG>
|
||||
--overwrite MemoryCheckCommandOptions=${MEMORYCHECK_COMMAND_OPTIONS}
|
||||
--verbose -T memcheck WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
add_custom_target(check ${CMAKE_COMMAND}
|
||||
-E env CTEST_OUTPUT_ON_FAILURE=1
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIG> --verbose
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
add_custom_target(check ${CMAKE_COMMAND}
|
||||
-E env CTEST_OUTPUT_ON_FAILURE=1
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIG> --verbose
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
add_dependencies(coverage check)
|
||||
add_dependencies(coverage check)
|
||||
|
||||
endif ()
|
||||
# ----------------------- Test Configuration End ---------------------------- #
|
||||
|
@ -159,6 +159,7 @@ void sc_cond_signal(struct sc_cond *cond, void *data)
|
||||
// This won't fail as long as we pass correct params.
|
||||
rc = pthread_cond_signal(&cond->cond);
|
||||
assert(rc == 0);
|
||||
(void) rc;
|
||||
|
||||
pthread_mutex_unlock(&cond->mtx);
|
||||
}
|
||||
@ -174,6 +175,7 @@ void *sc_cond_wait(struct sc_cond *cond)
|
||||
// This won't fail as long as we pass correct params.
|
||||
rc = pthread_cond_wait(&cond->cond, &cond->mtx);
|
||||
assert(rc == 0);
|
||||
(void) rc;
|
||||
}
|
||||
|
||||
data = cond->data;
|
||||
|
@ -79,6 +79,7 @@ int sc_mutex_init(struct sc_mutex *mtx)
|
||||
// This won't fail as long as we pass correct param.
|
||||
rv = pthread_mutexattr_destroy(&attr);
|
||||
assert(rv == 0);
|
||||
(void) rv;
|
||||
|
||||
return rc != 0 ? -1 : 0;
|
||||
}
|
||||
@ -98,6 +99,7 @@ void sc_mutex_lock(struct sc_mutex *mtx)
|
||||
// This won't fail as long as we pass correct param.
|
||||
rc = pthread_mutex_lock(&mtx->mtx);
|
||||
assert(rc == 0);
|
||||
(void) rc;
|
||||
}
|
||||
|
||||
void sc_mutex_unlock(struct sc_mutex *mtx)
|
||||
@ -107,6 +109,7 @@ void sc_mutex_unlock(struct sc_mutex *mtx)
|
||||
// This won't fail as long as we pass correct param.
|
||||
rc = pthread_mutex_unlock(&mtx->mtx);
|
||||
assert(rc == 0);
|
||||
(void) rc;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -510,12 +510,13 @@ int sc_signal_init()
|
||||
|
||||
void sc_signal_log(int fd, char *buf, size_t len, char *fmt, ...)
|
||||
{
|
||||
int written;
|
||||
int written, rc;
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
written = sc_signal_vsnprintf(buf, len, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
(void) write(fd, buf, (size_t) written);
|
||||
rc = write(fd, buf, (size_t) written);
|
||||
(void) rc;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ int sc_thread_start(struct sc_thread *thread, void *(*fn)(void *), void *arg)
|
||||
|
||||
rc = pthread_attr_init(&attr);
|
||||
if (rc != 0) {
|
||||
strncpy(thread->err, strerror(rc), sizeof(thread->err));
|
||||
strncpy(thread->err, strerror(rc), sizeof(thread->err) - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ int sc_thread_start(struct sc_thread *thread, void *(*fn)(void *), void *arg)
|
||||
|
||||
rc = pthread_create(&thread->id, &attr, fn, arg);
|
||||
if (rc != 0) {
|
||||
strncpy(thread->err, strerror(rc), sizeof(thread->err));
|
||||
strncpy(thread->err, strerror(rc), sizeof(thread->err) - 1);
|
||||
}
|
||||
|
||||
// This may only fail with EINVAL.
|
||||
@ -144,7 +144,7 @@ int sc_thread_join(struct sc_thread *thread, void **ret)
|
||||
|
||||
rc = pthread_join(thread->id, &val);
|
||||
if (rc != 0) {
|
||||
strncpy(thread->err, strerror(rc), sizeof(thread->err));
|
||||
strncpy(thread->err, strerror(rc), sizeof(thread->err) - 1);
|
||||
}
|
||||
|
||||
thread->id = 0;
|
||||
|
@ -54,6 +54,7 @@ uint64_t sc_time_ms()
|
||||
|
||||
rc = clock_gettime(CLOCK_REALTIME, &ts);
|
||||
assert(rc == 0);
|
||||
(void) rc;
|
||||
|
||||
return ts.tv_sec * 1000 + (uint64_t)(ts.tv_nsec / 10e6);
|
||||
#endif
|
||||
@ -76,6 +77,7 @@ uint64_t sc_time_ns()
|
||||
|
||||
rc = clock_gettime(CLOCK_REALTIME, &ts);
|
||||
assert(rc == 0);
|
||||
(void) rc;
|
||||
|
||||
return ts.tv_sec * (uint64_t)1000000000 + ts.tv_nsec;
|
||||
#endif
|
||||
@ -101,6 +103,7 @@ uint64_t sc_time_mono_ms()
|
||||
|
||||
rc = clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
assert(rc == 0);
|
||||
(void) rc;
|
||||
|
||||
return (uint64_t)((uint64_t) ts.tv_sec * 1000 +
|
||||
(uint64_t) ts.tv_nsec / 1000000);
|
||||
@ -126,6 +129,7 @@ uint64_t sc_time_mono_ns()
|
||||
|
||||
rc = clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
assert(rc == 0);
|
||||
(void) rc;
|
||||
|
||||
return ((uint64_t) ts.tv_sec * 1000000000 + (uint64_t) ts.tv_nsec);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user