Go to the documentation of this file.
34 #include "../detect-engine.h"
35 #include "../detect-engine-helper.h"
36 #include "../detect-parse.h"
37 #include "../util-byte.h"
38 #include "../util-unittest.h"
47 #define UTIL_PLUGIN_TEST_KW "util-plugin-test"
57 static int g_util_plugin_test_kw_id = -1;
66 const uint16_t
id = (uint16_t)g_util_plugin_test_kw_id;
94 static uint16_t UtilPluginTestKwRegister(
void)
96 if (g_util_plugin_test_kw_id < 0) {
99 .desc =
"unit test keyword for plugin patterns",
101 .Setup = UtilPluginTestKwSetup,
102 .Free = UtilPluginTestKwFree,
105 BUG_ON(
id == (uint16_t)-1);
106 g_util_plugin_test_kw_id = id;
108 return (uint16_t)g_util_plugin_test_kw_id;
120 static int UtilPluginKeywordNegationTest(
void)
122 const uint16_t
id = UtilPluginTestKwRegister();
132 FAIL_IF_NOT(UtilPluginTestKwGetData(sm)->value == 2);
137 FAIL_IF_NOT(UtilPluginTestKwGetData(sm)->value == 1);
138 FAIL_IF(UtilPluginTestKwGetData(sm)->negated);
149 static int UtilPluginKeywordLookupTest(
void)
151 const uint16_t
id = UtilPluginTestKwRegister();
162 FAIL_IF_NOT(UtilPluginTestKwGetData(sm)->value == 3);
164 FAIL_IF_NOT(UtilPluginTestKwGetData(sm)->prev_value == 2);
168 FAIL_IF_NOT(UtilPluginTestKwGetData(sm)->value == 2);
169 FAIL_IF_NOT(UtilPluginTestKwGetData(sm)->prev_value == 1);
174 FAIL_IF_NOT(UtilPluginTestKwGetData(sm)->value == 1);
175 FAIL_IF_NOT(UtilPluginTestKwGetData(sm)->prev_value == -1);
186 #ifndef DEBUG_VALIDATION
192 static int UtilPluginKeywordLookupDynamicListTest(
void)
194 const uint16_t
id = UtilPluginTestKwRegister();
213 UtRegisterTest(
"UtilPluginKeywordNegationTest", UtilPluginKeywordNegationTest);
214 UtRegisterTest(
"UtilPluginKeywordLookupTest", UtilPluginKeywordLookupTest);
215 #ifndef DEBUG_VALIDATION
217 "UtilPluginKeywordLookupDynamicListTest", UtilPluginKeywordLookupDynamicListTest);
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
const char * name
keyword name
void UtilPluginRegisterTests(void)
const SigMatchCtx * SCSigMatchGetCtx(const SigMatch *sm)
Get the keyword context of sm, as passed to SCSigMatchAppendSMToList() by the keyword's Setup callbac...
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define UTIL_PLUGIN_TEST_KW
main detection engine ctx
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
int StringParseInt32(int32_t *res, int base, size_t len, const char *str)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
App-layer light version of SigTableElmt.
struct UtilPluginTestKwData_ UtilPluginTestKwData
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
#define PASS
Pass the test.
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
uint16_t SCDetectHelperKeywordRegister(const SCSigTableAppLiteElmt *kw)
bool SCDetectSetupSignatureIsNegated(const Signature *s)
Check if the keyword option being set up was negated.
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
const SigMatch * SCDetectSignatureGetLastSMByType(const Signature *s, int list_id, uint16_t type)
Get the last SigMatch of keyword type in list list_id.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
@ DETECT_SM_LIST_POSTMATCH
const SigMatch * SCSigMatchGetPrevByType(const SigMatch *sm, uint16_t type)
Get the previous SigMatch of keyword type before sm.
a single match condition for a signature
DetectEngineCtx * DetectEngineCtxInit(void)
#define SIGMATCH_HANDLE_NEGATION