| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/eintr_wrapper.h" | |
| 8 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 11 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 13 #include "chrome/browser/net/url_fixer_upper.h" | 12 #include "chrome/browser/net/url_fixer_upper.h" |
| 14 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/test/automation/tab_proxy.h" | 16 #include "chrome/test/automation/tab_proxy.h" |
| 18 #include "chrome/test/automation/window_proxy.h" | 17 #include "chrome/test/automation/window_proxy.h" |
| 19 #include "chrome/test/chrome_process_util.h" | 18 #include "chrome/test/chrome_process_util.h" |
| 20 #include "chrome/test/ui/ui_test.h" | 19 #include "chrome/test/ui/ui_test.h" |
| 21 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 23 | 22 |
| 24 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
| 25 #include <errno.h> | |
| 26 #include <fcntl.h> | |
| 27 #include <string.h> | 24 #include <string.h> |
| 28 #include <sys/resource.h> | 25 #include <sys/resource.h> |
| 29 #endif | 26 #endif |
| 30 | 27 |
| 31 #ifndef NDEBUG | 28 #ifndef NDEBUG |
| 32 #define TEST_ITERATIONS 2 | 29 #define TEST_ITERATIONS 2 |
| 33 #define DATABASE_TEST_ITERATIONS 2 | 30 #define DATABASE_TEST_ITERATIONS 2 |
| 34 #else | 31 #else |
| 35 #define TEST_ITERATIONS 10 | 32 #define TEST_ITERATIONS 10 |
| 36 // For some unknown reason, the DB perf tests are much much slower on the | 33 // For some unknown reason, the DB perf tests are much much slower on the |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } else { | 66 } else { |
| 70 limits.rlim_cur = std::min(max_descriptors, limits.rlim_max); | 67 limits.rlim_cur = std::min(max_descriptors, limits.rlim_max); |
| 71 } | 68 } |
| 72 if (setrlimit(RLIMIT_NOFILE, &limits) != 0) { | 69 if (setrlimit(RLIMIT_NOFILE, &limits) != 0) { |
| 73 PLOG(ERROR) << "Failed to set file descriptor limit"; | 70 PLOG(ERROR) << "Failed to set file descriptor limit"; |
| 74 } | 71 } |
| 75 } else { | 72 } else { |
| 76 PLOG(ERROR) << "Failed to get file descriptor limit"; | 73 PLOG(ERROR) << "Failed to get file descriptor limit"; |
| 77 } | 74 } |
| 78 } | 75 } |
| 76 #endif // OS_MACOSX |
| 79 | 77 |
| 80 void PopulateUBC(const FilePath &test_dir) { | 78 void PopulateBufferCache(const FilePath& test_dir) { |
| 81 // This will recursively walk the directory given and read all the files it | 79 // This will recursively walk the directory given and read all the |
| 82 // finds. This is done so the Mac UBC is likely to have as much loaded as | 80 // files it finds. This is done so the system file cache is likely |
| 83 // possible. Without this, the tests of this build gets one set of timings | 81 // to have as much loaded as possible. Without this, the tests of |
| 84 // and then the reference build test, gets slightly faster ones (even if the | 82 // this build gets one set of timings and then the reference build |
| 85 // reference build is the same binary). The hope is by forcing all the | 83 // test, gets slightly faster ones (even if the reference build is |
| 86 // possible data into the UBC we equalize the tests for comparing timing data. | 84 // the same binary). The hope is by forcing all the possible data |
| 85 // into the cache we equalize the tests for comparing timing data. |
| 87 | 86 |
| 88 // We don't want to walk into .svn dirs, so we have to do the tree walk | 87 // We don't want to walk into .svn dirs, so we have to do the tree walk |
| 89 // ourselves. | 88 // ourselves. |
| 90 | 89 |
| 91 std::vector<FilePath> dirs; | 90 std::vector<FilePath> dirs; |
| 92 dirs.push_back(test_dir); | 91 dirs.push_back(test_dir); |
| 93 const FilePath svn_dir(FILE_PATH_LITERAL(".svn")); | 92 const FilePath svn_dir(FILE_PATH_LITERAL(".svn")); |
| 94 | 93 |
| 95 for (size_t idx = 0; idx < dirs.size(); ++idx) { | 94 for (size_t idx = 0; idx < dirs.size(); ++idx) { |
| 96 file_util::FileEnumerator dir_enumerator(dirs[idx], false, | 95 file_util::FileEnumerator dir_enumerator(dirs[idx], false, |
| 97 file_util::FileEnumerator::DIRECTORIES); | 96 file_util::FileEnumerator::DIRECTORIES); |
| 98 FilePath path; | 97 FilePath path; |
| 99 for (path = dir_enumerator.Next(); | 98 for (path = dir_enumerator.Next(); |
| 100 !path.empty(); | 99 !path.empty(); |
| 101 path = dir_enumerator.Next()) { | 100 path = dir_enumerator.Next()) { |
| 102 if (path.BaseName() != svn_dir) | 101 if (path.BaseName() != svn_dir) |
| 103 dirs.push_back(path); | 102 dirs.push_back(path); |
| 104 } | 103 } |
| 105 } | 104 } |
| 106 | 105 |
| 107 char buf[1024]; | |
| 108 unsigned int loaded = 0; | 106 unsigned int loaded = 0; |
| 109 | 107 |
| 110 // We seem to have some files in the data dirs that are just there for | 108 // We seem to have some files in the data dirs that are just there for |
| 111 // reference, make a quick attempt to skip them by matching suffixes. | 109 // reference, make a quick attempt to skip them by matching suffixes. |
| 112 std::vector<FilePath::StringType> ignore_suffixes; | 110 std::vector<FilePath::StringType> ignore_suffixes; |
| 113 ignore_suffixes.push_back(FILE_PATH_LITERAL(".orig.html")); | 111 ignore_suffixes.push_back(FILE_PATH_LITERAL(".orig.html")); |
| 114 ignore_suffixes.push_back(FILE_PATH_LITERAL(".html-original")); | 112 ignore_suffixes.push_back(FILE_PATH_LITERAL(".html-original")); |
| 115 | 113 |
| 116 std::vector<FilePath>::const_iterator iter; | 114 std::vector<FilePath>::const_iterator iter; |
| 117 for (iter = dirs.begin(); iter != dirs.end(); ++iter) { | 115 for (iter = dirs.begin(); iter != dirs.end(); ++iter) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 134 if ((base_name_size > suffix.size()) && | 132 if ((base_name_size > suffix.size()) && |
| 135 (base_name.value().compare(base_name_size - suffix.size(), | 133 (base_name.value().compare(base_name_size - suffix.size(), |
| 136 suffix.size(), suffix) == 0)) { | 134 suffix.size(), suffix) == 0)) { |
| 137 should_skip = true; | 135 should_skip = true; |
| 138 break; | 136 break; |
| 139 } | 137 } |
| 140 } | 138 } |
| 141 if (should_skip) | 139 if (should_skip) |
| 142 continue; | 140 continue; |
| 143 | 141 |
| 144 // Read the file to get it into the UBC | 142 // Read the file fully to get it into the cache. |
| 145 int fd = open(path.value().c_str(), O_RDONLY); | 143 // We don't care what the contents are. |
| 146 if (fd >= 0) { | 144 if (file_util::ReadFileToString(path, NULL)) |
| 147 ++loaded; | 145 ++loaded; |
| 148 while (HANDLE_EINTR(read(fd, buf, sizeof(buf))) > 0) { | |
| 149 } | |
| 150 HANDLE_EINTR(close(fd)); | |
| 151 } | |
| 152 } | 146 } |
| 153 } | 147 } |
| 154 LOG(INFO) << "UBC should be loaded with " << loaded << " files."; | 148 LOG(INFO) << "Buffer cache should be primed with " << loaded << " files."; |
| 155 } | 149 } |
| 156 #endif // defined(OS_MACOSX) | |
| 157 | 150 |
| 158 class PageCyclerTest : public UITest { | 151 class PageCyclerTest : public UITest { |
| 159 protected: | 152 protected: |
| 160 bool print_times_only_; | 153 bool print_times_only_; |
| 161 #if defined(OS_MACOSX) | 154 #if defined(OS_MACOSX) |
| 162 rlim_t fd_limit_; | 155 rlim_t fd_limit_; |
| 163 #endif | 156 #endif |
| 164 public: | 157 public: |
| 165 PageCyclerTest() | 158 PageCyclerTest() |
| 166 : print_times_only_(false) { | 159 : print_times_only_(false) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return TEST_ITERATIONS; | 194 return TEST_ITERATIONS; |
| 202 } | 195 } |
| 203 | 196 |
| 204 // For HTTP tests, the name must be safe for use in a URL without escaping. | 197 // For HTTP tests, the name must be safe for use in a URL without escaping. |
| 205 void RunPageCycler(const char* name, std::wstring* pages, | 198 void RunPageCycler(const char* name, std::wstring* pages, |
| 206 std::string* timings, bool use_http) { | 199 std::string* timings, bool use_http) { |
| 207 FilePath test_path = GetDataPath(name); | 200 FilePath test_path = GetDataPath(name); |
| 208 ASSERT_TRUE(file_util::DirectoryExists(test_path)) | 201 ASSERT_TRUE(file_util::DirectoryExists(test_path)) |
| 209 << "Missing test directory " << test_path.value(); | 202 << "Missing test directory " << test_path.value(); |
| 210 | 203 |
| 211 #if defined(OS_MACOSX) | 204 PopulateBufferCache(test_path); |
| 212 PopulateUBC(test_path); | |
| 213 #endif | |
| 214 | 205 |
| 215 GURL test_url; | 206 GURL test_url; |
| 216 if (use_http) { | 207 if (use_http) { |
| 217 test_url = GURL(std::string(kBaseUrl) + name + "/start.html"); | 208 test_url = GURL(std::string(kBaseUrl) + name + "/start.html"); |
| 218 } else { | 209 } else { |
| 219 test_path = test_path.Append(FILE_PATH_LITERAL("start.html")); | 210 test_path = test_path.Append(FILE_PATH_LITERAL("start.html")); |
| 220 test_url = net::FilePathToFileURL(test_path); | 211 test_url = net::FilePathToFileURL(test_path); |
| 221 } | 212 } |
| 222 | 213 |
| 223 // run N iterations | 214 // run N iterations |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 PAGE_CYCLER_DATABASE_TESTS("insert-transactions", | 481 PAGE_CYCLER_DATABASE_TESTS("insert-transactions", |
| 491 InsertTransactions); | 482 InsertTransactions); |
| 492 PAGE_CYCLER_DATABASE_TESTS("update-transactions", | 483 PAGE_CYCLER_DATABASE_TESTS("update-transactions", |
| 493 UpdateTransactions); | 484 UpdateTransactions); |
| 494 PAGE_CYCLER_DATABASE_TESTS("delete-transactions", | 485 PAGE_CYCLER_DATABASE_TESTS("delete-transactions", |
| 495 DeleteTransactions); | 486 DeleteTransactions); |
| 496 PAGE_CYCLER_DATABASE_TESTS("pseudo-random-transactions", | 487 PAGE_CYCLER_DATABASE_TESTS("pseudo-random-transactions", |
| 497 PseudoRandomTransactions); | 488 PseudoRandomTransactions); |
| 498 | 489 |
| 499 } // namespace | 490 } // namespace |
| OLD | NEW |