[llvm] [llvm-lit] Resolve env subcommand required error (PR #98414)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 17 23:36:25 PDT 2024
https://github.com/Harini0924 updated https://github.com/llvm/llvm-project/pull/98414
>From bd4f8975b8374e8e242c66834f38f2a0099dcec0 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Wed, 10 Jul 2024 23:22:04 +0000
Subject: [PATCH 1/4] [llvm-lit]
When executing not --crash env without any arguments,
it fails with exit code 127 because env reuires a
subcommand. This path addresses the issue by encoding
the command to properly return environment variables
even when no arguments are provided.
---
llvm/utils/lit/lit/TestRunner.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index da7fa86fd3917..8f0cd801ae9ff 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -743,7 +743,8 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
args = updateEnv(cmd_shenv, args)
if not args:
- raise InternalShellError(j, "Error: 'env' requires a" " subcommand")
+ # Return the environment variables if no argument is provided
+ return {key: value for key, value in cmd_shenv.env.items()}
elif args[0] == "not":
not_args.append(args.pop(0))
not_count += 1
>From 1c9b7a33aadd72acfd4d1405a9024574a39f9558 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Thu, 18 Jul 2024 06:12:28 +0000
Subject: [PATCH 2/4] [llvm-lit] Resolve env subcommand required error
This patch addresses an issue where calling env without any arguments
incorrectly returns a "requires subcommand" message. The patch modifies
the env command to properly display the current environment variables
even when no arguments are provided. Additionally, the test cases have been
updated: instead of returning an error, the tests now pass and check if
the environment variables are output correctly.
---
.../tests/Inputs/shtest-env/.lit_test_times.txt | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 llvm/utils/lit/tests/Inputs/shtest-env/.lit_test_times.txt
diff --git a/llvm/utils/lit/tests/Inputs/shtest-env/.lit_test_times.txt b/llvm/utils/lit/tests/Inputs/shtest-env/.lit_test_times.txt
new file mode 100644
index 0000000000000..fcaec704e4fe9
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env/.lit_test_times.txt
@@ -0,0 +1,16 @@
+3.034830e-03 env-args-last-is-assign.txt
+3.150702e-03 env-args-last-is-u-arg.txt
+3.008842e-03 env-args-last-is-u.txt
+3.021240e-03 env-args-nested-none.txt
+2.985716e-03 env-args-none.txt
+-3.101349e-03 env-calls-cd.txt
+-3.008127e-03 env-calls-colon.txt
+-3.023863e-03 env-calls-echo.txt
+-4.569292e-03 env-calls-env.txt
+-3.777266e-03 env-calls-export.txt
+-3.159523e-03 env-calls-mkdir.txt
+-3.111124e-03 env-calls-not-builtin.txt
+-2.997160e-03 env-calls-rm.txt
+-4.257917e-03 env-u.txt
+-4.087925e-03 env.txt
+-4.094124e-03 mixed.txt
>From a7fd33d7b9057becb6154da7fe167941b1f8877d Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Thu, 18 Jul 2024 06:22:59 +0000
Subject: [PATCH 3/4] [llvm-lit] Resolve env subcommand required error [change
2]
This patch addresses an issue where calling env without any arguments
incorrectly returns a "requires subcommand" message. The patch modifies
the env command to properly display the current environment variables
even when no arguments are provided. Additionally, the test cases have been
updated: instead of returning an error, the tests now pass and check if
the environment variables are output correctly.
---
.../tests/Inputs/shtest-env/env-args-none.txt | 31 ++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt b/llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
index dc5cdbad09afc..b42e6622587f2 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
@@ -1 +1,30 @@
-# RUN: env
+# Check Default Environment
+# RUN: env | FileCheck -check-prefix=CHECK-2-EMPTY %s
+#
+# CHECK-2-EMPTY: BAR = 2
+# CHECK-2-EMPTY: FOO = 1
+
+# Set Environment Variables
+# RUN: env FOO=2 BAR=1 | FileCheck -check-prefix=CHECK-2-VAL %s
+#
+# CHECK-2-VAL: BAR = 1
+# CHECK-2-VAL: FOO = 2
+
+# Unset Environment Variables
+# RUN: env -u FOO -u BAR | FileCheck -check-prefix=CHECK-2-U %s
+#
+# CHECK-2-U-NOT: BAR
+# CHECK-2-U-NOT: FOO
+
+# Mixed Set and Unset Environment Variables
+# RUN: env -u FOO BAR=1 -u BAR FOO=2 | FileCheck -check-prefix=CHECK-2-U-VAL %s
+#
+# CHECK-2-U-VAL-NOT: BAR
+# CHECK-2-U-VAL: FOO = 2
+
+# Mixed Set and Unset with Additional Variable
+# RUN: env -u FOO BAR=1 -u BAR FOO=2 BAZ=3 | FileCheck -check-prefix=CHECK-3 %s
+#
+# CHECK-3-NOT: BAR
+# CHECK-3: BAZ = 3
+# CHECK-3: FOO = 2
>From 920d5b162ee509f6e1d3a7f21c4141d8f205fc83 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Thu, 18 Jul 2024 06:34:08 +0000
Subject: [PATCH 4/4] [llvm-lit] Resolve env subcommand required error
This patch addresses an issue where calling env without any arguments
incorrectly returns a "requires subcommand" message. The patch modifies
the env command to properly display the current environment variables
even when no arguments are provided. Additionally, the test cases have been
updated: instead of returning an error, the tests now pass and check if
the environment variables are output correctly.
---
llvm/utils/lit/lit/TestRunner.py | 4 +++-
llvm/utils/lit/tests/shtest-env.py | 34 +++++++++++++++---------------
2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 8f0cd801ae9ff..da541c6b742a3 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -744,7 +744,9 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
args = updateEnv(cmd_shenv, args)
if not args:
# Return the environment variables if no argument is provided
- return {key: value for key, value in cmd_shenv.env.items()}
+ env_str = "\n".join(f"{key}={value}" for key, value in cmd_shenv.env.items())
+ results.append(ShellCommandResult(j, env_str, "", 0 , timeoutHelper.timeoutReached(), []))
+ return 0
elif args[0] == "not":
not_args.append(args.pop(0))
not_count += 1
diff --git a/llvm/utils/lit/tests/shtest-env.py b/llvm/utils/lit/tests/shtest-env.py
index 03bb4a3cae7dd..7e6ad751a7a3d 100644
--- a/llvm/utils/lit/tests/shtest-env.py
+++ b/llvm/utils/lit/tests/shtest-env.py
@@ -9,35 +9,35 @@
# CHECK: -- Testing: 16 tests{{.*}}
-# CHECK: FAIL: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
+# CHECK: PASS: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
# CHECK: env FOO=1
# CHECK: # executed command: env FOO=1
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
+# CHECK-NOT: {{^[^#]}}
+# CHECK: --
-# CHECK: FAIL: shtest-env :: env-args-last-is-u-arg.txt ({{[^)]*}})
+# CHECK: PASS: shtest-env :: env-args-last-is-u-arg.txt ({{[^)]*}})
# CHECK: env -u FOO
# CHECK: # executed command: env -u FOO
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
+# CHECK-NOT: {{^[^#]}}
+# CHECK: --
-# CHECK: FAIL: shtest-env :: env-args-last-is-u.txt ({{[^)]*}})
+# CHECK: PASS: shtest-env :: env-args-last-is-u.txt ({{[^)]*}})
# CHECK: env -u
# CHECK: # executed command: env -u
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
+# CHECK-NOT: {{^[^#]}}
+# CHECK: --
-# CHECK: FAIL: shtest-env :: env-args-nested-none.txt ({{[^)]*}})
+# CHECK: PASS: shtest-env :: env-args-nested-none.txt ({{[^)]*}})
# CHECK: env env env
# CHECK: # executed command: env env env
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
+# CHECK-NOT: {{^[^#]}}
+# CHECK: --
-# CHECK: FAIL: shtest-env :: env-args-none.txt ({{[^)]*}})
+# CHECK: PASS: shtest-env :: env-args-none.txt ({{[^)]*}})
# CHECK: env
# CHECK: # executed command: env
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
+# CHECK-NOT: {{^[^#]}}
+# CHECK: --
# CHECK: FAIL: shtest-env :: env-calls-cd.txt ({{[^)]*}})
# CHECK: env -u FOO BAR=3 cd foobar
@@ -121,6 +121,6 @@
# CHECK: --
# CHECK: Total Discovered Tests: 16
-# CHECK: Passed: 4 {{\([0-9]*\.[0-9]*%\)}}
-# CHECK: Failed: 12 {{\([0-9]*\.[0-9]*%\)}}
+# CHECK: Passed: 9 {{\([0-9]*\.[0-9]*%\)}}
+# CHECK: Failed: 7 {{\([0-9]*\.[0-9]*%\)}}
# CHECK-NOT: {{.}}
More information about the llvm-commits
mailing list