/[pcre]/code/trunk/pcre_jit_test.c
ViewVC logotype

Diff of /code/trunk/pcre_jit_test.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 691 by ph10, Sun Sep 11 14:31:21 2011 UTC revision 698 by ph10, Mon Sep 19 15:43:02 2011 UTC
# Line 40  POSSIBILITY OF SUCH DAMAGE. Line 40  POSSIBILITY OF SUCH DAMAGE.
40  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
41  */  */
42    
43    #ifdef HAVE_CONFIG_H
44    #include "config.h"
45    #endif
46    
47  #include <stdio.h>  #include <stdio.h>
48  #include <string.h>  #include <string.h>
 #include <time.h>  
49  #include "pcre.h"  #include "pcre.h"
50    
51  #define PCRE_BUG 0x80000000  #define PCRE_BUG 0x80000000
# Line 64  static int regression_tests(void); Line 67  static int regression_tests(void);
67    
68  int main(void)  int main(void)
69  {  {
70          return regression_tests();          int jit = 0;
71            pcre_config(PCRE_CONFIG_JIT, &jit);
72            if (!jit) {
73                    printf("JIT must be enabled to run pcre_jit_test\n");
74                    return 1;
75            }
76            return regression_tests();
77  }  }
78    
79  static pcre_jit_stack* callback(void *arg)  static pcre_jit_stack* callback(void *arg)
# Line 120  static struct regression_test_case regre Line 129  static struct regression_test_case regre
129          { MUA, 0, "[^a-dA-C]", "\xe6\x92\xad\xc3\xa9" },          { MUA, 0, "[^a-dA-C]", "\xe6\x92\xad\xc3\xa9" },
130          { CMUA, 0, "[^\xc3\xa9]", "\xc3\xa9\xc3\x89." },          { CMUA, 0, "[^\xc3\xa9]", "\xc3\xa9\xc3\x89." },
131          { MUA, 0, "[^\xc3\xa9]", "\xc3\xa9\xc3\x89." },          { MUA, 0, "[^\xc3\xa9]", "\xc3\xa9\xc3\x89." },
132          { MUA, 0, "[^a]", "\xc2\x80[]" },          { MUA, 0, "[^a]", "\xc2\x80[]" },
133          { CMUA, 0, "\xf0\x90\x90\xa7", "\xf0\x90\x91\x8f" },          { CMUA, 0, "\xf0\x90\x90\xa7", "\xf0\x90\x91\x8f" },
134          { CMA, 0, "1a2b3c4", "1a2B3c51A2B3C4" },          { CMA, 0, "1a2b3c4", "1a2B3c51A2B3C4" },
135          { PCRE_CASELESS, 0, "\xff#a", "\xff#\xff\xfe##\xff#A" },          { PCRE_CASELESS, 0, "\xff#a", "\xff#\xff\xfe##\xff#A" },
# Line 376  static struct regression_test_case regre Line 385  static struct regression_test_case regre
385          { MUA, 0, "(c(ab)?+ab)+", "cabcababcab" },          { MUA, 0, "(c(ab)?+ab)+", "cabcababcab" },
386          { MUA, 0, "(?>(a+)b)+aabab", "aaaabaaabaabab" },          { MUA, 0, "(?>(a+)b)+aabab", "aaaabaaabaabab" },
387    
388          /* Possessive quantifiers. */          /* Possessive quantifiers. */
389          { MUA, 0, "(?:a|b)++m", "mababbaaxababbaam" },          { MUA, 0, "(?:a|b)++m", "mababbaaxababbaam" },
390          { MUA, 0, "(?:a|b)*+m", "mababbaaxababbaam" },          { MUA, 0, "(?:a|b)*+m", "mababbaaxababbaam" },
391          { MUA, 0, "(?:a|b)*+m", "ababbaaxababbaam" },          { MUA, 0, "(?:a|b)*+m", "ababbaaxababbaam" },
392          { MUA, 0, "(a|b)++m", "mababbaaxababbaam" },          { MUA, 0, "(a|b)++m", "mababbaaxababbaam" },
393          { MUA, 0, "(a|b)*+m", "mababbaaxababbaam" },          { MUA, 0, "(a|b)*+m", "mababbaaxababbaam" },
394          { MUA, 0, "(a|b)*+m", "ababbaaxababbaam" },          { MUA, 0, "(a|b)*+m", "ababbaaxababbaam" },
395          { MUA, 0, "(a|b(*ACCEPT))++m", "maaxab" },          { MUA, 0, "(a|b(*ACCEPT))++m", "maaxab" },
396          { MUA, 0, "(?:b*)++m", "bxbbxbbbxm" },          { MUA, 0, "(?:b*)++m", "bxbbxbbbxm" },
397          { MUA, 0, "(?:b*)++m", "bxbbxbbbxbbm" },          { MUA, 0, "(?:b*)++m", "bxbbxbbbxbbm" },
# Line 392  static struct regression_test_case regre Line 401  static struct regression_test_case regre
401          { MUA, 0, "(b*)++m", "bxbbxbbbxbbm" },          { MUA, 0, "(b*)++m", "bxbbxbbbxbbm" },
402          { MUA, 0, "(b*)*+m", "bxbbxbbbxm" },          { MUA, 0, "(b*)*+m", "bxbbxbbbxm" },
403          { MUA, 0, "(b*)*+m", "bxbbxbbbxbbm" },          { MUA, 0, "(b*)*+m", "bxbbxbbbxbbm" },
404          { MUA, 0, "(?:a|(b))++m", "mababbaaxababbaam" },          { MUA, 0, "(?:a|(b))++m", "mababbaaxababbaam" },
405          { MUA, 0, "(?:(a)|b)*+m", "mababbaaxababbaam" },          { MUA, 0, "(?:(a)|b)*+m", "mababbaaxababbaam" },
406          { MUA, 0, "(?:(a)|(b))*+m", "ababbaaxababbaam" },          { MUA, 0, "(?:(a)|(b))*+m", "ababbaaxababbaam" },
407          { MUA, 0, "(a|(b))++m", "mababbaaxababbaam" },          { MUA, 0, "(a|(b))++m", "mababbaaxababbaam" },
408          { MUA, 0, "((a)|b)*+m", "mababbaaxababbaam" },          { MUA, 0, "((a)|b)*+m", "mababbaaxababbaam" },
409          { MUA, 0, "((a)|(b))*+m", "ababbaaxababbaam" },          { MUA, 0, "((a)|(b))*+m", "ababbaaxababbaam" },
410          { MUA, 0, "(a|(b)(*ACCEPT))++m", "maaxab" },          { MUA, 0, "(a|(b)(*ACCEPT))++m", "maaxab" },
411          { MUA, 0, "(?:(b*))++m", "bxbbxbbbxm" },          { MUA, 0, "(?:(b*))++m", "bxbbxbbbxm" },
412          { MUA, 0, "(?:(b*))++m", "bxbbxbbbxbbm" },          { MUA, 0, "(?:(b*))++m", "bxbbxbbbxbbm" },
# Line 517  static struct regression_test_case regre Line 526  static struct regression_test_case regre
526          { MUA, 0, "(?(?!b)a*)+aak", "aaaaab aaaaak" },          { MUA, 0, "(?(?!b)a*)+aak", "aaaaab aaaaak" },
527          { MUA, 0, "(?(?=(?=(?!(x))a)aa)aaa|(?(?=(?!y)bb)bbb))*k", "abaabbaaabbbaaabbb abaabbaaabbbaaabbbk" },          { MUA, 0, "(?(?=(?=(?!(x))a)aa)aaa|(?(?=(?!y)bb)bbb))*k", "abaabbaaabbbaaabbb abaabbaaabbbaaabbbk" },
528    
529          /* Set start of match. */          /* Set start of match. */
530          { MUA, 0, "(?:\\Ka)*aaaab", "aaaaaaaa aaaaaaabb" },          { MUA, 0, "(?:\\Ka)*aaaab", "aaaaaaaa aaaaaaabb" },
531          { MUA, 0, "(?>\\Ka\\Ka)*aaaab", "aaaaaaaa aaaaaaaaaabb" },          { MUA, 0, "(?>\\Ka\\Ka)*aaaab", "aaaaaaaa aaaaaaaaaabb" },
532          { MUA, 0, "a+\\K(?<=\\Gaa)a", "aaaaaa" },          { MUA, 0, "a+\\K(?<=\\Gaa)a", "aaaaaa" },
# Line 566  static struct regression_test_case regre Line 575  static struct regression_test_case regre
575    
576          /* Deep recursion. */          /* Deep recursion. */
577          { MUA, 0, "((((?:(?:(?:\\w)+)?)*|(?>\\w)+?)+|(?>\\w)?\?)*)?\\s", "aaaaa+ " },          { MUA, 0, "((((?:(?:(?:\\w)+)?)*|(?>\\w)+?)+|(?>\\w)?\?)*)?\\s", "aaaaa+ " },
578          { MUA, 0, "(?:((?:(?:(?:\\w*?)+)??|(?>\\w)?|\\w*+)*)+)+?\\s", "aa+ " },          { MUA, 0, "(?:((?:(?:(?:\\w*?)+)??|(?>\\w)?|\\w*+)*)+)+?\\s", "aa+ " },
579          { MUA, 0, "((a?)+)+b", "aaaaaaaaaaaaa b" },          { MUA, 0, "((a?)+)+b", "aaaaaaaaaaaaa b" },
580    
581          /* Deep recursion: Stack limit reached. */          /* Deep recursion: Stack limit reached. */
# Line 585  static int regression_tests(void) Line 594  static int regression_tests(void)
594          struct regression_test_case *current = regression_test_cases;          struct regression_test_case *current = regression_test_cases;
595          const char *error;          const char *error;
596          pcre_extra *extra;          pcre_extra *extra;
597            int utf8 = 0, ucp = 0;
598          int ovector1[32];          int ovector1[32];
599          int ovector2[32];          int ovector2[32];
600          int return_value1, return_value2;          int return_value1, return_value2;
601          int i, err_offs;          int i, err_offs;
602          int total = 0, succesful = 0;          int total = 0, succesful = 0;
603          int counter = 0;          int counter = 0;
604            int disabled_flags = PCRE_BUG;
605    
606            /* This test compares the behaviour of interpreter and JIT. Although disabling
607            utf8 or ucp may make tests fail, if the pcre_exec result is the SAME, it is
608            still considered successful from pcre_jit_test point of view. */
609    
610            pcre_config(PCRE_CONFIG_UTF8, &utf8);
611            pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &ucp);
612            if (!utf8)
613                    disabled_flags |= PCRE_UTF8;
614            if (!ucp)
615                    disabled_flags |= PCRE_UCP;
616    
617          printf("Running JIT regression tests:\n");          printf("Running JIT regression tests with utf8 %s and ucp %s:\n", utf8 ? "enabled" : "disabled", ucp ? "enabled" : "disabled");
618          while (current->pattern) {          while (current->pattern) {
619                  /* printf("\nPattern: %s :", current->pattern); */                  /* printf("\nPattern: %s :\n", current->pattern); */
620                  total++;                  total++;
621    
622                  error = NULL;                  error = NULL;
623                  re = pcre_compile(current->pattern, current->flags & ~(PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_BUG), &error, &err_offs, NULL);                  re = pcre_compile(current->pattern, current->flags & ~(PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | disabled_flags), &error, &err_offs, NULL);
624    
625                  if (!re) {                  if (!re) {
626                          printf("\nCannot compile pattern: %s\n", current->pattern);                          if (utf8 && ucp)
627                                    printf("\nCannot compile pattern: %s\n", current->pattern);
628                            else {
629                                    /* Some patterns cannot be compiled when either of utf8
630                                    or ucp is disabled. We just skip them. */
631                                    printf(".");
632                                    succesful++;
633                            }
634                          current++;                          current++;
635                          continue;                          continue;
636                  }                  }
# Line 669  static int regression_tests(void) Line 698  static int regression_tests(void)
698          if (total == succesful) {          if (total == succesful) {
699                  printf("\nAll JIT regression tests are successfully passed.\n");                  printf("\nAll JIT regression tests are successfully passed.\n");
700                  return 0;                  return 0;
701          } else {          } else {
702                  printf("\nSuccessful test ratio: %d%%\n", succesful * 100 / total);                  printf("\nSuccessful test ratio: %d%%\n", succesful * 100 / total);
703                  return 1;                  return 1;
704          }          }
705  }  }
706    
707  /* End of pcre_jit_test.c */  /* End of pcre_jit_test.c */

Legend:
Removed from v.691  
changed lines
  Added in v.698

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12