36 static int MemcmpTest01 (
void)
41 if (
SCMemcmp(a, b,
sizeof(a)-1) != 0)
47 static int MemcmpTest02 (
void)
49 uint8_t a[] =
"abcdabcdabcdabcd";
50 uint8_t b[] =
"abcdabcdabcdabcd";
52 if (
SCMemcmp(a, b,
sizeof(a)-1) != 0)
58 static int MemcmpTest03 (
void)
60 uint8_t a[] =
"abcdabcd";
61 uint8_t b[] =
"abcdabcd";
63 if (
SCMemcmp(a, b,
sizeof(a)-1) != 0)
69 static int MemcmpTest04 (
void)
76 printf(
"%s != %s, but memcmp returned %d: ", a, b, r);
83 static int MemcmpTest05 (
void)
85 uint8_t a[] =
"abcdabcdabcdabcd";
86 uint8_t b[] =
"abcDabcdabcdabcd";
88 if (
SCMemcmp(a, b,
sizeof(a)-1) != 1)
94 static int MemcmpTest06 (
void)
96 uint8_t a[] =
"abcdabcd";
97 uint8_t b[] =
"abcDabcd";
99 if (
SCMemcmp(a, b,
sizeof(a)-1) != 1)
105 static int MemcmpTest07 (
void)
107 uint8_t a[] =
"abcd";
108 uint8_t b[] =
"abcde";
110 if (
SCMemcmp(a, b,
sizeof(a)-1) != 0)
116 static int MemcmpTest08 (
void)
118 uint8_t a[] =
"abcdabcdabcdabcd";
119 uint8_t b[] =
"abcdabcdabcdabcde";
121 if (
SCMemcmp(a, b,
sizeof(a)-1) != 0)
127 static int MemcmpTest09 (
void)
129 uint8_t a[] =
"abcdabcd";
130 uint8_t b[] =
"abcdabcde";
132 if (
SCMemcmp(a, b,
sizeof(a)-1) != 0)
138 static int MemcmpTest10 (
void)
140 uint8_t a[] =
"abcd";
141 uint8_t b[] =
"Zbcde";
143 if (
SCMemcmp(a, b,
sizeof(a)-1) != 1)
149 static int MemcmpTest11 (
void)
151 uint8_t a[] =
"abcdabcdabcdabcd";
152 uint8_t b[] =
"Zbcdabcdabcdabcde";
154 if (
SCMemcmp(a, b,
sizeof(a)-1) != 1)
160 static int MemcmpTest12 (
void)
162 uint8_t a[] =
"abcdabcd";
163 uint8_t b[] =
"Zbcdabcde";
165 if (
SCMemcmp(a, b,
sizeof(a)-1) != 1)
171 static int MemcmpTest13 (
void)
173 uint8_t a[] =
"abcdefgh";
174 uint8_t b[] =
"AbCdEfGhIjK";
176 if (SCMemcmpLowercase(a, b,
sizeof(a)-1) != 0)
184 #define TEST_RUNS 1000000
186 static int MemcmpTest14 (
void)
189 uint64_t ticks_start = 0;
190 uint64_t ticks_end = 0;
191 const char *a[] = {
"0123456789012345",
"abc",
"abcdefghij",
"suricata",
"test",
"xyz",
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"abcdefghijklmnopqrstuvwxyz", NULL };
192 const char *b[] = {
"1234567890123456",
"abc",
"abcdefghik",
"suricatb",
"test",
"xyz",
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"abcdefghijklmnopqrstuvwxyz", NULL };
202 for (i = 0; a[i] != NULL; i++) {
204 size_t alen = strlen(a[i]) - 1;
206 for (j = 0; b[j] != NULL; j++) {
208 size_t blen = strlen(b[j]) - 1;
210 r1 += (memcmp((uint8_t *)a[i], (uint8_t *)b[j], (alen < blen) ? alen : blen) ? 1 : 0);
215 printf(
"memcmp(%d) \t\t\t%"PRIu64
"\n",
TEST_RUNS, ((uint64_t)(ticks_end - ticks_start))/
TEST_RUNS);
216 SCLogInfo(
"ticks passed %"PRIu64, ticks_end - ticks_start);
218 printf(
"r1 %d\n", r1);
225 static int MemcmpTest15 (
void)
228 uint64_t ticks_start = 0;
229 uint64_t ticks_end = 0;
230 const char *a[] = {
"0123456789012345",
"abc",
"abcdefghij",
"suricata",
"test",
"xyz",
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"abcdefghijklmnopqrstuvwxyz", NULL };
231 const char *b[] = {
"1234567890123456",
"abc",
"abcdefghik",
"suricatb",
"test",
"xyz",
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"abcdefghijklmnopqrstuvwxyz", NULL };
241 for (i = 0; a[i] != NULL; i++) {
243 size_t alen = strlen(a[i]) - 1;
245 for (j = 0; b[j] != NULL; j++) {
247 size_t blen = strlen(b[j]) - 1;
249 r2 += MemcmpLowercase((uint8_t *)a[i], (uint8_t *)b[j], (alen < blen) ? alen : blen);
254 printf(
"MemcmpLowercase(%d) \t\t%"PRIu64
"\n",
TEST_RUNS, ((uint64_t)(ticks_end - ticks_start))/
TEST_RUNS);
255 SCLogInfo(
"ticks passed %"PRIu64, ticks_end - ticks_start);
257 printf(
"r2 %d\n", r2);
264 static int MemcmpTest16 (
void)
267 uint64_t ticks_start = 0;
268 uint64_t ticks_end = 0;
269 const char *a[] = {
"0123456789012345",
"abc",
"abcdefghij",
"suricata",
"test",
"xyz",
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"abcdefghijklmnopqrstuvwxyz", NULL };
270 const char *b[] = {
"1234567890123456",
"abc",
"abcdefghik",
"suricatb",
"test",
"xyz",
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"abcdefghijklmnopqrstuvwxyz", NULL };
280 for (i = 0; a[i] != NULL; i++) {
282 size_t alen = strlen(a[i]) - 1;
284 for (j = 0; b[j] != NULL; j++) {
286 size_t blen = strlen(b[j]) - 1;
288 r3 +=
SCMemcmp((uint8_t *)a[i], (uint8_t *)b[j], (alen < blen) ? alen : blen);
293 printf(
"SCMemcmp(%d) \t\t\t%"PRIu64
"\n",
TEST_RUNS, ((uint64_t)(ticks_end - ticks_start))/
TEST_RUNS);
294 SCLogInfo(
"ticks passed %"PRIu64, ticks_end - ticks_start);
296 printf(
"r3 %d\n", r3);
303 static int MemcmpTest17 (
void)
306 uint64_t ticks_start = 0;
307 uint64_t ticks_end = 0;
308 const char *a[] = {
"0123456789012345",
"abc",
"abcdefghij",
"suricata",
"test",
"xyz",
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"abcdefghijklmnopqrstuvwxyz", NULL };
309 const char *b[] = {
"1234567890123456",
"abc",
"abcdefghik",
"suricatb",
"test",
"xyz",
"rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"abcdefghijklmnopqrstuvwxyz", NULL };
319 for (i = 0; a[i] != NULL; i++) {
321 size_t alen = strlen(a[i]) - 1;
323 for (j = 0; b[j] != NULL; j++) {
325 size_t blen = strlen(b[j]) - 1;
327 r4 += SCMemcmpLowercase((uint8_t *)a[i], (uint8_t *)b[j], (alen < blen) ? alen : blen);
332 printf(
"SCMemcmpLowercase(%d) \t\t%"PRIu64
"\n",
TEST_RUNS, ((uint64_t)(ticks_end - ticks_start))/
TEST_RUNS);
333 SCLogInfo(
"ticks passed %"PRIu64, ticks_end - ticks_start);
335 printf(
"r4 %d\n", r4);
347 {
"abcdefgh",
"!bcdefgh", 1, },
348 {
"?bcdefgh",
"!bcdefgh", 1, },
349 {
"!bcdefgh",
"abcdefgh", 1, },
350 {
"!bcdefgh",
"?bcdefgh", 1, },
351 {
"zbcdefgh",
"bbcdefgh", 1, },
353 {
"abcdefgh12345678",
"!bcdefgh12345678", 1, },
354 {
"?bcdefgh12345678",
"!bcdefgh12345678", 1, },
355 {
"!bcdefgh12345678",
"abcdefgh12345678", 1, },
356 {
"!bcdefgh12345678",
"?bcdefgh12345678", 1, },
357 {
"bbcdefgh12345678",
"zbcdefgh12345678", 1, },
359 {
"abcdefgh",
"abcdefgh", 0, },
360 {
"abcdefgh",
"Abcdefgh", 0, },
361 {
"abcdefgh12345678",
"Abcdefgh12345678", 0, },
367 static int MemcmpTest18 (
void)
371 while (t && t->
a != NULL) {
373 if (SCMemcmpLowercase(t->
a, t->
b, strlen(t->
a)-1) != t->
result)