[sanitizer] Second test fix to tolerate chmod not working as intended

Second attempt to fix a bot failure from
634da7a1c6 on an Android bot:
https://lab.llvm.org/buildbot#builders/77/builds/14339

With the fix in 986afe8479 there was a
different issue, because we need the fully qualified path name to the
binary, which is only available in arg[0]. New failure:
https://lab.llvm.org/buildbot/#/builders/77/builds/14346/steps/16/logs/stdio

Restructure the test so both attempts are made from the same invocation,
which sets up the bad paths directly.
This commit is contained in:
Teresa Johnson 2022-02-13 17:00:04 -08:00
parent 890beda4e1
commit 273600b6e3

View file

@ -1,13 +1,9 @@
// Test __sanitizer_set_report_path and __sanitizer_get_report_path: // Test __sanitizer_set_report_path and __sanitizer_get_report_path:
// RUN: rm -rf %t.report_path
// RUN: %clangxx -O2 %s -o %t // RUN: %clangxx -O2 %s -o %t
// RUN: %run %t %t | FileCheck %s // Create a directory without write access.
// Try again with a directory without write access.
// RUN: rm -rf %t.baddir && mkdir -p %t.baddir // RUN: rm -rf %t.baddir && mkdir -p %t.baddir
// RUN: chmod u-w %t.baddir || true // RUN: chmod u-w %t.baddir || true
// Use invalid characters in directory name in case chmod doesn't work as // RUN: not %run %t 2>&1 | FileCheck %s
// intended.
// RUN: not %run %t %t.baddir/?bad? 2>&1 | FileCheck %s --check-prefix=FAIL
#include <assert.h> #include <assert.h>
#include <sanitizer/common_interface_defs.h> #include <sanitizer/common_interface_defs.h>
@ -18,11 +14,21 @@ volatile int *null = 0;
int main(int argc, char **argv) { int main(int argc, char **argv) {
char buff[1000]; char buff[1000];
sprintf(buff, "%s.report_path/report", argv[1]); sprintf(buff, "%s.report_path/report", argv[0]);
__sanitizer_set_report_path(buff);
assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0);
printf("Path %s\n", __sanitizer_get_report_path());
fflush(stdout);
// Try setting again with an invalid/inaccessible directory.
// Use invalid characters in directory name in case chmod doesn't work as
// intended.
sprintf(buff, "%s.baddir/?bad?/report", argv[0]);
__sanitizer_set_report_path(buff); __sanitizer_set_report_path(buff);
assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0); assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0);
printf("Path %s\n", __sanitizer_get_report_path()); printf("Path %s\n", __sanitizer_get_report_path());
} }
// CHECK: Path {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp.report_path/report. // CHECK: Path {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp.report_path/report.
// FAIL: ERROR: Can't create directory: {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp.baddir // CHECK: ERROR: Can't create directory: {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp.baddir
// CHECK-NOT: Path {{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp.baddir