| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 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 #include "webrtc/base/common.h" | 11 #include "webrtc/base/common.h" |
| 12 #include "webrtc/base/gunit.h" | 12 #include "webrtc/base/gunit.h" |
| 13 #include "webrtc/base/messagehandler.h" | 13 #include "webrtc/base/messagehandler.h" |
| 14 #include "webrtc/base/messagequeue.h" | 14 #include "webrtc/base/messagequeue.h" |
| 15 #include "webrtc/base/scoped_ptr.h" | 15 #include "webrtc/base/scoped_ptr.h" |
| 16 #include "webrtc/base/sharedexclusivelock.h" | 16 #include "webrtc/base/sharedexclusivelock.h" |
| 17 #include "webrtc/base/thread.h" | 17 #include "webrtc/base/thread.h" |
| 18 #include "webrtc/base/timeutils.h" | 18 #include "webrtc/base/timeutils.h" |
| 19 | 19 |
| 20 #if defined(MEMORY_SANITIZER) |
| 21 // Flaky under MemorySanitizer, see |
| 22 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5824 |
| 23 #define MAYBE_TestSharedExclusive DISABLED_TestSharedExclusive |
| 24 #define MAYBE_TestExclusiveExclusive DISABLED_TestExclusiveExclusive |
| 25 #else |
| 26 #define MAYBE_TestSharedExclusive TestSharedExclusive |
| 27 #define MAYBE_TestExclusiveExclusive TestExclusiveExclusive |
| 28 #endif |
| 29 |
| 20 namespace rtc { | 30 namespace rtc { |
| 21 | 31 |
| 22 static const uint32_t kMsgRead = 0; | 32 static const uint32_t kMsgRead = 0; |
| 23 static const uint32_t kMsgWrite = 0; | 33 static const uint32_t kMsgWrite = 0; |
| 24 static const int kNoWaitThresholdInMs = 10; | 34 static const int kNoWaitThresholdInMs = 10; |
| 25 static const int kWaitThresholdInMs = 80; | 35 static const int kWaitThresholdInMs = 80; |
| 26 static const int kProcessTimeInMs = 100; | 36 static const int kProcessTimeInMs = 100; |
| 27 static const int kProcessTimeoutInMs = 5000; | 37 static const int kProcessTimeoutInMs = 5000; |
| 28 | 38 |
| 29 class SharedExclusiveTask : public MessageHandler { | 39 class SharedExclusiveTask : public MessageHandler { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 160 } |
| 151 | 161 |
| 152 EXPECT_TRUE_WAIT(done0, kProcessTimeoutInMs); | 162 EXPECT_TRUE_WAIT(done0, kProcessTimeoutInMs); |
| 153 EXPECT_EQ(1, value0); | 163 EXPECT_EQ(1, value0); |
| 154 EXPECT_LE(reader0.waiting_time_in_ms(), kNoWaitThresholdInMs); | 164 EXPECT_LE(reader0.waiting_time_in_ms(), kNoWaitThresholdInMs); |
| 155 EXPECT_TRUE_WAIT(done1, kProcessTimeoutInMs); | 165 EXPECT_TRUE_WAIT(done1, kProcessTimeoutInMs); |
| 156 EXPECT_EQ(1, value1); | 166 EXPECT_EQ(1, value1); |
| 157 EXPECT_LE(reader1.waiting_time_in_ms(), kNoWaitThresholdInMs); | 167 EXPECT_LE(reader1.waiting_time_in_ms(), kNoWaitThresholdInMs); |
| 158 } | 168 } |
| 159 | 169 |
| 160 TEST_F(SharedExclusiveLockTest, TestSharedExclusive) { | 170 TEST_F(SharedExclusiveLockTest, MAYBE_TestSharedExclusive) { |
| 161 bool done; | 171 bool done; |
| 162 WriteTask writer(shared_exclusive_lock_.get(), &value_, &done); | 172 WriteTask writer(shared_exclusive_lock_.get(), &value_, &done); |
| 163 | 173 |
| 164 // Test exclusive lock needs to wait for shared lock. | 174 // Test exclusive lock needs to wait for shared lock. |
| 165 { | 175 { |
| 166 SharedScope ss(shared_exclusive_lock_.get()); | 176 SharedScope ss(shared_exclusive_lock_.get()); |
| 167 value_ = 1; | 177 value_ = 1; |
| 168 done = false; | 178 done = false; |
| 169 writer.PostWrite(2); | 179 writer.PostWrite(2); |
| 170 Thread::SleepMs(kProcessTimeInMs); | 180 Thread::SleepMs(kProcessTimeInMs); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 189 reader.PostRead(&value); | 199 reader.PostRead(&value); |
| 190 Thread::SleepMs(kProcessTimeInMs); | 200 Thread::SleepMs(kProcessTimeInMs); |
| 191 value_ = 2; | 201 value_ = 2; |
| 192 } | 202 } |
| 193 | 203 |
| 194 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); | 204 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); |
| 195 EXPECT_EQ(2, value); | 205 EXPECT_EQ(2, value); |
| 196 EXPECT_GE(reader.waiting_time_in_ms(), kWaitThresholdInMs); | 206 EXPECT_GE(reader.waiting_time_in_ms(), kWaitThresholdInMs); |
| 197 } | 207 } |
| 198 | 208 |
| 199 TEST_F(SharedExclusiveLockTest, TestExclusiveExclusive) { | 209 TEST_F(SharedExclusiveLockTest, MAYBE_TestExclusiveExclusive) { |
| 200 bool done; | 210 bool done; |
| 201 WriteTask writer(shared_exclusive_lock_.get(), &value_, &done); | 211 WriteTask writer(shared_exclusive_lock_.get(), &value_, &done); |
| 202 | 212 |
| 203 // Test exclusive lock needs to wait for exclusive lock. | 213 // Test exclusive lock needs to wait for exclusive lock. |
| 204 { | 214 { |
| 205 ExclusiveScope es(shared_exclusive_lock_.get()); | 215 ExclusiveScope es(shared_exclusive_lock_.get()); |
| 206 value_ = 1; | 216 value_ = 1; |
| 207 done = false; | 217 done = false; |
| 208 writer.PostWrite(2); | 218 writer.PostWrite(2); |
| 209 Thread::SleepMs(kProcessTimeInMs); | 219 Thread::SleepMs(kProcessTimeInMs); |
| 210 EXPECT_EQ(1, value_); | 220 EXPECT_EQ(1, value_); |
| 211 } | 221 } |
| 212 | 222 |
| 213 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); | 223 EXPECT_TRUE_WAIT(done, kProcessTimeoutInMs); |
| 214 EXPECT_EQ(2, value_); | 224 EXPECT_EQ(2, value_); |
| 215 EXPECT_GE(writer.waiting_time_in_ms(), kWaitThresholdInMs); | 225 EXPECT_GE(writer.waiting_time_in_ms(), kWaitThresholdInMs); |
| 216 } | 226 } |
| 217 | 227 |
| 218 } // namespace rtc | 228 } // namespace rtc |
| OLD | NEW |