aboutsummaryrefslogtreecommitdiff
path: root/tests/torture.c
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 /tests/torture.c
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>
Diffstat (limited to 'tests/torture.c')
-rw-r--r--tests/torture.c39
1 files changed, 39 insertions, 0 deletions
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();
}