xref: /aosp_15_r20/external/compiler-rt/test/esan/TestCases/workingset-memset.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clang_esan_wset -O0 %s -o %t 2>&1
2*7c3d14c8STreehugger Robot // RUN: %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot 
4*7c3d14c8STreehugger Robot #include <stdlib.h>
5*7c3d14c8STreehugger Robot #include <string.h>
6*7c3d14c8STreehugger Robot #include <sys/mman.h>
7*7c3d14c8STreehugger Robot #include <assert.h>
8*7c3d14c8STreehugger Robot #include <string.h>
9*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)10*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
11*7c3d14c8STreehugger Robot   const int size = 128*1024*1024;
12*7c3d14c8STreehugger Robot   char *p = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
13*7c3d14c8STreehugger Robot                          MAP_ANON | MAP_PRIVATE, -1, 0);
14*7c3d14c8STreehugger Robot   // Test the slowpath at different cache line boundaries.
15*7c3d14c8STreehugger Robot   for (int i = 0; i < 630; i++)
16*7c3d14c8STreehugger Robot     memset((char *)p + 63*i, i, 63*i);
17*7c3d14c8STreehugger Robot   munmap(p, size);
18*7c3d14c8STreehugger Robot   return 0;
19*7c3d14c8STreehugger Robot   // CHECK: {{.*}} EfficiencySanitizer: the total working set size: 77 KB (12{{[0-9]+}} cache lines)
20*7c3d14c8STreehugger Robot }
21