proxygen
F14AsanSupportTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018-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 
17 #include <folly/Portability.h>
18 #include <folly/container/F14Set.h>
20 
21 using namespace folly;
22 
23 template <typename S>
25  S set;
26  auto iter = set.insert(1).first;
27  set.insert(2);
28  EXPECT_EQ(*iter, 1);
29 }
30 
31 template <typename S>
33  S set;
34  set.insert(10);
35  for (int i = 0; i < 1000; ++i) {
36  auto iter = set.find(10);
37  set.insert(i);
38  if (i > 500) {
39  EXPECT_EQ(*iter, 10);
40  }
41  }
42 }
43 
44 template <typename S>
46  S set;
47  auto& ref = *set.insert(1).first;
48  set.insert(2);
49  EXPECT_EQ(ref, 1);
50 }
51 
52 template <typename S>
54  S set;
55  set.insert(10);
56  for (int i = 0; i < 1000; ++i) {
57  auto& ref = *set.find(10);
58  set.insert(i);
59  if (i > 500) {
60  EXPECT_EQ(ref, 10);
61  }
62  }
63 }
64 
65 template <typename F>
66 void repeat(F const& func) {
67  for (int i = 0; i < 32; ++i) {
68  func();
69  }
70 }
71 
72 template <typename F>
73 void expectAsanFailure(F const& func) {
74  if (kIsSanitizeAddress) {
75  EXPECT_EXIT(
76  repeat(func), testing::ExitedWithCode(1), ".*heap-use-after-free.*");
77  }
78 }
79 
80 TEST(F14AsanSupportTest, F14ValueIterInsertSmall) {
82 }
83 TEST(F14AsanSupportTest, F14NodeIterInsertSmall) {
85 }
86 TEST(F14AsanSupportTest, F14VectorIterInsertSmall) {
88 }
89 TEST(F14AsanSupportTest, F14FastIterInsertSmall) {
91 }
92 
93 TEST(F14AsanSupportTest, F14ValueIterInsertLarge) {
95 }
96 TEST(F14AsanSupportTest, F14NodeIterInsertLarge) {
98 }
99 TEST(F14AsanSupportTest, F14VectorIterInsertLarge) {
101 }
102 TEST(F14AsanSupportTest, F14FastIterInsertLarge) {
104 }
105 
106 TEST(F14AsanSupportTest, F14ValueRefInsertSmall) {
108 }
109 TEST(F14AsanSupportTest, F14VectorRefInsertSmall) {
111 }
112 TEST(F14AsanSupportTest, F14FastRefInsertSmall) {
114 }
115 
116 TEST(F14AsanSupportTest, F14ValueRefInsertLarge) {
118 }
119 TEST(F14AsanSupportTest, F14VectorRefInsertLarge) {
121 }
122 TEST(F14AsanSupportTest, F14FastRefInsertLarge) {
124 }
125 
126 TEST(F14AsanSupportTest, F14VectorErase) {
127  F14VectorSet<int> set;
128  set.insert(1);
129  set.insert(2);
130  set.insert(3);
131  auto& v = *set.begin();
132  EXPECT_EQ(v, 3);
133  set.erase(2);
134  if (kIsSanitizeAddress) {
135  EXPECT_NE(v, 3);
136  }
137 }
void useIteratorAfterInsertSmall()
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr bool kIsSanitizeAddress
Definition: Portability.h:118
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void expectAsanFailure(F const &func)
void repeat(F const &func)
void useIteratorAfterInsertLarge()
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
void useReferenceAfterInsertLarge()
TEST(SequencedExecutor, CPUThreadPoolExecutor)
void useReferenceAfterInsertSmall()