1 // Tests ASAN_OPTIONS=allocator_release_to_os=1
3 // RUN: %clangxx_asan -std=c++11 %s -o %t
4 // RUN: %env_asan_opts=allocator_release_to_os_interval_ms=0 %run %t 2>&1 | FileCheck %s --check-prefix=RELEASE
5 // RUN: %env_asan_opts=allocator_release_to_os_interval_ms=-1 %run %t 2>&1 | FileCheck %s --check-prefix=NO_RELEASE
6 // RUN: %env_asan_opts=allocator_release_to_os_interval_ms=-1 %run %t force 2>&1 | FileCheck %s --check-prefix=FORCE_RELEASE
8 // REQUIRES: x86_64-target-arch
18 #include <sanitizer/allocator_interface.h>
19 #include <sanitizer/asan_interface.h>
21 void MallocReleaseStress() {
22 const size_t kNumChunks
= 10000;
23 const size_t kAllocSize
= 100;
24 const size_t kNumIter
= 100;
25 uintptr_t *chunks
[kNumChunks
] = {0};
28 for (size_t iter
= 0; iter
< kNumIter
; iter
++) {
29 std::shuffle(chunks
, chunks
+ kNumChunks
, r
);
30 size_t to_replace
= rand() % kNumChunks
;
31 for (size_t i
= 0; i
< kNumChunks
; i
++) {
33 assert(chunks
[i
][0] == (uintptr_t)chunks
[i
]);
36 chunks
[i
] = new uintptr_t[kAllocSize
];
37 chunks
[i
][0] = (uintptr_t)chunks
[i
];
45 int main(int argc
, char **argv
) {
46 MallocReleaseStress();
47 if (argc
> 1 && !strcmp("force", argv
[1]))
48 __sanitizer_purge_allocator();
49 __asan_print_accumulated_stats();
52 // RELEASE: mapped:{{.*}}releases: {{[1-9]}}
53 // NO_RELEASE: mapped:{{.*}}releases: 0
54 // FORCE_RELEASE: mapped:{{.*}}releases: {{[1-9]}}