Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: base/process/process_metrics_unittest.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_metrics_linux.cc ('k') | base/process/process_metrics_unittest_ios.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/process/process_metrics.h" 5 #include "base/process/process_metrics.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <sstream> 10 #include <sstream>
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 296 }
297 #endif // defined(OS_LINUX) || defined(OS_ANDROID) 297 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
298 298
299 #if defined(OS_LINUX) || defined(OS_CHROMEOS) 299 #if defined(OS_LINUX) || defined(OS_CHROMEOS)
300 300
301 // Test that ProcessMetrics::GetCPUUsage() doesn't return negative values when 301 // Test that ProcessMetrics::GetCPUUsage() doesn't return negative values when
302 // the number of threads running on the process decreases between two successive 302 // the number of threads running on the process decreases between two successive
303 // calls to it. 303 // calls to it.
304 TEST_F(SystemMetricsTest, TestNoNegativeCpuUsage) { 304 TEST_F(SystemMetricsTest, TestNoNegativeCpuUsage) {
305 ProcessHandle handle = GetCurrentProcessHandle(); 305 ProcessHandle handle = GetCurrentProcessHandle();
306 scoped_ptr<ProcessMetrics> metrics( 306 std::unique_ptr<ProcessMetrics> metrics(
307 ProcessMetrics::CreateProcessMetrics(handle)); 307 ProcessMetrics::CreateProcessMetrics(handle));
308 308
309 EXPECT_GE(metrics->GetCPUUsage(), 0.0); 309 EXPECT_GE(metrics->GetCPUUsage(), 0.0);
310 Thread thread1("thread1"); 310 Thread thread1("thread1");
311 Thread thread2("thread2"); 311 Thread thread2("thread2");
312 Thread thread3("thread3"); 312 Thread thread3("thread3");
313 313
314 thread1.StartAndWaitForTesting(); 314 thread1.StartAndWaitForTesting();
315 thread2.StartAndWaitForTesting(); 315 thread2.StartAndWaitForTesting();
316 thread3.StartAndWaitForTesting(); 316 thread3.StartAndWaitForTesting();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // Disable on Android because base_unittests runs inside a Dalvik VM that 417 // Disable on Android because base_unittests runs inside a Dalvik VM that
418 // starts and stop threads (crbug.com/175563). 418 // starts and stop threads (crbug.com/175563).
419 #if defined(OS_LINUX) 419 #if defined(OS_LINUX)
420 // http://crbug.com/396455 420 // http://crbug.com/396455
421 TEST(ProcessMetricsTest, DISABLED_GetNumberOfThreads) { 421 TEST(ProcessMetricsTest, DISABLED_GetNumberOfThreads) {
422 const ProcessHandle current = GetCurrentProcessHandle(); 422 const ProcessHandle current = GetCurrentProcessHandle();
423 const int initial_threads = GetNumberOfThreads(current); 423 const int initial_threads = GetNumberOfThreads(current);
424 ASSERT_GT(initial_threads, 0); 424 ASSERT_GT(initial_threads, 0);
425 const int kNumAdditionalThreads = 10; 425 const int kNumAdditionalThreads = 10;
426 { 426 {
427 scoped_ptr<Thread> my_threads[kNumAdditionalThreads]; 427 std::unique_ptr<Thread> my_threads[kNumAdditionalThreads];
428 for (int i = 0; i < kNumAdditionalThreads; ++i) { 428 for (int i = 0; i < kNumAdditionalThreads; ++i) {
429 my_threads[i].reset(new Thread("GetNumberOfThreadsTest")); 429 my_threads[i].reset(new Thread("GetNumberOfThreadsTest"));
430 my_threads[i]->Start(); 430 my_threads[i]->Start();
431 ASSERT_EQ(GetNumberOfThreads(current), initial_threads + 1 + i); 431 ASSERT_EQ(GetNumberOfThreads(current), initial_threads + 1 + i);
432 } 432 }
433 } 433 }
434 // The Thread destructor will stop them. 434 // The Thread destructor will stop them.
435 ASSERT_EQ(initial_threads, GetNumberOfThreads(current)); 435 ASSERT_EQ(initial_threads, GetNumberOfThreads(current));
436 } 436 }
437 #endif // defined(OS_LINUX) 437 #endif // defined(OS_LINUX)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 ScopedTempDir temp_dir; 489 ScopedTempDir temp_dir;
490 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 490 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
491 const FilePath temp_path = temp_dir.path(); 491 const FilePath temp_path = temp_dir.path();
492 CommandLine child_command_line(GetMultiProcessTestChildBaseCommandLine()); 492 CommandLine child_command_line(GetMultiProcessTestChildBaseCommandLine());
493 child_command_line.AppendSwitchPath(kTempDirFlag, temp_path); 493 child_command_line.AppendSwitchPath(kTempDirFlag, temp_path);
494 Process child = SpawnMultiProcessTestChild( 494 Process child = SpawnMultiProcessTestChild(
495 ChildMainString, child_command_line, LaunchOptions()); 495 ChildMainString, child_command_line, LaunchOptions());
496 ASSERT_TRUE(child.IsValid()); 496 ASSERT_TRUE(child.IsValid());
497 WaitForEvent(temp_path, kSignalClosed); 497 WaitForEvent(temp_path, kSignalClosed);
498 498
499 scoped_ptr<ProcessMetrics> metrics( 499 std::unique_ptr<ProcessMetrics> metrics(
500 ProcessMetrics::CreateProcessMetrics(child.Handle())); 500 ProcessMetrics::CreateProcessMetrics(child.Handle()));
501 EXPECT_EQ(0, metrics->GetOpenFdCount()); 501 EXPECT_EQ(0, metrics->GetOpenFdCount());
502 ASSERT_TRUE(child.Terminate(0, true)); 502 ASSERT_TRUE(child.Terminate(0, true));
503 } 503 }
504 #endif // defined(OS_LINUX) 504 #endif // defined(OS_LINUX)
505 505
506 } // namespace debug 506 } // namespace debug
507 } // namespace base 507 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_metrics_linux.cc ('k') | base/process/process_metrics_unittest_ios.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698