47 static pcre2_code *parse_regex;
48 static pcre2_match_data *parse_regex_match;
60 static UtTest *UtAllocTest(
void)
66 memset(ut, 0,
sizeof(
UtTest));
87 while (tmp->
next != NULL) {
105 UtTest *ut = UtAllocTest();
114 UtAppendTest(&ut_list, ut);
125 static int UtRegex (
const char *
regex_arg)
129 int opts = PCRE2_CASELESS;
135 pcre2_compile((PCRE2_SPTR8)
regex_arg, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
136 if(parse_regex == NULL)
138 PCRE2_UCHAR errbuffer[256];
139 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
140 SCLogError(
"pcre2 compile of \"%s\" failed at "
145 parse_regex_match = pcre2_match_data_create_from_pattern(parse_regex, NULL);
160 int ret = 0, rcomp = 0;
164 for (ut = ut_list; ut != NULL; ut = ut->
next) {
166 ret = pcre2_match(parse_regex, (PCRE2_SPTR8)ut->
name, strlen(ut->
name), 0, 0,
167 parse_regex_match, NULL);
169 printf(
"%s\n", ut->
name);
173 printf(
"%s\n", ut->
name);
176 pcre2_code_free(parse_regex);
177 pcre2_match_data_free(parse_regex_match);
191 uint32_t good = 0, bad = 0, matchcnt = 0;
192 int ret = 0, rcomp = 0;
200 for (ut = ut_list; ut != NULL; ut = ut->
next) {
201 ret = pcre2_match(parse_regex, (PCRE2_SPTR8)ut->
name, strlen(ut->
name), 0, 0,
202 parse_regex_match, NULL);
204 printf(
"Test %-60.60s : ", ut->
name);
228 printf(
"%s\n", ret ?
"pass" :
"FAILED");
232 fprintf(stderr,
"ERROR: unittest failed.\n");
242 printf(
"==== TEST RESULTS ====\n");
243 printf(
"PASSED: %" PRIu32
"\n", good);
244 printf(
"FAILED: %" PRIu32
"\n", bad);
245 printf(
"======================\n");
247 SCLogInfo(
"UtRunTests: regex provided regex_arg: %s did not match any tests",
regex_arg);
250 SCLogInfo(
"UtRunTests: pcre compilation failed");
252 pcre2_code_free(parse_regex);
253 pcre2_match_data_free(parse_regex_match);
272 UtTest *tmp = ut_list, *otmp;
274 while (tmp != NULL) {
297 static int UtSelftestTrue(
void)
308 static int UtSelftestFalse(
void)
323 printf(
"* Running Unittesting subsystem selftests...\n");
332 printf(
"* Done running Unittesting subsystem selftests...\n");
334 printf(
"* ERROR running Unittesting subsystem selftests failed...\n");