Skip to content

Commit c69b8c4

Browse files
authored
[compiler-rt][NFC] Replace environment variable with %t (#102197)
Certain tests within the compiler-rt subproject encountered "command not found" errors when using lit's internal shell, particularly when trying to use the `DIR` environment variable. When checking with the command `LIT_USE_INTERNAL_SHELL=1 ninja check-compiler-rt`, I encountered the following error: ``` ******************** Testing: FAIL: SanitizerCommon-ubsan-i386-Linux :: sanitizer_coverage_trace_pc_guard-init.cpp (146 of 9570) ******************** TEST 'SanitizerCommon-ubsan-i386-Linux :: sanitizer_coverage_trace_pc_guard-init.cpp' FAILED ******************** Exit Code: 127 Command Output (stdout): -- # RUN: at line 5 DIR=/usr/local/google/home/harinidonthula/llvm-project/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Output/sanitizer_coverage_trace_pc_guard-init.cpp.tmp_workdir # executed command: DIR=/usr/local/google/home/harinidonthula/llvm-project/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Output/sanitizer_coverage_trace_pc_guard-init.cpp.tmp_workdir # .---command stderr------------ # | 'DIR=/usr/local/google/home/harinidonthula/llvm-project/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-i386-Linux/Output/sanitizer_coverage_trace_pc_guard-init.cpp.tmp_workdir': command not found # `----------------------------- # error: command failed with exit status: 127 ``` In this patch, I resolved these issues by removing the use of the `DIR` environment variable. Instead, the tests now directly utilize `%t_workdir` for managing temporary directories. Additionally, I simplified the tests by embedding the clang command arguments directly into the test scripts, which avoids complications with environment variable expansion under lit's internal shell. This fix ensures that the tests run smoothly with lit's internal shell and prevents the "command not found" errors, improving the reliability of the test suite when executed in this environment. fixes: #102395 [link to RFC](https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179)
1 parent 4bffbba commit c69b8c4

5 files changed

+26
-33
lines changed

compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_allowlist_ignorelist.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
// XFAIL: ubsan,tsan
88
// XFAIL: android && asan
99

10-
// RUN: DIR=%t_workdir
11-
// RUN: rm -rf $DIR
12-
// RUN: mkdir -p $DIR
13-
// RUN: cd $DIR
10+
// RUN: rm -rf %t_workdir
11+
// RUN: mkdir -p %t_workdir
12+
// RUN: cd %t_workdir
1413

1514
// RUN: echo -e "src:*\nfun:*" > al_all.txt
1615
// RUN: echo -e "" > al_none.txt
@@ -82,7 +81,7 @@
8281
// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_bar.txt -fsanitize-coverage-ignorelist=bl_bar.txt 2>&1 | not grep -f patterns.txt
8382

8483
// RUN: cd -
85-
// RUN: rm -rf $DIR
84+
// RUN: rm -rf %t_workdir
8685

8786
// foo has 3 instrumentation points, 0 indirect call, 1 comparison point
8887

compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_symbolize.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
// REQUIRES: x86_64-linux
44
// XFAIL: tsan
55
//
6-
// RUN: DIR=%t_workdir
7-
// RUN: rm -rf $DIR
8-
// RUN: mkdir -p $DIR
9-
// RUN: cd $DIR
6+
// RUN: rm -rf %t_workdir
7+
// RUN: mkdir -p %t_workdir
8+
// RUN: cd %t_workdir
109
/// In glibc 2.39+, fprintf has a nonnull attribute. Disable nonnull-attribute,
1110
/// which would increase counters for ubsan.
1211
// RUN: %clangxx -O0 -fsanitize-coverage=trace-pc-guard -fno-sanitize=nonnull-attribute %s -o %t
1312
// RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s
14-
// RUN: rm -rf $DIR
13+
// RUN: rm -rf %t_workdir
1514

1615
#include <stdio.h>
1716

compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
// XFAIL: tsan,darwin
66
// XFAIL: android && asan
77

8-
// RUN: DIR=%t_workdir
9-
// RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard"
10-
// RUN: rm -rf $DIR
11-
// RUN: mkdir -p $DIR
12-
// RUN: cd $DIR
13-
// RUN: %clangxx -DSHARED1 $CLANG_ARGS -shared %s -o %t_1.so -fPIC
14-
// RUN: %clangxx -DSHARED2 $CLANG_ARGS -shared %s -o %t_2.so -fPIC
15-
// RUN: %clangxx -DMAIN $CLANG_ARGS %s -o %t %t_1.so %t_2.so
8+
// RUN: rm -rf %t_workdir
9+
// RUN: mkdir -p %t_workdir
10+
// RUN: cd %t_workdir
11+
// RUN: %clangxx -DSHARED1 -O0 -fsanitize-coverage=trace-pc-guard -shared %s -o %t_1.so -fPIC
12+
// RUN: %clangxx -DSHARED2 -O0 -fsanitize-coverage=trace-pc-guard -shared %s -o %t_2.so -fPIC
13+
// RUN: %clangxx -DMAIN -O0 -fsanitize-coverage=trace-pc-guard %s -o %t %t_1.so %t_2.so
1614
// RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s
1715
// RUN: %sancovcc -covered-functions -strip_path_prefix=TestCases/ *.sancov \
1816
// RUN: %t %t_1.so %t_2.so 2>&1 | \
1917
// RUN: FileCheck --check-prefix=CHECK-SANCOV %s
20-
// RUN: rm -rf $DIR
18+
// RUN: rm -rf %t_workdir
2119

2220
#include <stdio.h>
2321

compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-init.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
//
33
// REQUIRES: has_sancovcc,stable-runtime,x86_64-linux
44
//
5-
// RUN: DIR=%t_workdir
6-
// RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard"
7-
// RUN: rm -rf $DIR
8-
// RUN: mkdir -p $DIR
9-
// RUN: cd $DIR
10-
// RUN: %clangxx -DSHARED1 $CLANG_ARGS -shared %s -o %t_1.so -fPIC
11-
// RUN: %clangxx -DSTATIC1 $CLANG_ARGS %s -c -o %t_2.o
12-
// RUN: %clangxx -DMAIN $CLANG_ARGS %s -o %t %t_1.so %t_2.o
5+
// RUN: rm -rf %t_workdir
6+
// RUN: mkdir -p %t_workdir
7+
// RUN: cd %t_workdir
8+
// RUN: %clangxx -DSHARED1 -O0 -fsanitize-coverage=trace-pc-guard -shared %s -o %t_1.so -fPIC
9+
// RUN: %clangxx -DSTATIC1 -O0 -fsanitize-coverage=trace-pc-guard %s -c -o %t_2.o
10+
// RUN: %clangxx -DMAIN -O0 -fsanitize-coverage=trace-pc-guard %s -o %t %t_1.so %t_2.o
1311
// RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s
14-
// RUN: rm -rf $DIR
12+
// RUN: rm -rf %t_workdir
1513

1614
#include <stdio.h>
1715
#include <stdint.h>

compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
// XFAIL: tsan
88
// XFAIL: android && asan
99

10-
// RUN: DIR=%t_workdir
11-
// RUN: rm -rf $DIR
12-
// RUN: mkdir -p $DIR
13-
// RUN: cd $DIR
10+
// RUN: rm -rf %t_workdir
11+
// RUN: mkdir -p %t_workdir
12+
// RUN: cd %t_workdir
1413
// RUN: %clangxx -O0 -fsanitize-coverage=trace-pc-guard %s -o %t
1514
// RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s
1615
// RUN: %sancovcc -covered-functions -strip_path_prefix=TestCases/ *.sancov %t 2>&1 | \
1716
// RUN: FileCheck --check-prefix=CHECK-SANCOV %s
1817
// RUN: %env_tool_opts=coverage=0 %t 2>&1 | FileCheck --check-prefix=CHECK-NOCOV %s
19-
// RUN: rm -rf $DIR
18+
// RUN: rm -rf %t_workdir
2019
// Make some room to stabilize line numbers
2120

2221
#include <stdio.h>

0 commit comments

Comments
 (0)