Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions .evergreen/generated_configs/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,22 @@ tasks:
- func: send dashboard data
tags: [perf]

# Sanitizer tests
- name: test-sanitizer
commands:
- func: run server
vars:
AUTH: noauth
SSL: nossl
TOPOLOGY: standalone
- func: run tests
vars:
AUTH: noauth
SSL: nossl
TOPOLOGY: standalone
TEST_NAME: sanitizer
tags: [sanitizer, pr]

# Search index tests
- name: test-search-index-helpers
commands:
Expand Down Expand Up @@ -4816,29 +4832,6 @@ tasks:
- sync
- free-threaded

# String query preview tests
- name: test-string-query-preview-v8.2-python3.15-noauth-ssl-replica-set
commands:
- func: run server
vars:
AUTH: noauth
SSL: ssl
TOPOLOGY: replica_set
VERSION: "8.2"
- func: run tests
vars:
AUTH: noauth
SSL: ssl
TOPOLOGY: replica_set
VERSION: "8.2"
UV_PYTHON: "3.15"
tags:
- test-string-query-preview
- server-8.2
- python-3.15
- replica_set-noauth-ssl
- noauth

# Test non standard tests
- name: test-non-standard-v4.4-python3.12-noauth-ssl-replica-set
commands:
Expand Down
17 changes: 11 additions & 6 deletions .evergreen/generated_configs/variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ buildvariants:
- name: encryption-rhel8
tasks:
- name: .test-non-standard !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption RHEL8
run_on:
- rhel8.10-small
Expand All @@ -198,7 +197,6 @@ buildvariants:
tasks:
- name: .test-non-standard !.cov !.python-3.15t
- name: .test-non-standard-no-cov !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption macOS
run_on:
- macos-14
Expand All @@ -210,7 +208,6 @@ buildvariants:
tasks:
- name: .test-non-standard !.cov !.python-3.15t
- name: .test-non-standard-no-cov !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption Win64
run_on:
- windows-2022-latest-small
Expand All @@ -221,7 +218,6 @@ buildvariants:
- name: encryption-crypt_shared-rhel8
tasks:
- name: .test-non-standard !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption crypt_shared RHEL8
run_on:
- rhel8.10-small
Expand All @@ -234,7 +230,6 @@ buildvariants:
tasks:
- name: .test-non-standard !.cov !.python-3.15t
- name: .test-non-standard-no-cov !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption crypt_shared macOS
run_on:
- macos-14
Expand All @@ -247,7 +242,6 @@ buildvariants:
tasks:
- name: .test-non-standard !.cov !.python-3.15t
- name: .test-non-standard-no-cov !.python-3.15t
- name: .test-string-query-preview
display_name: Encryption crypt_shared Win64
run_on:
- windows-2022-latest-small
Expand Down Expand Up @@ -536,6 +530,17 @@ buildvariants:
SUB_TEST_NAME: pyopenssl
tags: [pr]

# Sanitizer tests
- name: sanitizer-rhel8
tasks:
- name: .sanitizer
display_name: Sanitizer RHEL8
run_on:
- rhel8.10-large
expansions:
VERSION: "9.0"
tags: [pr]

# Search index tests
- name: search-index-helpers-rhel8
tasks:
Expand Down
62 changes: 32 additions & 30 deletions .evergreen/scripts/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get_encryption_expansions(encryption):
):
expansions = get_encryption_expansions(encryption)
display_name = get_variant_name(encryption, host, **expansions)
tasks = [".test-non-standard !.python-3.15t", ".test-string-query-preview"]
tasks = [".test-non-standard !.python-3.15t"]
if host != "rhel8":
# Exclude coverage tasks (encryption suites exceed the 60-min timeout with
# coverage overhead on macOS/win64).
Expand All @@ -160,7 +160,6 @@ def get_encryption_expansions(encryption):
tasks = [
".test-non-standard !.cov !.python-3.15t",
".test-non-standard-no-cov !.python-3.15t",
".test-string-query-preview",
]
variant = create_variant(
tasks,
Expand Down Expand Up @@ -528,6 +527,24 @@ def create_fuzz_variants():
return [pr_variant, nightly]


def create_sanitizer_variants() -> list[BuildVariant]:
# ASan/UBSan checks on every PR (PYTHON-6048). The rhel8 toolchain
# provides the instrumented CPython (utils.SANITIZER_PYTHON), and the
# large distro gives ASan's shadow memory and redzones room for the
# ~6GiB test_encode_size_limit allocation, so no test is skipped.
host = DEFAULT_HOST
return [
create_variant(
[".sanitizer"],
get_variant_name("Sanitizer", host),
host=host,
run_on="rhel8.10-large",
version=MAX_VERSION,
tags=["pr"],
)
]


def create_atlas_connect_variants():
host = DEFAULT_HOST
return [
Expand Down Expand Up @@ -822,34 +839,6 @@ def create_test_non_standard_tasks():
return tasks


def create_string_query_preview_tasks():
"""Tasks for the preview Queryable Encryption string query types.

The preview query types need a server that is at least 8.2 and older than
9.0, and ALL_VERSIONS jumps straight from 8.0 to 9.0, so they have nowhere
to run without a dedicated task. setup_tests.py pins the released
pymongocrypt for 8.x, which bundles a libmongocrypt still carrying the
preview types.
"""
python = CPYTHONS[-1]
topology = "replica_set"
auth, ssl = get_standard_auth_ssl(topology)
expansions = dict(AUTH=auth, SSL=ssl, TOPOLOGY=topology, VERSION="8.2")
tags = [
"test-string-query-preview",
"server-8.2",
f"python-{python}",
f"{topology}-{auth}-{ssl}",
auth,
]
name = get_task_name("test-string-query-preview", python=python, **expansions)
server_func = FunctionCall(func="run server", vars=expansions)
test_vars = expansions.copy()
test_vars["UV_PYTHON"] = python
test_func = FunctionCall(func="run tests", vars=test_vars)
return [EvgTask(name=name, tags=tags, commands=[server_func, test_func])]


def create_test_standard_auth_tasks():
"""We only use auth on sharded clusters"""
tasks = []
Expand Down Expand Up @@ -972,6 +961,19 @@ def create_fuzz_tasks():
return tasks


def create_sanitizer_tasks():
# VERSION comes from the variant: a task-level VERSION would trip the
# pr-tasks-run-coverage rule, and coverage under ASan is not useful.
tags = ["sanitizer", "pr"]
expansions = dict(AUTH="noauth", SSL="nossl", TOPOLOGY="standalone")
server_func = FunctionCall(func="run server", vars=expansions)
test_vars = expansions.copy()
test_vars["TEST_NAME"] = "sanitizer"
test_func = FunctionCall(func="run tests", vars=test_vars)
name = get_task_name("test-sanitizer")
return [EvgTask(name=name, tags=tags, commands=[server_func, test_func])]


def create_kms_tasks():
tasks = []
for kms_type in ["gcp", "azure"]:
Expand Down
1 change: 1 addition & 0 deletions .evergreen/scripts/generate_config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Host:
"rhel82-arm64-small",
"amazon2023-arm64-latest-large-m8g",
],
strict=True,
):
HOSTS[name] = Host(name, run_on, name, dict())

Expand Down
109 changes: 72 additions & 37 deletions .evergreen/scripts/setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
PERF_PYTHON_VERSION,
PLATFORM,
ROOT,
SANITIZER_PYTHON,
TEST_SUITE_MAP,
Distro,
check_drivers_tools,
Expand Down Expand Up @@ -56,9 +57,22 @@
# Map the test name to test group.
GROUP_MAP = dict(fuzz="fuzz", mockupdb="mockupdb", perf="perf")

# The test files run under ASan/UBSan (PYTHON-6048). They exercise the
# buffer-protocol acquisition path in bson/_cbsonmodule.c
# (_get_buffer/_prepare_input_buffer) and the wire-message builders in
# pymongo/_cmessagemodule.c (_op_msg, _batched_op_msg,
# _encode_batched_write_command).
SANITIZER_FILES = [
"test/test_bson.py",
"test/test_raw_bson.py",
"test/test_raw_bson_shared.py",
"test/test_client.py",
]

# The libmongocrypt release used when LIBMONGOCRYPT_URL is not set. Must be at
# least 1.20.0 for the GA "substring" query type.
LIBMONGOCRYPT_VERSION = "1.20.2"
# least 1.21.0; the beta preview string query types were removed in 1.21.0
# (MONGOCRYPT-938).
LIBMONGOCRYPT_VERSION = "1.21.0"


def is_set(var: str) -> bool:
Expand Down Expand Up @@ -390,44 +404,33 @@ def handle_test_env() -> None:
UV_ARGS.append("--extra zstd")

if test_name in ["encryption", "kms"]:
# The "String" algorithm and the GA prefix/suffix/substring query types
# need libmongocrypt 1.19.0+, which is only exercised against MongoDB
# 9.0+. Servers before 9.0 test the preview query types instead, which
# need the "textPreview" algorithm, so pin to the released pymongocrypt
# and use the libmongocrypt bundled in its wheel rather than the
# unreleased master build.
# Evergreen exposes the server version as VERSION, not MONGODB_VERSION
# (which is only set inside the separate run_server.py process).
use_pymongocrypt_text_preview = os.environ.get("VERSION", "").startswith("8.")

if not use_pymongocrypt_text_preview:
# Check for libmongocrypt download.
if not (ROOT / "libmongocrypt").exists():
setup_libmongocrypt()
# The GA string query types need libmongocrypt 1.19.0+ and the beta
# preview query types were removed in 1.21.0 (PYTHON-5959), so always
# use the master pymongocrypt build against the pinned libmongocrypt
# rather than the lib bundled in the released wheel.
# Check for libmongocrypt download.
if not (ROOT / "libmongocrypt").exists():
setup_libmongocrypt()

if not opts.test_min_deps:
if use_pymongocrypt_text_preview:
UV_ARGS.append("--with pymongocrypt<1.19")
else:
UV_ARGS.append(
"--with pymongocrypt@git+https://github.com/mongodb/libmongocrypt@master#subdirectory=bindings/python"
)

if not use_pymongocrypt_text_preview:
# Use the nocrypto build to avoid dependency issues with older windows/python versions.
BASE = get_libmongocrypt_base()
if PLATFORM == "linux":
if (BASE / "lib/libmongocrypt.so").exists():
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.so"
else:
PYMONGOCRYPT_LIB = BASE / "lib64/libmongocrypt.so"
elif PLATFORM == "darwin":
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.dylib"
UV_ARGS.append(
"--with pymongocrypt@git+https://github.com/mongodb/libmongocrypt@master#subdirectory=bindings/python"
)

# Use the nocrypto build to avoid dependency issues with older windows/python versions.
BASE = get_libmongocrypt_base()
if PLATFORM == "linux":
if (BASE / "lib/libmongocrypt.so").exists():
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.so"
else:
PYMONGOCRYPT_LIB = BASE / "bin/mongocrypt.dll"
if not PYMONGOCRYPT_LIB.exists():
raise RuntimeError("Cannot find libmongocrypt shared object file")
write_env("PYMONGOCRYPT_LIB", PYMONGOCRYPT_LIB.as_posix())
PYMONGOCRYPT_LIB = BASE / "lib64/libmongocrypt.so"
elif PLATFORM == "darwin":
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.dylib"
else:
PYMONGOCRYPT_LIB = BASE / "bin/mongocrypt.dll"
if not PYMONGOCRYPT_LIB.exists():
raise RuntimeError("Cannot find libmongocrypt shared object file")
write_env("PYMONGOCRYPT_LIB", PYMONGOCRYPT_LIB.as_posix())
# PATH is updated by configure-env.sh for access to mongocryptd.

if test_name == "encryption":
Expand Down Expand Up @@ -546,6 +549,38 @@ def handle_test_env() -> None:
zip_path.unlink()
write_env("FUZZ_CORPUS_DIR", str(corpus_dir))

if test_name == "sanitizer":
if PLATFORM != "linux":
raise RuntimeError("The sanitizer tests require the Linux Python toolchain.")
if not Path(SANITIZER_PYTHON).is_file():
raise RuntimeError(
f"Sanitizer interpreter not found at {SANITIZER_PYTHON}; "
"the task must run on a host with the ASan/UBSan toolchain Python."
)
# Clear stale C artifacts: build_ext reuses them by mtime, and a
# plain same-version CPython build shares the ABI tag.
shutil.rmtree(ROOT / "build", ignore_errors=True)
for pkg in ["bson", "pymongo"]:
for ext in (ROOT / pkg).glob("*.so"):
ext.unlink()
# Build and run against the ASan/UBSan-instrumented toolchain CPython,
# and fail loudly rather than silently skip the C extension build.
write_env("UV_PYTHON", SANITIZER_PYTHON)
write_env("PYMONGO_C_EXT_MUST_BUILD")
write_env("CFLAGS", "-fsanitize=address,undefined -fno-omit-frame-pointer -g -O1")
write_env("LDFLAGS", "-fsanitize=address,undefined")
# CPython's pymalloc trips LeakSanitizer with false positives.
write_env("ASAN_OPTIONS", "detect_leaks=0")
# UBSan only warns by default; make undefined behavior fail the task.
write_env("UBSAN_OPTIONS", "halt_on_error=1:print_stacktrace=1")
# The toolchain interpreter self-initializes the sanitizer runtimes,
# so no LD_PRELOAD: gcc's libasan.so is a linker script that ld.so
# cannot preload, and preloading a mismatched runtime would mix two
# sanitizers in one process.
# -s: with halt_on_error=1, a sanitizer failure exits the interpreter
# before pytest replays captured stderr, losing the report and trace.
TEST_ARGS = "-s " + " ".join(SANITIZER_FILES) + " " + TEST_ARGS

# Add coverage if requested.
if opts.cov:
# Keep in sync with combine-coverage.sh.
Expand Down
Loading
Loading