summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authormnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 15:05:58 +0000
committermnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 15:05:58 +0000
commite9ff5e31b28b6ee684ceaf47afe4f483163f6d1d (patch)
treefd6d4d707ecd42716e827face33a884e6de161db /webkit
parenteed0011868749ef759ab95cb906fc0fe8e23cde1 (diff)
downloadchromium_src-e9ff5e31b28b6ee684ceaf47afe4f483163f6d1d.zip
chromium_src-e9ff5e31b28b6ee684ceaf47afe4f483163f6d1d.tar.gz
chromium_src-e9ff5e31b28b6ee684ceaf47afe4f483163f6d1d.tar.bz2
Change ListenerLeakTest tests to use the new V8 profiler API.
This eliminates the need of doing heap snapshots on every GC round when running test_shell_tests. BUG=none TEST=ListenerLeakTest.* Review URL: http://codereview.chromium.org/6454003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74117 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/tools/test_shell/listener_leak_test.cc59
-rw-r--r--webkit/tools/test_shell/run_all_tests.cc2
2 files changed, 26 insertions, 35 deletions
diff --git a/webkit/tools/test_shell/listener_leak_test.cc b/webkit/tools/test_shell/listener_leak_test.cc
index ce8fe3f..157891a 100644
--- a/webkit/tools/test_shell/listener_leak_test.cc
+++ b/webkit/tools/test_shell/listener_leak_test.cc
@@ -9,51 +9,43 @@
#include "base/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "v8/include/v8.h"
+#include "v8/include/v8-profiler.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/test_shell.h"
#include "webkit/tools/test_shell/test_shell_test.h"
-static const char kHeapSampleBegin[] = "heap-sample-begin,";
-static const char kHeapObjectLogEntryPrefix[] = "\nheap-js-cons-item,";
-static const char kHeapObjectLogEntrySuffix[] = ",";
-
class ListenerLeakTest : public TestShellTest {
};
-static std::string GetV8Log(int skip) {
- std::string v8_log;
- char buf[2048];
- int read_size;
- do {
- read_size = v8::V8::GetLogLines(skip + static_cast<int>(v8_log.size()),
- buf, sizeof(buf));
- v8_log.append(buf, read_size);
- } while (read_size > 0);
- return v8_log;
+static const v8::HeapGraphNode* GetChild(
+ const v8::HeapGraphNode* node,
+ v8::HeapGraphNode::Type type,
+ const char* name) {
+ for (int i = 0, count = node->GetChildrenCount(); i < count; ++i) {
+ const v8::HeapGraphEdge* prop = node->GetChild(i);
+ const v8::HeapGraphNode* child = prop->GetToNode();
+ v8::String::AsciiValue child_name(child->GetName());
+ if (child->GetType() == type && strcmp(name, *child_name) == 0)
+ return child;
+ }
+ return NULL;
}
-static int GetNumObjects(int log_skip, const std::string& constructor) {
- std::string v8_log = GetV8Log(log_skip);
- size_t sample_begin = v8_log.rfind(kHeapSampleBegin);
- CHECK(sample_begin != std::string::npos);
- std::string log_entry =
- kHeapObjectLogEntryPrefix + constructor + kHeapObjectLogEntrySuffix;
- size_t i = v8_log.find(log_entry, sample_begin);
- if (i == std::string::npos) return 0;
- i += log_entry.size();
- size_t j = v8_log.find(",", i);
- CHECK(j != std::string::npos);
- int num_objects;
- CHECK(base::StringToInt(v8_log.begin() + i,
- v8_log.begin() + j,
- &num_objects));
- return num_objects;
+static int GetNumObjects(const char* constructor) {
+ v8::HandleScope scope;
+ const v8::HeapSnapshot* snapshot =
+ v8::HeapProfiler::TakeSnapshot(v8::String::New(""),
+ v8::HeapSnapshot::kAggregated);
+ CHECK(snapshot);
+ const v8::HeapGraphNode* node = GetChild(snapshot->GetRoot(),
+ v8::HeapGraphNode::kObject,
+ constructor);
+ return node != NULL ? node->GetInstancesCount() : 0;
}
// This test tries to create a reference cycle between node and its listener.
// See http://crbug/17400.
TEST_F(ListenerLeakTest, ReferenceCycle) {
- const int log_skip = static_cast<int>(GetV8Log(0).size());
FilePath listener_file;
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &listener_file));
listener_file = listener_file.Append(FILE_PATH_LITERAL("webkit"))
@@ -62,13 +54,12 @@ TEST_F(ListenerLeakTest, ReferenceCycle) {
.Append(FILE_PATH_LITERAL("listener_leak1.html"));
test_shell_->LoadFile(listener_file);
test_shell_->WaitTestFinished();
- ASSERT_EQ(0, GetNumObjects(log_skip, "EventListenerLeakTestObject1"));
+ ASSERT_EQ(0, GetNumObjects("EventListenerLeakTestObject1"));
}
// This test sets node onclick many times to expose a possible memory
// leak where all listeners get referenced by the node.
TEST_F(ListenerLeakTest, HiddenReferences) {
- const int log_skip = static_cast<int>(GetV8Log(0).size());
FilePath listener_file;
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &listener_file));
listener_file = listener_file.Append(FILE_PATH_LITERAL("webkit"))
@@ -77,6 +68,6 @@ TEST_F(ListenerLeakTest, HiddenReferences) {
.Append(FILE_PATH_LITERAL("listener_leak2.html"));
test_shell_->LoadFile(listener_file);
test_shell_->WaitTestFinished();
- ASSERT_EQ(1, GetNumObjects(log_skip, "EventListenerLeakTestObject2"));
+ ASSERT_EQ(1, GetNumObjects("EventListenerLeakTestObject2"));
}
diff --git a/webkit/tools/test_shell/run_all_tests.cc b/webkit/tools/test_shell/run_all_tests.cc
index 59357df..b2d422e 100644
--- a/webkit/tools/test_shell/run_all_tests.cc
+++ b/webkit/tools/test_shell/run_all_tests.cc
@@ -65,7 +65,7 @@ class TestShellTestSuite : public base::TestSuite {
// triggering function.
std::string js_flags =
parsed_command_line.GetSwitchValueASCII(test_shell::kJavaScriptFlags);
- js_flags += " --logfile=* --log_gc --expose_gc";
+ js_flags += " --expose_gc";
webkit_glue::SetJavaScriptFlags(js_flags);
// Suppress error dialogs and do not show GP fault error box on Windows.