From d14ebc9a7c0754ca9a256e34978ae7d8533b5db2 Mon Sep 17 00:00:00 2001 From: Jacob Bower Date: Tue, 23 Apr 2024 21:36:45 -0700 Subject: [PATCH] Misc. Buck ASAN fixes 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 --- Lib/test/cinder_support.py | 15 ++++++++++++--- cinderx/TestScripts/asan_skip_tests.txt | 5 +++++ cinderx/TestScripts/cinder_test_runner.py | 8 +++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Lib/test/cinder_support.py b/Lib/test/cinder_support.py index bbe22aaf4a5..5ef237f1528 100644 --- a/Lib/test/cinder_support.py +++ b/Lib/test/cinder_support.py @@ -1,5 +1,6 @@ # Copyright (c) Meta Platforms, Inc. and affiliates. +import ctypes import multiprocessing import sys import tempfile @@ -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 diff --git a/cinderx/TestScripts/asan_skip_tests.txt b/cinderx/TestScripts/asan_skip_tests.txt index 94ec6ccfb00..71e50b3edfd 100644 --- a/cinderx/TestScripts/asan_skip_tests.txt +++ b/cinderx/TestScripts/asan_skip_tests.txt @@ -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 diff --git a/cinderx/TestScripts/cinder_test_runner.py b/cinderx/TestScripts/cinder_test_runner.py index e82df1fc5bd..f09681289a7 100644 --- a/cinderx/TestScripts/cinder_test_runner.py +++ b/cinderx/TestScripts/cinder_test_runner.py @@ -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 @@ -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,