suricata
Testing

Unit testing support functions. More...

Data Structures

struct  UtTest_
 

Macros

#define MAX_SUBSTRINGS   30
 
#define FAIL
 
#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...
 

Typedefs

typedef struct UtTest_ UtTest
 

Functions

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...
 

Variables

int unittests_fatal = 0
 
int unittests_fatal
 

Detailed Description

Unit testing support functions.

Macro Definition Documentation

#define FAIL
Value:
do { \
BUG_ON(1); \
} else { \
return 0; \
} \
} while (0)
#define BUG_ON(x)
int unittests_fatal
Definition: util-unittest.c:52

Fail a test.

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

Referenced by DecodeICMPV6(), DetectDnsQueryRegister(), DetectHostbitFree(), DetectPcrePayloadMatch(), and NoWinDivertSupportExit().

#define FAIL_IF (   expr)
Value:
do { \
BUG_ON(expr); \
} else if (expr) { \
return 0; \
} \
} while (0)
#define BUG_ON(x)
int unittests_fatal
Definition: util-unittest.c:52

Fail a test if expression evaluates to false.

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

Referenced by AppLayerProtoDetectUnittestCtxRestore(), ConfNodeIsSequence(), DecodeICMPV6(), DecodeIPV4(), DecodeIPV6(), DecodeTCP(), DecodeUDP(), DetectAppLayerProtocolRegister(), DetectAsn1Register(), DetectBypassRegister(), DetectCipServiceRegister(), DetectDceIfaceRegister(), DetectDceStubDataRegister(), DetectDNP3Register(), DetectDnsQueryRegister(), DetectEngineInspectENIP(), DetectEngineInspectModbus(), DetectEngineStateResetTxs(), DetectFastPatternRegister(), DetectFilestoreRegister(), DetectFlowbitsAnalyze(), DetectFlowFree(), DetectFlowintFree(), DetectFragBitsRegister(), DetectFtpbounceRegister(), DetectFtpdataRegister(), DetectGeoipRegister(), DetectHostbitFree(), DetectHttpRequestLineRegister(), DetectHttpResponseLineRegister(), DetectIPProtoRemoveAllSMs(), DetectIsdataatFree(), DetectMetadataHashFree(), DetectPcrePayloadMatch(), DetectPortHashFree(), DetectSetupParseRegexes(), DetectSshVersionRegister(), DetectSslStateRegister(), DetectSslVersionRegister(), DetectTemplateRustBufferRegister(), DetectTlsFingerprintRegister(), DetectTlsIssuerRegister(), DetectTlsJa3HashRegister(), DetectTlsJa3StringRegister(), DetectTlsSerialRegister(), DetectTlsSniRegister(), DetectTlsSubjectRegister(), DetectTlsValidityRegister(), DetectTlsVersionRegister(), DetectUricontentRegister(), FlowUpdateState(), HtpConfigRestoreBackup(), IPOnlyAddSignature(), LogCustomFormatWriteTimestamp(), RegisterDCERPCParsers(), RegisterDNP3Parsers(), RegisterENIPTCPParsers(), RegisterModbusParsers(), RegisterSSLParsers(), SCHInfoLoadFromConfig(), SCSigSignatureOrderingModuleCleanup(), SCThresholdConfParseFile(), SMTPParserCleanup(), StreamingBufferCompareRawData(), StreamTcpSackFreeList(), and StreamTcpUTAddSegmentWithByte().

#define FAIL_IF_NOT (   expr)
Value:
do { \
FAIL_IF(!(expr)); \
} while (0)
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:71

Fail a test if expression to true.

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

Referenced by ConfNodeIsSequence(), DetectAppLayerProtocolRegister(), DetectAsn1Register(), DetectDNP3Register(), DetectDnsQueryRegister(), DetectEngineInspectModbus(), DetectEngineStateResetTxs(), DetectEnipCommandRegister(), DetectFlagsSignatureNeedsSynOnlyPackets(), DetectFlowbitsAnalyze(), DetectFlowFree(), DetectFtpbounceRegister(), DetectHostbitFree(), DetectHttpRequestLineRegister(), DetectIPProtoRemoveAllSMs(), DetectIsdataatFree(), DetectModbusRegister(), DetectNfsProcedureRegister(), DetectNfsVersionRegister(), DetectPcrePayloadMatch(), DetectPortHashFree(), DetectSetupParseRegexes(), DetectSslStateRegister(), DetectSslVersionRegister(), DetectTlsFingerprintRegister(), DetectTlsIssuerRegister(), DetectTlsJa3HashRegister(), DetectTlsJa3StringRegister(), DetectTlsSerialRegister(), DetectTlsSniRegister(), DetectTlsSubjectRegister(), DetectTlsValidityRegister(), DetectTlsVersionRegister(), DetectUricontentRegister(), DetectWithinRegister(), HtpConfigRestoreBackup(), LogCustomFormatWriteTimestamp(), RegisterDCERPCParsers(), RegisterDNP3Parsers(), RegisterModbusParsers(), RegisterSMBParsers(), RegisterSSLParsers(), SCLogDeInitLogModule(), SCSigSignatureOrderingModuleCleanup(), SCThresholdConfParseFile(), StreamingBufferCompareRawData(), StreamTcpSackFreeList(), UTHAddStreamToFlow(), and UTHRemoveSessionFromFlow().

#define FAIL_IF_NULL (   expr)
Value:
do { \
FAIL_IF(NULL == expr); \
} while (0)
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:71

Fail a test if expression evaluates to NULL.

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

Referenced by AppLayerProtoDetectUnittestCtxRestore(), ConfNodeIsSequence(), DecodeICMPV6(), DetectAppLayerProtocolRegister(), DetectAsn1Register(), DetectCipServiceRegister(), DetectDceStubDataRegister(), DetectDNP3Register(), DetectDnsQueryRegister(), DetectEngineInspectENIP(), DetectEngineInspectModbus(), DetectEngineStateResetTxs(), DetectEnipCommandRegister(), DetectFastPatternRegister(), DetectFlagsSignatureNeedsSynOnlyPackets(), DetectFlowbitsAnalyze(), DetectFlowFree(), DetectFtpdataRegister(), DetectHostbitFree(), DetectHttpRequestLineRegister(), DetectHttpResponseLineRegister(), DetectIPProtoRemoveAllSMs(), DetectMetadataHashFree(), DetectModbusRegister(), DetectNfsProcedureRegister(), DetectNfsVersionRegister(), DetectPcrePayloadMatch(), DetectPortHashFree(), DetectSetupParseRegexes(), DetectSshVersionRegister(), DetectSslStateRegister(), DetectSslVersionRegister(), DetectTargetRegister(), DetectTemplateRustBufferRegister(), DetectTlsFingerprintRegister(), DetectTlsIssuerRegister(), DetectTlsJa3HashRegister(), DetectTlsJa3StringRegister(), DetectTlsSerialRegister(), DetectTlsSniRegister(), DetectTlsSubjectRegister(), DetectTlsValidityRegister(), DetectTlsVersionRegister(), DetectTransformCompressWhitespaceRegister(), DetectTransformStripWhitespaceRegister(), DetectUricontentRegister(), DetectWithinRegister(), DetectXbitFree(), HtpConfigRestoreBackup(), RegisterDCERPCParsers(), RegisterDNP3Parsers(), RegisterENIPTCPParsers(), RegisterModbusParsers(), RegisterSMBParsers(), RegisterSSLParsers(), SCLogDeInitLogModule(), SCSigSignatureOrderingModuleCleanup(), SCThresholdConfParseFile(), StreamingBufferCompareRawData(), StreamTcpSackFreeList(), StreamTcpUTAddSegmentWithByte(), UTHAddSessionToFlow(), UTHAddStreamToFlow(), UTHParseSignature(), and UTHRemoveSessionFromFlow().

#define MAX_SUBSTRINGS   30

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

Referenced by UtListTests(), and UtRunTests().

#define PASS
Value:
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 105 of file util-unittest.h.

Referenced by AppLayerProtoDetectUnittestCtxRestore(), ConfNodeIsSequence(), DecodeICMPV6(), DecodeIPV4(), DecodeIPV6(), DecodeTCP(), DecodeUDP(), DetectAppLayerProtocolRegister(), DetectAsn1Register(), DetectBypassRegister(), DetectCipServiceRegister(), DetectDceIfaceRegister(), DetectDceStubDataRegister(), DetectDNP3Register(), DetectDnsQueryRegister(), DetectEngineInspectENIP(), DetectEngineInspectModbus(), DetectEngineStateResetTxs(), DetectEnipCommandRegister(), DetectFastPatternRegister(), DetectFlagsSignatureNeedsSynOnlyPackets(), DetectFlowbitsAnalyze(), DetectFlowFree(), DetectFlowintFree(), DetectFragBitsRegister(), DetectFtpbounceRegister(), DetectFtpdataRegister(), DetectGeoipRegister(), DetectHostbitFree(), DetectHttpRequestLineRegister(), DetectHttpResponseLineRegister(), DetectIPProtoRemoveAllSMs(), DetectIsdataatFree(), DetectMetadataHashFree(), DetectModbusRegister(), DetectNfsProcedureRegister(), DetectNfsVersionRegister(), DetectPcrePayloadMatch(), DetectPortHashFree(), DetectSetupParseRegexes(), DetectSshVersionRegister(), DetectSslStateRegister(), DetectSslVersionRegister(), DetectTargetRegister(), DetectTemplateRustBufferRegister(), DetectTlsFingerprintRegister(), DetectTlsIssuerRegister(), DetectTlsJa3HashRegister(), DetectTlsJa3StringRegister(), DetectTlsSerialRegister(), DetectTlsSniRegister(), DetectTlsSubjectRegister(), DetectTlsValidityRegister(), DetectTlsVersionRegister(), DetectTransformCompressWhitespaceRegister(), DetectTransformMd5Register(), DetectTransformSha1Register(), DetectTransformSha256Register(), DetectTransformStripWhitespaceRegister(), DetectUricontentRegister(), DetectWithinRegister(), DetectXbitFree(), FlowUpdateState(), HtpConfigRestoreBackup(), IPOnlyAddSignature(), MimeDecParseFullMsg(), NoWinDivertSupportExit(), RegisterDCERPCParsers(), RegisterDNP3Parsers(), RegisterENIPTCPParsers(), RegisterModbusParsers(), RegisterSMBParsers(), RegisterSSLParsers(), SCHInfoLoadFromConfig(), SCLogDeInitLogModule(), SCSigSignatureOrderingModuleCleanup(), SCThresholdConfParseFile(), SMTPParserCleanup(), StreamingBufferCompareRawData(), StreamTcpSackFreeList(), StreamTcpUTAddSegmentWithByte(), and UTHParseSignature().

#define PASS_IF (   expr)
Value:
do { \
FAIL_IF(!(expr)); \
} while (0)
#define PASS
Pass the test.
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:71

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 117 of file util-unittest.h.

Referenced by StatsThreadCleanup().

Typedef Documentation

typedef struct UtTest_ UtTest

Function Documentation

void UtCleanup ( void  )

Cleanup unit test list.

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

References UtTest_::next, and SCFree.

Referenced by RunUnittests(), and UtRunSelftest().

Here is the caller graph for this function:

void UtInitialize ( void  )

Initialize unit test list.

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

Referenced by RunUnittests(), and UtRunSelftest().

Here is the caller graph for this function:

void UtListTests ( const char *  regex_arg)

List all registered unit tests.

Parameters
regex_argRegular expression to limit listed tests.

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

References MAX_SUBSTRINGS, UtTest_::name, and UtTest_::next.

Referenced by RunUnittests().

Here is the caller graph for this function:

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

Register unit test.

Parameters
nameUnit test name
TestFnUnit test function

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

References UtTest_::name, UtTest_::next, regex_arg, and UtTest_::TestFn.

Referenced by AlertFastLogRegisterTests(), AppLayerParserRegisterUnittests(), AppLayerProtoDetectUnittestsRegister(), AppLayerUnittestsRegister(), BloomFilterCountingRegisterTests(), BloomFilterRegisterTests(), ByteRegisterTests(), ConfRegisterTests(), ConfYamlRegisterTests(), DcePayloadRegisterTests(), DCERPCParserRegisterTests(), DCERPCUDPParserRegisterTests(), DecodeAsn1RegisterTests(), DecodeEthernetRegisterTests(), DecodeGRERegisterTests(), DecodeICMPV4RegisterTests(), DecodeICMPV6RegisterTests(), DecodeIPV4RegisterTests(), DecodeIPV6RegisterTests(), DecodeMPLSRegisterTests(), DecodePPPOERegisterTests(), DecodePPPRegisterTests(), DecodeRawRegisterTests(), DecodeTCPRegisterTests(), DecodeUDPV4RegisterTests(), DecodeVLANRegisterTests(), DefragRegisterTests(), DeStateRegisterTests(), DetectAckRegister(), DetectAddressIPv4Tests(), DetectAddressIPv6Tests(), DetectAddressTests(), DetectAppLayerProtocolRegister(), DetectAsn1Register(), DetectBase64DataDoMatch(), DetectBase64DecodeDoMatch(), DetectBypassRegister(), DetectByteExtractRetrieveSMVar(), DetectBytejumpDoMatch(), DetectBytetestDoMatch(), DetectCipServiceRegister(), DetectClasstypeRegister(), DetectDceIfaceRegister(), DetectDceOpnumRegister(), DetectDceStubDataRegister(), DetectDetectionFilterRegister(), DetectDistanceRegister(), DetectDNP3Register(), DetectDnsQueryRegister(), DetectEngineContentInspectionRegisterTests(), DetectEngineInspectENIPRegisterTests(), DetectEngineInspectModbusRegisterTests(), DetectEngineRegisterTests(), DetectEngineTagRegisterTests(), DetectEnipCommandRegister(), DetectFastPatternRegisterTests(), DetectFiledataRegisterTests(), DetectFileextRegister(), DetectFilemagicRegister(), DetectFileMd5Register(), DetectFileSha1Register(), DetectFileSha256Register(), DetectFilesizeRegister(), DetectFilestoreRegister(), DetectFlowintRegisterTests(), DetectFlowRegisterTests(), DetectFragOffsetRegisterTests(), DetectFtpbounceRegister(), DetectFtpdataRegister(), DetectGeoipRegister(), DetectHttpClientBodyRegisterTests(), DetectHttpCookieRegisterTests(), DetectHttpHeaderRegisterTests(), DetectHttpHHRegisterTests(), DetectHttpMethodRegisterTests(), DetectHttpRawHeaderRegisterTests(), DetectHttpRequestLineRegister(), DetectHttpResponseLineRegister(), DetectHttpServerBodyRegisterTests(), DetectHttpStatCodeRegisterTests(), DetectHttpStatMsgRegisterTests(), DetectIcmpIdRegisterTests(), DetectIcmpSeqRegisterTests(), DetectICodeRegisterTests(), DetectIdRegisterTests(), DetectIPProtoRemoveAllSMs(), DetectIsdataatRegisterTests(), DetectITypeRegisterTests(), DetectL3protoRegisterTests(), DetectLuaRegister(), DetectMetadataHashFree(), DetectModbusRegisterTests(), DetectMsgRegisterTests(), DetectNfsProcedureRegister(), DetectNfsVersionRegister(), DetectPcrePayloadMatch(), DetectPktDataRegister(), DetectPortTests(), DetectProtoTests(), DetectReplaceRegisterTests(), DetectRpcRegisterTests(), DetectSameipRegister(), DetectSeqRegister(), DetectSidRegister(), DetectSshSoftwareVersionRegister(), DetectSshVersionRegister(), DetectSslStateRegister(), DetectSslVersionRegister(), DetectStreamSizeRegisterTests(), DetectTagRegisterTests(), DetectTargetRegister(), DetectTemplate2RegisterTests(), DetectTemplateRegisterTests(), DetectTemplateRustBufferRegister(), DetectTlsFingerprintRegister(), DetectTlsIssuerRegister(), DetectTlsJa3HashRegister(), DetectTlsJa3StringRegister(), DetectTlsSerialRegister(), DetectTlsSniRegister(), DetectTlsSubjectRegister(), DetectTlsValidityRegister(), DetectTlsVersionRegister(), DetectTosRegister(), DetectTransformCompressWhitespaceRegister(), DetectTransformMd5Register(), DetectTransformSha1Register(), DetectTransformSha256Register(), DetectTransformStripWhitespaceRegister(), DetectTtlRegisterTests(), DetectUricontentRegister(), DetectUrilenRegisterTests(), DetectWindowRegisterTests(), DetectWithinRegisterTests(), DNP3ParserRegisterTests(), EngineEventRegisterTests(), ENIPParserRegisterTests(), FlagsRegisterTests(), FlowBitRegisterTests(), FlowBitsRegisterTests(), FlowMgrRegisterTests(), FlowRegisterTests(), FragBitsRegisterTests(), FTPParserRegisterTests(), GidRegisterTests(), HashListTableRegisterTests(), HashTableRegisterTests(), HostBitRegisterTests(), HostBitsRegisterTests(), HTPFileParserRegisterTests(), HTPParserRegisterTests(), HTPXFFParserRegisterTests(), IPOnlyRegisterTests(), IpOptsRegisterTests(), IPPairBitRegisterTests(), IPRepRegisterTests(), LogCustomFormatWriteTimestamp(), MagicRegisterTests(), MarkRegisterTests(), MemcmpRegisterTests(), MemrchrRegisterTests(), MimeDecRegisterTests(), ModbusParserRegisterTests(), NoWinDivertSupportExit(), PayloadRegisterTests(), PoolRegisterTests(), PoolThreadRegisterTests(), ReferenceRegisterTests(), RegisterFlowStorageTests(), RegisterHostStorageTests(), RegisterIPPairStorageTests(), RegisterSMBParsers(), SCACBSRegisterTests(), SCACRegisterTests(), SCACTileRegisterTests(), SCAtomicRegisterTests(), SCClassConfRegisterTests(), SCHInfoRegisterTests(), SCLogRegisterTests(), SCPriorityRegisterTests(), SCProfilingRegisterTests(), SCRadixRegisterTests(), SCRConfRegisterTests(), SCReputationRegisterTests(), SCRuleVarsRegisterTests(), SCSigRegisterSignatureOrderingTests(), SCThresholdConfRegisterTests(), SigGroupHeadRegisterTests(), SigParseApplyDsizeToContent(), SigParseRegisterTests(), SigRegisterTests(), SMTPParserRegisterTests(), SSHParserRegisterTests(), SSLParserRegisterTests(), StatsRegisterTests(), StorageRegisterTests(), StreamingBufferRegisterTests(), StreamTcpInlineRegisterTests(), StreamTcpListRegisterTests(), StreamTcpReassembleRegisterTests(), StreamTcpRegisterTests(), StreamTcpSackRegisterTests(), StreamTcpUtilRegisterTests(), ThreadMacrosRegisterTests(), ThresholdRegisterTests(), TmqhFlowRegisterTests(), Unified2RegisterTests(), UTHRegisterTests(), UtilActionRegisterTests(), UtilMiscRegisterTests(), UtilSpmSearchRegistertests(), UtRunSelftest(), and XBitsRegisterTests().

void UtRunModeRegister ( void  )

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

References RUNMODE_UNITTEST, and RunModeRegisterNewRunMode().

Referenced by RunModeRegisterRunModes().

Here is the call graph for this function:

Here is the caller graph for this function:

int UtRunSelftest ( const char *  regex_arg)

Run self tests.

Parameters
regex_argThe regular expression
Return values
0all successful

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

References UtCleanup(), UtInitialize(), UtRegisterTest(), and UtRunTests().

Referenced by RunUnittests().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t UtRunTests ( const char *  regex_arg)

Run all registered unittests.

Parameters
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, UtTest_::name, UtTest_::next, SCLogInfo, StreamTcpInitMemuse(), StreamTcpMemuseCounter(), StreamTcpReassembleInitMemuse(), StreamTcpReassembleMemuseGlobalCounter(), UtTest_::TestFn, TimeModeSetOffline(), TimeSetToCurrentTime(), and unittests_fatal.

Referenced by RunUnittests(), and UtRunSelftest().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int unittests_fatal = 0

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

Referenced by RegisterAllModules(), and UtRunTests().

int unittests_fatal

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

Referenced by RegisterAllModules(), and UtRunTests().