2 * Copyright 2016 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 #include <folly/Baton.h>
18 #include <folly/test/BatonTestHelpers.h>
19 #include <folly/test/DeterministicSchedule.h>
21 #include <semaphore.h>
22 #include <gtest/gtest.h>
24 using namespace folly;
25 using namespace folly::test;
26 using folly::detail::EmulatedFutexAtomic;
28 typedef DeterministicSchedule DSched;
36 TEST(Baton, pingpong) {
37 DSched sched(DSched::uniform(0));
39 run_pingpong_test<DeterministicAtomic>(1000);
42 TEST(Baton, timed_wait_basic_system_clock) {
43 run_basic_timed_wait_tests<std::atomic, std::chrono::system_clock>();
44 run_basic_timed_wait_tests<EmulatedFutexAtomic, std::chrono::system_clock>();
45 run_basic_timed_wait_tests<DeterministicAtomic, std::chrono::system_clock>();
48 TEST(Baton, timed_wait_timeout_system_clock) {
49 run_timed_wait_tmo_tests<std::atomic, std::chrono::system_clock>();
50 run_timed_wait_tmo_tests<EmulatedFutexAtomic, std::chrono::system_clock>();
51 run_timed_wait_tmo_tests<DeterministicAtomic, std::chrono::system_clock>();
54 TEST(Baton, timed_wait_system_clock) {
55 run_timed_wait_regular_test<std::atomic, std::chrono::system_clock>();
56 run_timed_wait_regular_test<EmulatedFutexAtomic, std::chrono::system_clock>();
57 run_timed_wait_regular_test<DeterministicAtomic, std::chrono::system_clock>();
60 TEST(Baton, timed_wait_basic_steady_clock) {
61 run_basic_timed_wait_tests<std::atomic, std::chrono::steady_clock>();
62 run_basic_timed_wait_tests<EmulatedFutexAtomic, std::chrono::steady_clock>();
63 run_basic_timed_wait_tests<DeterministicAtomic, std::chrono::steady_clock>();
66 TEST(Baton, timed_wait_timeout_steady_clock) {
67 run_timed_wait_tmo_tests<std::atomic, std::chrono::steady_clock>();
68 run_timed_wait_tmo_tests<EmulatedFutexAtomic, std::chrono::steady_clock>();
69 run_timed_wait_tmo_tests<DeterministicAtomic, std::chrono::steady_clock>();
72 TEST(Baton, timed_wait_steady_clock) {
73 run_timed_wait_regular_test<std::atomic, std::chrono::steady_clock>();
74 run_timed_wait_regular_test<EmulatedFutexAtomic, std::chrono::steady_clock>();
75 run_timed_wait_regular_test<DeterministicAtomic, std::chrono::steady_clock>();
78 TEST(Baton, try_wait) {
79 run_try_wait_tests<std::atomic>();
80 run_try_wait_tests<EmulatedFutexAtomic>();
81 run_try_wait_tests<DeterministicAtomic>();