[compiler-rt] 42d06b8 - [compiler-rt][test] Change tests to remove the use of `unset` command in lit internal shell (#104880)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 14:39:26 PDT 2024


Author: Harini0924
Date: 2024-08-22T14:39:23-07:00
New Revision: 42d06b8e555727e8e043d5ea9240ad103d950192

URL: https://github.com/llvm/llvm-project/commit/42d06b8e555727e8e043d5ea9240ad103d950192
DIFF: https://github.com/llvm/llvm-project/commit/42d06b8e555727e8e043d5ea9240ad103d950192.diff

LOG: [compiler-rt][test] Change tests to remove the use of `unset` command in lit internal shell  (#104880)

This patch rewrites tests to remove the use of the `unset` command,
which is not supported in the lit internal shell. The tests now use the
`env -u` to unset environment variables.

The `unset` command is used in shell environments to remove the
environment variable. However, because the lit internal shell does not
support the `unset` command, using it in tests would result in errors or
other unexpected behavior. To overcome this limitation, the tests have
been updated to use the `env -u` command instead. `env -u` is supported
by lit and effectively removes specified environment variables. This
allows the tests to achieve the same goal of unsetting environment
variables while ensuring compatibility with the lit internal shell.

This change is relevant for [[RFC] Enabling the Lit Internal Shell by
Default](https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179/3)
Fixes: #102397

Added: 
    

Modified: 
    compiler-rt/test/fuzzer/afl-driver-close-fd-mask.test
    compiler-rt/test/fuzzer/afl-driver-stderr.test

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/fuzzer/afl-driver-close-fd-mask.test b/compiler-rt/test/fuzzer/afl-driver-close-fd-mask.test
index 71f74e27ec4fe6..98c7f08697c174 100644
--- a/compiler-rt/test/fuzzer/afl-driver-close-fd-mask.test
+++ b/compiler-rt/test/fuzzer/afl-driver-close-fd-mask.test
@@ -3,29 +3,28 @@ RUN: %no_fuzzer_cpp_compiler %S/AFLDriverTest.cpp %libfuzzer_src/afl/afl_driver.
 
 ; Test that not specifying AFL_DRIVER_CLOSE_FD_MASK works as intended.
 RUN: echo -n "abc" > %t.file3
-RUN: unset AFL_DRIVER_CLOSE_FD_MASK
-RUN: %run %t-AFLDriverTest < %t.file3 2>&1 | FileCheck %s --check-prefixes=STDERR,STDOUT
+RUN: env -u AFL_DRIVER_CLOSE_FD_MASK %run %t-AFLDriverTest < %t.file3 2>&1 | FileCheck %s --check-prefixes=STDERR,STDOUT
 STDOUT: STDOUT MESSAGE
 STDERR: STDERR MESSAGE
 
 ; Test that stdout is closed properly.
-RUN: AFL_DRIVER_CLOSE_FD_MASK=1 %run %t-AFLDriverTest < %t.file3 2>&1 | FileCheck %s --check-prefixes=NOT_STDOUT,STDERR
+RUN: env AFL_DRIVER_CLOSE_FD_MASK=1 %run %t-AFLDriverTest < %t.file3 2>&1 | FileCheck %s --check-prefixes=NOT_STDOUT,STDERR
 NOT_STDOUT-NOT: STDOUT MESSAGE
 
 ; Test that stderr is closed properly.
-RUN: AFL_DRIVER_CLOSE_FD_MASK=2 %run %t-AFLDriverTest < %t.file3 2>&1 | FileCheck %s --check-prefixes=NOT_STDERR,STDOUT
+RUN: env AFL_DRIVER_CLOSE_FD_MASK=2 %run %t-AFLDriverTest < %t.file3 2>&1 | FileCheck %s --check-prefixes=NOT_STDERR,STDOUT
 NOT_STDERR-NOT: STDERR MESSAGE
 
 ; Test that both are closed properly.
-RUN: AFL_DRIVER_CLOSE_FD_MASK=3 %run %t-AFLDriverTest < %t.file3 2>&1 | FileCheck %s --check-prefixes=NOT_STDERR,NOT_STDOUT
+RUN: env AFL_DRIVER_CLOSE_FD_MASK=3 %run %t-AFLDriverTest < %t.file3 2>&1 | FileCheck %s --check-prefixes=NOT_STDERR,NOT_STDOUT
 
 ; Test that a stack is printed when we close stderr
 RUN: echo -n "abcd" > %t.file4
-RUN: AFL_DRIVER_CLOSE_FD_MASK=2 not %run %t-AFLDriverTest < %t.file4 2>&1  | FileCheck %s --check-prefixes=ASAN_CRASH,STDOUT,NOT_STDERR
+RUN: env AFL_DRIVER_CLOSE_FD_MASK=2 not %run %t-AFLDriverTest < %t.file4 2>&1  | FileCheck %s --check-prefixes=ASAN_CRASH,STDOUT,NOT_STDERR
 ASAN_CRASH: ERROR: AddressSanitizer
 
 ; Test that a stack is written to the stderr duplicate file when we close stderr
 ; and specify a duplicate.
 RUN: rm -f %t.stderr
-RUN: AFL_DRIVER_STDERR_DUPLICATE_FILENAME=%t.stderr AFL_DRIVER_CLOSE_FD_MASK=2 not %run %t-AFLDriverTest < %t.file4
+RUN: env AFL_DRIVER_STDERR_DUPLICATE_FILENAME=%t.stderr AFL_DRIVER_CLOSE_FD_MASK=2 not %run %t-AFLDriverTest < %t.file4
 RUN: cat %t.stderr | FileCheck %s --check-prefixes=ASAN_CRASH,NOT_STDERR

diff  --git a/compiler-rt/test/fuzzer/afl-driver-stderr.test b/compiler-rt/test/fuzzer/afl-driver-stderr.test
index 84f21d4da5cbda..4b0c3b40221afd 100644
--- a/compiler-rt/test/fuzzer/afl-driver-stderr.test
+++ b/compiler-rt/test/fuzzer/afl-driver-stderr.test
@@ -4,12 +4,11 @@ XFAIL: ios
 RUN: %no_fuzzer_cpp_compiler %S/AFLDriverTest.cpp %libfuzzer_src/afl/afl_driver.cpp -o %t-AFLDriverTest
 
 ; Test that not specifying a stderr file isn't broken.
-RUN: unset AFL_DRIVER_STDERR_DUPLICATE_FILENAME
-RUN: %run %t-AFLDriverTest
+RUN: env -u AFL_DRIVER_STDERR_DUPLICATE_FILENAME %run %t-AFLDriverTest
 
 ; Test that specifying an invalid file causes a crash.
-RUN: ASAN_OPTIONS= AFL_DRIVER_STDERR_DUPLICATE_FILENAME="%T" not --crash %run %t-AFLDriverTest
+RUN: env ASAN_OPTIONS= AFL_DRIVER_STDERR_DUPLICATE_FILENAME="%T" not --crash %run %t-AFLDriverTest
 
 ; Test that a file is created when specified as the duplicate stderr.
-RUN: AFL_DRIVER_STDERR_DUPLICATE_FILENAME=%t %run %t-AFLDriverTest
+RUN: env AFL_DRIVER_STDERR_DUPLICATE_FILENAME=%t %run %t-AFLDriverTest
 RUN: stat %t


        


More information about the llvm-commits mailing list