| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/synchronization/atomic_flag.h" | 5 #include "base/synchronization/atomic_flag.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/gtest_util.h" |
| 11 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 // Death tests misbehave on Android. | |
| 17 // TODO(fdoray): Remove this when https://codereview.chromium.org/2162053006 | |
| 18 // lands. | |
| 19 #if DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) | |
| 20 #define EXPECT_DCHECK_DEATH(statement, regex) EXPECT_DEATH(statement, regex) | |
| 21 #else | |
| 22 #define EXPECT_DCHECK_DEATH(statement, regex) | |
| 23 #endif | |
| 24 | |
| 25 namespace base { | 17 namespace base { |
| 26 | 18 |
| 27 namespace { | 19 namespace { |
| 28 | 20 |
| 29 void ExpectSetFlagDeath(AtomicFlag* flag) { | 21 void ExpectSetFlagDeath(AtomicFlag* flag) { |
| 30 ASSERT_TRUE(flag); | 22 ASSERT_TRUE(flag); |
| 31 EXPECT_DCHECK_DEATH(flag->Set(), ""); | 23 EXPECT_DCHECK_DEATH(flag->Set(), ""); |
| 32 } | 24 } |
| 33 | 25 |
| 34 void BusyWaitUntilFlagIsSet(AtomicFlag* flag) { | 26 void BusyWaitUntilFlagIsSet(AtomicFlag* flag) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // die on a DCHECK if Set() is called from other thread. | 70 // die on a DCHECK if Set() is called from other thread. |
| 79 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; | 71 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 80 Thread t("AtomicFlagTest.SetOnDifferentThreadDeathTest"); | 72 Thread t("AtomicFlagTest.SetOnDifferentThreadDeathTest"); |
| 81 ASSERT_TRUE(t.Start()); | 73 ASSERT_TRUE(t.Start()); |
| 82 | 74 |
| 83 AtomicFlag flag; | 75 AtomicFlag flag; |
| 84 t.task_runner()->PostTask(FROM_HERE, Bind(&ExpectSetFlagDeath, &flag)); | 76 t.task_runner()->PostTask(FROM_HERE, Bind(&ExpectSetFlagDeath, &flag)); |
| 85 } | 77 } |
| 86 | 78 |
| 87 } // namespace base | 79 } // namespace base |
| OLD | NEW |