Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL][E2E][NFC] Fix NameError if directive fails to parse #16767

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

Maetveis
Copy link
Contributor

Currently if a test contains a malformed directive, the following exception is raised along with the original parsing error:

Exception during script execution:
(original error)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "llvm/llvm/utils/lit/lit/worker.py", line 76, in _execute_test_handle_errors
    result = test.config.test_format.execute(test, lit_config)
  File "llvm/sycl/test-e2e/format.py", line 232, in execute
    script = self.parseTestScript(test)
  File "llvm/sycl/test-e2e/format.py", line 105, in parseTestScript
    return lit.Test.Result(Test.UNRESOLVED, str(e))
NameError: name 'Test' is not defined

The test ends up as UNRESOLVED either way, but fixing it is easy and improves the error message greatly.

Currently if a test contains a malformed directive, the following
exception is raised along with the original parsing error:
```plaintext
Exception during script execution:
(original error)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "llvm/llvm/utils/lit/lit/worker.py", line 76, in _execute_test_handle_errors
    result = test.config.test_format.execute(test, lit_config)
  File "llvm/sycl/test-e2e/format.py", line 232, in execute
    script = self.parseTestScript(test)
  File "llvm/sycl/test-e2e/format.py", line 105, in parseTestScript
    return lit.Test.Result(Test.UNRESOLVED, str(e))
NameError: name 'Test' is not defined
```
The test ends up as UNRESOLVED either way, but fixing it is easy and
improves the error message greatly.
@Maetveis Maetveis requested a review from a team as a code owner January 24, 2025 14:03
@cperkinsintel
Copy link
Contributor

what does the improved error message look like?

@Maetveis
Copy link
Contributor Author

what does the improved error message look like?

With the following change to show the error:

diff --git a/sycl/test-e2e/AbiNeutral/catch-exception.cpp b/sycl/test-e2e/AbiNeutral/catch-exception.cpp
index b2c30cabe5fe..ec8bf902243f 100644
--- a/sycl/test-e2e/AbiNeutral/catch-exception.cpp
+++ b/sycl/test-e2e/AbiNeutral/catch-exception.cpp
@@ -2,7 +2,7 @@
 // RUN: %{run} %t.out
 // RUN: %if preview-breaking-changes-supported %{ %{build} -fpreview-breaking-changes -D_GLIBCXX_USE_CXX11_ABI=0 -o %t2.out %}
 // RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %}
-// REQUIRES: level_zero && gpu
+// REQUIRES: level_zero && gpu ||
 
 // This test case tests if compiling works with or without
 // _GLIBCXX_USE_CXX11_ABI=0.
Error message before the PR
>  build/bin/llvm-lit sycl/test-e2e/AbiNeutral/catch-exception.cpp -a
(...)
-- Testing: 1 tests, 1 workers --
UNRESOLVED: SYCL :: AbiNeutral/catch-exception.cpp (1 of 1)
******************** TEST 'SYCL :: AbiNeutral/catch-exception.cpp' FAILED ********************
Exception during script execution:
Traceback (most recent call last):
  File "intel-llvm/llvm/llvm/utils/lit/lit/BooleanExpression.py", line 32, in evaluate
    return parser.parseAll()
  File "intel-llvm/llvm/llvm/utils/lit/lit/BooleanExpression.py", line 152, in parseAll
    self.parseOR()
  File "intel-llvm/llvm/llvm/utils/lit/lit/BooleanExpression.py", line 144, in parseOR
    self.parseAND()
  File "intel-llvm/llvm/llvm/utils/lit/lit/BooleanExpression.py", line 131, in parseAND
    self.parseNOT()
  File "intel-llvm/llvm/llvm/utils/lit/lit/BooleanExpression.py", line 123, in parseNOT
    raise ValueError(
ValueError: expected: '!', '(', '{{', or identifier
have: <end of expression>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "intel-llvm/llvm/llvm/utils/lit/lit/TestRunner.py", line 1973, in parseLine
    self.value = self.parser(line_number, line, self.value)
  File "intel-llvm/llvm/llvm/utils/lit/lit/TestRunner.py", line 2061, in _handleBooleanExpr
    BooleanExpression.evaluate(s, [])
  File "intel-llvm/llvm/llvm/utils/lit/lit/BooleanExpression.py", line 34, in evaluate
    raise ValueError(str(e) + ("\nin expression: %r" % string))
ValueError: expected: '!', '(', '{{', or identifier
have: <end of expression>
in expression: 'level_zero && gpu ||'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "intel-llvm/llvm/sycl/test-e2e/format.py", line 63, in parseTestScript
    parsed = lit.TestRunner._parseKeywords(
  File "intel-llvm/llvm/llvm/utils/lit/lit/TestRunner.py", line 2121, in _parseKeywords
    parser.parseLine(line_number, ln)
  File "intel-llvm/llvm/llvm/utils/lit/lit/TestRunner.py", line 1975, in parseLine
    raise ValueError(
ValueError: expected: '!', '(', '{{', or identifier
have: <end of expression>
in expression: 'level_zero && gpu ||'
in REQUIRES: directive on test line 5

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "intel-llvm/llvm/llvm/utils/lit/lit/worker.py", line 76, in _execute_test_handle_errors
    result = test.config.test_format.execute(test, lit_config)
  File "intel-llvm/llvm/sycl/test-e2e/format.py", line 150, in execute
    script = self.parseTestScript(test)
  File "intel-llvm/llvm/sycl/test-e2e/format.py", line 75, in parseTestScript
    return lit.Test.Result(Test.UNRESOLVED, str(e))
NameError: name 'Test' is not defined


********************
********************
Unresolved Tests (1):
  SYCL :: AbiNeutral/catch-exception.cpp
Error message with the PR
>  build/bin/llvm-lit sycl/test-e2e/AbiNeutral/catch-exception.cpp -a
(...)
-- Testing: 1 tests, 1 workers --
UNRESOLVED: SYCL :: AbiNeutral/catch-exception.cpp (1 of 1)
******************** TEST 'SYCL :: AbiNeutral/catch-exception.cpp' FAILED ********************
expected: '!', '(', '{{', or identifier
have: <end of expression>
in expression: 'level_zero && gpu ||'
in REQUIRES: directive on test line 5
********************
********************
Unresolved Tests (1):
  SYCL :: AbiNeutral/catch-exception.cpp

@Maetveis
Copy link
Contributor Author

@intel/llvm-gatekeepers please merge :)

@aelovikov-intel aelovikov-intel merged commit 367f355 into intel:sycl Jan 27, 2025
18 checks passed
@Maetveis Maetveis deleted the sycl_e2e_fix_namerror branch January 27, 2025 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants