1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2 // XFAIL: android
3 //
4 // RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
5 // RUN: rm -rf %T/coverage-maybe-open-file
6 // RUN: mkdir -p %T/coverage-maybe-open-file && cd %T/coverage-maybe-open-file
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
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 
16 #include <sanitizer/coverage_interface.h>
17 
18 // FIXME: the code below might not work on Windows.
main(int argc,char ** argv)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
33