OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sandbox/linux/services/thread_helpers.h" | 5 #include "sandbox/linux/services/thread_helpers.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #define MAYBE_IsSingleThreadedStartAndStop DISABLED_IsSingleThreadedStartAndStop | 57 #define MAYBE_IsSingleThreadedStartAndStop DISABLED_IsSingleThreadedStartAndStop |
58 #else | 58 #else |
59 #define MAYBE_IsSingleThreadedBasic IsSingleThreadedBasic | 59 #define MAYBE_IsSingleThreadedBasic IsSingleThreadedBasic |
60 #define MAYBE_IsSingleThreadedIterated IsSingleThreadedIterated | 60 #define MAYBE_IsSingleThreadedIterated IsSingleThreadedIterated |
61 #define MAYBE_IsSingleThreadedStartAndStop IsSingleThreadedStartAndStop | 61 #define MAYBE_IsSingleThreadedStartAndStop IsSingleThreadedStartAndStop |
62 #endif | 62 #endif |
63 | 63 |
64 TEST(ThreadHelpers, MAYBE_IsSingleThreadedBasic) { | 64 TEST(ThreadHelpers, MAYBE_IsSingleThreadedBasic) { |
65 ScopedProcSelfTask task; | 65 ScopedProcSelfTask task; |
66 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); | 66 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); |
| 67 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(-1)); |
67 | 68 |
68 base::Thread thread("sandbox_tests"); | 69 base::Thread thread("sandbox_tests"); |
69 ASSERT_TRUE(thread.Start()); | 70 ASSERT_TRUE(thread.Start()); |
70 ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(task.fd())); | 71 ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(task.fd())); |
| 72 ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(-1)); |
71 // Explicitly stop the thread here to not pollute the next test. | 73 // Explicitly stop the thread here to not pollute the next test. |
72 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread)); | 74 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread)); |
73 } | 75 } |
74 | 76 |
75 TEST(ThreadHelpers, MAYBE_IsSingleThreadedIterated) { | 77 TEST(ThreadHelpers, MAYBE_IsSingleThreadedIterated) { |
76 ScopedProcSelfTask task; | 78 ScopedProcSelfTask task; |
77 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); | 79 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); |
78 | 80 |
79 // Iterate to check for race conditions. | 81 // Iterate to check for race conditions. |
80 for (int i = 0; i < GetRaceTestIterations(); ++i) { | 82 for (int i = 0; i < GetRaceTestIterations(); ++i) { |
(...skipping 18 matching lines...) Expand all Loading... |
99 | 101 |
100 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread)); | 102 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread)); |
101 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); | 103 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); |
102 ASSERT_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); | 104 ASSERT_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); |
103 } | 105 } |
104 } | 106 } |
105 | 107 |
106 } // namespace | 108 } // namespace |
107 | 109 |
108 } // namespace sandbox | 110 } // namespace sandbox |
OLD | NEW |