diff options
author | chase@chromium.org <chase@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-14 20:26:41 +0000 |
---|---|---|
committer | chase@chromium.org <chase@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-14 20:26:41 +0000 |
commit | 6eb717945d816bb5b5e410183c948cdf136c0be1 (patch) | |
tree | ac6e9dd0b44872661f0c5d41f65ad4746d7df984 /chrome/test/tab_switching | |
parent | 36779fae2a6b23bf2673021cd12bcf6881c89c98 (diff) | |
download | chromium_src-6eb717945d816bb5b5e410183c948cdf136c0be1.zip chromium_src-6eb717945d816bb5b5e410183c948cdf136c0be1.tar.gz chromium_src-6eb717945d816bb5b5e410183c948cdf136c0be1.tar.bz2 |
Add reference build to tab switching tests.
Moves 'UseReferenceBuild' from NewTabUIStartupTest
into UITest. Run multiple tab switching tests for
the current and reference build. Locate the debug log
based on the current browser directory. Reformat the
output of the test so we print "times" as our test
type instead of "tab_switch" (probably requires a perf
dashboard update).
BUG=25200
TEST=tab switching test also tests reference build
Review URL: http://codereview.chromium.org/491090
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34483 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/tab_switching')
-rw-r--r-- | chrome/test/tab_switching/tab_switching_test.cc | 182 |
1 files changed, 108 insertions, 74 deletions
diff --git a/chrome/test/tab_switching/tab_switching_test.cc b/chrome/test/tab_switching/tab_switching_test.cc index 727c0f6..a367414 100644 --- a/chrome/test/tab_switching/tab_switching_test.cc +++ b/chrome/test/tab_switching/tab_switching_test.cc @@ -6,9 +6,11 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/platform_thread.h" +#include "base/time.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/env_vars.h" #include "chrome/common/pref_names.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/browser_proxy.h" @@ -16,7 +18,7 @@ #include "googleurl/src/gurl.h" #include "net/base/net_util.h" -#define NUMBER_OF_ITERATIONS 5 +using base::TimeDelta; namespace { @@ -36,78 +38,104 @@ class TabSwitchingUITest : public UITest { show_window_ = true; } - void RunTabSwitchingUITest() { - // Create a browser proxy. - browser_proxy_ = automation()->GetBrowserWindow(0); - - // Open all the tabs. - int initial_tab_count = 0; - ASSERT_TRUE(browser_proxy_->GetTabCount(&initial_tab_count)); - int new_tab_count = OpenTabs(); - ASSERT_TRUE(browser_proxy_->WaitForTabCountToBecome( - initial_tab_count + new_tab_count, 10000)); - - // Switch linearly between tabs. - browser_proxy_->ActivateTab(0); - int final_tab_count = 0; - ASSERT_TRUE(browser_proxy_->GetTabCount(&final_tab_count)); - for (int i = initial_tab_count; i < final_tab_count; ++i) { - browser_proxy_->ActivateTab(i); - ASSERT_TRUE(browser_proxy_->WaitForTabToBecomeActive(i, 10000)); - } + void SetUp() { + // Set the log_file_name_ path according to the selected browser_directory_. + log_file_name_ = browser_directory_.AppendASCII("chrome_debug.log"); + + // Set the log file path for the browser test. +#if defined(OS_WIN) + SetEnvironmentVariable(env_vars::kLogFileName, + log_file_name_.value().c_str()); +#else + setenv(WideToASCII(env_vars::kLogFileName).c_str(), + log_file_name_.value().c_str(), 1); +#endif + + // Run the rest of the UITest initialization. + UITest::SetUp(); + } + + static const int kNumCycles = 5; + + void PrintTimings(const char* label, TimeDelta timings[kNumCycles], + bool important) { + std::string times; + for (int i = 0; i < kNumCycles; ++i) + StringAppendF(×, "%.2f,", timings[i].InMillisecondsF()); + PrintResultList("times", "", label, times, "ms", important); + } - // Close the browser to force a dump of log. - bool application_closed = false; - EXPECT_TRUE(CloseBrowser(browser_proxy_.get(), &application_closed)); - - // Now open the corresponding log file and collect average and std dev from - // the histogram stats generated for RenderWidgetHost_TabSwitchPaintDuration - FilePath log_file_name; - ASSERT_TRUE(PathService::Get(chrome::DIR_LOGS, &log_file_name)); - log_file_name = log_file_name.AppendASCII("chrome_debug.log"); - - bool log_has_been_dumped = false; - std::string contents; - int max_tries = 20; - do { - log_has_been_dumped = file_util::ReadFileToString(log_file_name, - &contents); - if (!log_has_been_dumped) - PlatformThread::Sleep(100); - } while (!log_has_been_dumped && max_tries--); - ASSERT_TRUE(log_has_been_dumped) << "Failed to read the log file"; - - // Parse the contents to get average and std deviation. - std::string average("0.0"), std_dev("0.0"); - const std::string average_str("average = "); - const std::string std_dev_str("standard deviation = "); - std::string::size_type pos = contents.find( - "Histogram: MPArch.RWH_TabSwitchPaintDuration", 0); - std::string::size_type comma_pos; - std::string::size_type number_length; - - ASSERT_NE(pos, std::string::npos) << - "Histogram: MPArch.RWH_TabSwitchPaintDuration wasn't found\n" << - contents; - - // Get the average. - pos = contents.find(average_str, pos); - comma_pos = contents.find(",", pos); - pos += average_str.length(); - number_length = comma_pos - pos; - average = contents.substr(pos, number_length); - - // Get the std dev. - pos = contents.find(std_dev_str, pos); - pos += std_dev_str.length(); - comma_pos = contents.find(" ", pos); - number_length = comma_pos - pos; - std_dev = contents.substr(pos, number_length); - - // Print the average and standard deviation. - PrintResultMeanAndError("tab_switch", "", "t", - average + ", " + std_dev, "ms", - true /* important */); + void RunTabSwitchingUITest(const char* label, bool important) { + // Shut down from window UITest sets up automatically. + UITest::TearDown(); + + TimeDelta timings[kNumCycles]; + for (int i = 0; i < kNumCycles; ++i) { + // Prepare for this test run. + SetUp(); + + // Create a browser proxy. + browser_proxy_ = automation()->GetBrowserWindow(0); + + // Open all the tabs. + int initial_tab_count = 0; + ASSERT_TRUE(browser_proxy_->GetTabCount(&initial_tab_count)); + int new_tab_count = OpenTabs(); + ASSERT_TRUE(browser_proxy_->WaitForTabCountToBecome( + initial_tab_count + new_tab_count, 10000)); + + // Switch linearly between tabs. + browser_proxy_->ActivateTab(0); + int final_tab_count = 0; + ASSERT_TRUE(browser_proxy_->GetTabCount(&final_tab_count)); + for (int j = initial_tab_count; j < final_tab_count; ++j) { + browser_proxy_->ActivateTab(j); + ASSERT_TRUE(browser_proxy_->WaitForTabToBecomeActive(j, 10000)); + } + + // Close the browser to force a dump of log. + bool application_closed = false; + EXPECT_TRUE(CloseBrowser(browser_proxy_.get(), &application_closed)); + + // Open the corresponding log file and collect average from the + // histogram stats generated for RenderWidgetHost_TabSwitchPaintDuration. + bool log_has_been_dumped = false; + std::string contents; + int max_tries = 20; + do { + log_has_been_dumped = file_util::ReadFileToString(log_file_name_, + &contents); + if (!log_has_been_dumped) + PlatformThread::Sleep(100); + } while (!log_has_been_dumped && max_tries--); + ASSERT_TRUE(log_has_been_dumped) << "Failed to read the log file"; + + // Parse the contents to get average. + int64 average = 0; + const std::string average_str("average = "); + std::string::size_type pos = contents.find( + "Histogram: MPArch.RWH_TabSwitchPaintDuration", 0); + std::string::size_type comma_pos; + std::string::size_type number_length; + + ASSERT_NE(pos, std::string::npos) << + "Histogram: MPArch.RWH_TabSwitchPaintDuration wasn't found\n" << + contents; + + // Get the average. + pos = contents.find(average_str, pos); + comma_pos = contents.find(",", pos); + pos += average_str.length(); + number_length = comma_pos - pos; + average = atoi(contents.substr(pos, number_length).c_str()); + + // Print the average and standard deviation. + timings[i] = TimeDelta::FromMilliseconds(average); + + // Clean up from the test run. + UITest::TearDown(); + } + PrintTimings(label, timings, important); } protected: @@ -133,14 +161,20 @@ class TabSwitchingUITest : public UITest { } FilePath path_prefix_; + FilePath log_file_name_; scoped_refptr<BrowserProxy> browser_proxy_; private: DISALLOW_COPY_AND_ASSIGN(TabSwitchingUITest); }; -TEST_F(TabSwitchingUITest, GenerateTabSwitchStats) { - RunTabSwitchingUITest(); +TEST_F(TabSwitchingUITest, TabSwitch) { + RunTabSwitchingUITest("t", true); +} + +TEST_F(TabSwitchingUITest, TabSwitchRef) { + UseReferenceBuild(); + RunTabSwitchingUITest("t_ref", true); } } // namespace |