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> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/posix/eintr_wrapper.h" | 16 #include "base/posix/eintr_wrapper.h" |
17 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "build/build_config.h" |
20 #include "sandbox/linux/tests/unit_tests.h" | 21 #include "sandbox/linux/tests/unit_tests.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using base::PlatformThread; | 24 using base::PlatformThread; |
24 | 25 |
25 namespace sandbox { | 26 namespace sandbox { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 int GetRaceTestIterations() { | 30 int GetRaceTestIterations() { |
(...skipping 27 matching lines...) Expand all Loading... |
57 #define MAYBE_IsSingleThreadedStartAndStop DISABLED_IsSingleThreadedStartAndStop | 58 #define MAYBE_IsSingleThreadedStartAndStop DISABLED_IsSingleThreadedStartAndStop |
58 #else | 59 #else |
59 #define MAYBE_IsSingleThreadedBasic IsSingleThreadedBasic | 60 #define MAYBE_IsSingleThreadedBasic IsSingleThreadedBasic |
60 #define MAYBE_IsSingleThreadedIterated IsSingleThreadedIterated | 61 #define MAYBE_IsSingleThreadedIterated IsSingleThreadedIterated |
61 #define MAYBE_IsSingleThreadedStartAndStop IsSingleThreadedStartAndStop | 62 #define MAYBE_IsSingleThreadedStartAndStop IsSingleThreadedStartAndStop |
62 #endif | 63 #endif |
63 | 64 |
64 TEST(ThreadHelpers, MAYBE_IsSingleThreadedBasic) { | 65 TEST(ThreadHelpers, MAYBE_IsSingleThreadedBasic) { |
65 ScopedProcSelfTask task; | 66 ScopedProcSelfTask task; |
66 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); | 67 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); |
| 68 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(-1)); |
67 | 69 |
68 base::Thread thread("sandbox_tests"); | 70 base::Thread thread("sandbox_tests"); |
69 ASSERT_TRUE(thread.Start()); | 71 ASSERT_TRUE(thread.Start()); |
70 ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(task.fd())); | 72 ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(task.fd())); |
| 73 ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(-1)); |
71 // Explicitly stop the thread here to not pollute the next test. | 74 // Explicitly stop the thread here to not pollute the next test. |
72 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread)); | 75 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread)); |
73 } | 76 } |
74 | 77 |
75 TEST(ThreadHelpers, MAYBE_IsSingleThreadedIterated) { | 78 TEST(ThreadHelpers, MAYBE_IsSingleThreadedIterated) { |
76 ScopedProcSelfTask task; | 79 ScopedProcSelfTask task; |
77 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); | 80 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); |
78 | 81 |
79 // Iterate to check for race conditions. | 82 // Iterate to check for race conditions. |
80 for (int i = 0; i < GetRaceTestIterations(); ++i) { | 83 for (int i = 0; i < GetRaceTestIterations(); ++i) { |
(...skipping 18 matching lines...) Expand all Loading... |
99 | 102 |
100 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread)); | 103 ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread)); |
101 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); | 104 ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd())); |
102 ASSERT_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); | 105 ASSERT_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle())); |
103 } | 106 } |
104 } | 107 } |
105 | 108 |
106 } // namespace | 109 } // namespace |
107 | 110 |
108 } // namespace sandbox | 111 } // namespace sandbox |
OLD | NEW |