Skip to content

test_import crashes with a --forever option #119584

Description

@Eclips4

Crash report

Bug description:

./python.exe -m test -v test_import -m test_check_state_first --forever
== CPython 3.14.0a0 (heads/main:5d04cc50e5, May 26 2024, 21:33:31) [Clang 15.0.0 (clang-1500.3.9.4)]
== macOS-14.5-arm64-arm-64bit-Mach-O little-endian
== Python build: debug
== cwd: /Users/admin/Projects/cpython/build/test_python_worker_94626æ
== CPU count: 8
== encodings: locale=UTF-8 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 4127756675
0:00:00 load avg: 4.71 Run tests sequentially
0:00:00 load avg: 4.71 [  1] test_import
test_check_state_first (test.test_import.SinglephaseInitTests.test_check_state_first) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
0:00:00 load avg: 4.71 [  2] test_import
test_check_state_first (test.test_import.SinglephaseInitTests.test_check_state_first) ... Assertion failed: (_testsinglephase_with_reinit_check_cache_first.m_base.m_index == 0), function PyInit__testsinglephase_with_reinit_check_cache_first, file _testsinglephase.c, line 714.
Fatal Python error: Aborted

Current thread 0x00000001f61d0c00 (most recent call first):
  File "<frozen importlib._bootstrap>", line 488 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1316 in create_module
  File "<frozen importlib._bootstrap>", line 813 in module_from_spec
  File "<frozen importlib._bootstrap>", line 921 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 966 in _load
  File "/Users/admin/Projects/cpython/Lib/test/test_import/__init__.py", line 2495 in _load_dynamic
  File "/Users/admin/Projects/cpython/Lib/test/test_import/__init__.py", line 2894 in test_check_state_first
  File "/Users/admin/Projects/cpython/Lib/unittest/case.py", line 606 in _callTestMethod
  File "/Users/admin/Projects/cpython/Lib/unittest/case.py", line 651 in run
  File "/Users/admin/Projects/cpython/Lib/unittest/case.py", line 707 in __call__
  File "/Users/admin/Projects/cpython/Lib/unittest/suite.py", line 122 in run
  File "/Users/admin/Projects/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/Users/admin/Projects/cpython/Lib/unittest/suite.py", line 122 in run
  File "/Users/admin/Projects/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/Users/admin/Projects/cpython/Lib/unittest/runner.py", line 240 in run
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/single.py", line 57 in _run_suite
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/single.py", line 37 in run_unittest
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/single.py", line 135 in test_func
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/single.py", line 91 in regrtest_runner
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/single.py", line 138 in _load_run_test
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/single.py", line 181 in _runtest_env_changed_exc
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/single.py", line 281 in _runtest
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/single.py", line 310 in run_single_test
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/main.py", line 355 in run_test
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/main.py", line 389 in run_tests_sequentially
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/main.py", line 533 in _run_tests
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/main.py", line 568 in run_tests
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/main.py", line 731 in main
  File "/Users/admin/Projects/cpython/Lib/test/libregrtest/main.py", line 739 in main
  File "/Users/admin/Projects/cpython/Lib/test/__main__.py", line 2 in <module>
  File "/Users/admin/Projects/cpython/Lib/runpy.py", line 88 in _run_code
  File "/Users/admin/Projects/cpython/Lib/runpy.py", line 198 in _run_module_as_main

Extension modules: _testinternalcapi, _testmultiphase (total: 2)
zsh: abort      ./python.exe -m test -v test_import -m test_check_state_first --forever

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    testsTests in the Lib/test dir
    type-crashA hard crash of the interpreter, possibly with a core dump
    on May 26, 2024
  2. Eclips4 commented on May 26, 2024

    @Eclips4
    MemberAuthor
  3. Eclips4 commented on May 27, 2024

    @Eclips4
    MemberAuthor

    I'm guess this test (and two other tests which are similar) is cannot be run multiple times:

    PyMODINIT_FUNC
    PyInit__testsinglephase_check_cache_first(void)
    {
    assert(_testsinglephase_check_cache_first.m_base.m_index == 0);
    PyObject *mod = PyState_FindModule(&_testsinglephase_check_cache_first);
    if (mod != NULL) {
    return Py_NewRef(mod);
    }
    return PyModule_Create(&_testsinglephase_check_cache_first);
    }

    Firstly we check if m_index == 0, which means that our module is not in the cache. Then, we try to find this module using the PyState_FindModule which relies on the m_index field, and works only when m_index >= 0. These two steps seem weird for me.
    1)We can just mark the test_check_state_first with a no_rerun decorator, due to the reason that this test is to check whether initializing the module with different m_size works.
    2) Change the assert to m_index >= 0 instead of m_index == 0

  4. ericsnowcurrently commented on May 27, 2024

    @ericsnowcurrently
    Member

    I'll have a fix up shortly.

  5. added a commit that references this issue on May 27, 2024
  6. added a commit that references this issue on May 27, 2024
  7. added a commit that references this issue on May 27, 2024
  8. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

testsTests in the Lib/test dirtype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions