blob: cab3d5770aa5ae358d16ce15497806b5694ea48e [file] [log] [blame]
Stephen Hines6a211c52014-07-21 00:49:56 -07001// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2// XFAIL: android
3//
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07004// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
Stephen Hines2d1fdb22014-05-28 23:58:16 -07005// 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 Nainar799172d2016-03-03 15:50:30 -08007// 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 Hines2d1fdb22014-05-28 23:58:16 -07009// 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 Hines86277eb2015-03-23 12:06:32 -070016#include <sanitizer/coverage_interface.h>
Stephen Hines2d1fdb22014-05-28 23:58:16 -070017
Pirama Arumuga Nainar7c915052015-04-08 08:58:29 -070018// FIXME: the code below might not work on Windows.
Stephen Hines2d1fdb22014-05-28 23:58:16 -070019int 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