From f180c0ec5717f8d48d905574453396466d1c6d22 Mon Sep 17 00:00:00 2001 From: Connie Zhu Date: Sat, 24 Aug 2024 21:53:26 +0000 Subject: [PATCH 1/3] [llvm-lit] Fixed typo in raising InternalShellError in built-in export command This patch fixes a typo in lit's built-in export command, which returns an InternalShellError when more than one argument is given to the export. The InternalShellError was missing the cmd parameter when raised, leading to issues when a test using export fails in high-address-dereference.c in compiler-rt. --- llvm/utils/lit/lit/TestRunner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index da7fa86fd3917..63ab5e4c18349 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -356,7 +356,7 @@ def executeBuiltinPopd(cmd, shenv): def executeBuiltinExport(cmd, shenv): """executeBuiltinExport - Set an environment variable.""" if len(cmd.args) != 2: - raise InternalShellError("'export' supports only one argument") + raise InternalShellError(cmd, "'export' supports only one argument") updateEnv(shenv, cmd.args) return ShellCommandResult(cmd, "", "", 0, False) From 5889fc5fd0b07c92aa5b4becbfe4cfdd37e9e2ad Mon Sep 17 00:00:00 2001 From: Connie Zhu Date: Sat, 24 Aug 2024 22:00:26 +0000 Subject: [PATCH 2/3] [compiler-rt][test] Rewrote test to fix usage of export with 2 arguments This patch fixes the incorrect usage of lit's built-in export command in this compiler-rt test. The export command only allows for one argument, but %env_asan_opts expands to "env ASAN_OPTIONS", which gives export two arguments instead of only one. Instead of using export, which propogates the environment variable value to all subsequent commands, the environment variable is manually set before all RUN lines following the original export line. --- .../asan/TestCases/Posix/high-address-dereference.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler-rt/test/asan/TestCases/Posix/high-address-dereference.c b/compiler-rt/test/asan/TestCases/Posix/high-address-dereference.c index 845e126d3f89b..37a7b1702e982 100644 --- a/compiler-rt/test/asan/TestCases/Posix/high-address-dereference.c +++ b/compiler-rt/test/asan/TestCases/Posix/high-address-dereference.c @@ -5,12 +5,11 @@ // REQUIRES: x86_64-target-arch // RUN: %clang_asan %s -o %t -// RUN: export %env_asan_opts=print_scariness=1 -// RUN: not %run %t 0x0000000000000000 2>&1 | FileCheck %s --check-prefixes=ZERO,HINT-PAGE0 -// RUN: not %run %t 0x0000000000000FFF 2>&1 | FileCheck %s --check-prefixes=LOW1,HINT-PAGE0 -// RUN: not %run %t 0x0000000000001000 2>&1 | FileCheck %s --check-prefixes=LOW2,HINT-NONE -// RUN: not %run %t 0x4141414141414141 2>&1 | FileCheck %s --check-prefixes=HIGH,HINT-HIGHADDR -// RUN: not %run %t 0xFFFFFFFFFFFFFFFF 2>&1 | FileCheck %s --check-prefixes=MAX,HINT-HIGHADDR +// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000000000 2>&1 | FileCheck %s --check-prefixes=ZERO,HINT-PAGE0 +// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000000FFF 2>&1 | FileCheck %s --check-prefixes=LOW1,HINT-PAGE0 +// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000001000 2>&1 | FileCheck %s --check-prefixes=LOW2,HINT-NONE +// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x4141414141414141 2>&1 | FileCheck %s --check-prefixes=HIGH,HINT-HIGHADDR +// RUN: %env_asan_opts=print_scariness=1 not %run %t 0xFFFFFFFFFFFFFFFF 2>&1 | FileCheck %s --check-prefixes=MAX,HINT-HIGHADDR #include #include From c83d7e0cb82b7ed9edbdc183d8a252f84aa9363b Mon Sep 17 00:00:00 2001 From: Connie Zhu Date: Mon, 26 Aug 2024 20:38:32 +0000 Subject: [PATCH 3/3] [llvm-lit][test] Created test for built-in export with too many args This patch creates a test to show the failing behavior for lit's built-in export command when given more than one argument. --- .../asan/TestCases/Posix/high-address-dereference.c | 11 ++++++----- .../Inputs/shtest-export/export-too-many-args.txt | 2 ++ llvm/utils/lit/tests/Inputs/shtest-export/lit.cfg | 7 +++++++ llvm/utils/lit/tests/shtest-export.py | 12 ++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 llvm/utils/lit/tests/Inputs/shtest-export/export-too-many-args.txt create mode 100644 llvm/utils/lit/tests/Inputs/shtest-export/lit.cfg create mode 100644 llvm/utils/lit/tests/shtest-export.py diff --git a/compiler-rt/test/asan/TestCases/Posix/high-address-dereference.c b/compiler-rt/test/asan/TestCases/Posix/high-address-dereference.c index 37a7b1702e982..845e126d3f89b 100644 --- a/compiler-rt/test/asan/TestCases/Posix/high-address-dereference.c +++ b/compiler-rt/test/asan/TestCases/Posix/high-address-dereference.c @@ -5,11 +5,12 @@ // REQUIRES: x86_64-target-arch // RUN: %clang_asan %s -o %t -// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000000000 2>&1 | FileCheck %s --check-prefixes=ZERO,HINT-PAGE0 -// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000000FFF 2>&1 | FileCheck %s --check-prefixes=LOW1,HINT-PAGE0 -// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000001000 2>&1 | FileCheck %s --check-prefixes=LOW2,HINT-NONE -// RUN: %env_asan_opts=print_scariness=1 not %run %t 0x4141414141414141 2>&1 | FileCheck %s --check-prefixes=HIGH,HINT-HIGHADDR -// RUN: %env_asan_opts=print_scariness=1 not %run %t 0xFFFFFFFFFFFFFFFF 2>&1 | FileCheck %s --check-prefixes=MAX,HINT-HIGHADDR +// RUN: export %env_asan_opts=print_scariness=1 +// RUN: not %run %t 0x0000000000000000 2>&1 | FileCheck %s --check-prefixes=ZERO,HINT-PAGE0 +// RUN: not %run %t 0x0000000000000FFF 2>&1 | FileCheck %s --check-prefixes=LOW1,HINT-PAGE0 +// RUN: not %run %t 0x0000000000001000 2>&1 | FileCheck %s --check-prefixes=LOW2,HINT-NONE +// RUN: not %run %t 0x4141414141414141 2>&1 | FileCheck %s --check-prefixes=HIGH,HINT-HIGHADDR +// RUN: not %run %t 0xFFFFFFFFFFFFFFFF 2>&1 | FileCheck %s --check-prefixes=MAX,HINT-HIGHADDR #include #include diff --git a/llvm/utils/lit/tests/Inputs/shtest-export/export-too-many-args.txt b/llvm/utils/lit/tests/Inputs/shtest-export/export-too-many-args.txt new file mode 100644 index 0000000000000..b282e1a176498 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-export/export-too-many-args.txt @@ -0,0 +1,2 @@ +## Test export command with too many arguments. +# RUN: export FOO=1 BAR=2 diff --git a/llvm/utils/lit/tests/Inputs/shtest-export/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-export/lit.cfg new file mode 100644 index 0000000000000..22ddf13ea3857 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-export/lit.cfg @@ -0,0 +1,7 @@ +import lit.formats + +config.name = "shtest-export" +config.suffixes = [".txt"] +config.test_format = lit.formats.ShTest() +config.test_source_root = None +config.test_exec_root = None diff --git a/llvm/utils/lit/tests/shtest-export.py b/llvm/utils/lit/tests/shtest-export.py new file mode 100644 index 0000000000000..f2de8e8cd8b5f --- /dev/null +++ b/llvm/utils/lit/tests/shtest-export.py @@ -0,0 +1,12 @@ +## Test the export command. + +# RUN: not %{lit} -a -v %{inputs}/shtest-export \ +# RUN: | FileCheck -match-full-lines %s +# +# END. + +# CHECK: FAIL: shtest-export :: export-too-many-args.txt {{.*}} +# CHECK: export FOO=1 BAR=2 +# CHECK: # executed command: export FOO=1 BAR=2 +# CHECK: # | 'export' supports only one argument +# CHECK: # error: command failed with exit status: {{.*}}