Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 |
| 2 | // XFAIL: android |
| 3 | // |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 4 | // RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 5 | // RUN: rm -rf %T/coverage-maybe-open-file |
| 6 | // RUN: mkdir -p %T/coverage-maybe-open-file && cd %T/coverage-maybe-open-file |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 7 | // RUN: %env_asan_opts=coverage=1 %run %t | FileCheck %s --check-prefix=CHECK-success |
| 8 | // RUN: %env_asan_opts=coverage=0 %run %t | FileCheck %s --check-prefix=CHECK-fail |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 9 | // RUN: [ "$(cat test.sancov.packed)" == "test" ] |
| 10 | // RUN: cd .. && rm -rf %T/coverage-maybe-open-file |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <string.h> |
| 14 | #include <unistd.h> |
| 15 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 16 | #include <sanitizer/coverage_interface.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 17 | |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 18 | // FIXME: the code below might not work on Windows. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 19 | int main(int argc, char **argv) { |
| 20 | int fd = __sanitizer_maybe_open_cov_file("test"); |
| 21 | if (fd > 0) { |
| 22 | printf("SUCCESS\n"); |
| 23 | const char s[] = "test\n"; |
| 24 | write(fd, s, strlen(s)); |
| 25 | close(fd); |
| 26 | } else { |
| 27 | printf("FAIL\n"); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // CHECK-success: SUCCESS |
| 32 | // CHECK-fail: FAIL |