MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / DEFINE_FLAG

Function DEFINE_FLAG

extern/re2/re2/testing/dfa_test.cc:24–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23DEFINE_FLAG(int, size, 8, "log2(number of DFA nodes)");
24DEFINE_FLAG(int, repeat, 2, "Repetition count.");
25DEFINE_FLAG(int, threads, 4, "number of threads");
26
27namespace re2 {
28
29static int state_cache_resets = 0;
30static int search_failures = 0;
31
32struct SetHooks {
33 SetHooks() {
34 hooks::SetDFAStateCacheResetHook([](const hooks::DFAStateCacheReset&) {
35 ++state_cache_resets;
36 });
37 hooks::SetDFASearchFailureHook([](const hooks::DFASearchFailure&) {
38 ++search_failures;
39 });
40 }
41} set_hooks;
42
43// Check that multithreaded access to DFA class works.
44
45// Helper function: builds entire DFA for prog.
46static void DoBuild(Prog* prog) {
47 ASSERT_TRUE(prog->BuildEntireDFA(Prog::kFirstMatch, nullptr));
48}
49
50TEST(Multithreaded, BuildEntireDFA) {
51 // Create regexp with 2^FLAGS_size states in DFA.
52 std::string s = "a";
53 for (int i = 0; i < GetFlag(FLAGS_size); i++)
54 s += "[ab]";
55 s += "b";
56 Regexp* re = Regexp::Parse(s, Regexp::LikePerl, NULL);
57 ASSERT_TRUE(re != NULL);
58
59 // Check that single-threaded code works.
60 {
61 Prog* prog = re->CompileToProg(0);
62 ASSERT_TRUE(prog != NULL);
63
64 std::thread t(DoBuild, prog);
65 t.join();
66
67 delete prog;
68 }
69
70 // Build the DFA simultaneously in a bunch of threads.
71 for (int i = 0; i < GetFlag(FLAGS_repeat); i++) {
72 Prog* prog = re->CompileToProg(0);
73 ASSERT_TRUE(prog != NULL);
74
75 std::vector<std::thread> threads;
76 for (int j = 0; j < GetFlag(FLAGS_threads); j++)
77 threads.emplace_back(DoBuild, prog);
78 for (int j = 0; j < GetFlag(FLAGS_threads); j++)
79 threads[j].join();
80
81 // One more compile, to make sure everything is okay.

Callers 1

Calls 15

GetFlagFunction · 0.85
ParseFunction · 0.85
StringPrintfFunction · 0.85
DeBruijnStringFunction · 0.85
StringPieceClass · 0.85
BuildEntireDFAMethod · 0.80
CompileToProgMethod · 0.80
emplace_backMethod · 0.80
HeapGrowthMethod · 0.80
SearchDFAMethod · 0.80
PeakHeapGrowthMethod · 0.80
CompileToReverseProgMethod · 0.80

Tested by

no test coverage detected