From 7e9a0fedb7b3dae0bd0dd62b4c8de0b390b7c94b Mon Sep 17 00:00:00 2001 From: "Garcia Orozco, David" Date: Tue, 18 Mar 2025 07:12:19 -0700 Subject: [PATCH 1/8] Fix lit hang --- llvm/utils/lit/lit/TestRunner.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 00432b8d31778..471c76b732e62 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -201,7 +201,12 @@ def executeShCmd(cmd, shenv, results, timeout=0): timeoutHelper = TimeoutHelper(timeout) if timeout > 0: timeoutHelper.startTimer() - finalExitCode = _executeShCmd(cmd, shenv, results, timeoutHelper) + try: + finalExitCode = _executeShCmd(cmd, shenv, results, timeoutHelper) + except InternalShellError: + e = sys.exc_info()[1] + finalExitCode = 127 + results.append(ShellCommandResult(e.command, "", e.message, finalExitCode, False)) timeoutHelper.cancel() timeoutInfo = None if timeoutHelper.timeoutReached(): @@ -1105,15 +1110,10 @@ def executeScriptInternal( results = [] timeoutInfo = None - try: - shenv = ShellEnvironment(cwd, test.config.environment) - exitCode, timeoutInfo = executeShCmd( + shenv = ShellEnvironment(cwd, test.config.environment) + exitCode, timeoutInfo = executeShCmd( cmd, shenv, results, timeout=litConfig.maxIndividualTestTime - ) - except InternalShellError: - e = sys.exc_info()[1] - exitCode = 127 - results.append(ShellCommandResult(e.command, "", e.message, exitCode, False)) + ) out = err = "" for i, result in enumerate(results): From 42bc1aef0edc82a499d24abac8cc25708cddb6ae Mon Sep 17 00:00:00 2001 From: "Garcia Orozco, David" Date: Tue, 18 Mar 2025 07:22:39 -0700 Subject: [PATCH 2/8] Always use internal shell in e2e tests --- sycl/test-e2e/format.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sycl/test-e2e/format.py b/sycl/test-e2e/format.py index cf0c99fe87ea3..2135bf92b99cd 100644 --- a/sycl/test-e2e/format.py +++ b/sycl/test-e2e/format.py @@ -372,14 +372,11 @@ def get_extra_env(sycl_devices): recursion_limit=test.config.recursiveExpansionLimit, ) - # TODO: workaround for lit hanging when executing non-existent binary - # inside our containers if len(script) == 0: return lit.Test.Result(lit.Test.UNSUPPORTED, "Lit script is empty") - useExternalSh = test.config.test_mode == "run-only" result = lit.TestRunner._runShTest( - test, litConfig, useExternalSh, script, tmpBase + test, litConfig, False, script, tmpBase ) # Single triple/device - might be an XFAIL. From 7a6fc6df1f83fa61b53e95ae01ed6dbc003c2476 Mon Sep 17 00:00:00 2001 From: "Garcia Orozco, David" Date: Tue, 18 Mar 2025 07:24:39 -0700 Subject: [PATCH 3/8] Add dummy test that would hang without the changes for testing --- sycl/test-e2e/dummy_test.cpp | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 sycl/test-e2e/dummy_test.cpp diff --git a/sycl/test-e2e/dummy_test.cpp b/sycl/test-e2e/dummy_test.cpp new file mode 100644 index 0000000000000..dee0bc4a4499a --- /dev/null +++ b/sycl/test-e2e/dummy_test.cpp @@ -0,0 +1,3 @@ +// This should fail but not hang +// RUN: non-existent +// RUN: %{run-aux} non-existent From a9d562a37f0e315b4732d12ef10f6fcd331082d4 Mon Sep 17 00:00:00 2001 From: "Garcia Orozco, David" Date: Tue, 18 Mar 2025 08:03:56 -0700 Subject: [PATCH 4/8] Remove dummy test --- sycl/test-e2e/dummy_test.cpp | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 sycl/test-e2e/dummy_test.cpp diff --git a/sycl/test-e2e/dummy_test.cpp b/sycl/test-e2e/dummy_test.cpp deleted file mode 100644 index dee0bc4a4499a..0000000000000 --- a/sycl/test-e2e/dummy_test.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// This should fail but not hang -// RUN: non-existent -// RUN: %{run-aux} non-existent From 7c953ebc6c2a914d848b4f9af03c0eea2d4a9f9a Mon Sep 17 00:00:00 2001 From: David Garcia Orozco Date: Tue, 1 Apr 2025 18:43:13 +0000 Subject: [PATCH 5/8] Initial commit for timeout hang test --- llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg | 7 +++++++ .../utils/lit/tests/Inputs/timeout-hang/run-nonexistent.py | 1 + llvm/utils/lit/tests/timeout-hang.py | 6 ++++++ 3 files changed, 14 insertions(+) create mode 100644 llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg create mode 100644 llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.py create mode 100644 llvm/utils/lit/tests/timeout-hang.py diff --git a/llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg b/llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg new file mode 100644 index 0000000000000..d1fb2a223ccfd --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg @@ -0,0 +1,7 @@ +import lit.formats + +config.name = "timeout-hang" +config.suffixes = [".py"] +config.test_format = lit.formats.ShTest() +config.test_source_root = None +config.test_exec_root = None diff --git a/llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.py b/llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.py new file mode 100644 index 0000000000000..79776d262f109 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.py @@ -0,0 +1 @@ +# RUN: nonexistent diff --git a/llvm/utils/lit/tests/timeout-hang.py b/llvm/utils/lit/tests/timeout-hang.py new file mode 100644 index 0000000000000..5950cbd010575 --- /dev/null +++ b/llvm/utils/lit/tests/timeout-hang.py @@ -0,0 +1,6 @@ +# REQUIRES: lit-max-individual-test-time + +# https://github.com/llvm/llvm-project/issues/133914 + +# RUN: not %{lit} %{inputs}/timeout-hang/run-nonexistent.py \ +# RUN: --timeout=1 --param external=0 -a From 26fd14a7aba1f8545540cb8a922dea0e455986a7 Mon Sep 17 00:00:00 2001 From: David Garcia Orozco Date: Tue, 1 Apr 2025 20:25:20 +0000 Subject: [PATCH 6/8] Implement timeout hang test --- .../lit/tests/Inputs/timeout-hang/lit.cfg | 2 +- ...run-nonexistent.py => run-nonexistent.txt} | 0 llvm/utils/lit/tests/timeout-hang.py | 27 ++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) rename llvm/utils/lit/tests/Inputs/timeout-hang/{run-nonexistent.py => run-nonexistent.txt} (100%) diff --git a/llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg b/llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg index d1fb2a223ccfd..1019d94898b6d 100644 --- a/llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg +++ b/llvm/utils/lit/tests/Inputs/timeout-hang/lit.cfg @@ -1,7 +1,7 @@ import lit.formats config.name = "timeout-hang" -config.suffixes = [".py"] +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/Inputs/timeout-hang/run-nonexistent.py b/llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.txt similarity index 100% rename from llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.py rename to llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.txt diff --git a/llvm/utils/lit/tests/timeout-hang.py b/llvm/utils/lit/tests/timeout-hang.py index 5950cbd010575..1a43ee548f330 100644 --- a/llvm/utils/lit/tests/timeout-hang.py +++ b/llvm/utils/lit/tests/timeout-hang.py @@ -1,6 +1,27 @@ # REQUIRES: lit-max-individual-test-time -# https://github.com/llvm/llvm-project/issues/133914 +# Python has some issues dealing with exceptions when multiprocessing, +# which can cause hangs. Previously this could occur when we encountered +# an internal shell exception, and had a timeout set. -# RUN: not %{lit} %{inputs}/timeout-hang/run-nonexistent.py \ -# RUN: --timeout=1 --param external=0 -a +# This test runs a lit test that tries to launch a non-existent file, +# throwing an exception. We expect this to fail immediately, rather than +# timeout. + +# DEFINE: %{timeout}=1 + +# RUN: not %{lit} %{inputs}/timeout-hang/run-nonexistent.txt \ +# RUN: --timeout=%{timeout} --param external=0 | %{python} %s %{timeout} + +import sys +import re + +timeout_time = float(sys.argv[1]) +testing_time = float(re.search(r'Testing Time: (.*)s', sys.stdin.read()).group(1)) + +if testing_time < timeout_time: + print("Testing took less than timeout") + sys.exit(0) +else: + print("Testing took as long or longer than timeout") + sys.exit(1) From dff686beaac0f94948112fea60785d72c0ed3d82 Mon Sep 17 00:00:00 2001 From: "Garcia Orozco, David" Date: Tue, 8 Apr 2025 06:31:21 -0700 Subject: [PATCH 7/8] Format lit files --- llvm/utils/lit/lit/TestRunner.py | 8 +++++--- .../lit/tests/Inputs/timeout-hang/run-nonexistent.txt | 2 +- llvm/utils/lit/tests/timeout-hang.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 471c76b732e62..5d8c8b5ed16d5 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -206,7 +206,9 @@ def executeShCmd(cmd, shenv, results, timeout=0): except InternalShellError: e = sys.exc_info()[1] finalExitCode = 127 - results.append(ShellCommandResult(e.command, "", e.message, finalExitCode, False)) + results.append( + ShellCommandResult(e.command, "", e.message, finalExitCode, False) + ) timeoutHelper.cancel() timeoutInfo = None if timeoutHelper.timeoutReached(): @@ -1112,8 +1114,8 @@ def executeScriptInternal( timeoutInfo = None shenv = ShellEnvironment(cwd, test.config.environment) exitCode, timeoutInfo = executeShCmd( - cmd, shenv, results, timeout=litConfig.maxIndividualTestTime - ) + cmd, shenv, results, timeout=litConfig.maxIndividualTestTime + ) out = err = "" for i, result in enumerate(results): diff --git a/llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.txt b/llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.txt index 79776d262f109..fd7ed210baee0 100644 --- a/llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.txt +++ b/llvm/utils/lit/tests/Inputs/timeout-hang/run-nonexistent.txt @@ -1 +1 @@ -# RUN: nonexistent +RUN: nonexistent diff --git a/llvm/utils/lit/tests/timeout-hang.py b/llvm/utils/lit/tests/timeout-hang.py index 1a43ee548f330..486f07983708f 100644 --- a/llvm/utils/lit/tests/timeout-hang.py +++ b/llvm/utils/lit/tests/timeout-hang.py @@ -17,7 +17,7 @@ import re timeout_time = float(sys.argv[1]) -testing_time = float(re.search(r'Testing Time: (.*)s', sys.stdin.read()).group(1)) +testing_time = float(re.search(r"Testing Time: (.*)s", sys.stdin.read()).group(1)) if testing_time < timeout_time: print("Testing took less than timeout") From ba222490953d3c625409f34bf37f05fa54f6cffc Mon Sep 17 00:00:00 2001 From: "Garcia Orozco, David" Date: Tue, 8 Apr 2025 06:33:30 -0700 Subject: [PATCH 8/8] Format format.py --- sycl/test-e2e/format.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sycl/test-e2e/format.py b/sycl/test-e2e/format.py index e4984214d4cb8..116579c21f825 100644 --- a/sycl/test-e2e/format.py +++ b/sycl/test-e2e/format.py @@ -377,9 +377,7 @@ def get_extra_env(sycl_devices): if len(script) == 0: return lit.Test.Result(lit.Test.UNSUPPORTED, "Lit script is empty") - result = lit.TestRunner._runShTest( - test, litConfig, False, script, tmpBase - ) + result = lit.TestRunner._runShTest(test, litConfig, False, script, tmpBase) # Single triple/device - might be an XFAIL. def map_result(features, code):