]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/asan/TestCases/coverage-caller-callee-total-count.cc
1 // Test __sanitizer_get_total_unique_coverage for caller-callee coverage
3 // RUN: %clangxx_asan -fsanitize-coverage=edge,indirect-calls %s -o %t
4 // RUN: %env_asan_opts=coverage=1 %run %t
5 // RUN: rm -f caller-callee*.sancov
7 // REQUIRES: asan-64-bits
9 #include <sanitizer/coverage_interface.h>
13 struct Foo
{virtual void f() {if (P
) printf("Foo::f()\n");}};
14 struct Foo1
: Foo
{virtual void f() {if (P
) printf("%d\n", __LINE__
);}};
15 struct Foo2
: Foo
{virtual void f() {if (P
) printf("%d\n", __LINE__
);}};
17 Foo
*foo
[3] = {new Foo
, new Foo1
, new Foo2
};
19 uintptr_t CheckNewTotalUniqueCoverageIsLargerAndReturnIt(uintptr_t old_total
) {
20 uintptr_t new_total
= __sanitizer_get_total_unique_caller_callee_pairs();
21 fprintf(stderr
, "Caller-Callee: old %zd new %zd\n", old_total
, new_total
);
22 assert(new_total
> old_total
);
26 int main(int argc
, char **argv
) {
27 uintptr_t total
= __sanitizer_get_total_unique_caller_callee_pairs();
29 total
= CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total
);
31 total
= CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total
);
33 total
= CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total
);
34 // Ok, called every function once.
35 // Now call them again from another call site. Should get new coverage.
37 total
= CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total
);
39 total
= CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total
);
41 total
= CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total
);