Add fatal failures on unittest and siginit failure (using Conf API)

remotes/origin/master-1.0.x
Gerardo Iglesias Galvan 16 years ago committed by Victor Julien
parent 658eac2825
commit b254719ffc

@ -4,6 +4,7 @@
#include "debug.h"
#include "detect.h"
#include "flow.h"
#include "conf.h"
#include "detect-parse.h"
#include "detect-engine-sigorder.h"
@ -21,6 +22,7 @@
//#include "util-mpm.h"
#include "util-hash.h"
#include "util-debug.h"
#include "util-var-name.h"
#include "tm-modules.h"
@ -35,6 +37,10 @@ DetectEngineCtx *DetectEngineCtxInit(void) {
memset(de_ctx,0,sizeof(DetectEngineCtx));
if (ConfGetBool("engine.init_failure_fatal", &(de_ctx->failure_fatal)) != 1) {
SCLogDebug("ConfGetBool could not load the value.");
}
de_ctx->mpm_matcher = PatternMatchDefaultMatcher();
SigGroupHeadHashInit(de_ctx);

@ -601,6 +601,10 @@ Signature *SigInit(DetectEngineCtx *de_ctx, char *sigstr) {
error:
SigFree(sig);
if (de_ctx->failure_fatal == 1) {
fprintf(stderr, "ERROR: Signature init failed.\n");
exit(EXIT_FAILURE);
}
return NULL;
}

@ -222,6 +222,7 @@ typedef struct DetectEngineLookupDsize_ {
/** \brief main detection engine ctx */
typedef struct DetectEngineCtx_ {
uint8_t flags;
uint8_t failure_fatal;
Signature *sig_list;
uint32_t sig_cnt;

@ -309,6 +309,8 @@ int main(int argc, char **argv)
{"pfring-clusterid", required_argument, 0, 0},
{"unittest-filter", required_argument, 0, 'U'},
{"list-unittests", 0, &list_unittests, 1},
{"init-errors-fatal", 0, 0, 0},
{"fatal-unittests", 0, 0, 0},
{NULL, 0, NULL, 0}
};
@ -334,6 +336,12 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
}
else if(strcmp((long_opts[option_index]).name, "init-errors-fatal") == 0) {
if (ConfSet("engine.init_failure_fatal", "1", 0) != 1) {
fprintf(stderr, "ERROR: Failed to set engine init_failure_fatal.\n");
exit(EXIT_FAILURE);
}
}
else if(strcmp((long_opts[option_index]).name, "list-unittests") == 0) {
#ifdef UNITTESTS
/* Set mode to unit tests. */
@ -341,6 +349,17 @@ int main(int argc, char **argv)
#else
fprintf(stderr, "ERROR: Unit tests not enabled. Make sure to pass --enable-unittests to configure when building.\n");
exit(EXIT_FAILURE);
#endif /* UNITTESTS */
}
else if(strcmp((long_opts[option_index]).name, "fatal-unittests") == 0) {
#ifdef UNITTESTS
if (ConfSet("unittests.failure_fatal", "1", 0) != 1) {
fprintf(stderr, "ERROR: Failed to set unittests failure_fatal.\n");
exit(EXIT_FAILURE);
}
#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;

@ -9,6 +9,7 @@
#include "util-unittest.h"
#include "util-debug.h"
#include "util-time.h"
#include "conf.h"
static pcre *parse_regex;
static pcre_extra *parse_regex_study;
@ -157,6 +158,12 @@ uint32_t UtRunTests(char *regex_arg) {
uint32_t good = 0, bad = 0, matchcnt = 0;
int ret = 0, rcomp = 0;
int ov[MAX_SUBSTRINGS];
int failure_fatal;
if (ConfGetBool("unittests.failure_fatal", &failure_fatal) != 1) {
SCLogDebug("ConfGetBool could not load the value.");
failure_fatal = 0;
}
rcomp = UtRegex(regex_arg);
@ -175,6 +182,10 @@ uint32_t UtRunTests(char *regex_arg) {
ret = ut->TestFn();
printf("%s\n", (ret == ut->evalue) ? "pass" : "FAILED");
if (ret != ut->evalue) {
if (failure_fatal == 1) {
fprintf(stderr, "ERROR: unittest failed.\n");
exit(EXIT_FAILURE);
}
bad++;
} else {
good++;

Loading…
Cancel
Save