Unit testing support functions. More...

Data Structures

struct  UtTest_


#define MAX_SUBSTRINGS   30
#define FAIL
 Fail a test. More...
#define FAIL_IF(expr)
 Fail a test if expression evaluates to false. More...
#define FAIL_IF_NOT(expr)
 Fail a test if expression to true. More...
#define FAIL_IF_NULL(expr)
 Fail a test if expression evaluates to NULL. More...
#define FAIL_IF_NOT_NULL(expr)
 Fail a test if expression evaluates to non-NULL. More...
#define PASS
 Pass the test. More...
#define PASS_IF(expr)
 Pass the test if expression evaluates to true. More...


typedef struct UtTest_ UtTest


void UtRegisterTest (const char *name, int(*TestFn)(void))
 Register unit test. More...
void UtListTests (const char *regex_arg)
 List all registered unit tests. More...
uint32_t UtRunTests (const char *regex_arg)
 Run all registered unittests. More...
void UtInitialize (void)
 Initialize unit test list. More...
void UtCleanup (void)
 Cleanup unit test list. More...
void UtRunModeRegister (void)
int UtRunSelftest (const char *regex_arg)
 Run self tests. More...


int unittests_fatal = 0
int unittests_fatal

Detailed Description

Unit testing support functions.

Macro Definition Documentation


#define FAIL
do { \
if (unittests_fatal) { \
BUG_ON(1); \
} else { \
return 0; \
} \
} while (0)

Fail a test.

Definition at line 61 of file util-unittest.h.


#define FAIL_IF (   expr)
do { \
if (unittests_fatal) { \
BUG_ON(expr); \
} else if (expr) { \
return 0; \
} \
} while (0)

Fail a test if expression evaluates to false.

Definition at line 72 of file util-unittest.h.


#define FAIL_IF_NOT (   expr)
do { \
FAIL_IF(!(expr)); \
} while (0)

Fail a test if expression to true.

Definition at line 83 of file util-unittest.h.


#define FAIL_IF_NOT_NULL (   expr)
do { \
FAIL_IF(NULL != expr); \
} while (0)

Fail a test if expression evaluates to non-NULL.

Definition at line 97 of file util-unittest.h.


#define FAIL_IF_NULL (   expr)
do { \
FAIL_IF(NULL == expr); \
} while (0)

Fail a test if expression evaluates to NULL.

Definition at line 90 of file util-unittest.h.


#define MAX_SUBSTRINGS   30

Definition at line 155 of file util-unittest.c.


#define PASS
do { \
return 1; \
} while (0)

Pass the test.

Only to be used at the end of a function instead instead of "return 1."

Definition at line 106 of file util-unittest.h.


#define PASS_IF (   expr)
do { \
FAIL_IF(!(expr)); \
} while (0)

Pass the test if expression evaluates to true.

Only to be used at the end of a function instead of returning the result of an expression.

Definition at line 118 of file util-unittest.h.

Typedef Documentation

◆ UtTest

typedef struct UtTest_ UtTest

Function Documentation

◆ UtCleanup()

void UtCleanup ( void  )

Cleanup unit test list.

Definition at line 269 of file util-unittest.c.

◆ UtInitialize()

void UtInitialize ( void  )

Initialize unit test list.

Definition at line 260 of file util-unittest.c.

Referenced by RunUnittests(), and UtRunSelftest().

Here is the caller graph for this function:

◆ UtListTests()

void UtListTests ( const char *  regex_arg)

List all registered unit tests.

regex_argRegular expression to limit listed tests.

Definition at line 160 of file util-unittest.c.


◆ UtRegisterTest()

void UtRegisterTest ( const char *  name,
int(*)(void)  TestFn 

Register unit test.

nameUnit test name
TestFnUnit test function

Definition at line 103 of file util-unittest.c.

Referenced by AlertFastLogRegisterTests(), AppLayerHtpFileRegisterTests(), AppLayerProtoDetectUnittestsRegister(), AppLayerUnittestsRegister(), BloomFilterCountingRegisterTests(), BloomFilterRegisterTests(), ByteRegisterTests(), ConfRegisterTests(), ConfYamlRegisterTests(), DecodeCHDLCRegisterTests(), DecodeEthernetRegisterTests(), DecodeGeneveRegisterTests(), DecodeGRERegisterTests(), DecodeICMPV4RegisterTests(), DecodeICMPV6RegisterTests(), DecodeIPV4RegisterTests(), DecodeIPV6RegisterTests(), DecodeMPLSRegisterTests(), DecodePPPOERegisterTests(), DecodePPPRegisterTests(), DecodeRawRegisterTests(), DecodeTCPRegisterTests(), DecodeUDPV4RegisterTests(), DecodeVLANRegisterTests(), DecodeVXLANRegisterTests(), DefragRegisterTests(), DeStateRegisterTests(), DetectAddressIPv4Tests(), DetectAddressIPv6Tests(), DetectEngineContentInspectionRegisterTests(), DetectEngineInspectENIPRegisterTests(), DetectEngineInspectModbusRegisterTests(), DetectEngineRegisterTests(), DetectEngineTagRegisterTests(), DetectFiledataRegisterTests(), DetectFragOffsetRegisterTests(), DetectHTTP2errorCodeRegisterTests(), DetectHTTP2frameTypeRegisterTests(), DetectHTTP2priorityRegisterTests(), DetectHTTP2settingsRegisterTests(), DetectHTTP2sizeUpdateRegisterTests(), DetectHTTP2windowRegisterTests(), DetectHttpClientBodyRegisterTests(), DetectHttpHeaderRegisterTests(), DetectHttpHHRegisterTests(), DetectHttpMethodRegisterTests(), DetectHttpRawHeaderRegisterTests(), DetectHttpServerBodyRegisterTests(), DetectHttpStatCodeRegisterTests(), DetectHttpStatMsgRegisterTests(), DetectICMPv6hdrRegisterTests(), DetectICMPv6mtuRegisterTests(), DetectIpv4hdrRegisterTests(), DetectIpv6hdrRegisterTests(), DetectModbusRegisterTests(), DetectParseRegisterTests(), DetectProtoTests(), DetectTcphdrRegisterTests(), DetectTcpmssRegisterTests(), DetectTemplate2RegisterTests(), DetectTemplateRegisterTests(), DetectTransformPcrexformRegisterTests(), DetectTtlRegisterTests(), DetectUdphdrRegisterTests(), DNP3ParserRegisterTests(), EngineEventRegisterTests(), ENIPParserRegisterTests(), FlowBitRegisterTests(), FlowBitsRegisterTests(), FlowRegisterTests(), FTPParserRegisterTests(), HashListTableRegisterTests(), HashTableRegisterTests(), HostBitRegisterTests(), HostBitsRegisterTests(), HTPFileParserRegisterTests(), HTPXFFParserRegisterTests(), IPOnlyRegisterTests(), IPPairBitRegisterTests(), MacSetRegisterTests(), MagicRegisterTests(), MemcmpRegisterTests(), MemrchrRegisterTests(), MimeDecRegisterTests(), ModbusParserRegisterTests(), MQTTConnackSessionPresentRegisterTests(), MQTTConnectFlagsRegisterTests(), MQTTFlagsRegisterTests(), MQTTProtocolVersionRegisterTests(), MQTTQosRegisterTests(), MQTTReasonCodeRegisterTests(), MQTTTypeRegisterTests(), PayloadRegisterTests(), PoolRegisterTests(), PoolThreadRegisterTests(), RegisterFlowStorageTests(), RegisterHostStorageTests(), RegisterIPPairStorageTests(), RFBParserRegisterTests(), SCACBSRegisterTests(), SCACRegisterTests(), SCACTileRegisterTests(), SCAtomicRegisterTests(), SCClassConfRegisterTests(), SCHInfoRegisterTests(), SCLogRegisterTests(), SCProfilingRegisterTests(), SCRadixRegisterTests(), SCRConfRegisterTests(), SCReputationRegisterTests(), SCRuleVarsRegisterTests(), SCSigRegisterSignatureOrderingTests(), SCThresholdConfRegisterTests(), SigGroupHeadRegisterTests(), SigParseRegisterTests(), SigRegisterTests(), SMTPParserRegisterTests(), SSHParserRegisterTests(), SSLParserRegisterTests(), StatsRegisterTests(), StorageRegisterTests(), StreamingBufferRegisterTests(), StreamTcpInlineRegisterTests(), StreamTcpListRegisterTests(), StreamTcpReassembleRegisterTests(), StreamTcpRegisterTests(), StreamTcpSackRegisterTests(), StreamTcpUtilRegisterTests(), ThreadMacrosRegisterTests(), TlsExpiredRegisterTests(), TlsNotAfterRegisterTests(), TlsNotBeforeRegisterTests(), TlsValidRegisterTests(), TmqhFlowRegisterTests(), UTHRegisterTests(), UtilActionRegisterTests(), UtilMiscRegisterTests(), UtilSpmSearchRegistertests(), and UtRunSelftest().

◆ UtRunModeRegister()

void UtRunModeRegister ( void  )

Definition at line 283 of file util-unittest.c.

References RUNMODE_UNITTEST, and RunModeRegisterNewRunMode().

Here is the call graph for this function:

◆ UtRunSelftest()

int UtRunSelftest ( const char *  regex_arg)

Run self tests.

regex_argThe regular expression
Return values
0all successful

Definition at line 326 of file util-unittest.c.

References UtInitialize(), and UtRegisterTest().

Referenced by RunUnittests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UtRunTests()

uint32_t UtRunTests ( const char *  regex_arg)

Run all registered unittests.

regex_argThe regular expression
Return values
0all successful
resultnumber of tests that failed

Definition at line 190 of file util-unittest.c.

References MAX_SUBSTRINGS, StreamTcpInitMemuse(), and StreamTcpReassembleInitMemuse().

Here is the call graph for this function:

Variable Documentation

◆ unittests_fatal [1/2]

int unittests_fatal = 0

Definition at line 52 of file util-unittest.c.

◆ unittests_fatal [2/2]

int unittests_fatal

Definition at line 52 of file util-unittest.c.

int unittests_fatal
Definition: util-unittest.c:52