aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2014-09-02 09:07:17 +0200
committerAndreas Schneider <asn@cryptomilk.org>2015-02-02 17:34:15 +0100
commitd42a1a35b0c2f2178e459b9328f97f9e988a1cb0 (patch)
tree509cf5ffb852bead71db43dc1b183686aadc6dda
parent8af829a42aea835219113e13a176fa36a397db35 (diff)
downloadlibssh-d42a1a35b0c2f2178e459b9328f97f9e988a1cb0.tar.gz
libssh-d42a1a35b0c2f2178e459b9328f97f9e988a1cb0.tar.xz
libssh-d42a1a35b0c2f2178e459b9328f97f9e988a1cb0.zip
tests: allow conditionnal execution on pattern
Option can be used to filter out irrelevant tests usage: ./torture_pki '*ed25519' Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/client/torture_algorithms.c4
-rw-r--r--tests/client/torture_auth.c4
-rw-r--r--tests/client/torture_connect.c3
-rw-r--r--tests/client/torture_forward.c3
-rw-r--r--tests/client/torture_knownhosts.c3
-rw-r--r--tests/client/torture_proxycommand.c3
-rw-r--r--tests/client/torture_request_env.c3
-rw-r--r--tests/client/torture_session.c3
-rw-r--r--tests/client/torture_sftp_dir.c3
-rw-r--r--tests/client/torture_sftp_read.c3
-rw-r--r--tests/client/torture_sftp_static.c3
-rw-r--r--tests/cmdline.c1
-rw-r--r--tests/torture.c39
-rw-r--r--tests/torture.h5
-rw-r--r--tests/unittests/torture_buffer.c3
-rw-r--r--tests/unittests/torture_callbacks.c3
-rw-r--r--tests/unittests/torture_channel.c3
-rw-r--r--tests/unittests/torture_init.c4
-rw-r--r--tests/unittests/torture_isipaddr.c3
-rw-r--r--tests/unittests/torture_keyfiles.c3
-rw-r--r--tests/unittests/torture_list.c3
-rw-r--r--tests/unittests/torture_misc.c3
-rw-r--r--tests/unittests/torture_options.c3
-rw-r--r--tests/unittests/torture_pki.c3
-rw-r--r--tests/unittests/torture_rand.c3
25 files changed, 88 insertions, 26 deletions
diff --git a/tests/client/torture_algorithms.c b/tests/client/torture_algorithms.c
index 8a466380..dc7b6539 100644
--- a/tests/client/torture_algorithms.c
+++ b/tests/client/torture_algorithms.c
@@ -289,7 +289,7 @@ static void torture_algorithms_dh_group1(void **state) {
}
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha1, setup, teardown),
unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha2_256, setup, teardown),
unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha2_512, setup, teardown),
@@ -323,7 +323,7 @@ int torture_run_tests(void) {
};
ssh_init();
-
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c
index af36b79f..7f5167e8 100644
--- a/tests/client/torture_auth.c
+++ b/tests/client/torture_auth.c
@@ -421,7 +421,7 @@ static void torture_auth_none_nonblocking(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_auth_kbdint, setup, teardown),
unit_test_setup_teardown(torture_auth_kbdint_nonblocking, setup, teardown),
unit_test_setup_teardown(torture_auth_password, setup, teardown),
@@ -435,7 +435,7 @@ int torture_run_tests(void) {
};
ssh_init();
-
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_connect.c b/tests/client/torture_connect.c
index 31573ea3..bb28609a 100644
--- a/tests/client/torture_connect.c
+++ b/tests/client/torture_connect.c
@@ -139,7 +139,7 @@ static void torture_connect_socket(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_connect_nonblocking, setup, teardown),
unit_test_setup_teardown(torture_connect_double, setup, teardown),
unit_test_setup_teardown(torture_connect_failure, setup, teardown),
@@ -149,6 +149,7 @@ int torture_run_tests(void) {
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_forward.c b/tests/client/torture_forward.c
index 0ffeae05..876ed74b 100644
--- a/tests/client/torture_forward.c
+++ b/tests/client/torture_forward.c
@@ -81,12 +81,13 @@ static void torture_ssh_forward(void **state)
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_ssh_forward, setup, teardown),
};
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_knownhosts.c b/tests/client/torture_knownhosts.c
index df99ae90..ee7e04c8 100644
--- a/tests/client/torture_knownhosts.c
+++ b/tests/client/torture_knownhosts.c
@@ -282,7 +282,7 @@ static void torture_knownhosts_precheck(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_knownhosts_port, setup, teardown),
unit_test_setup_teardown(torture_knownhosts_fail, setup, teardown),
unit_test_setup_teardown(torture_knownhosts_other, setup, teardown),
@@ -293,6 +293,7 @@ int torture_run_tests(void) {
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_proxycommand.c b/tests/client/torture_proxycommand.c
index 8cf68685..a1508811 100644
--- a/tests/client/torture_proxycommand.c
+++ b/tests/client/torture_proxycommand.c
@@ -42,7 +42,7 @@ static void torture_options_set_proxycommand_notexist(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_options_set_proxycommand, setup, teardown),
unit_test_setup_teardown(torture_options_set_proxycommand_notexist, setup, teardown),
};
@@ -50,6 +50,7 @@ int torture_run_tests(void) {
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_request_env.c b/tests/client/torture_request_env.c
index fc3843df..5296f7d2 100644
--- a/tests/client/torture_request_env.c
+++ b/tests/client/torture_request_env.c
@@ -100,12 +100,13 @@ static void torture_request_env(void **state)
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_request_env, setup, teardown),
};
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_session.c b/tests/client/torture_session.c
index ef9ef653..94296a3f 100644
--- a/tests/client/torture_session.c
+++ b/tests/client/torture_session.c
@@ -99,12 +99,13 @@ static void torture_channel_read_error(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_channel_read_error, setup, teardown),
};
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_sftp_dir.c b/tests/client/torture_sftp_dir.c
index b2e3fa38..67303324 100644
--- a/tests/client/torture_sftp_dir.c
+++ b/tests/client/torture_sftp_dir.c
@@ -61,12 +61,13 @@ static void torture_sftp_mkdir(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_sftp_mkdir, setup, teardown)
};
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_sftp_read.c b/tests/client/torture_sftp_read.c
index dac5ef7b..6586d49e 100644
--- a/tests/client/torture_sftp_read.c
+++ b/tests/client/torture_sftp_read.c
@@ -70,12 +70,13 @@ static void torture_sftp_read_blocking(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_sftp_read_blocking, setup, teardown)
};
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/client/torture_sftp_static.c b/tests/client/torture_sftp_static.c
index 7631def0..0cfd9e20 100644
--- a/tests/client/torture_sftp_static.c
+++ b/tests/client/torture_sftp_static.c
@@ -19,12 +19,13 @@ static void torture_sftp_ext_new(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test(torture_sftp_ext_new),
};
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/cmdline.c b/tests/cmdline.c
index 4e2a7d02..ad58af78 100644
--- a/tests/cmdline.c
+++ b/tests/cmdline.c
@@ -41,6 +41,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
break;
case ARGP_KEY_ARG:
/* End processing here. */
+ arguments->pattern = state->argv[state->next - 1];
cmdline = &state->argv [state->next - 1];
state->next = state->argc;
break;
diff --git a/tests/torture.c b/tests/torture.c
index bb7c926a..c139f6aa 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -39,6 +39,8 @@
#endif
#include "torture.h"
+/* for pattern matching */
+#include "match.c"
#define TORTURE_TESTKEY_PASSWORD "libssh-rocks"
@@ -220,6 +222,7 @@ static const char torture_ed25519_testkey_pp[]=
"-----END OPENSSH PRIVATE KEY-----\n";
static int verbosity = 0;
+static const char *pattern = NULL;
#ifndef _WIN32
static int _torture_auth_kbdint(ssh_session session,
@@ -650,12 +653,48 @@ int torture_libssh_verbosity(void){
return verbosity;
}
+void _torture_filter_tests(UnitTest *tests, size_t ntests){
+ size_t i,j;
+ const char *name, *last_name=NULL;
+ if (pattern == NULL){
+ return;
+ }
+ for (i=0; i < ntests; ++i){
+ if(tests[i].function_type == UNIT_TEST_FUNCTION_TYPE_SETUP){
+ /* match on the next test name */
+ name = tests[i+1].name;
+ } else if (tests[i].function_type == UNIT_TEST_FUNCTION_TYPE_TEARDOWN){
+ /* match on the previous test name */
+ name = last_name;
+ } else {
+ name = last_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].function = NULL;
+ ntests--;
+ --i;
+ }
+ }
+ if (ntests != 0){
+ printf("%d tests left\n",(int)ntests);
+ } else {
+ printf("No matching test left\n");
+ }
+}
+
int main(int argc, char **argv) {
struct argument_s arguments;
arguments.verbose=0;
+ arguments.pattern=NULL;
torture_cmdline_parse(argc, argv, &arguments);
verbosity=arguments.verbose;
+ pattern=arguments.pattern;
return torture_run_tests();
}
diff --git a/tests/torture.h b/tests/torture.h
index e1738ab0..f5897561 100644
--- a/tests/torture.h
+++ b/tests/torture.h
@@ -42,7 +42,7 @@
/* Used by main to communicate with parse_opt. */
struct argument_s {
- char *args[2];
+ const char *pattern;
int verbose;
};
@@ -83,6 +83,9 @@ const char *torture_get_testkey_passphrase(void);
void torture_write_file(const char *filename, const char *data);
+#define torture_filter_tests(tests) _torture_filter_tests(tests, sizeof(tests) / sizeof(tests)[0])
+void _torture_filter_tests(UnitTest *tests, size_t ntests);
+
/*
* This function must be defined in every unit test file.
*/
diff --git a/tests/unittests/torture_buffer.c b/tests/unittests/torture_buffer.c
index ec87259d..0934cbf1 100644
--- a/tests/unittests/torture_buffer.c
+++ b/tests/unittests/torture_buffer.c
@@ -250,7 +250,7 @@ static void torture_buffer_pack_badformat(void **state){
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_growing_buffer, setup, teardown),
unit_test_setup_teardown(torture_growing_buffer_shifting, setup, teardown),
unit_test_setup_teardown(torture_buffer_prepend, setup, teardown),
@@ -262,6 +262,7 @@ int torture_run_tests(void) {
};
ssh_init();
+ torture_filter_tests(tests);
rc=run_tests(tests);
ssh_finalize();
return rc;
diff --git a/tests/unittests/torture_callbacks.c b/tests/unittests/torture_callbacks.c
index 3c836b79..0fdeb3d4 100644
--- a/tests/unittests/torture_callbacks.c
+++ b/tests/unittests/torture_callbacks.c
@@ -98,13 +98,14 @@ static void torture_log_callback(void **state)
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_callbacks_size, setup, teardown),
unit_test_setup_teardown(torture_callbacks_exists, setup, teardown),
unit_test(torture_log_callback),
};
ssh_init();
+ torture_filter_tests(tests);
rc=run_tests(tests);
ssh_finalize();
return rc;
diff --git a/tests/unittests/torture_channel.c b/tests/unittests/torture_channel.c
index 1d928b84..a5819d8d 100644
--- a/tests/unittests/torture_channel.c
+++ b/tests/unittests/torture_channel.c
@@ -37,11 +37,12 @@ static void torture_channel_select(void **state)
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test(torture_channel_select),
};
ssh_init();
+ torture_filter_tests(tests);
rc = run_tests(tests);
ssh_finalize();
diff --git a/tests/unittests/torture_init.c b/tests/unittests/torture_init.c
index 85bd95e1..b608c04f 100644
--- a/tests/unittests/torture_init.c
+++ b/tests/unittests/torture_init.c
@@ -15,9 +15,9 @@ static void torture_ssh_init(void **state) {
}
int torture_run_tests(void) {
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test(torture_ssh_init),
};
-
+ torture_filter_tests(tests);
return run_tests(tests);
}
diff --git a/tests/unittests/torture_isipaddr.c b/tests/unittests/torture_isipaddr.c
index c2a1e079..258082ea 100644
--- a/tests/unittests/torture_isipaddr.c
+++ b/tests/unittests/torture_isipaddr.c
@@ -45,11 +45,12 @@ static void torture_ssh_is_ipaddr(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test(torture_ssh_is_ipaddr)
};
ssh_init();
+ torture_filter_tests(tests);
rc=run_tests(tests);
ssh_finalize();
return rc;
diff --git a/tests/unittests/torture_keyfiles.c b/tests/unittests/torture_keyfiles.c
index 9446bc6d..b1d88c5f 100644
--- a/tests/unittests/torture_keyfiles.c
+++ b/tests/unittests/torture_keyfiles.c
@@ -240,7 +240,7 @@ static void torture_privatekey_from_file_passphrase(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_pubkey_from_file,
setup_rsa_key,
teardown),
@@ -255,6 +255,7 @@ int torture_run_tests(void) {
ssh_init();
+ torture_filter_tests(tests);
rc=run_tests(tests);
ssh_finalize();
return rc;
diff --git a/tests/unittests/torture_list.c b/tests/unittests/torture_list.c
index 75f41825..09031699 100644
--- a/tests/unittests/torture_list.c
+++ b/tests/unittests/torture_list.c
@@ -78,13 +78,14 @@ static void torture_ssh_list_prepend(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test(torture_ssh_list_new),
unit_test(torture_ssh_list_append),
unit_test(torture_ssh_list_prepend),
};
ssh_init();
+ torture_filter_tests(tests);
rc=run_tests(tests);
ssh_finalize();
return rc;
diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c
index 26770324..ad772450 100644
--- a/tests/unittests/torture_misc.c
+++ b/tests/unittests/torture_misc.c
@@ -187,7 +187,7 @@ static void torture_timeout_update(void **state){
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test(torture_get_user_home_dir),
unit_test(torture_basename),
unit_test(torture_dirname),
@@ -204,6 +204,7 @@ int torture_run_tests(void) {
};
ssh_init();
+ torture_filter_tests(tests);
rc=run_tests(tests);
ssh_finalize();
return rc;
diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c
index 6f5df1bb..9653fa21 100644
--- a/tests/unittests/torture_options.c
+++ b/tests/unittests/torture_options.c
@@ -195,7 +195,7 @@ static void torture_options_proxycommand(void **state) {
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_options_set_host, setup, teardown),
unit_test_setup_teardown(torture_options_get_host, setup, teardown),
unit_test_setup_teardown(torture_options_set_port, setup, teardown),
@@ -209,6 +209,7 @@ int torture_run_tests(void) {
};
ssh_init();
+ torture_filter_tests(tests);
rc=run_tests(tests);
ssh_finalize();
return rc;
diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c
index 01cf79db..027322a5 100644
--- a/tests/unittests/torture_pki.c
+++ b/tests/unittests/torture_pki.c
@@ -1437,7 +1437,7 @@ static void torture_pki_ecdsa_name521(void **state)
int torture_run_tests(void) {
int rc;
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test(torture_pki_keytype),
unit_test(torture_pki_signature),
@@ -1607,6 +1607,7 @@ int torture_run_tests(void) {
(void)setup_both_keys;
ssh_init();
+ torture_filter_tests(tests);
rc=run_tests(tests);
ssh_finalize();
return rc;
diff --git a/tests/unittests/torture_rand.c b/tests/unittests/torture_rand.c
index 829989b0..b69201a1 100644
--- a/tests/unittests/torture_rand.c
+++ b/tests/unittests/torture_rand.c
@@ -60,9 +60,10 @@ static void torture_rand_threading(void **state) {
}
int torture_run_tests(void) {
- const UnitTest tests[] = {
+ UnitTest tests[] = {
unit_test_setup_teardown(torture_rand_threading, setup, teardown),
};
+ torture_filter_tests(tests);
return run_tests(tests);
}