Skip to content

Commit

Permalink
Misc. Buck ASAN fixes
Browse files Browse the repository at this point in the history
Summary: Grab-bag of fixes for ASAN in Python tests under Buck. The biggest change which takes up most of this diff is updating `mini_configure.py` to make changes to `CFLAGS` in the sysconfig data so test libraries can detect sanitizers are enabled.

Reviewed By: alexmalyshev

Differential Revision: D56221781

fbshipit-source-id: f38c4dbc38008edc930f70fc2745b8afbb59f6fa
  • Loading branch information
jbower-fb authored and facebook-github-bot committed Apr 24, 2024
1 parent b301115 commit d14ebc9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
15 changes: 12 additions & 3 deletions Lib/test/cinder_support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

import ctypes
import multiprocessing
import sys
import tempfile
Expand Down Expand Up @@ -102,9 +103,17 @@ def wrapper(*args):
return func


# This is pretty long because ASAN + JIT + subprocess + the Python compiler can
# be pretty slow in CI.
SUBPROCESS_TIMEOUT_SEC = 5
def is_asan_build():
try:
ctypes.pythonapi.__asan_init
return True
except AttributeError:
return False


# This is long because ASAN + JIT + subprocess + the Python compiler can be
# pretty slow in CI.
SUBPROCESS_TIMEOUT_SEC = 100 if is_asan_build() else 5


@contextmanager
Expand Down
5 changes: 5 additions & 0 deletions cinderx/TestScripts/asan_skip_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ test_wait3
test_logging
# Monkey patching in cinder_test_runner.py for ASAN breaks this
test.test_trace.TestCoverage.test_coverage_ignore

# These get segfaults in the sub-processes they start. I didn't look at the
# details but my guess is thread memory stack size limits. With ASAN we need a
# bigger default thread stack-size (as set in cinder_test_runner.py).
test.test_multiprocessing_main_handling.SpawnCmdLineTest
8 changes: 7 additions & 1 deletion cinderx/TestScripts/cinder_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from pathlib import Path

from test import support
from test.cinder_support import is_asan_build
from test.support import os_helper
from test.libregrtest.cmdline import Namespace
from test.libregrtest.main import Regrtest
Expand Down Expand Up @@ -950,9 +951,14 @@ def replay_main(args):
# runaway loops. This 8GiB number is arbitrary but seems to be enough at
# the time of writing.
mem_limit_default = (
8192 * 1024 * 1024 if os.environ.get('ASAN_OPTIONS') is None else -1
-1 if is_asan_build() else 8192 * 1024 * 1024
)

# Increase default stack size for threads in ASAN builds as this can use
# a lot more stack space.
if is_asan_build():
threading.stack_size(1024 * 1024 * 10)

parser.add_argument(
"--memory-limit",
type=int,
Expand Down

0 comments on commit d14ebc9

Please sign in to comment.