Skip to content

Commit 74bf44a

Browse files
vitalybukaAdvenamTacet
authored andcommitted
benchmark mode in test
1 parent b08a90c commit 74bf44a

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

compiler-rt/test/asan/TestCases/copy_container_annotations.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ static std::vector<int> GetPoisonedState(char *begin, char *end) {
3636
static void RandomPoison(char *beg, char *end) {
3737
assert(beg == RoundDown(beg));
3838
assert(end == RoundDown(end));
39-
for (beg = RoundUp(beg); beg + kGranularity <= end; beg += kGranularity) {
40-
__asan_poison_memory_region(beg, kGranularity);
39+
__asan_poison_memory_region(beg, end - beg);
40+
for (beg = RoundUp(beg); beg < end; beg += kGranularity) {
4141
__asan_unpoison_memory_region(beg, rand() % (kGranularity + 1));
4242
}
4343
}
4444

45+
template <bool benchmark>
4546
static void Test(size_t capacity, size_t off_src, size_t off_dst,
4647
char *src_buffer_beg, char *src_buffer_end,
4748
char *dst_buffer_beg, char *dst_buffer_end) {
@@ -51,6 +52,11 @@ static void Test(size_t capacity, size_t off_src, size_t off_dst,
5152

5253
char *dst_beg = dst_buffer_beg + off_dst;
5354
char *dst_end = dst_beg + capacity;
55+
if (benchmark) {
56+
__sanitizer_copy_contiguous_container_annotations(src_beg, src_end, dst_beg,
57+
dst_end);
58+
return;
59+
}
5460

5561
std::vector<int> src_poison_states =
5662
GetPoisonedState(src_buffer_beg, src_buffer_end);
@@ -84,6 +90,7 @@ static void Test(size_t capacity, size_t off_src, size_t off_dst,
8490
}
8591
}
8692

93+
template <bool benchmark>
8794
static void TestNonOverlappingContainers(size_t capacity, size_t off_src,
8895
size_t off_dst) {
8996
// Test will copy [off_src, off_src + capacity) to [off_dst, off_dst + capacity).
@@ -107,17 +114,20 @@ static void TestNonOverlappingContainers(size_t capacity, size_t off_src,
107114
assert(RoundDown(dst_buffer_beg) == dst_buffer_beg);
108115

109116
for (int i = 0; i < 35; i++) {
110-
RandomPoison(src_buffer_beg, src_buffer_end);
111-
RandomPoison(dst_buffer_beg, dst_buffer_end);
117+
if (!benchmark || !i) {
118+
RandomPoison(src_buffer_beg, src_buffer_end);
119+
RandomPoison(dst_buffer_beg, dst_buffer_end);
120+
}
112121

113-
Test(capacity, off_src, off_dst, src_buffer_beg, src_buffer_end,
114-
dst_buffer_beg, dst_buffer_end);
122+
Test<benchmark>(capacity, off_src, off_dst, src_buffer_beg, src_buffer_end,
123+
dst_buffer_beg, dst_buffer_end);
115124
}
116125

117126
__asan_unpoison_memory_region(src_buffer_beg, src_buffer_size);
118127
__asan_unpoison_memory_region(dst_buffer_beg, dst_buffer_size);
119128
}
120129

130+
template <bool benchmark>
121131
static void TestOverlappingContainers(size_t capacity, size_t off_src,
122132
size_t off_dst) {
123133
// Test will copy [off_src, off_src + capacity) to [off_dst, off_dst + capacity).
@@ -135,10 +145,10 @@ static void TestOverlappingContainers(size_t capacity, size_t off_src,
135145
assert(RoundDown(buffer_beg) == buffer_beg);
136146

137147
for (int i = 0; i < 35; i++) {
138-
RandomPoison(buffer_beg, buffer_end);
139-
140-
Test(capacity, off_src, off_dst, buffer_beg, buffer_end, buffer_beg,
141-
buffer_end);
148+
if (!benchmark || !i)
149+
RandomPoison(buffer_beg, buffer_end);
150+
Test<benchmark>(capacity, off_src, off_dst, buffer_beg, buffer_end,
151+
buffer_beg, buffer_end);
142152
}
143153

144154
__asan_unpoison_memory_region(buffer_beg, buffer_size);
@@ -149,9 +159,14 @@ int main(int argc, char **argv) {
149159
for (size_t off_src = 0; off_src < kGranularity; off_src++) {
150160
for (size_t off_dst = 0; off_dst < kGranularity; off_dst++) {
151161
for (int capacity = 0; capacity <= n; capacity++) {
152-
TestNonOverlappingContainers(capacity, off_src, off_dst);
153-
TestOverlappingContainers(capacity, off_src, off_dst);
162+
if (n < 1024) {
163+
TestNonOverlappingContainers<false>(capacity, off_src, off_dst);
164+
TestOverlappingContainers<false>(capacity, off_src, off_dst);
165+
} else {
166+
TestNonOverlappingContainers<true>(capacity, off_src, off_dst);
167+
TestOverlappingContainers<true>(capacity, off_src, off_dst);
168+
}
154169
}
155170
}
156171
}
157-
}
172+
}

0 commit comments

Comments
 (0)