1// Test __sanitizer_set_report_path and __sanitizer_get_report_path with an
2// unwritable directory.
3// RUN: rm -rf %t.report_path && mkdir -p %t.report_path
4// RUN: chmod u-w %t.report_path || true
5// RUN: %clangxx -O2 %s -o %t
6// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=FAIL
7
8// The chmod is not working on the android bot for some reason.
9// UNSUPPORTED: android
10
11#include <assert.h>
12#include <sanitizer/common_interface_defs.h>
13#include <stdio.h>
14#include <string.h>
15
16volatile int *null = 0;
17
18int main(int argc, char **argv) {
19 char buff[1000];
20 sprintf(s: buff, format: "%s.report_path/report", argv[0]);
21 __sanitizer_set_report_path(path: buff);
22 assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0);
23 printf(format: "Path %s\n", __sanitizer_get_report_path());
24}
25
26// FAIL: ERROR: Can't open file: {{.*}}Posix/Output/sanitizer_bad_report_path_test.cpp.tmp.report_path/report.
27// FAIL-NOT: Path {{.*}}Posix/Output/sanitizer_bad_report_path_test.cpp.tmp.report_path/report.
28

source code of compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_bad_report_path_test.cpp