2 * Copyright 2017 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/experimental/flat_combining/test/FlatCombiningTestHelpers.h>
19 #include <folly/portability/GTest.h>
20 #include <glog/logging.h>
24 using namespace folly::test;
26 constexpr int LINES = 5;
27 constexpr int NUM_RECS = 20;
28 constexpr int WORK = 0;
29 constexpr int ITERS = 100;
31 static std::vector<int> nthr = {1, 10, 20};
34 bool combining, simple, dedicated, tc, syncop;
37 class FlatCombiningTest : public ::testing::TestWithParam<Params> {};
39 TEST(FlatCombiningTest, lock_holder) {
40 folly::FcSimpleExample<> ex(10);
42 std::unique_lock<std::mutex> l;
47 std::unique_lock<std::mutex> l;
48 ex.holdLock(l, std::defer_lock);
51 CHECK(ex.tryExclusive());
52 ex.releaseExclusive();
55 TEST_P(FlatCombiningTest, combining) {
56 Params p = GetParam();
74 TEST_P(FlatCombiningTest, more_threads_than_records) {
78 Params p = GetParam();
94 constexpr Params params[] = {
95 {false, false, false, false, false}, // no combining
98 {true, true, true, false, true}, // no-tc sync
99 {true, true, true, false, false}, // no-tc async
100 {true, true, true, true, true}, // tc sync
101 {true, true, true, true, false}, // tc async
103 {true, true, false, false, true}, // no-tc sync
104 {true, true, false, false, false}, // no-tc async
105 {true, true, false, true, true}, // tc sync
106 {true, true, false, true, false}, // tc async
109 {true, false, true, false, true}, // no-tc sync
110 {true, false, true, false, false}, // no-tc async
111 {true, false, true, true, true}, // tc sync
112 {true, false, true, true, false}, // tc async
114 {true, false, false, false, true}, // no-tc sync
115 {true, false, false, false, false}, // no-tc async
116 {true, false, false, true, true}, // tc sync
117 {true, false, false, true, false}, // tc async
120 INSTANTIATE_TEST_CASE_P(Foo, FlatCombiningTest, ::testing::ValuesIn(params));