Flat Combining
[folly.git] / folly / experimental / flat_combining / test / FlatCombiningTest.cpp
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <folly/experimental/flat_combining/test/FlatCombiningTestHelpers.h>
18
19 #include <folly/portability/GTest.h>
20 #include <glog/logging.h>
21
22 using namespace folly::test;
23
24 constexpr int LINES = 5;
25 constexpr int NUM_RECS = 20;
26 constexpr int WORK = 0;
27 constexpr int ITERS = 100;
28
29 static std::vector<int> nthr = {1, 10, 20};
30
31 struct Params {
32   bool combining, simple, dedicated, tc, syncop;
33 };
34
35 class FlatCombiningTest : public ::testing::TestWithParam<Params> {};
36
37 TEST_P(FlatCombiningTest, combining) {
38   Params p = GetParam();
39   for (auto n : nthr) {
40     run_test(
41         n,
42         LINES,
43         NUM_RECS,
44         WORK,
45         ITERS,
46         p.combining,
47         p.simple,
48         p.dedicated,
49         p.tc,
50         p.syncop,
51         true,
52         true);
53   }
54 }
55
56 TEST_P(FlatCombiningTest, more_threads_than_records) {
57   int n = 20;
58   int num_recs = 1;
59
60   Params p = GetParam();
61   run_test(
62       n,
63       LINES,
64       num_recs,
65       WORK,
66       ITERS,
67       p.combining,
68       p.simple,
69       p.dedicated,
70       p.tc,
71       p.syncop,
72       true,
73       true);
74 }
75
76 constexpr Params params[] = {
77     {false, false, false, false, false}, // no combining
78     // simple combining
79     //  dedicated
80     {true, true, true, false, true}, // no-tc sync
81     {true, true, true, false, false}, // no-tc async
82     {true, true, true, true, true}, // tc sync
83     {true, true, true, true, false}, // tc async
84     //   no dedicated
85     {true, true, false, false, true}, // no-tc sync
86     {true, true, false, false, false}, // no-tc async
87     {true, true, false, true, true}, // tc sync
88     {true, true, false, true, false}, // tc async
89     // custom combining
90     //  dedicated
91     {true, false, true, false, true}, // no-tc sync
92     {true, false, true, false, false}, // no-tc async
93     {true, false, true, true, true}, // tc sync
94     {true, false, true, true, false}, // tc async
95     //   no dedicated
96     {true, false, false, false, true}, // no-tc sync
97     {true, false, false, false, false}, // no-tc async
98     {true, false, false, true, true}, // tc sync
99     {true, false, false, true, false}, // tc async
100 };
101
102 INSTANTIATE_TEST_CASE_P(Foo, FlatCombiningTest, ::testing::ValuesIn(params));