proxygen
FlatCombiningTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present 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 
18 
20 #include <glog/logging.h>
21 
22 #include <mutex>
23 
24 using namespace folly::test;
25 
26 constexpr int LINES = 5;
27 constexpr int NUM_RECS = 20;
28 constexpr int WORK = 0;
29 constexpr int ITERS = 100;
30 
31 static std::vector<int> nthr = {1, 10, 20};
32 
33 struct Params {
34  bool combining, simple, dedicated, tc, syncop;
35 };
36 
37 class FlatCombiningTest : public ::testing::TestWithParam<Params> {};
38 
39 TEST(FlatCombiningTest, lock_holder) {
41  {
42  std::unique_lock<std::mutex> l;
43  ex.holdLock(l);
44  CHECK(l.owns_lock());
45  }
46  {
47  std::unique_lock<std::mutex> l;
48  ex.holdLock(l, std::defer_lock);
49  CHECK(l.try_lock());
50  }
51  CHECK(ex.tryExclusive());
52  ex.releaseExclusive();
53 }
54 
56  Params p = GetParam();
57  for (auto n : nthr) {
58  run_test(
59  n,
60  LINES,
61  NUM_RECS,
62  WORK,
63  ITERS,
64  p.combining,
65  p.simple,
66  p.dedicated,
67  p.tc,
68  p.syncop,
69  true,
70  true);
71  }
72 }
73 
74 TEST_P(FlatCombiningTest, more_threads_than_records) {
75  int n = 20;
76  int num_recs = 1;
77 
78  Params p = GetParam();
79  run_test(
80  n,
81  LINES,
82  num_recs,
83  WORK,
84  ITERS,
85  p.combining,
86  p.simple,
87  p.dedicated,
88  p.tc,
89  p.syncop,
90  true,
91  true);
92 }
93 
94 constexpr Params params[] = {
95  {false, false, false, false, false}, // no combining
96  // simple combining
97  // dedicated
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
102  // no dedicated
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
107  // custom combining
108  // dedicated
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
113  // no dedicated
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
118 };
119 
120 INSTANTIATE_TEST_CASE_P(Foo, FlatCombiningTest, ::testing::ValuesIn(params));
static std::vector< int > nthr
constexpr int ITERS
uint64_t run_test(int nthreads, int lines, int numRecs, int work, int ops, bool combining, bool simple, bool dedicated, bool tc, bool syncops, bool excl=false, bool allocAll=false)
static bool simple
constexpr int LINES
TEST_P(FlatCombiningTest, combining)
static bool dedicated
constexpr Params params[]
constexpr int NUM_RECS
TEST(ProgramOptionsTest, Errors)
INSTANTIATE_TEST_CASE_P(Foo, FlatCombiningTest,::testing::ValuesIn(params))
constexpr int WORK