summaryrefslogtreecommitdiffstats
path: root/base/vlog_unittest.cc
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-11-18 18:32:45 +0000
committerBen Murdoch <benm@google.com>2010-11-18 18:38:07 +0000
commit513209b27ff55e2841eac0e4120199c23acce758 (patch)
treeaeba30bb08c5f47c57003544e378a377c297eee6 /base/vlog_unittest.cc
parent164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff)
downloadexternal_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'base/vlog_unittest.cc')
-rw-r--r--base/vlog_unittest.cc152
1 files changed, 83 insertions, 69 deletions
diff --git a/base/vlog_unittest.cc b/base/vlog_unittest.cc
index 95aa1b9..f583f44 100644
--- a/base/vlog_unittest.cc
+++ b/base/vlog_unittest.cc
@@ -18,19 +18,69 @@ class VlogTest : public testing::Test {
};
TEST_F(VlogTest, NoVmodule) {
- EXPECT_EQ(0, VlogInfo("", "").GetVlogLevel("test1"));
- EXPECT_EQ(0, VlogInfo("0", "").GetVlogLevel("test2"));
- EXPECT_EQ(0, VlogInfo("blah", "").GetVlogLevel("test3"));
- EXPECT_EQ(0, VlogInfo("0blah1", "").GetVlogLevel("test4"));
- EXPECT_EQ(1, VlogInfo("1", "").GetVlogLevel("test5"));
- EXPECT_EQ(5, VlogInfo("5", "").GetVlogLevel("test6"));
+ int min_log_level = 0;
+ EXPECT_EQ(0, VlogInfo("", "", &min_log_level).GetVlogLevel("test1"));
+ EXPECT_EQ(0, VlogInfo("0", "", &min_log_level).GetVlogLevel("test2"));
+ EXPECT_EQ(0, VlogInfo("blah", "", &min_log_level).GetVlogLevel("test3"));
+ EXPECT_EQ(0, VlogInfo("0blah1", "", &min_log_level).GetVlogLevel("test4"));
+ EXPECT_EQ(1, VlogInfo("1", "", &min_log_level).GetVlogLevel("test5"));
+ EXPECT_EQ(5, VlogInfo("5", "", &min_log_level).GetVlogLevel("test6"));
}
-TEST_F(VlogTest, Vmodule) {
+TEST_F(VlogTest, MatchVlogPattern) {
+ // Degenerate cases.
+ EXPECT_TRUE(MatchVlogPattern("", ""));
+ EXPECT_TRUE(MatchVlogPattern("", "****"));
+ EXPECT_FALSE(MatchVlogPattern("", "x"));
+ EXPECT_FALSE(MatchVlogPattern("x", ""));
+
+ // Basic.
+ EXPECT_TRUE(MatchVlogPattern("blah", "blah"));
+
+ // ? should match exactly one character.
+ EXPECT_TRUE(MatchVlogPattern("blah", "bl?h"));
+ EXPECT_FALSE(MatchVlogPattern("blh", "bl?h"));
+ EXPECT_FALSE(MatchVlogPattern("blaah", "bl?h"));
+ EXPECT_TRUE(MatchVlogPattern("blah", "?lah"));
+ EXPECT_FALSE(MatchVlogPattern("lah", "?lah"));
+ EXPECT_FALSE(MatchVlogPattern("bblah", "?lah"));
+
+ // * can match any number (even 0) of characters.
+ EXPECT_TRUE(MatchVlogPattern("blah", "bl*h"));
+ EXPECT_TRUE(MatchVlogPattern("blabcdefh", "bl*h"));
+ EXPECT_TRUE(MatchVlogPattern("blh", "bl*h"));
+ EXPECT_TRUE(MatchVlogPattern("blah", "*blah"));
+ EXPECT_TRUE(MatchVlogPattern("ohblah", "*blah"));
+ EXPECT_TRUE(MatchVlogPattern("blah", "blah*"));
+ EXPECT_TRUE(MatchVlogPattern("blahhhh", "blah*"));
+ EXPECT_TRUE(MatchVlogPattern("blahhhh", "blah*"));
+ EXPECT_TRUE(MatchVlogPattern("blah", "*blah*"));
+ EXPECT_TRUE(MatchVlogPattern("blahhhh", "*blah*"));
+ EXPECT_TRUE(MatchVlogPattern("bbbblahhhh", "*blah*"));
+
+ // Multiple *s should work fine.
+ EXPECT_TRUE(MatchVlogPattern("ballaah", "b*la*h"));
+ EXPECT_TRUE(MatchVlogPattern("blah", "b*la*h"));
+ EXPECT_TRUE(MatchVlogPattern("bbbblah", "b*la*h"));
+ EXPECT_TRUE(MatchVlogPattern("blaaah", "b*la*h"));
+
+ // There should be no escaping going on.
+ EXPECT_TRUE(MatchVlogPattern("bl\\ah", "bl\\?h"));
+ EXPECT_FALSE(MatchVlogPattern("bl?h", "bl\\?h"));
+ EXPECT_TRUE(MatchVlogPattern("bl\\aaaah", "bl\\*h"));
+ EXPECT_FALSE(MatchVlogPattern("bl*h", "bl\\*h"));
+
+ // Any slash matches any slash.
+ EXPECT_TRUE(MatchVlogPattern("/b\\lah", "/b\\lah"));
+ EXPECT_TRUE(MatchVlogPattern("\\b/lah", "/b\\lah"));
+}
+
+TEST_F(VlogTest, VmoduleBasic) {
const char kVSwitch[] = "-1";
const char kVModuleSwitch[] =
- "foo=,bar=0,baz=blah,,qux=0blah1,quux=1,corge=5";
- VlogInfo vlog_info(kVSwitch, kVModuleSwitch);
+ "foo=,bar=0,baz=blah,,qux=0blah1,quux=1,corge.ext=5";
+ int min_log_level = 0;
+ VlogInfo vlog_info(kVSwitch, kVModuleSwitch, &min_log_level);
EXPECT_EQ(-1, vlog_info.GetVlogLevel("/path/to/grault.cc"));
EXPECT_EQ(0, vlog_info.GetVlogLevel("/path/to/foo.cc"));
EXPECT_EQ(0, vlog_info.GetVlogLevel("D:\\Path\\To\\bar-inl.mm"));
@@ -38,70 +88,34 @@ TEST_F(VlogTest, Vmodule) {
EXPECT_EQ(0, vlog_info.GetVlogLevel("baz.h"));
EXPECT_EQ(0, vlog_info.GetVlogLevel("/another/path/to/qux.h"));
EXPECT_EQ(1, vlog_info.GetVlogLevel("/path/to/quux"));
- EXPECT_EQ(5, vlog_info.GetVlogLevel("c:\\path/to/corge.h"));
-}
-
-#define BENCHMARK(iters, elapsed, code) \
- do { \
- base::TimeTicks start = base::TimeTicks::Now(); \
- for (int i = 0; i < iters; ++i) code; \
- base::TimeTicks end = base::TimeTicks::Now(); \
- elapsed = end - start; \
- double cps = iters / elapsed.InSecondsF(); \
- LOG(INFO) << cps << " cps (" << elapsed.InSecondsF() \
- << "s elapsed)"; \
- } while (0)
-
-double GetSlowdown(const base::TimeDelta& base,
- const base::TimeDelta& elapsed) {
- return elapsed.InSecondsF() / base.InSecondsF();
+ EXPECT_EQ(5, vlog_info.GetVlogLevel("c:\\path/to/corge.ext.h"));
}
-
-TEST_F(VlogTest, Perf) {
- const char* kVlogs[] = {
- "/path/to/foo.cc",
- "C:\\path\\to\\bar.h",
- "/path/to/not-matched.mm",
- "C:\\path\\to\\baz-inl.mm",
- "C:\\path\\to\\qux.mm",
- "/path/to/quux.mm",
- "/path/to/another-not-matched.mm",
- };
- const int kVlogCount = arraysize(kVlogs);
- const int kBenchmarkIterations = RunningOnValgrind() ? 30000 : 10000000;
-
- base::TimeDelta null_elapsed;
- {
- VlogInfo null_vlog_info("", "");
- BENCHMARK(kBenchmarkIterations, null_elapsed, {
- EXPECT_NE(-1, null_vlog_info.GetVlogLevel(kVlogs[i % kVlogCount]));
- });
- }
-
- {
- VlogInfo small_vlog_info("0", "foo=1,bar=2,baz=3,qux=4,quux=5");
- base::TimeDelta elapsed;
- BENCHMARK(kBenchmarkIterations, elapsed, {
- EXPECT_NE(-1, small_vlog_info.GetVlogLevel(kVlogs[i % kVlogCount]));
- });
- LOG(INFO) << "slowdown = " << GetSlowdown(null_elapsed, elapsed)
- << "x";
- }
-
- {
- VlogInfo pattern_vlog_info("0", "fo*=1,ba?=2,b*?z=3,*ux=4,?uux=5");
- base::TimeDelta elapsed;
- BENCHMARK(kBenchmarkIterations, elapsed, {
- EXPECT_NE(-1, pattern_vlog_info.GetVlogLevel(kVlogs[i % kVlogCount]));
- });
- LOG(INFO) << "slowdown = " << GetSlowdown(null_elapsed, elapsed)
- << "x";
- }
+TEST_F(VlogTest, VmoduleDirs) {
+ const char kVModuleSwitch[] =
+ "foo/bar.cc=1,baz\\*\\qux.cc=2,*quux/*=3,*/*-inl.h=4";
+ int min_log_level = 0;
+ VlogInfo vlog_info("", kVModuleSwitch, &min_log_level);
+ EXPECT_EQ(0, vlog_info.GetVlogLevel("/foo/bar.cc"));
+ EXPECT_EQ(0, vlog_info.GetVlogLevel("bar.cc"));
+ EXPECT_EQ(1, vlog_info.GetVlogLevel("foo/bar.cc"));
+
+ EXPECT_EQ(0, vlog_info.GetVlogLevel("baz/grault/qux.h"));
+ EXPECT_EQ(0, vlog_info.GetVlogLevel("/baz/grault/qux.cc"));
+ EXPECT_EQ(2, vlog_info.GetVlogLevel("baz/grault/qux.cc"));
+ EXPECT_EQ(2, vlog_info.GetVlogLevel("baz/grault/blah/qux.cc"));
+ EXPECT_EQ(2, vlog_info.GetVlogLevel("baz\\grault\\qux.cc"));
+ EXPECT_EQ(2, vlog_info.GetVlogLevel("baz\\grault//blah\\qux.cc"));
+
+ EXPECT_EQ(0, vlog_info.GetVlogLevel("/foo/bar/baz/quux.cc"));
+ EXPECT_EQ(3, vlog_info.GetVlogLevel("/foo/bar/baz/quux/grault.cc"));
+ EXPECT_EQ(3, vlog_info.GetVlogLevel("/foo\\bar/baz\\quux/grault.cc"));
+
+ EXPECT_EQ(0, vlog_info.GetVlogLevel("foo/bar/test-inl.cc"));
+ EXPECT_EQ(4, vlog_info.GetVlogLevel("foo/bar/test-inl.h"));
+ EXPECT_EQ(4, vlog_info.GetVlogLevel("foo/bar/baz/blah-inl.h"));
}
-#undef BENCHMARK
-
} // namespace
} // namespace logging