Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 1 | // Test __sanitizer_get_total_unique_coverage for caller-callee coverage |
| 2 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 3 | // RUN: %clangxx_asan -fsanitize-coverage=edge,indirect-calls %s -o %t |
| 4 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1 %run %t |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 5 | // RUN: rm -f caller-callee*.sancov |
| 6 | // |
| 7 | // REQUIRES: asan-64-bits |
| 8 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 9 | #include <sanitizer/coverage_interface.h> |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <assert.h> |
| 12 | int P = 0; |
| 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__);}}; |
| 16 | |
| 17 | Foo *foo[3] = {new Foo, new Foo1, new Foo2}; |
| 18 | |
| 19 | uintptr_t CheckNewTotalUniqueCoverageIsLargerAndReturnIt(uintptr_t old_total) { |
| 20 | uintptr_t new_total = __sanitizer_get_total_unique_coverage(); |
| 21 | assert(new_total > old_total); |
| 22 | return new_total; |
| 23 | } |
| 24 | |
| 25 | int main(int argc, char **argv) { |
| 26 | uintptr_t total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(0); |
| 27 | foo[0]->f(); |
| 28 | total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total); |
| 29 | foo[1]->f(); |
| 30 | total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total); |
| 31 | foo[2]->f(); |
| 32 | total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total); |
| 33 | // Ok, called every function once. |
| 34 | // Now call them again from another call site. Should get new coverage. |
| 35 | foo[0]->f(); |
| 36 | total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total); |
| 37 | foo[1]->f(); |
| 38 | total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total); |
| 39 | foo[2]->f(); |
| 40 | total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total); |
| 41 | } |