blob: 955ffe5a9040a18aad8f135b8635c6832ce69a14 [file] [log] [blame]
Stephen Hines6d186232014-11-26 17:56:19 -08001// Test __sanitizer_get_total_unique_coverage for caller-callee coverage
2
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07003// RUN: %clangxx_asan -fsanitize-coverage=edge,indirect-calls %s -o %t
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08004// RUN: %env_asan_opts=coverage=1 %run %t
Stephen Hines6d186232014-11-26 17:56:19 -08005// RUN: rm -f caller-callee*.sancov
6//
7// REQUIRES: asan-64-bits
8
Stephen Hines86277eb2015-03-23 12:06:32 -07009#include <sanitizer/coverage_interface.h>
Stephen Hines6d186232014-11-26 17:56:19 -080010#include <stdio.h>
11#include <assert.h>
12int P = 0;
13struct Foo {virtual void f() {if (P) printf("Foo::f()\n");}};
14struct Foo1 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
15struct Foo2 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
16
17Foo *foo[3] = {new Foo, new Foo1, new Foo2};
18
19uintptr_t CheckNewTotalUniqueCoverageIsLargerAndReturnIt(uintptr_t old_total) {
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080020 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);
Stephen Hines6d186232014-11-26 17:56:19 -080022 assert(new_total > old_total);
23 return new_total;
24}
25
26int main(int argc, char **argv) {
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080027 uintptr_t total = __sanitizer_get_total_unique_caller_callee_pairs();
Stephen Hines6d186232014-11-26 17:56:19 -080028 foo[0]->f();
29 total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
30 foo[1]->f();
31 total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
32 foo[2]->f();
33 total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
34 // Ok, called every function once.
35 // Now call them again from another call site. Should get new coverage.
36 foo[0]->f();
37 total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
38 foo[1]->f();
39 total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
40 foo[2]->f();
41 total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
42}