Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // Borrowed from Chromium's src/base/threading/thread_checker_unittest.cc. | 11 // Borrowed from Chromium's src/base/threading/thread_checker_unittest.cc. |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/constructormagic.h" | 17 #include "webrtc/base/constructormagic.h" |
| 18 #include "webrtc/base/task_queue.h" | |
| 18 #include "webrtc/base/thread.h" | 19 #include "webrtc/base/thread.h" |
| 19 #include "webrtc/base/thread_checker.h" | 20 #include "webrtc/base/thread_checker.h" |
| 20 | 21 |
| 21 // Duplicated from base/threading/thread_checker.h so that we can be | 22 // Duplicated from base/threading/thread_checker.h so that we can be |
| 22 // good citizens there and undef the macro. | 23 // good citizens there and undef the macro. |
| 23 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | 24 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
| 24 #define ENABLE_THREAD_CHECKER 1 | 25 #define ENABLE_THREAD_CHECKER 1 |
| 25 #else | 26 #else |
| 26 #define ENABLE_THREAD_CHECKER 0 | 27 #define ENABLE_THREAD_CHECKER 0 |
| 27 #endif | 28 #endif |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 }, ""); | 188 }, ""); |
| 188 } | 189 } |
| 189 #else | 190 #else |
| 190 TEST(ThreadCheckerTest, DetachFromThreadInRelease) { | 191 TEST(ThreadCheckerTest, DetachFromThreadInRelease) { |
| 191 ThreadCheckerClass::DetachThenCallFromDifferentThreadImpl(); | 192 ThreadCheckerClass::DetachThenCallFromDifferentThreadImpl(); |
| 192 } | 193 } |
| 193 #endif // ENABLE_THREAD_CHECKER | 194 #endif // ENABLE_THREAD_CHECKER |
| 194 | 195 |
| 195 #endif // GTEST_HAS_DEATH_TEST || !ENABLE_THREAD_CHECKER | 196 #endif // GTEST_HAS_DEATH_TEST || !ENABLE_THREAD_CHECKER |
| 196 | 197 |
| 198 class ThreadAnnotateTest { | |
| 199 public: | |
| 200 rtc::Thread* thread; | |
|
tommi
2016/05/19 08:26:14
move these member variables to the bottom of the c
danilchap
2016/05/19 11:45:29
Done.
| |
| 201 rtc::ThreadChecker checker; | |
| 202 rtc::TaskQueue* queue; | |
| 203 | |
| 204 int var_thread ACCESS_ON(thread); | |
| 205 int var_checker ACCESS_ON(checker); | |
| 206 int var_queue ACCESS_ON(queue); | |
| 207 void function() RUN_ON(thread) {} | |
| 208 void fun_acccess_var() RUN_ON(thread) { var_thread = 13; } | |
| 209 | |
| 210 // Next two function should create warnings when compile (e.g. if used with | |
| 211 // specific T) | |
| 212 // TODO(danilchap): Find a way to test they do not compile when thread | |
| 213 // annotation checks enabled. | |
| 214 template<typename T> | |
| 215 void access_var_no_annotate() { | |
| 216 var_thread = 42; | |
| 217 } | |
| 218 | |
| 219 template<typename T> | |
| 220 void access_fun_no_annotate() { | |
| 221 function(); | |
| 222 } | |
| 223 | |
| 224 // Functions below should be able to compile. | |
| 225 void access_var_annotate_thread() { | |
| 226 RTC_DCHECK_RUN_ON(thread); | |
| 227 var_thread = 42; | |
| 228 } | |
| 229 | |
| 230 void access_var_annotate_checker() { | |
| 231 RTC_DCHECK_RUN_ON(&checker); | |
| 232 var_checker = 44; | |
| 233 } | |
| 234 | |
| 235 void access_var_annotate_queue() { | |
| 236 RTC_DCHECK_RUN_ON(queue); | |
| 237 var_queue = 46; | |
| 238 } | |
| 239 | |
| 240 void access_fun_annotate() { | |
| 241 RTC_DCHECK_RUN_ON(thread); | |
| 242 function(); | |
| 243 } | |
| 244 | |
| 245 void access_fun_and_var() { | |
| 246 RTC_DCHECK_RUN_ON(thread); | |
| 247 fun_acccess_var(); | |
| 248 } | |
| 249 }; | |
| 250 | |
| 197 // Just in case we ever get lumped together with other compilation units. | 251 // Just in case we ever get lumped together with other compilation units. |
| 198 #undef ENABLE_THREAD_CHECKER | 252 #undef ENABLE_THREAD_CHECKER |
| 199 | 253 |
| 200 } // namespace rtc | 254 } // namespace rtc |
| OLD | NEW |