tests: Replace tests filtering with cmocka builtin filter

This completely removes the tests filter code from torture.c and calls
cmocka_set_test_filter() instead, if available.  The checks for required
libraries, headers, and the availability of cmocka_set_test_filter()
were added to the cmake configuration.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Anderson Toshiyuki Sasaki
2018-11-21 13:59:42 +01:00
committed by Andreas Schneider
parent 74285d3aca
commit 1f6b929735
4 changed files with 41 additions and 42 deletions

View File

@@ -70,6 +70,10 @@ else (WITH_GCRYPT)
endif (NOT OPENSSL_FOUND) endif (NOT OPENSSL_FOUND)
endif(WITH_GCRYPT) endif(WITH_GCRYPT)
if (UNIT_TESTING)
find_package(CMocka REQUIRED)
endif ()
# Find out if we have threading available # Find out if we have threading available
set(CMAKE_THREAD_PREFER_PTHREADS ON) set(CMAKE_THREAD_PREFER_PTHREADS ON)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
@@ -150,7 +154,6 @@ if (WITH_EXAMPLES)
endif (WITH_EXAMPLES) endif (WITH_EXAMPLES)
if (UNIT_TESTING) if (UNIT_TESTING)
find_package(CMocka REQUIRED)
include(AddCMockaTest) include(AddCMockaTest)
add_subdirectory(tests) add_subdirectory(tests)
endif (UNIT_TESTING) endif (UNIT_TESTING)

View File

@@ -261,6 +261,14 @@ if (CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 1) set(HAVE_PTHREAD 1)
endif (CMAKE_USE_PTHREADS_INIT) endif (CMAKE_USE_PTHREADS_INIT)
if (UNIT_TESTING)
if (CMOCKA_FOUND)
set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES})
check_function_exists(cmocka_set_test_filter HAVE_CMOCKA_SET_TEST_FILTER)
unset(CMAKE_REQUIRED_LIBRARIES)
endif ()
endif ()
# OPTIONS # OPTIONS
check_c_source_compiles(" check_c_source_compiles("
__thread int tls; __thread int tls;

View File

@@ -187,6 +187,9 @@
/* Define to 1 if you have the `SecureZeroMemory' function. */ /* Define to 1 if you have the `SecureZeroMemory' function. */
#cmakedefine HAVE_SECURE_ZERO_MEMORY 1 #cmakedefine HAVE_SECURE_ZERO_MEMORY 1
/* Define to 1 if you have the `cmocka_set_test_filter' function. */
#cmakedefine HAVE_CMOCKA_SET_TEST_FILTER 1
/*************************** LIBRARIES ***************************/ /*************************** LIBRARIES ***************************/
/* Define to 1 if you have the `crypto' library (-lcrypto). */ /* Define to 1 if you have the `crypto' library (-lcrypto). */
@@ -201,6 +204,9 @@
/* Define to 1 if you have the `pthread' library (-lpthread). */ /* Define to 1 if you have the `pthread' library (-lpthread). */
#cmakedefine HAVE_PTHREAD 1 #cmakedefine HAVE_PTHREAD 1
/* Define to 1 if you have the `cmocka' library (-lcmocka). */
#cmakedefine HAVE_CMOCKA 1
/**************************** OPTIONS ****************************/ /**************************** OPTIONS ****************************/
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1 #cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1

View File

@@ -50,9 +50,6 @@
#include "torture_key.h" #include "torture_key.h"
#include "libssh/misc.h" #include "libssh/misc.h"
/* for pattern matching */
#include "match.c"
#define TORTURE_SSHD_SRV_IPV4 "127.0.0.10" #define TORTURE_SSHD_SRV_IPV4 "127.0.0.10"
/* socket wrapper IPv6 prefix fd00::5357:5fxx */ /* socket wrapper IPv6 prefix fd00::5357:5fxx */
#define TORTURE_SSHD_SRV_IPV6 "fd00::5357:5f0a" #define TORTURE_SSHD_SRV_IPV6 "fd00::5357:5f0a"
@@ -799,29 +796,10 @@ int torture_libssh_verbosity(void){
void _torture_filter_tests(struct CMUnitTest *tests, size_t ntests) void _torture_filter_tests(struct CMUnitTest *tests, size_t ntests)
{ {
size_t i,j; (void) tests;
const char *name; (void) ntests;
if (pattern == NULL){
return; return;
}
for (i=0; i < ntests; ++i){
name = tests[i].name;
/*printf("match(%s,%s)\n",name,pattern);*/
if (!match_pattern(name, pattern)){
for (j = i; j < ntests-1;++j){
tests[j]=tests[j+1];
}
tests[ntests-1].name = NULL;
tests[ntests-1].test_func = NULL;
ntests--;
--i;
}
}
if (ntests != 0){
printf("%d tests left\n",(int)ntests);
} else {
printf("No matching test left\n");
}
} }
void torture_write_file(const char *filename, const char *data){ void torture_write_file(const char *filename, const char *data){
@@ -858,5 +836,9 @@ int main(int argc, char **argv) {
} }
} }
#if defined HAVE_CMOCKA_SET_TEST_FILTER
cmocka_set_test_filter(pattern);
#endif
return torture_run_tests(); return torture_run_tests();
} }