45 static pcre2_code *parse_regex;
46 static pcre2_match_data *parse_regex_match;
58 static UtTest *UtAllocTest(
void)
64 memset(ut, 0,
sizeof(
UtTest));
85 while (tmp->
next != NULL) {
103 UtTest *ut = UtAllocTest();
112 UtAppendTest(&ut_list, ut);
123 static int UtRegex (
const char *
regex_arg)
127 int opts = PCRE2_CASELESS;
133 pcre2_compile((PCRE2_SPTR8)
regex_arg, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
134 if(parse_regex == NULL)
136 PCRE2_UCHAR errbuffer[256];
137 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
138 SCLogError(
"pcre2 compile of \"%s\" failed at "
143 parse_regex_match = pcre2_match_data_create_from_pattern(parse_regex, NULL);
158 int ret = 0, rcomp = 0;
162 for (ut = ut_list; ut != NULL; ut = ut->
next) {
164 ret = pcre2_match(parse_regex, (PCRE2_SPTR8)ut->
name, strlen(ut->
name), 0, 0,
165 parse_regex_match, NULL);
167 printf(
"%s\n", ut->
name);
171 printf(
"%s\n", ut->
name);
174 pcre2_code_free(parse_regex);
175 pcre2_match_data_free(parse_regex_match);
189 uint32_t good = 0, bad = 0, matchcnt = 0;
190 int ret = 0, rcomp = 0;
198 for (ut = ut_list; ut != NULL; ut = ut->
next) {
199 ret = pcre2_match(parse_regex, (PCRE2_SPTR8)ut->
name, strlen(ut->
name), 0, 0,
200 parse_regex_match, NULL);
202 printf(
"Test %-60.60s : ", ut->
name);
226 printf(
"%s\n", ret ?
"pass" :
"FAILED");
230 fprintf(stderr,
"ERROR: unittest failed.\n");
240 printf(
"==== TEST RESULTS ====\n");
241 printf(
"PASSED: %" PRIu32
"\n", good);
242 printf(
"FAILED: %" PRIu32
"\n", bad);
243 printf(
"======================\n");
245 SCLogInfo(
"UtRunTests: regex provided regex_arg: %s did not match any tests",
regex_arg);
248 SCLogInfo(
"UtRunTests: pcre compilation failed");
250 pcre2_code_free(parse_regex);
251 pcre2_match_data_free(parse_regex_match);
270 UtTest *tmp = ut_list, *otmp;
272 while (tmp != NULL) {
295 static int UtSelftestTrue(
void)
307 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");