| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef MultiThreadedTestUtil_h | 5 #ifndef MultiThreadedTestUtil_h |
| 6 #define MultiThreadedTestUtil_h | 6 #define MultiThreadedTestUtil_h |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 #include "platform/CrossThreadFunctional.h" | 10 #include "platform/CrossThreadFunctional.h" |
| 11 #include "platform/WaitableEvent.h" | 11 #include "platform/WaitableEvent.h" |
| 12 #include "platform/WebTaskRunner.h" | 12 #include "platform/WebTaskRunner.h" |
| 13 #include "platform/WebThreadSupportingGC.h" | 13 #include "platform/WebThreadSupportingGC.h" |
| 14 #include "platform/scheduler/child/web_scheduler.h" | 14 #include "platform/scheduler/child/web_scheduler.h" |
| 15 #include "platform/wtf/Functional.h" | 15 #include "platform/wtf/Functional.h" |
| 16 #include "platform/wtf/RefCounted.h" | 16 #include "platform/wtf/RefCounted.h" |
| 17 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
| 18 #include "public/platform/WebThread.h" | 18 #include "public/platform/WebThread.h" |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 // This creates 2 macros for TSAN: TSAN_TEST and TSAN_TEST_F. | 22 // This creates 2 macros for TSAN: TSAN_TEST and TSAN_TEST_F. |
| 23 // Those tests are automatically disabled on non-tsan builds and should be used | 23 // Those tests are automatically disabled on non-tsan builds and should be used |
| 24 // instead of the normal gtest macros for MultiThreadedTests. | 24 // instead of the normal gtest macros for MultiThreadedTests. |
| 25 // It guarantees that those tests are only run on Thread Sanitizer enabled | 25 // It guarantees that those tests are only run on Thread Sanitizer enabled |
| 26 // builds. | 26 // builds. |
| 27 // Also, TSAN_TEST subclasses MultiThreadTest instead of testing::Test. | 27 // Also, TSAN_TEST subclasses MultiThreadTest instead of ::testing::Test. |
| 28 #if defined(THREAD_SANITIZER) | 28 #if defined(THREAD_SANITIZER) |
| 29 | 29 |
| 30 #define TSAN_TEST(test_case_name, test_name) \ | 30 #define TSAN_TEST(test_case_name, test_name) \ |
| 31 GTEST_TEST_(test_case_name, test_name, ::blink::MultiThreadedTest, \ | 31 GTEST_TEST_(test_case_name, test_name, ::blink::MultiThreadedTest, \ |
| 32 ::testing::internal::GetTypeId<::blink::MultiThreadedTest>()) | 32 ::testing::internal::GetTypeId<::blink::MultiThreadedTest>()) |
| 33 | 33 |
| 34 #define TSAN_TEST_F(test_fixture, test_name) TEST_F(test_fixture, test_name) | 34 #define TSAN_TEST_F(test_fixture, test_name) TEST_F(test_fixture, test_name) |
| 35 | 35 |
| 36 #else | 36 #else |
| 37 | 37 |
| 38 #define TSAN_TEST(test_case_name, test_name) \ | 38 #define TSAN_TEST(test_case_name, test_name) \ |
| 39 GTEST_TEST_(test_case_name, DISABLED_##test_name, \ | 39 GTEST_TEST_(test_case_name, DISABLED_##test_name, \ |
| 40 ::blink::MultiThreadedTest, \ | 40 ::blink::MultiThreadedTest, \ |
| 41 ::testing::internal::GetTypeId<::blink::MultiThreadedTest>()) | 41 ::testing::internal::GetTypeId<::blink::MultiThreadedTest>()) |
| 42 | 42 |
| 43 #define TSAN_TEST_F(test_fixture, test_name) \ | 43 #define TSAN_TEST_F(test_fixture, test_name) \ |
| 44 TEST_F(test_fixture, DISABLED_##test_name) | 44 TEST_F(test_fixture, DISABLED_##test_name) |
| 45 | 45 |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 class MultiThreadedTest : public testing::Test { | 48 class MultiThreadedTest : public ::testing::Test { |
| 49 public: | 49 public: |
| 50 // RunOnThreads run a closure num_threads * callbacks_per_thread times. | 50 // RunOnThreads run a closure num_threads * callbacks_per_thread times. |
| 51 // The default for this is 10*100 = 1000 times. | 51 // The default for this is 10*100 = 1000 times. |
| 52 template <typename FunctionType, typename... Ps> | 52 template <typename FunctionType, typename... Ps> |
| 53 void RunOnThreads(FunctionType function, Ps&&... parameters) { | 53 void RunOnThreads(FunctionType function, Ps&&... parameters) { |
| 54 Vector<std::unique_ptr<WebThreadSupportingGC>> threads; | 54 Vector<std::unique_ptr<WebThreadSupportingGC>> threads; |
| 55 Vector<std::unique_ptr<WaitableEvent>> waits; | 55 Vector<std::unique_ptr<WaitableEvent>> waits; |
| 56 | 56 |
| 57 for (int i = 0; i < num_threads_; ++i) { | 57 for (int i = 0; i < num_threads_; ++i) { |
| 58 threads.push_back(WebThreadSupportingGC::Create("")); | 58 threads.push_back(WebThreadSupportingGC::Create("")); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 protected: | 92 protected: |
| 93 int num_threads_ = 10; | 93 int num_threads_ = 10; |
| 94 int callbacks_per_thread_ = 100; | 94 int callbacks_per_thread_ = 100; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 } // namespace blink | 97 } // namespace blink |
| 98 | 98 |
| 99 #endif // MultiThreadedTestUtil_h | 99 #endif // MultiThreadedTestUtil_h |
| OLD | NEW |