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 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 // cat /proc/self/stat on a random other machine I have. | 939 // cat /proc/self/stat on a random other machine I have. |
940 const char kSelfStat[] = "5364 (cat) R 5354 5364 5354 34819 5364 " | 940 const char kSelfStat[] = "5364 (cat) R 5354 5364 5354 34819 5364 " |
941 "0 142 0 0 0 " | 941 "0 142 0 0 0 " |
942 "0 0 0 0 " // <- No CPU, apparently. | 942 "0 0 0 0 " // <- No CPU, apparently. |
943 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " | 943 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " |
944 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; | 944 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; |
945 | 945 |
946 EXPECT_EQ(0, base::ParseProcStatCPU(kSelfStat)); | 946 EXPECT_EQ(0, base::ParseProcStatCPU(kSelfStat)); |
947 } | 947 } |
948 | 948 |
| 949 // Disable on Android because base_unittests runs inside a Dalvik VM that |
| 950 // starts and stop threads (crbug.com/175563). |
| 951 #if !defined(OS_ANDROID) |
949 TEST_F(ProcessUtilTest, GetNumberOfThreads) { | 952 TEST_F(ProcessUtilTest, GetNumberOfThreads) { |
950 const base::ProcessHandle current = base::GetCurrentProcessHandle(); | 953 const base::ProcessHandle current = base::GetCurrentProcessHandle(); |
951 const int initial_threads = base::GetNumberOfThreads(current); | 954 const int initial_threads = base::GetNumberOfThreads(current); |
952 ASSERT_GT(initial_threads, 0); | 955 ASSERT_GT(initial_threads, 0); |
953 const int kNumAdditionalThreads = 10; | 956 const int kNumAdditionalThreads = 10; |
954 { | 957 { |
955 scoped_ptr<base::Thread> my_threads[kNumAdditionalThreads]; | 958 scoped_ptr<base::Thread> my_threads[kNumAdditionalThreads]; |
956 for (int i = 0; i < kNumAdditionalThreads; ++i) { | 959 for (int i = 0; i < kNumAdditionalThreads; ++i) { |
957 my_threads[i].reset(new base::Thread("GetNumberOfThreadsTest")); | 960 my_threads[i].reset(new base::Thread("GetNumberOfThreadsTest")); |
958 my_threads[i]->Start(); | 961 my_threads[i]->Start(); |
959 ASSERT_EQ(base::GetNumberOfThreads(current), initial_threads + 1 + i); | 962 ASSERT_EQ(base::GetNumberOfThreads(current), initial_threads + 1 + i); |
960 } | 963 } |
961 } | 964 } |
962 // The Thread destructor will stop them. | 965 // The Thread destructor will stop them. |
963 ASSERT_EQ(initial_threads, base::GetNumberOfThreads(current)); | 966 ASSERT_EQ(initial_threads, base::GetNumberOfThreads(current)); |
964 } | 967 } |
| 968 #endif // !defined(OS_ANDROID) |
965 | 969 |
966 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 970 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
967 | 971 |
968 // TODO(port): port those unit tests. | 972 // TODO(port): port those unit tests. |
969 bool IsProcessDead(base::ProcessHandle child) { | 973 bool IsProcessDead(base::ProcessHandle child) { |
970 // waitpid() will actually reap the process which is exactly NOT what we | 974 // waitpid() will actually reap the process which is exactly NOT what we |
971 // want to test for. The good thing is that if it can't find the process | 975 // want to test for. The good thing is that if it can't find the process |
972 // we'll get a nice value for errno which we can test for. | 976 // we'll get a nice value for errno which we can test for. |
973 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); | 977 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
974 return result == -1 && errno == ECHILD; | 978 return result == -1 && errno == ECHILD; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 SetUpInDeathAssert(); | 1234 SetUpInDeathAssert(); |
1231 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 1235 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
1232 }, ""); | 1236 }, ""); |
1233 } | 1237 } |
1234 | 1238 |
1235 #endif // !ARCH_CPU_64_BITS | 1239 #endif // !ARCH_CPU_64_BITS |
1236 #endif // OS_MACOSX | 1240 #endif // OS_MACOSX |
1237 | 1241 |
1238 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 1242 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
1239 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 1243 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
OLD | NEW |