| 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/file_path.h" |
| 5 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 7 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
| 8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/test_file_util.h" |
| 9 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "chrome/common/chrome_constants.h" |
| 10 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/test/ui/ui_test.h" | 14 #include "chrome/test/ui/ui_test.h" |
| 12 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 13 | 16 |
| 14 using base::TimeDelta; | 17 using base::TimeDelta; |
| 15 using base::TimeTicks; | 18 using base::TimeTicks; |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 // Wrapper around CopyFile to retry 10 times if there is an error. | |
| 20 // For some reasons on buildbot it happens quite often that | |
| 21 // the test fails because the dll is still in use. | |
| 22 bool CopyFileWrapper(const std::wstring &src, const std::wstring &dest) { | |
| 23 for (int i = 0; i < 10; ++i) { | |
| 24 if (file_util::CopyFile(src, dest)) | |
| 25 return true; | |
| 26 Sleep(1000); | |
| 27 } | |
| 28 return false; | |
| 29 } | |
| 30 | |
| 31 class StartupTest : public UITest { | 22 class StartupTest : public UITest { |
| 32 public: | 23 public: |
| 33 StartupTest() { | 24 StartupTest() { |
| 34 show_window_ = true; | 25 show_window_ = true; |
| 35 pages_ = "about:blank"; | 26 pages_ = "about:blank"; |
| 36 } | 27 } |
| 37 void SetUp() {} | 28 void SetUp() {} |
| 38 void TearDown() {} | 29 void TearDown() {} |
| 39 | 30 |
| 40 void RunStartupTest(const wchar_t* graph, const wchar_t* trace, | 31 void RunStartupTest(const wchar_t* graph, const wchar_t* trace, |
| 41 bool test_cold, bool important) { | 32 bool test_cold, bool important) { |
| 42 const int kNumCycles = 20; | 33 const int kNumCycles = 20; |
| 43 | 34 |
| 44 // Make a backup of gears.dll so we can overwrite the original, which | |
| 45 // flushes the disk cache for that file. | |
| 46 std::wstring chrome_dll, chrome_dll_copy; | |
| 47 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &chrome_dll)); | |
| 48 file_util::AppendToPath(&chrome_dll, L"chrome.dll"); | |
| 49 chrome_dll_copy = chrome_dll + L".copy"; | |
| 50 ASSERT_TRUE(CopyFileWrapper(chrome_dll, chrome_dll_copy)); | |
| 51 | |
| 52 std::wstring gears_dll, gears_dll_copy; | |
| 53 ASSERT_TRUE(PathService::Get(chrome::FILE_GEARS_PLUGIN, &gears_dll)); | |
| 54 gears_dll_copy = gears_dll + L".copy"; | |
| 55 ASSERT_TRUE(CopyFileWrapper(gears_dll, gears_dll_copy)); | |
| 56 | |
| 57 TimeDelta timings[kNumCycles]; | 35 TimeDelta timings[kNumCycles]; |
| 58 for (int i = 0; i < kNumCycles; ++i) { | 36 for (int i = 0; i < kNumCycles; ++i) { |
| 59 if (test_cold) { | 37 if (test_cold) { |
| 60 ASSERT_TRUE(CopyFileWrapper(chrome_dll_copy, chrome_dll)); | 38 FilePath dir_app; |
| 61 ASSERT_TRUE(CopyFileWrapper(gears_dll_copy, gears_dll)); | 39 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir_app)); |
| 40 |
| 41 FilePath chrome_exe(dir_app.Append( |
| 42 FilePath::FromWStringHack(chrome::kBrowserProcessExecutableName))); |
| 43 ASSERT_TRUE(file_util::EvictFileFromSystemCache(chrome_exe)); |
| 44 #if defined(OS_WIN) |
| 45 // TODO(port): these files do not exist on other platforms. |
| 46 // Decide what to do. |
| 47 |
| 48 FilePath chrome_dll(dir_app.Append(FILE_PATH_LITERAL("chrome.dll"))); |
| 49 ASSERT_TRUE(file_util::EvictFileFromSystemCache(chrome_dll)); |
| 50 |
| 51 FilePath gears_dll; |
| 52 ASSERT_TRUE(PathService::Get(chrome::FILE_GEARS_PLUGIN, &gears_dll)); |
| 53 ASSERT_TRUE(file_util::EvictFileFromSystemCache(gears_dll)); |
| 54 #endif // defined(OS_WIN) |
| 62 } | 55 } |
| 63 | 56 |
| 64 UITest::SetUp(); | 57 UITest::SetUp(); |
| 65 TimeTicks end_time = TimeTicks::Now(); | 58 TimeTicks end_time = TimeTicks::Now(); |
| 66 timings[i] = end_time - browser_launch_time_; | 59 timings[i] = end_time - browser_launch_time_; |
| 67 // TODO(beng): Can't shut down so quickly. Figure out why, and fix. If we | 60 // TODO(beng): Can't shut down so quickly. Figure out why, and fix. If we |
| 68 // do, we crash. | 61 // do, we crash. |
| 69 PlatformThread::Sleep(50); | 62 PlatformThread::Sleep(50); |
| 70 UITest::TearDown(); | 63 UITest::TearDown(); |
| 71 | 64 |
| 72 if (i == 0) { | 65 if (i == 0) { |
| 73 // Re-use the profile data after first run so that the noise from | 66 // Re-use the profile data after first run so that the noise from |
| 74 // creating databases doesn't impact all the runs. | 67 // creating databases doesn't impact all the runs. |
| 75 clear_profile_ = false; | 68 clear_profile_ = false; |
| 76 } | 69 } |
| 77 } | 70 } |
| 78 | 71 |
| 79 ASSERT_TRUE(file_util::Delete(chrome_dll_copy, false)); | |
| 80 ASSERT_TRUE(file_util::Delete(gears_dll_copy, false)); | |
| 81 | |
| 82 std::wstring times; | 72 std::wstring times; |
| 83 for (int i = 0; i < kNumCycles; ++i) | 73 for (int i = 0; i < kNumCycles; ++i) |
| 84 StringAppendF(×, L"%.2f,", timings[i].InMillisecondsF()); | 74 StringAppendF(×, L"%.2f,", timings[i].InMillisecondsF()); |
| 85 PrintResultList(graph, L"", trace, times, L"ms", important); | 75 PrintResultList(graph, L"", trace, times, L"ms", important); |
| 86 } | 76 } |
| 87 | 77 |
| 88 protected: | 78 protected: |
| 89 std::string pages_; | 79 std::string pages_; |
| 90 }; | 80 }; |
| 91 | 81 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 109 void SetUp() { | 99 void SetUp() { |
| 110 std::wstring file_url; | 100 std::wstring file_url; |
| 111 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &file_url)); | 101 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &file_url)); |
| 112 file_util::AppendToPath(&file_url, L"empty.html"); | 102 file_util::AppendToPath(&file_url, L"empty.html"); |
| 113 ASSERT_TRUE(file_util::PathExists(file_url)); | 103 ASSERT_TRUE(file_util::PathExists(file_url)); |
| 114 launch_arguments_.AppendLooseValue(file_url); | 104 launch_arguments_.AppendLooseValue(file_url); |
| 115 | 105 |
| 116 pages_ = WideToUTF8(file_url); | 106 pages_ = WideToUTF8(file_url); |
| 117 } | 107 } |
| 118 }; | 108 }; |
| 109 |
| 119 } // namespace | 110 } // namespace |
| 120 | 111 |
| 121 TEST_F(StartupTest, Perf) { | 112 TEST_F(StartupTest, Perf) { |
| 122 RunStartupTest(L"warm", L"t", false /* not cold */, true /* important */); | 113 RunStartupTest(L"warm", L"t", false /* not cold */, true /* important */); |
| 123 } | 114 } |
| 124 | 115 |
| 116 #if defined(OS_WIN) |
| 117 // TODO(port): Enable reference tests on other platforms. |
| 118 |
| 125 TEST_F(StartupReferenceTest, Perf) { | 119 TEST_F(StartupReferenceTest, Perf) { |
| 126 RunStartupTest(L"warm", L"t_ref", false /* not cold */, | 120 RunStartupTest(L"warm", L"t_ref", false /* not cold */, |
| 127 true /* important */); | 121 true /* important */); |
| 128 } | 122 } |
| 129 | 123 |
| 130 // TODO(mpcomplete): Should we have reference timings for all these? | 124 // TODO(mpcomplete): Should we have reference timings for all these? |
| 131 | 125 |
| 132 TEST_F(StartupTest, PerfCold) { | 126 TEST_F(StartupTest, PerfCold) { |
| 133 RunStartupTest(L"cold", L"t", true /* cold */, false /* not important */); | 127 RunStartupTest(L"cold", L"t", true /* cold */, false /* not important */); |
| 134 } | 128 } |
| 135 | 129 |
| 136 TEST_F(StartupFileTest, PerfGears) { | 130 TEST_F(StartupFileTest, PerfGears) { |
| 137 RunStartupTest(L"warm", L"gears", false /* not cold */, | 131 RunStartupTest(L"warm", L"gears", false /* not cold */, |
| 138 false /* not important */); | 132 false /* not important */); |
| 139 } | 133 } |
| 140 | 134 |
| 141 TEST_F(StartupFileTest, PerfColdGears) { | 135 TEST_F(StartupFileTest, PerfColdGears) { |
| 142 RunStartupTest(L"cold", L"gears", true /* cold */, | 136 RunStartupTest(L"cold", L"gears", true /* cold */, |
| 143 false /* not important */); | 137 false /* not important */); |
| 144 } | 138 } |
| 145 | 139 |
| 140 #endif // defined(OS_WIN) |
| 141 |
| OLD | NEW |