2 * Copyright 2015 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 // @author: Andrei Alexandrescu (aalexandre)
19 // Test bed for folly/Synchronized.h
21 #include <folly/Synchronized.h>
22 #include <folly/RWSpinLock.h>
23 #include <folly/SharedMutex.h>
24 #include <folly/test/SynchronizedTestLib.h>
25 #include <gtest/gtest.h>
29 template <class Mutex>
30 class SynchronizedTest : public testing::Test {};
32 using SynchronizedTestTypes = testing::Types
33 < folly::SharedMutexReadPriority
34 , folly::SharedMutexWritePriority
36 , std::recursive_mutex
37 #ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
39 , std::recursive_timed_mutex
42 , boost::recursive_mutex
43 #ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
45 , boost::recursive_timed_mutex
48 #ifdef RW_SPINLOCK_USE_X86_INTRINSIC_
49 , folly::RWTicketSpinLock32
50 , folly::RWTicketSpinLock64
53 TYPED_TEST_CASE(SynchronizedTest, SynchronizedTestTypes);
55 TYPED_TEST(SynchronizedTest, Basic) {
56 testBasic<TypeParam>();
59 TYPED_TEST(SynchronizedTest, Concurrency) {
60 testConcurrency<TypeParam>();
63 TYPED_TEST(SynchronizedTest, DualLocking) {
64 testDualLocking<TypeParam>();
67 TYPED_TEST(SynchronizedTest, DualLockingWithConst) {
68 testDualLockingWithConst<TypeParam>();
71 TYPED_TEST(SynchronizedTest, ConstCopy) {
72 testConstCopy<TypeParam>();
75 template <class Mutex>
76 class SynchronizedTimedTest : public testing::Test {};
78 using SynchronizedTimedTestTypes = testing::Types
79 < folly::SharedMutexReadPriority
80 , folly::SharedMutexWritePriority
81 #ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
83 , std::recursive_timed_mutex
85 , boost::recursive_timed_mutex
88 #ifdef RW_SPINLOCK_USE_X86_INTRINSIC_
89 , folly::RWTicketSpinLock32
90 , folly::RWTicketSpinLock64
93 TYPED_TEST_CASE(SynchronizedTimedTest, SynchronizedTimedTestTypes);
95 TYPED_TEST(SynchronizedTimedTest, TimedSynchronized) {
96 testTimedSynchronized<TypeParam>();
99 template <class Mutex>
100 class SynchronizedTimedWithConstTest : public testing::Test {};
102 using SynchronizedTimedWithConstTestTypes = testing::Types
103 < folly::SharedMutexReadPriority
104 , folly::SharedMutexWritePriority
105 #ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
106 , boost::shared_mutex
108 #ifdef RW_SPINLOCK_USE_X86_INTRINSIC_
109 , folly::RWTicketSpinLock32
110 , folly::RWTicketSpinLock64
114 SynchronizedTimedWithConstTest, SynchronizedTimedWithConstTestTypes);
116 TYPED_TEST(SynchronizedTimedWithConstTest, TimedSynchronizeWithConst) {
117 testTimedSynchronizedWithConst<TypeParam>();