python / cpython

The Python programming language
https://www.python.org
Other
63.19k stars 30.26k forks source link

AddressSanitizer: Skip tests directly in Python, not with external config #90791

Closed vstinner closed 2 years ago

vstinner commented 2 years ago
BPO 46633
Nosy @vstinner, @pablogsal
PRs
  • python/cpython#31632
  • python/cpython#31634
  • python/cpython#31644
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = created_at = labels = ['tests', '3.11'] title = 'AddressSanitizer: Skip tests directly in Python, not with external config' updated_at = user = 'https://github.com/vstinner' ``` bugs.python.org fields: ```python activity = actor = 'vstinner' assignee = 'none' closed = True closed_date = closer = 'vstinner' components = ['Tests'] creation = creator = 'vstinner' dependencies = [] files = [] hgrepos = [] issue_num = 46633 keywords = ['patch'] message_count = 11.0 messages = ['412499', '412501', '412506', '414247', '414248', '414250', '414262', '414266', '414370', '414379', '414380'] nosy_count = 2.0 nosy_names = ['vstinner', 'pablogsal'] pr_nums = ['31632', '31634', '31644'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue46633' versions = ['Python 3.11'] ```

    Linked PRs

    vstinner commented 2 years ago

    It seems like bpo-45200: "Address Sanitizer: libasan dead lock in pthread_create() (test_multiprocessing_fork.test_get() hangs)" is not fixed yet.

    In the GitHub Action job, test_multiprocessing_fork is skipped because it's too slow, so the job doesn't hang.

    Yesterday, I modified the ASAN buildbot to double its timeout from 20 to 40 minutes: https://github.com/python/buildmaster-config/commit/5a37411e75c9475d48eabaac18102a3c9fc2d467

    But it's useful, when it hangs, it hangs forever. Exmaple on the AMD64 Arch Linux Asan Debug 3.9 buildbot (with the new config):

    --- (test.test_multiprocessing_fork.WithProcessesTestPicklingConnections) ... ok Timeout (0:35:00)! --- https://buildbot.python.org/all/#/builders/588/builds/332

    Tests are tuned for ASAN, but the configuration is copied and inconsistent between the GitHub Actions job and the buildbot configuration.

    I propose to move this configuration directly into Python.

    test_decimal.py checks for "-fsanitize=address" in CFLAGS and skip some tests if it's present.

    vstinner commented 2 years ago

    Notes:

    MEMORY_SANITIZER = (
        '-fsanitize=memory' in _cflags or
        '--with-memory-sanitizer' in _config_args
    )   

    Comment: --- # Skip test_tools test_peg_generator test_concurrent_futures because # there are too slow: between 5 and 20 minutes on this CI. # # Skip multiprocessing and concurrent.futures tests which are affected by # bpo-45200 bug: libasan dead lock in pthread_create(). # # test_all is skipped because importing some modules directly can trigger # known problems with ASAN (like tk or crypt). ---

      ASAN_OPTIONS='detect_leaks=0:allocator_may_return_null=1:handle_segv=0'

    With the comment: --- # See https://bugs.python.org/issue42985 for more context on why # SIGSEGV is ignored on purpose. ---

    Skipped tests:

    With the comment: --- # These tests are currently raising false positives or are interfering with the ASAN mechanism, # so we need to skip them unfortunately. ---

    pablogsal commented 2 years ago

    I have recently added some decorators in test. support to deactivate tests if running under the sanitizers.

    vstinner commented 2 years ago

    I created a PR to no longer skip tests in buildbots: https://github.com/python/buildmaster-config/pull/314

    vstinner commented 2 years ago

    Status with the 2 pending PRs:

    Tests only skipped on ASAN:

    Skip on ASAN and MSAN:

    No longer skipped:

    vstinner commented 2 years ago

    I created bpo-46887: ./Programs/_freeze_module fails with MSAN: Uninitialized value was created by an allocation of 'stat.i'.

    vstinner commented 2 years ago

    """ No longer skipped:

    I built Python manually with:

    ./configure --with-pydebug CC=clang LD=clang --with-address-sanitizer

    These tests no longer with ASAN_OPTIONS used on our CI:

    ASAN_OPTIONS='detect_leaks=0:allocator_may_return_null=1:handle_segv=0' ./python -m test (...)
    vstinner commented 2 years ago

    New changeset 9204bb72a2da5885facc747e63d2bd2d654606fe by Victor Stinner in branch 'main': bpo-46633: Skip tests on ASAN and/or MSAN builds (GH-31632) https://github.com/python/cpython/commit/9204bb72a2da5885facc747e63d2bd2d654606fe

    vstinner commented 2 years ago

    New changeset 93264452d952d9ba604bacf2947c2df5dd477931 by Victor Stinner in branch '3.10': [3.10] bpo-46633: Skip tests on ASAN and/or MSAN builds (GH-31632) (GH-31634) https://github.com/python/cpython/commit/93264452d952d9ba604bacf2947c2df5dd477931

    vstinner commented 2 years ago

    New changeset 359bc392ba2b8f2acca223426c8210bb74f724c6 by Victor Stinner in branch '3.9': [3.10] bpo-46633: Skip tests on ASAN and/or MSAN builds (GH-31632) (GH-31634) (GH-31644) https://github.com/python/cpython/commit/359bc392ba2b8f2acca223426c8210bb74f724c6

    vstinner commented 2 years ago

    https://github.com/python/buildmaster-config/pull/314

    I merged this PR as well. The new buildbot configuration will be deployed soon.

    vstinner commented 2 years ago

    Lib/test/test_asyncio/test_subprocess.py and Lib/test/test_distutils.py are now skipped on ASAN tests by the commit: https://github.com/python/cpython/commit/f6dd14c65336cda4e2ebccbc6408dfe3b0a68a34 (cc @gpshead)

    gpshead commented 2 years ago

    FWIW I disabled those two because they triggered ASAN on Ubuntu 20.04's gcc 9.4 and in github's CI (which might use that?). They do not trigger ASAN on more recent Debian bullseye or Ubuntu 22.04 based systems with a more recent gcc.

    In the _posixsubprocess.c case it was at a callsite that has ~25 parameters (ugh) and just gained one more. But the asan assertion would only trigger during one consistent but seemingly random test_asyncio.test_subprocess test rather than all the time; so if there is a bug in the ASAN implementation itself it isn't clear what it was.

    vstinner commented 1 year ago

    I enabled test_faulthandler on ASAN: commit 58f9c635002673e35a56eeaa122cade7a2b6bae1.

    vstinner commented 1 year ago

    I enabled more tests in test_all: commit https://github.com/python/cpython/commit/a541e01537cc07b326cc37cc29412b816bc2b4fc