| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/browser/url_fixer_upper.h" | 11 #include "chrome/browser/url_fixer_upper.h" |
| 12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/chrome_process_filter.h" | 14 #include "chrome/common/chrome_process_filter.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/test/automation/browser_proxy.h" | 16 #include "chrome/test/automation/browser_proxy.h" |
| 17 #include "chrome/test/automation/tab_proxy.h" | 17 #include "chrome/test/automation/tab_proxy.h" |
| 18 #include "chrome/test/automation/window_proxy.h" | 18 #include "chrome/test/automation/window_proxy.h" |
| 19 #include "chrome/test/ui/ui_test.h" | 19 #include "chrome/test/ui/ui_test.h" |
| 20 #include "chrome/test/perf/mem_usage.h" | 20 #include "chrome/test/perf/mem_usage.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 static const wchar_t kTempDirName[] = L"memory_test_profile"; | 26 static const wchar_t kTempDirName[] = L"memory_test_profile"; |
| 27 | 27 |
| 28 class MemoryTest : public UITest { | 28 class MemoryTest : public UITest { |
| 29 public: | 29 public: |
| 30 MemoryTest() { | 30 MemoryTest() : cleanup_temp_dir_on_exit_(false) { |
| 31 show_window_ = true; | 31 show_window_ = true; |
| 32 | 32 |
| 33 // For now, turn off plugins because they crash like crazy. | 33 // For now, turn off plugins because they crash like crazy. |
| 34 // TODO(mbelshe): Fix Chrome to not crash with plugins. | 34 // TODO(mbelshe): Fix Chrome to not crash with plugins. |
| 35 CommandLine::AppendSwitch(&launch_arguments_, switches::kDisablePlugins); | 35 CommandLine::AppendSwitch(&launch_arguments_, switches::kDisablePlugins); |
| 36 | 36 |
| 37 CommandLine::AppendSwitch(&launch_arguments_, switches::kEnableLogging); | 37 CommandLine::AppendSwitch(&launch_arguments_, switches::kEnableLogging); |
| 38 | 38 |
| 39 // Use the playback cache, but don't use playback events. | 39 // Use the playback cache, but don't use playback events. |
| 40 CommandLine::AppendSwitch(&launch_arguments_, switches::kPlaybackMode); | 40 CommandLine::AppendSwitch(&launch_arguments_, switches::kPlaybackMode); |
| 41 CommandLine::AppendSwitch(&launch_arguments_, switches::kNoEvents); | 41 CommandLine::AppendSwitch(&launch_arguments_, switches::kNoEvents); |
| 42 | 42 |
| 43 // Get the specified user data dir (optional) | 43 // Get the specified user data dir (optional) |
| 44 std::wstring profile_dir = | 44 std::wstring profile_dir = |
| 45 CommandLine().GetSwitchValue(switches::kUserDataDir); | 45 CommandLine().GetSwitchValue(switches::kUserDataDir); |
| 46 | 46 |
| 47 if (profile_dir.length() == 0) { | 47 if (profile_dir.length() == 0) { |
| 48 // Compute the user-data-dir which contains our test cache. | 48 // Compute the user-data-dir which contains our test cache. |
| 49 PathService::Get(base::DIR_EXE, &profile_dir); | 49 PathService::Get(base::DIR_EXE, &profile_dir); |
| 50 file_util::UpOneDirectory(&profile_dir); | 50 file_util::UpOneDirectory(&profile_dir); |
| 51 file_util::UpOneDirectory(&profile_dir); | 51 file_util::UpOneDirectory(&profile_dir); |
| 52 file_util::AppendToPath(&profile_dir, L"data"); | 52 file_util::AppendToPath(&profile_dir, L"data"); |
| 53 file_util::AppendToPath(&profile_dir, L"memory_test"); | 53 file_util::AppendToPath(&profile_dir, L"memory_test"); |
| 54 file_util::AppendToPath(&profile_dir, L"general_mix"); | 54 file_util::AppendToPath(&profile_dir, L"general_mix"); |
| 55 } | |
| 56 | 55 |
| 57 if (!SetupTempDirectory(profile_dir)) { | 56 if (!SetupTempDirectory(profile_dir)) { |
| 58 // There isn't really a way to fail gracefully here. | 57 // There isn't really a way to fail gracefully here. |
| 59 // Neither this constuctor nor the SetUp() method return | 58 // Neither this constuctor nor the SetUp() method return |
| 60 // status to the caller. So, just fall through using the | 59 // status to the caller. So, just fall through using the |
| 61 // default profile and log this. The failure will be | 60 // default profile and log this. The failure will be |
| 62 // obvious. | 61 // obvious. |
| 63 LOG(ERROR) << "Error preparing temp directory for test"; | 62 LOG(ERROR) << "Error preparing temp directory for test"; |
| 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 CommandLine::AppendSwitchWithValue(&launch_arguments_, | 66 CommandLine::AppendSwitchWithValue(&launch_arguments_, |
| 67 switches::kUserDataDir, | 67 switches::kUserDataDir, |
| 68 user_data_dir_); | 68 user_data_dir_); |
| 69 } | 69 } |
| 70 | 70 |
| 71 ~MemoryTest() { | 71 ~MemoryTest() { |
| 72 // Cleanup our temporary directory. | 72 // Cleanup our temporary directory. |
| 73 if (user_data_dir_.length() > 0) | 73 if (cleanup_temp_dir_on_exit_) |
| 74 file_util::Delete(user_data_dir_, true); | 74 file_util::Delete(user_data_dir_, true); |
| 75 } | 75 } |
| 76 | 76 |
| 77 // TODO(mbelshe): Separate this data to an external file. | 77 // TODO(mbelshe): Separate this data to an external file. |
| 78 // This memory test loads a set of URLs across a set of tabs, maintaining the | 78 // This memory test loads a set of URLs across a set of tabs, maintaining the |
| 79 // number of concurrent open tabs at num_target_tabs. | 79 // number of concurrent open tabs at num_target_tabs. |
| 80 // <NEWTAB> is a special URL which informs the loop when we should create a | 80 // <NEWTAB> is a special URL which informs the loop when we should create a |
| 81 // new tab. | 81 // new tab. |
| 82 // <PAUSE> is a special URL that informs the loop to pause before proceeding | 82 // <PAUSE> is a special URL that informs the loop to pause before proceeding |
| 83 // to the next URL. | 83 // to the next URL. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 int tab_index = counter % num_target_tabs; // A pseudo-random tab. | 241 int tab_index = counter % num_target_tabs; // A pseudo-random tab. |
| 242 tab.reset(window->GetTab(tab_index)); | 242 tab.reset(window->GetTab(tab_index)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 const int kMaxWaitTime = 5000; | 245 const int kMaxWaitTime = 5000; |
| 246 bool timed_out = false; | 246 bool timed_out = false; |
| 247 tab->NavigateToURLWithTimeout(GURL(urls[counter]), kMaxWaitTime, | 247 tab->NavigateToURLWithTimeout(GURL(urls[counter]), kMaxWaitTime, |
| 248 &timed_out); | 248 &timed_out); |
| 249 if (timed_out) | 249 if (timed_out) |
| 250 printf("warning: %s timed out!\n", urls[counter].c_str()); | 250 printf("warning: %s timed out!\n", urls[counter].c_str()); |
| 251 |
| 252 // TODO(mbelshe): Bug 2953 |
| 253 // The automation crashes periodically if we cycle too quickly. |
| 254 // To make these tests more reliable, slowing them down a bit. |
| 255 Sleep(100); |
| 251 } | 256 } |
| 252 size_t stop_size = GetSystemCommitCharge(); | 257 size_t stop_size = GetSystemCommitCharge(); |
| 253 | 258 |
| 254 PrintResults(test_name, stop_size - start_size); | 259 PrintResults(test_name, stop_size - start_size); |
| 255 } | 260 } |
| 256 | 261 |
| 257 void PrintResults(const wchar_t* test_name, size_t commit_size) { | 262 void PrintResults(const wchar_t* test_name, size_t commit_size) { |
| 258 PrintMemoryUsageInfo(test_name); | 263 PrintMemoryUsageInfo(test_name); |
| 259 std::wstring trace_name(test_name); | 264 std::wstring trace_name(test_name); |
| 260 trace_name.append(L"_cc"); | 265 trace_name.append(L"_cc"); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 false /* not important */); | 369 false /* not important */); |
| 365 } | 370 } |
| 366 | 371 |
| 367 private: | 372 private: |
| 368 // Setup a temporary directory to store the profile to use | 373 // Setup a temporary directory to store the profile to use |
| 369 // with these tests. | 374 // with these tests. |
| 370 // Input: | 375 // Input: |
| 371 // src_dir is set to the source directory | 376 // src_dir is set to the source directory |
| 372 // Output: | 377 // Output: |
| 373 // On success, modifies user_data_dir_ to be a new profile directory | 378 // On success, modifies user_data_dir_ to be a new profile directory |
| 379 // and sets cleanup_temp_dir_on_exit_ to true. |
| 374 bool SetupTempDirectory(std::wstring src_dir) { | 380 bool SetupTempDirectory(std::wstring src_dir) { |
| 381 LOG(INFO) << "Setting up temp directory in " << src_dir.c_str(); |
| 375 // We create a copy of the test dir and use it so that each | 382 // We create a copy of the test dir and use it so that each |
| 376 // run of this test starts with the same data. Running this | 383 // run of this test starts with the same data. Running this |
| 377 // test has the side effect that it will change the profile. | 384 // test has the side effect that it will change the profile. |
| 378 std::wstring temp_dir; | 385 std::wstring temp_dir; |
| 379 if (!file_util::CreateNewTempDirectory(kTempDirName, &temp_dir)) | 386 if (!file_util::CreateNewTempDirectory(kTempDirName, &temp_dir)) { |
| 387 LOG(ERROR) << "Could not create temp directory:" << kTempDirName; |
| 380 return false; | 388 return false; |
| 389 } |
| 381 | 390 |
| 382 src_dir.append(L"\\*"); | 391 src_dir.append(L"\\*"); |
| 383 | 392 |
| 384 if (!file_util::CopyDirectory(src_dir, temp_dir, true)) | 393 if (!file_util::CopyDirectory(src_dir, temp_dir, true)) { |
| 394 LOG(ERROR) << "Could not copy temp directory"; |
| 385 return false; | 395 return false; |
| 396 } |
| 386 | 397 |
| 387 user_data_dir_ = temp_dir; | 398 user_data_dir_ = temp_dir; |
| 399 cleanup_temp_dir_on_exit_ = true; |
| 400 LOG(INFO) << "Finished temp directory setup."; |
| 388 return true; | 401 return true; |
| 389 } | 402 } |
| 390 | 403 |
| 404 bool cleanup_temp_dir_on_exit_; |
| 391 std::wstring user_data_dir_; | 405 std::wstring user_data_dir_; |
| 392 }; | 406 }; |
| 393 | 407 |
| 394 class MemoryReferenceTest : public MemoryTest { | 408 class MemoryReferenceTest : public MemoryTest { |
| 395 public: | 409 public: |
| 396 // override the browser directory that is used by UITest::SetUp to cause it | 410 // override the browser directory that is used by UITest::SetUp to cause it |
| 397 // to use the reference build instead. | 411 // to use the reference build instead. |
| 398 void SetUp() { | 412 void SetUp() { |
| 399 std::wstring dir; | 413 std::wstring dir; |
| 400 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); | 414 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 417 } | 431 } |
| 418 | 432 |
| 419 TEST_F(MemoryTest, FiveTabTest) { | 433 TEST_F(MemoryTest, FiveTabTest) { |
| 420 RunTest(L"5t", 5); | 434 RunTest(L"5t", 5); |
| 421 } | 435 } |
| 422 | 436 |
| 423 TEST_F(MemoryTest, TwelveTabTest) { | 437 TEST_F(MemoryTest, TwelveTabTest) { |
| 424 RunTest(L"12t", 12); | 438 RunTest(L"12t", 12); |
| 425 } | 439 } |
| 426 | 440 |
| OLD | NEW |