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

test_gdb are not skipped properly if gdb is not available (instead, an uncaught exception is raised) #110995

Closed
befeleme opened this issue Oct 17, 2023 · 2 comments
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@befeleme
Copy link
Contributor

befeleme commented Oct 17, 2023

Bug report

Bug description:

I'm bootstrapping Python 3.13a1 in Fedora Linux.
In my environment I've got gdb built without Python. Now I want to build full Python and run its tests during the RPM build.

What happens
Tests from package test_gdb fail due to uncaught exception.

What should happen
Tests should be marked as skipped and not executed at all.

Traceback

0:28:25 load avg: 2.73 Re-running 5 failed tests in verbose mode in subprocesses
0:28:25 load avg: 2.73 Run 5 tests in parallel using 2 worker processes (timeout: 45 min, worker timeout: 50 min)
0:28:26 load avg: 2.73 [1/5/1] test.test_gdb.test_cfunction failed (uncaught exception)
Re-running test.test_gdb.test_cfunction in verbose mode
test test.test_gdb.test_cfunction crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_cfunction.py", line 5, in 
    from .util import setup_module, DebuggerTests
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
0:28:26 load avg: 2.73 [2/5/2] test.test_gdb.test_backtrace failed (uncaught exception)
Re-running test.test_gdb.test_backtrace in verbose mode
test test.test_gdb.test_backtrace crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_backtrace.py", line 6, in 
    from .util import setup_module, DebuggerTests, CET_PROTECTION, SAMPLE_SCRIPT
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
0:28:27 load avg: 2.73 [3/5/3] test.test_gdb.test_cfunction_full failed (uncaught exception)
Re-running test.test_gdb.test_cfunction_full in verbose mode
test test.test_gdb.test_cfunction_full crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_cfunction_full.py", line 7, in 
    from .util import setup_module
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
0:28:27 load avg: 2.73 [4/5/4] test.test_gdb.test_misc failed (uncaught exception)
Re-running test.test_gdb.test_misc in verbose mode
test test.test_gdb.test_misc crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_misc.py", line 5, in 
    from .util import run_gdb, setup_module, DebuggerTests, SAMPLE_SCRIPT
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
0:28:27 load avg: 2.73 [5/5/5] test.test_gdb.test_pretty_print failed (uncaught exception)
Re-running test.test_gdb.test_pretty_print in verbose mode
test test.test_gdb.test_pretty_print crashed -- Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test
    test_mod = importlib.import_module(module_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1381, in _gcd_import
  File "", line 1354, in _find_and_load
  File "", line 1325, in _find_and_load_unlocked
  File "", line 929, in _load_unlocked
  File "", line 1008, in exec_module
  File "", line 488, in _call_with_frames_removed
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_pretty_print.py", line 5, in 
    from .util import (
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in 
    check_usable_gdb()
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb
    stdout, stderr = run_gdb(
                     ^^^^^^^^
  File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb
    raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, "
Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0:
stdout=''
stderr='Python scripting is not supported in this copy of GDB.\n'
5 tests failed again:
    test.test_gdb.test_backtrace test.test_gdb.test_cfunction
    test.test_gdb.test_cfunction_full test.test_gdb.test_misc
    test.test_gdb.test_pretty_print

I believe the refactoring done in #110026 has introduced a regression. run_gdb() used to always return a tuple (stdout, stderr), but now it checks exitcode and raises an exception in case it's not what was expected. check_usable_gdb() consumes the values returned from run_gdb() and only then marks tests as skipped, but in this case the exception breaks the test run even before this can happen.

cc: @vstinner

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@befeleme befeleme added the type-bug An unexpected behavior, bug, or error label Oct 17, 2023
@AlexWaygood AlexWaygood added the tests Tests in the Lib/test dir label Oct 17, 2023
@befeleme befeleme changed the title test/test_gdb/utils.py: run_gdb() doesn't skip the gdb tests properly test_gdb are not skipped properly if gdb is not available (instead, an uncaught exception is raised) Oct 17, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Oct 17, 2023
check_usable_gdb() doesn't check gdb exit code when calling
run_gdb().

Use shutil.which() to get the path to the gdb program.
vstinner added a commit to vstinner/cpython that referenced this issue Oct 17, 2023
check_usable_gdb() doesn't check gdb exit code when calling
run_gdb().

Use shutil.which() to get the path to the gdb program.
vstinner added a commit to vstinner/cpython that referenced this issue Oct 17, 2023
check_usable_gdb() doesn't check gdb exit code when calling
run_gdb().

Use shutil.which() to get the path to the gdb program.
vstinner added a commit to vstinner/cpython that referenced this issue Oct 17, 2023
Fix detection of gdb built without Python scripting support.

* check_usable_gdb() doesn't check gdb exit code when calling
  run_gdb().
* Use shutil.which() to get the path to the gdb program.
@vstinner
Copy link
Member

I wrote PR #110998 to fix test_gdb. I'm not sure of my fix. I tried to write a fake gdb which behaves as gdb, writes Python scripting is not supported in this copy of GDB. to stderr. My mock was too different from gdb and so I failed to test my fix.

vstinner added a commit that referenced this issue Oct 17, 2023
Fix detection of gdb built without Python scripting support.

* check_usable_gdb() doesn't check gdb exit code when calling
  run_gdb().
* Use shutil.which() to get the path to the gdb program.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 17, 2023
Fix detection of gdb built without Python scripting support.

* check_usable_gdb() doesn't check gdb exit code when calling
  run_gdb().
* Use shutil.which() to get the path to the gdb program.
(cherry picked from commit 920b3df)

Co-authored-by: Victor Stinner <vstinner@python.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 17, 2023
Fix detection of gdb built without Python scripting support.

* check_usable_gdb() doesn't check gdb exit code when calling
  run_gdb().
* Use shutil.which() to get the path to the gdb program.
(cherry picked from commit 920b3df)

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner
Copy link
Member

Fixed by commit 920b3df. Thanks @befeleme for the bug report and @hroncok for testing the fix.

vstinner added a commit that referenced this issue Oct 17, 2023
gh-110995: Fix test_gdb check_usable_gdb() (GH-110998)

Fix detection of gdb built without Python scripting support.

* check_usable_gdb() doesn't check gdb exit code when calling
  run_gdb().
* Use shutil.which() to get the path to the gdb program.
(cherry picked from commit 920b3df)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this issue Oct 17, 2023
gh-110995: Fix test_gdb check_usable_gdb() (GH-110998)

Fix detection of gdb built without Python scripting support.

* check_usable_gdb() doesn't check gdb exit code when calling
  run_gdb().
* Use shutil.which() to get the path to the gdb program.
(cherry picked from commit 920b3df)

Co-authored-by: Victor Stinner <vstinner@python.org>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Fix detection of gdb built without Python scripting support.

* check_usable_gdb() doesn't check gdb exit code when calling
  run_gdb().
* Use shutil.which() to get the path to the gdb program.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants