Add a new command line option, --list-unittests to list all registered unit tests then exit.  If -U is supplied, the regex will be respected.
remotes/origin/master-1.0.x
Jason Ish 17 years ago committed by Victor Julien
parent f76a740fe2
commit 097a77e9fd

@ -238,6 +238,7 @@ void usage(const char *progname)
#ifdef UNITTESTS
printf("\t-u : run the unittests and exit\n");
printf("\t-U, --unittest-filter=REGEX : filter unittests with a regex\n");
printf("\t--list-unittests : list unit tests\n");
#endif /* UNITTESTS */
printf("\n");
}
@ -254,6 +255,7 @@ int main(int argc, char **argv)
char *conf_filename = NULL;
char *regex_arg = NULL;
int dump_config = 0;
int list_unittests = 0;
/* initialize the logging subsys */
SCLogInitLogModule(NULL);
@ -266,6 +268,7 @@ int main(int argc, char **argv)
{"pfring-int", required_argument, 0, 0},
{"pfring-clusterid", required_argument, 0, 0},
{"unittest-filter", required_argument, 0, 'U'},
{"list-unittests", 0, &list_unittests, 1},
{NULL, 0, NULL, 0}
};
@ -291,6 +294,15 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
}
else if(strcmp((long_opts[option_index]).name, "list-unittests") == 0) {
#ifdef UNITTESTS
/* Set mode to unit tests. */
mode = MODE_UNITTEST;
#else
fprintf(stderr, "ERROR: Unit tests not enabled. Make sure to pass --enable-unittests to configure when building.\n");
exit(EXIT_FAILURE);
#endif /* UNITTESTS */
}
break;
case 'c':
conf_filename = optarg;
@ -440,10 +452,16 @@ int main(int argc, char **argv)
SCSigRegisterSignatureOrderingTests();
SCLogRegisterTests();
SCRadixRegisterTests();
uint32_t failed = UtRunTests(regex_arg);
UtCleanup();
if (failed) exit(EXIT_FAILURE);
else exit(EXIT_SUCCESS);
if (list_unittests) {
UtListTests(regex_arg);
}
else {
uint32_t failed = UtRunTests(regex_arg);
UtCleanup();
if (failed)
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
#endif /* UNITTESTS */

@ -115,6 +115,33 @@ error:
return -1;
}
#define MAX_SUBSTRINGS 30
/** \brief List all registered unit tests.
*
* \param regex_arg Regular expression to limit listed tests.
*/
void UtListTests(char *regex_arg) {
UtTest *ut;
int ret = 0, rcomp = 0;
int ov[MAX_SUBSTRINGS];
rcomp = UtRegex(regex_arg);
for (ut = ut_list; ut != NULL; ut = ut->next) {
if (rcomp == 1) {
ret = pcre_exec(parse_regex, parse_regex_study, ut->name,
strlen(ut->name), 0, 0, ov, MAX_SUBSTRINGS);
if (ret >= 1) {
printf("%s\n", ut->name);
}
}
else {
printf("%s\n", ut->name);
}
}
}
/** \brief Run all registered unittests.
*
* \param regex_arg The regular expression
@ -126,7 +153,6 @@ error:
uint32_t UtRunTests(char *regex_arg) {
UtTest *ut;
uint32_t good = 0, bad = 0;
#define MAX_SUBSTRINGS 30
int ret = 0, rcomp = 0;
int ov[MAX_SUBSTRINGS];

@ -23,6 +23,7 @@ uint32_t UtRunTests(char *regex_arg);
void UtInitialize(void);
void UtCleanup(void);
int UtRunSelftest (char *regex_arg);
void UtListTests(char *regex_arg);
#endif /* __UTIL_UNITTEST_H__ */

Loading…
Cancel
Save