1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-24 19:37:48 +03:00

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(WITH_GCRYPT)
if (UNIT_TESTING)
find_package(CMocka REQUIRED)
endif ()
# Find out if we have threading available
set(CMAKE_THREAD_PREFER_PTHREADS ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
@@ -150,9 +154,8 @@ if (WITH_EXAMPLES)
endif (WITH_EXAMPLES)
if (UNIT_TESTING)
find_package(CMocka REQUIRED)
include(AddCMockaTest)
add_subdirectory(tests)
include(AddCMockaTest)
add_subdirectory(tests)
endif (UNIT_TESTING)
### SOURCE PACKAGE

View File

@@ -261,6 +261,14 @@ if (CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 1)
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
check_c_source_compiles("
__thread int tls;

View File

@@ -187,6 +187,9 @@
/* Define to 1 if you have the `SecureZeroMemory' function. */
#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 ***************************/
/* Define to 1 if you have the `crypto' library (-lcrypto). */
@@ -201,6 +204,9 @@
/* Define to 1 if you have the `pthread' library (-lpthread). */
#cmakedefine HAVE_PTHREAD 1
/* Define to 1 if you have the `cmocka' library (-lcmocka). */
#cmakedefine HAVE_CMOCKA 1
/**************************** OPTIONS ****************************/
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1

View File

@@ -50,9 +50,6 @@
#include "torture_key.h"
#include "libssh/misc.h"
/* for pattern matching */
#include "match.c"
#define TORTURE_SSHD_SRV_IPV4 "127.0.0.10"
/* socket wrapper IPv6 prefix fd00::5357:5fxx */
#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)
{
size_t i,j;
const char *name;
if (pattern == NULL){
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) tests;
(void) ntests;
return;
}
void torture_write_file(const char *filename, const char *data){
@@ -843,20 +821,24 @@ void torture_write_file(const char *filename, const char *data){
int main(int argc, char **argv) {
struct argument_s arguments;
char *env = getenv("LIBSSH_VERBOSITY");
struct argument_s arguments;
char *env = getenv("LIBSSH_VERBOSITY");
arguments.verbose=0;
arguments.pattern=NULL;
torture_cmdline_parse(argc, argv, &arguments);
verbosity=arguments.verbose;
pattern=arguments.pattern;
arguments.verbose=0;
arguments.pattern=NULL;
torture_cmdline_parse(argc, argv, &arguments);
verbosity=arguments.verbose;
pattern=arguments.pattern;
if (verbosity == 0 && env != NULL && env[0] != '\0') {
if (env[0] > '0' && env[0] < '9') {
verbosity = atoi(env);
}
}
if (verbosity == 0 && env != NULL && env[0] != '\0') {
if (env[0] > '0' && env[0] < '9') {
verbosity = atoi(env);
}
}
return torture_run_tests();
#if defined HAVE_CMOCKA_SET_TEST_FILTER
cmocka_set_test_filter(pattern);
#endif
return torture_run_tests();
}