OLD | NEW |
1 // Copyright 2009 The RE2 Authors. All Rights Reserved. | 1 // Copyright 2009 The RE2 Authors. All Rights Reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RE2_TESTING_EXHAUSTIVE_TESTER_H__ | 5 #ifndef RE2_TESTING_EXHAUSTIVE_TESTER_H__ |
6 #define RE2_TESTING_EXHAUSTIVE_TESTER_H__ | 6 #define RE2_TESTING_EXHAUSTIVE_TESTER_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include "util/util.h" | 10 #include "util/util.h" |
11 #include "re2/testing/regexp_generator.h" | 11 #include "re2/testing/regexp_generator.h" |
12 #include "re2/testing/string_generator.h" | 12 #include "re2/testing/string_generator.h" |
13 | 13 |
14 namespace re2 { | 14 namespace re2 { |
15 | 15 |
| 16 #if !defined(NDEBUG) |
| 17 // We are in a debug build. |
| 18 const bool RE2_DEBUG_MODE = true; |
| 19 #elif ADDRESS_SANITIZER || MEMORY_SANITIZER || THREAD_SANITIZER |
| 20 // Not a debug build, but still under sanitizers. |
| 21 const bool RE2_DEBUG_MODE = true; |
| 22 #else |
| 23 const bool RE2_DEBUG_MODE = false; |
| 24 #endif |
| 25 |
16 // Exhaustive regular expression test: generate all regexps within parameters, | 26 // Exhaustive regular expression test: generate all regexps within parameters, |
17 // then generate all strings of a given length over a given alphabet, | 27 // then generate all strings of a given length over a given alphabet, |
18 // then check that NFA, DFA, and PCRE agree about whether each regexp matches | 28 // then check that NFA, DFA, and PCRE agree about whether each regexp matches |
19 // each possible string, and if so, where the match is. | 29 // each possible string, and if so, where the match is. |
20 // | 30 // |
21 // Can also be used in a "random" mode that generates a given number | 31 // Can also be used in a "random" mode that generates a given number |
22 // of random regexp and strings, allowing testing of larger expressions | 32 // of random regexp and strings, allowing testing of larger expressions |
23 // and inputs. | 33 // and inputs. |
24 class ExhaustiveTester : public RegexpGenerator { | 34 class ExhaustiveTester : public RegexpGenerator { |
25 public: | 35 public: |
(...skipping 30 matching lines...) Expand all Loading... |
56 StringGenerator strgen_; | 66 StringGenerator strgen_; |
57 string wrapper_; // Regexp wrapper - either empty or has one %s. | 67 string wrapper_; // Regexp wrapper - either empty or has one %s. |
58 string topwrapper_; // Regexp top-level wrapper. | 68 string topwrapper_; // Regexp top-level wrapper. |
59 int regexps_; // Number of HandleRegexp calls | 69 int regexps_; // Number of HandleRegexp calls |
60 int tests_; // Number of regexp tests. | 70 int tests_; // Number of regexp tests. |
61 int failures_; // Number of tests failed. | 71 int failures_; // Number of tests failed. |
62 | 72 |
63 bool randomstrings_; // Whether to use random strings | 73 bool randomstrings_; // Whether to use random strings |
64 int32 stringseed_; // If so, the seed. | 74 int32 stringseed_; // If so, the seed. |
65 int stringcount_; // If so, how many to generate. | 75 int stringcount_; // If so, how many to generate. |
66 DISALLOW_EVIL_CONSTRUCTORS(ExhaustiveTester); | 76 DISALLOW_COPY_AND_ASSIGN(ExhaustiveTester); |
67 }; | 77 }; |
68 | 78 |
69 // Runs an exhaustive test on the given parameters. | 79 // Runs an exhaustive test on the given parameters. |
70 void ExhaustiveTest(int maxatoms, int maxops, | 80 void ExhaustiveTest(int maxatoms, int maxops, |
71 const vector<string>& alphabet, | 81 const vector<string>& alphabet, |
72 const vector<string>& ops, | 82 const vector<string>& ops, |
73 int maxstrlen, const vector<string>& stralphabet, | 83 int maxstrlen, const vector<string>& stralphabet, |
74 const string& wrapper, | 84 const string& wrapper, |
75 const string& topwrapper); | 85 const string& topwrapper); |
76 | 86 |
77 // Runs an exhaustive test using the given parameters and | 87 // Runs an exhaustive test using the given parameters and |
78 // the basic egrep operators. | 88 // the basic egrep operators. |
79 void EgrepTest(int maxatoms, int maxops, const string& alphabet, | 89 void EgrepTest(int maxatoms, int maxops, const string& alphabet, |
80 int maxstrlen, const string& stralphabet, | 90 int maxstrlen, const string& stralphabet, |
81 const string& wrapper); | 91 const string& wrapper); |
82 | 92 |
83 } // namespace re2 | 93 } // namespace re2 |
84 | 94 |
85 #endif // RE2_TESTING_EXHAUSTIVE_TESTER_H__ | 95 #endif // RE2_TESTING_EXHAUSTIVE_TESTER_H__ |
OLD | NEW |