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>
This commit is contained in:
Aris Adamantiadis
2014-09-02 09:07:17 +02:00
committed by Andreas Schneider
parent 8af829a42a
commit d42a1a35b0
25 changed files with 88 additions and 26 deletions

View File

@@ -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();
}