OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/test/test_launcher.h" | 5 #include "content/public/test/test_launcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 user_data_dir_map_.clear(); | 229 user_data_dir_map_.clear(); |
230 | 230 |
231 // Number of additional tests to run because of dependencies. | 231 // Number of additional tests to run because of dependencies. |
232 size_t additional_tests_to_run_count = 0; | 232 size_t additional_tests_to_run_count = 0; |
233 | 233 |
234 // Compute dependencies of tests to be run. | 234 // Compute dependencies of tests to be run. |
235 for (size_t i = 0; i < test_names.size(); i++) { | 235 for (size_t i = 0; i < test_names.size(); i++) { |
236 std::string full_name(test_names[i]); | 236 std::string full_name(test_names[i]); |
237 std::string pre_test_name(GetPreTestName(full_name)); | 237 std::string pre_test_name(GetPreTestName(full_name)); |
238 | 238 |
239 while (ContainsKey(all_test_names_, pre_test_name)) { | 239 while (base::ContainsKey(all_test_names_, pre_test_name)) { |
240 additional_tests_to_run_count++; | 240 additional_tests_to_run_count++; |
241 | 241 |
242 DCHECK(!ContainsKey(dependent_test_map_, pre_test_name)); | 242 DCHECK(!base::ContainsKey(dependent_test_map_, pre_test_name)); |
243 dependent_test_map_[pre_test_name] = full_name; | 243 dependent_test_map_[pre_test_name] = full_name; |
244 | 244 |
245 DCHECK(!ContainsKey(reverse_dependent_test_map_, full_name)); | 245 DCHECK(!base::ContainsKey(reverse_dependent_test_map_, full_name)); |
246 reverse_dependent_test_map_[full_name] = pre_test_name; | 246 reverse_dependent_test_map_[full_name] = pre_test_name; |
247 | 247 |
248 full_name = pre_test_name; | 248 full_name = pre_test_name; |
249 pre_test_name = GetPreTestName(pre_test_name); | 249 pre_test_name = GetPreTestName(pre_test_name); |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 for (size_t i = 0; i < test_names.size(); i++) { | 253 for (size_t i = 0; i < test_names.size(); i++) { |
254 std::string full_name(test_names[i]); | 254 std::string full_name(test_names[i]); |
255 | 255 |
256 // Make sure no PRE_ tests were requested explicitly. | 256 // Make sure no PRE_ tests were requested explicitly. |
257 DCHECK_EQ(full_name, RemoveAnyPrePrefixes(full_name)); | 257 DCHECK_EQ(full_name, RemoveAnyPrePrefixes(full_name)); |
258 | 258 |
259 if (!ContainsKey(user_data_dir_map_, full_name)) { | 259 if (!base::ContainsKey(user_data_dir_map_, full_name)) { |
260 base::FilePath temp_dir; | 260 base::FilePath temp_dir; |
261 CHECK(base::CreateTemporaryDirInDir(temp_dir_.path(), | 261 CHECK(base::CreateTemporaryDirInDir(temp_dir_.path(), |
262 FILE_PATH_LITERAL("d"), &temp_dir)); | 262 FILE_PATH_LITERAL("d"), &temp_dir)); |
263 user_data_dir_map_[full_name] = temp_dir; | 263 user_data_dir_map_[full_name] = temp_dir; |
264 } | 264 } |
265 | 265 |
266 // If the test has any dependencies, get to the root and start with that. | 266 // If the test has any dependencies, get to the root and start with that. |
267 while (ContainsKey(reverse_dependent_test_map_, full_name)) | 267 while (base::ContainsKey(reverse_dependent_test_map_, full_name)) |
268 full_name = GetPreTestName(full_name); | 268 full_name = GetPreTestName(full_name); |
269 | 269 |
270 std::vector<std::string> test_list; | 270 std::vector<std::string> test_list; |
271 test_list.push_back(full_name); | 271 test_list.push_back(full_name); |
272 DoRunTests(test_launcher, test_list); | 272 DoRunTests(test_launcher, test_list); |
273 } | 273 } |
274 | 274 |
275 return test_names.size() + additional_tests_to_run_count; | 275 return test_names.size() + additional_tests_to_run_count; |
276 } | 276 } |
277 | 277 |
278 size_t WrapperTestLauncherDelegate::RetryTests( | 278 size_t WrapperTestLauncherDelegate::RetryTests( |
279 base::TestLauncher* test_launcher, | 279 base::TestLauncher* test_launcher, |
280 const std::vector<std::string>& test_names) { | 280 const std::vector<std::string>& test_names) { |
281 // List of tests we can kick off right now, depending on no other tests. | 281 // List of tests we can kick off right now, depending on no other tests. |
282 std::vector<std::string> tests_to_run_now; | 282 std::vector<std::string> tests_to_run_now; |
283 | 283 |
284 // We retry at least the tests requested to retry. | 284 // We retry at least the tests requested to retry. |
285 std::set<std::string> test_names_set(test_names.begin(), test_names.end()); | 285 std::set<std::string> test_names_set(test_names.begin(), test_names.end()); |
286 | 286 |
287 // In the face of PRE_ tests, we need to retry the entire chain of tests, | 287 // In the face of PRE_ tests, we need to retry the entire chain of tests, |
288 // from the very first one. | 288 // from the very first one. |
289 for (size_t i = 0; i < test_names.size(); i++) { | 289 for (size_t i = 0; i < test_names.size(); i++) { |
290 std::string test_name(test_names[i]); | 290 std::string test_name(test_names[i]); |
291 while (ContainsKey(reverse_dependent_test_map_, test_name)) { | 291 while (base::ContainsKey(reverse_dependent_test_map_, test_name)) { |
292 test_name = reverse_dependent_test_map_[test_name]; | 292 test_name = reverse_dependent_test_map_[test_name]; |
293 test_names_set.insert(test_name); | 293 test_names_set.insert(test_name); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 // Discard user data directories from any previous runs. Start with | 297 // Discard user data directories from any previous runs. Start with |
298 // fresh state. | 298 // fresh state. |
299 for (UserDataDirMap::const_iterator i = user_data_dir_map_.begin(); | 299 for (UserDataDirMap::const_iterator i = user_data_dir_map_.begin(); |
300 i != user_data_dir_map_.end(); | 300 i != user_data_dir_map_.end(); |
301 ++i) { | 301 ++i) { |
302 // Delete temporary directories now to avoid using too much space in /tmp. | 302 // Delete temporary directories now to avoid using too much space in /tmp. |
303 if (!base::DeleteFile(i->second, true)) { | 303 if (!base::DeleteFile(i->second, true)) { |
304 LOG(WARNING) << "Failed to delete " << i->second.value(); | 304 LOG(WARNING) << "Failed to delete " << i->second.value(); |
305 } | 305 } |
306 } | 306 } |
307 user_data_dir_map_.clear(); | 307 user_data_dir_map_.clear(); |
308 | 308 |
309 for (std::set<std::string>::const_iterator i = test_names_set.begin(); | 309 for (std::set<std::string>::const_iterator i = test_names_set.begin(); |
310 i != test_names_set.end(); | 310 i != test_names_set.end(); |
311 ++i) { | 311 ++i) { |
312 std::string full_name(*i); | 312 std::string full_name(*i); |
313 | 313 |
314 // Make sure PRE_ tests and tests that depend on them share the same | 314 // Make sure PRE_ tests and tests that depend on them share the same |
315 // data directory - based it on the test name without prefixes. | 315 // data directory - based it on the test name without prefixes. |
316 std::string test_name_no_pre(RemoveAnyPrePrefixes(full_name)); | 316 std::string test_name_no_pre(RemoveAnyPrePrefixes(full_name)); |
317 if (!ContainsKey(user_data_dir_map_, test_name_no_pre)) { | 317 if (!base::ContainsKey(user_data_dir_map_, test_name_no_pre)) { |
318 base::FilePath temp_dir; | 318 base::FilePath temp_dir; |
319 CHECK(base::CreateTemporaryDirInDir(temp_dir_.path(), | 319 CHECK(base::CreateTemporaryDirInDir(temp_dir_.path(), |
320 FILE_PATH_LITERAL("d"), &temp_dir)); | 320 FILE_PATH_LITERAL("d"), &temp_dir)); |
321 user_data_dir_map_[test_name_no_pre] = temp_dir; | 321 user_data_dir_map_[test_name_no_pre] = temp_dir; |
322 } | 322 } |
323 | 323 |
324 size_t dot_pos = full_name.find('.'); | 324 size_t dot_pos = full_name.find('.'); |
325 CHECK_NE(dot_pos, std::string::npos); | 325 CHECK_NE(dot_pos, std::string::npos); |
326 std::string test_case_name = full_name.substr(0, dot_pos); | 326 std::string test_case_name = full_name.substr(0, dot_pos); |
327 std::string test_name = full_name.substr(dot_pos + 1); | 327 std::string test_name = full_name.substr(dot_pos + 1); |
328 std::string pre_test_name( | 328 std::string pre_test_name( |
329 test_case_name + "." + kPreTestPrefix + test_name); | 329 test_case_name + "." + kPreTestPrefix + test_name); |
330 if (!ContainsKey(test_names_set, pre_test_name)) | 330 if (!base::ContainsKey(test_names_set, pre_test_name)) |
331 tests_to_run_now.push_back(full_name); | 331 tests_to_run_now.push_back(full_name); |
332 } | 332 } |
333 | 333 |
334 DoRunTests(test_launcher, tests_to_run_now); | 334 DoRunTests(test_launcher, tests_to_run_now); |
335 | 335 |
336 return test_names_set.size(); | 336 return test_names_set.size(); |
337 } | 337 } |
338 | 338 |
339 void WrapperTestLauncherDelegate::DoRunTests( | 339 void WrapperTestLauncherDelegate::DoRunTests( |
340 base::TestLauncher* test_launcher, | 340 base::TestLauncher* test_launcher, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 std::vector<std::string> test_list; | 396 std::vector<std::string> test_list; |
397 test_list.push_back(test_name); | 397 test_list.push_back(test_name); |
398 DoRunTests(test_launcher, test_list); | 398 DoRunTests(test_launcher, test_list); |
399 } else { | 399 } else { |
400 // Otherwise skip the test. | 400 // Otherwise skip the test. |
401 base::TestResult test_result; | 401 base::TestResult test_result; |
402 test_result.full_name = test_name; | 402 test_result.full_name = test_name; |
403 test_result.status = base::TestResult::TEST_SKIPPED; | 403 test_result.status = base::TestResult::TEST_SKIPPED; |
404 test_launcher->OnTestFinished(test_result); | 404 test_launcher->OnTestFinished(test_result); |
405 | 405 |
406 if (ContainsKey(dependent_test_map_, test_name)) { | 406 if (base::ContainsKey(dependent_test_map_, test_name)) { |
407 RunDependentTest(test_launcher, | 407 RunDependentTest(test_launcher, |
408 dependent_test_map_[test_name], | 408 dependent_test_map_[test_name], |
409 test_result); | 409 test_result); |
410 } | 410 } |
411 } | 411 } |
412 } | 412 } |
413 | 413 |
414 void WrapperTestLauncherDelegate::GTestCallback( | 414 void WrapperTestLauncherDelegate::GTestCallback( |
415 base::TestLauncher* test_launcher, | 415 base::TestLauncher* test_launcher, |
416 const std::vector<std::string>& test_names, | 416 const std::vector<std::string>& test_names, |
(...skipping 11 matching lines...) Expand all Loading... |
428 result.status = base::TestResult::TEST_SUCCESS; | 428 result.status = base::TestResult::TEST_SUCCESS; |
429 else if (was_timeout) | 429 else if (was_timeout) |
430 result.status = base::TestResult::TEST_TIMEOUT; | 430 result.status = base::TestResult::TEST_TIMEOUT; |
431 else | 431 else |
432 result.status = base::TestResult::TEST_FAILURE; | 432 result.status = base::TestResult::TEST_FAILURE; |
433 | 433 |
434 result.elapsed_time = elapsed_time; | 434 result.elapsed_time = elapsed_time; |
435 | 435 |
436 result.output_snippet = GetTestOutputSnippet(result, output); | 436 result.output_snippet = GetTestOutputSnippet(result, output); |
437 | 437 |
438 if (ContainsKey(dependent_test_map_, test_name)) { | 438 if (base::ContainsKey(dependent_test_map_, test_name)) { |
439 RunDependentTest(test_launcher, dependent_test_map_[test_name], result); | 439 RunDependentTest(test_launcher, dependent_test_map_[test_name], result); |
440 } else { | 440 } else { |
441 // No other tests depend on this, we can delete the temporary directory now. | 441 // No other tests depend on this, we can delete the temporary directory now. |
442 // Do so to avoid too many temporary files using lots of disk space. | 442 // Do so to avoid too many temporary files using lots of disk space. |
443 std::string test_name_no_pre(RemoveAnyPrePrefixes(test_name)); | 443 std::string test_name_no_pre(RemoveAnyPrePrefixes(test_name)); |
444 if (ContainsKey(user_data_dir_map_, test_name_no_pre)) { | 444 if (base::ContainsKey(user_data_dir_map_, test_name_no_pre)) { |
445 if (!base::DeleteFile(user_data_dir_map_[test_name_no_pre], true)) { | 445 if (!base::DeleteFile(user_data_dir_map_[test_name_no_pre], true)) { |
446 LOG(WARNING) << "Failed to delete " | 446 LOG(WARNING) << "Failed to delete " |
447 << user_data_dir_map_[test_name_no_pre].value(); | 447 << user_data_dir_map_[test_name_no_pre].value(); |
448 } | 448 } |
449 user_data_dir_map_.erase(test_name_no_pre); | 449 user_data_dir_map_.erase(test_name_no_pre); |
450 } | 450 } |
451 } | 451 } |
452 | 452 |
453 test_launcher->OnTestFinished(result); | 453 test_launcher->OnTestFinished(result); |
454 | 454 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 550 |
551 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { | 551 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { |
552 return g_launcher_delegate; | 552 return g_launcher_delegate; |
553 } | 553 } |
554 | 554 |
555 ContentMainParams* GetContentMainParams() { | 555 ContentMainParams* GetContentMainParams() { |
556 return g_params; | 556 return g_params; |
557 } | 557 } |
558 | 558 |
559 } // namespace content | 559 } // namespace content |
OLD | NEW |