tester.c: reenable JUnit output when having CUnit >= 3.0.1 and compute time in milliseconds

parent e9289203
......@@ -94,8 +94,9 @@ if(POLARSSL_FOUND)
endif()
if(ENABLE_TESTS_COMPONENT)
find_package(CUnit)
find_package(CUnit 3.0.1) # we need cunit 3.0.1 for automated junit output
if(CUNIT_FOUND)
set(HAVE_CU_FIXED_JUNIT 1)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${CUNIT_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CUNIT_LIBRARIES})
......@@ -106,8 +107,15 @@ if(ENABLE_TESTS_COMPONENT)
set(TESTER_REQUIRES_PRIVATE "cunit")
else()
message(WARNING "Could not find the cunit library!")
set(ENABLE_TESTS_COMPONENT OFF CACHE BOOL "Enable compilation of tests helper library" FORCE)
# if we found Cunit but with improper version, do not enable HAVE_CU_FIXED_JUNIT and search again for CUnit
if (CUNIT_LIBRARIES)
find_package(CUnit)
endif()
if (NOT CUNIT_FOUND)
message(WARNING "Could not find the Cunit library, disable tests.")
set(ENABLE_TESTS_COMPONENT OFF CACHE BOOL "Enable compilation of tests helper library" FORCE)
endif()
endif()
endif()
......
......@@ -41,6 +41,9 @@ find_path(CUNIT_INCLUDE_DIRS
if(CUNIT_INCLUDE_DIRS)
set(HAVE_CUNIT_CUNIT_H 1)
file(STRINGS "${CUNIT_INCLUDE_DIRS}/CUnit/CUnit.h" CUNIT_VERSION_STR
REGEX "^#define[\t ]+CU_VERSION[\t ]+\"(.+)\"$")
string(REGEX REPLACE "^.*CU_VERSION[\t ]+\"(.+)\"$" "\\1" CUNIT_VERSION "${CUNIT_VERSION_STR}")
endif()
find_library(CUNIT_LIBRARIES
......@@ -50,9 +53,16 @@ find_library(CUNIT_LIBRARIES
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CUnit
DEFAULT_MSG
CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES
)
if (CUNIT_VERSION)
find_package_handle_standard_args(CUnit
REQUIRED_VARS CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES
VERSION_VAR CUNIT_VERSION
)
else()
find_package_handle_standard_args(CUnit
REQUIRED_VARS CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES
)
endif()
mark_as_advanced(CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES)
......@@ -20,10 +20,11 @@
*
****************************************************************************/
#cmakedefine HAVE_DTLS_SRTP
#cmakedefine HAVE_CTR_DRGB_FREE
#cmakedefine HAVE_CU_GET_SUITE
#cmakedefine HAVE_CU_CURSES
#cmakedefine HAVE_CU_SET_TRACE_HANDLER
#cmakedefine HAVE_DTLS_SRTP 1
#cmakedefine HAVE_CTR_DRGB_FREE 1
#cmakedefine HAVE_CU_GET_SUITE 1
#cmakedefine HAVE_CU_CURSES 1
#cmakedefine HAVE_CU_SET_TRACE_HANDLER 1
#cmakedefine HAVE_CU_FIXED_JUNIT 1
#cmakedefine HAVE_LIBRT
#cmakedefine HAVE_LIBRT 1
......@@ -20,16 +20,9 @@
#
############################################################################
set(HEADER_FILES
bctoolbox/bc_vfs.h
bctoolbox/crypto.h
bctoolbox/list.h
bctoolbox/logging.h
bctoolbox/map.h
bctoolbox/port.h
)
if(ENABLE_TESTS_COMPONENT)
list(APPEND HEADER_FILES bctoolbox/tester.h)
file(GLOB HEADER_FILES "bctoolbox/*.h")
if (NOT ENABLE_TESTS_COMPONENT)
list(REMOVE_ITEM HEADER_FILES bctoolbox/tester.h)
endif()
install(FILES ${HEADER_FILES}
......
......@@ -158,11 +158,11 @@ endif()
if(CUNIT_FOUND)
if(ENABLE_STATIC)
target_include_directories(bctoolbox-tester-static PUBLIC ${CUNIT_INCLUDE_DIRS})
target_link_libraries(bctoolbox-tester-static ${CUNIT_LIBRARIES})
target_link_libraries(bctoolbox-tester-static bctoolbox-static ${CUNIT_LIBRARIES})
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox-tester PUBLIC ${CUNIT_INCLUDE_DIRS})
target_link_libraries(bctoolbox-tester PRIVATE ${CUNIT_LIBRARIES})
target_link_libraries(bctoolbox-tester PRIVATE bctoolbox ${CUNIT_LIBRARIES})
endif()
endif()
......
......@@ -225,25 +225,25 @@ static void suite_cleanup_failure_message_handler(const CU_pSuite pSuite) {
}
#ifdef HAVE_CU_GET_SUITE
static time_t suite_start_time = 0;
static uint64_t suite_start_time = 0;
static void suite_start_message_handler(const CU_pSuite pSuite) {
bc_tester_printf(bc_printf_verbosity_info,"Suite [%s] started", pSuite->pName);
suite_start_time = time(NULL);
bc_tester_printf(bc_printf_verbosity_info,"Suite [%s] started\n", pSuite->pName);
suite_start_time = bctbx_get_cur_time_ms();
bc_current_suite_name = pSuite->pName;
}
static void suite_complete_message_handler(const CU_pSuite pSuite, const CU_pFailureRecord pFailure) {
bc_tester_printf(bc_printf_verbosity_info, "Suite [%s] ended in %lu sec", pSuite->pName,
time(NULL) - suite_start_time);
bc_tester_printf(bc_printf_verbosity_info, "Suite [%s] ended in %.3f sec\n", pSuite->pName,
(bctbx_get_cur_time_ms() - suite_start_time) / 1000.f);
}
static time_t test_start_time = 0;
static uint64_t test_start_time = 0;
static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite) {
int suite_index = bc_tester_suite_index(pSuite->pName);
if (test_suite[suite_index]->before_each) {
test_suite[suite_index]->before_each();
}
bc_tester_printf(bc_printf_verbosity_info,"Suite [%s] Test [%s] started", pSuite->pName,pTest->pName);
test_start_time = time(NULL);
test_start_time = bctbx_get_cur_time_ms();
bc_current_test_name = pTest->pName;
}
......@@ -254,8 +254,8 @@ static void test_complete_message_handler(const CU_pTest pTest, const CU_pSuite
int suite_index = bc_tester_suite_index(pSuite->pName);
CU_pFailureRecord pFailure = pFailureList;
char *buffer = NULL;
char* result = bc_sprintf("Suite [%s] Test [%s] %s in %lu secs", pSuite->pName, pTest->pName,
pFailure ? "failed" : "passed", (unsigned long)(time(NULL) - test_start_time));
char* result = bc_sprintf("Suite [%s] Test [%s] %s in %.3f secs", pSuite->pName, pTest->pName,
pFailure ? "failed" : "passed", (bctbx_get_cur_time_ms() - test_start_time) / 1000.f);
if (pFailure) {
for (i = 1; (NULL != pFailure); pFailure = pFailure->pNext, i++) {
......@@ -601,7 +601,9 @@ int bc_tester_start(const char* prog_name) {
if( xml_enabled ){
char * xml_tmp_file = bc_sprintf("%s.tmp", xml_file);
CU_set_output_filename(xml_tmp_file);
// CU_automated_enable_junit_xml(TRUE); /* do not enable me yet: this is bugged on cunit 2.1.2 (crash in automated.c)
#ifdef HAVE_CU_FIXED_JUNIT
CU_automated_enable_junit_xml(TRUE); /* this requires 3.0.1 because previous versions crash automated.c */
#endif
free(xml_tmp_file);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment