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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 | 92 |
93 TEST(ThreadHelpers, IsSingleThreadedStartAndStop) { | 93 TEST(ThreadHelpers, IsSingleThreadedStartAndStop) { |
94 ScopedProc proc_fd; | 94 ScopedProc proc_fd; |
95 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(proc_fd.fd())); | 95 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(proc_fd.fd())); |
96 | 96 |
97 base::Thread thread("sandbox_tests"); | 97 base::Thread thread("sandbox_tests"); |
98 // This is testing for a race condition, so iterate. | 98 // This is testing for a race condition, so iterate. |
99 // Manually, this has been tested with more that 1M iterations. | 99 // Manually, this has been tested with more that 1M iterations. |
100 for (int i = 0; i < GetRaceTestIterations(); ++i) { | 100 for (int i = 0; i < GetRaceTestIterations(); ++i) { |
101 ASSERT_TRUE(thread.Start()); | 101 ASSERT_TRUE(thread.StartAndWait()); |
102 ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(proc_fd.fd())); | 102 ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(proc_fd.fd())); |
103 | 103 |
104 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(proc_fd.fd(), &thread)); | 104 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(proc_fd.fd(), &thread)); |
105 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(proc_fd.fd())); | 105 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(proc_fd.fd())); |
106 ASSERT_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); | 106 ASSERT_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 SANDBOX_TEST(ThreadHelpers, AssertSingleThreadedAfterThreadStopped) { | 110 SANDBOX_TEST(ThreadHelpers, AssertSingleThreadedAfterThreadStopped) { |
111 SANDBOX_ASSERT(ThreadHelpers::IsSingleThreaded()); | 111 SANDBOX_ASSERT(ThreadHelpers::IsSingleThreaded()); |
(...skipping 27 matching lines...) Expand all Loading... |
139 SANDBOX_ASSERT(thread1.Start()); | 139 SANDBOX_ASSERT(thread1.Start()); |
140 ThreadHelpers::AssertSingleThreaded(); | 140 ThreadHelpers::AssertSingleThreaded(); |
141 } | 141 } |
142 #endif // !defined(NDEBUG) | 142 #endif // !defined(NDEBUG) |
143 | 143 |
144 #endif // !defined(THREAD_SANITIZER) | 144 #endif // !defined(THREAD_SANITIZER) |
145 | 145 |
146 } // namespace | 146 } // namespace |
147 | 147 |
148 } // namespace sandbox | 148 } // namespace sandbox |
OLD | NEW |