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>
20 #include <folly/portability/GTest.h>
23 #include <semaphore.h>
25 using namespace folly;
26 using namespace folly::test;
27 using folly::detail::EmulatedFutexAtomic;
35 TEST(Baton, pingpong) {
36 DSched sched(DSched::uniform(0));
38 run_pingpong_test<DeterministicAtomic>(1000);
41 TEST(Baton, timed_wait_basic_system_clock) {
42 run_basic_timed_wait_tests<std::atomic, std::chrono::system_clock>();
43 run_basic_timed_wait_tests<EmulatedFutexAtomic, std::chrono::system_clock>();
44 run_basic_timed_wait_tests<DeterministicAtomic, std::chrono::system_clock>();
47 TEST(Baton, timed_wait_timeout_system_clock) {
48 run_timed_wait_tmo_tests<std::atomic, std::chrono::system_clock>();
49 run_timed_wait_tmo_tests<EmulatedFutexAtomic, std::chrono::system_clock>();
50 run_timed_wait_tmo_tests<DeterministicAtomic, std::chrono::system_clock>();
53 TEST(Baton, timed_wait_system_clock) {
54 run_timed_wait_regular_test<std::atomic, std::chrono::system_clock>();
55 run_timed_wait_regular_test<EmulatedFutexAtomic, std::chrono::system_clock>();
56 run_timed_wait_regular_test<DeterministicAtomic, std::chrono::system_clock>();
59 TEST(Baton, timed_wait_basic_steady_clock) {
60 run_basic_timed_wait_tests<std::atomic, std::chrono::steady_clock>();
61 run_basic_timed_wait_tests<EmulatedFutexAtomic, std::chrono::steady_clock>();
62 run_basic_timed_wait_tests<DeterministicAtomic, std::chrono::steady_clock>();
65 TEST(Baton, timed_wait_timeout_steady_clock) {
66 run_timed_wait_tmo_tests<std::atomic, std::chrono::steady_clock>();
67 run_timed_wait_tmo_tests<EmulatedFutexAtomic, std::chrono::steady_clock>();
68 run_timed_wait_tmo_tests<DeterministicAtomic, std::chrono::steady_clock>();
71 TEST(Baton, timed_wait_steady_clock) {
72 run_timed_wait_regular_test<std::atomic, std::chrono::steady_clock>();
73 run_timed_wait_regular_test<EmulatedFutexAtomic, std::chrono::steady_clock>();
74 run_timed_wait_regular_test<DeterministicAtomic, std::chrono::steady_clock>();
77 TEST(Baton, try_wait) {
78 run_try_wait_tests<std::atomic>();
79 run_try_wait_tests<EmulatedFutexAtomic>();
80 run_try_wait_tests<DeterministicAtomic>();