aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt9
-rw-r--r--ConfigureChecks.cmake8
-rw-r--r--config.h.cmake6
-rw-r--r--tests/torture.c64
4 files changed, 43 insertions, 44 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5f2be383..e2188a38 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 24fed78b..c549d8fc 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -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;
diff --git a/config.h.cmake b/config.h.cmake
index f3660c78..f4659049 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -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
diff --git a/tests/torture.c b/tests/torture.c
index 6f2b60f0..f12fc23b 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -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");
-
- 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);
- }
- }
+ 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;
+
+ if (verbosity == 0 && env != NULL && env[0] != '\0') {
+ if (env[0] > '0' && env[0] < '9') {
+ verbosity = atoi(env);
+ }
+ }
+
+#if defined HAVE_CMOCKA_SET_TEST_FILTER
+ cmocka_set_test_filter(pattern);
+#endif
- return torture_run_tests();
+ return torture_run_tests();
}