Add test to make sure sanitizers really work when expected (#10838)

This commit is contained in:
Alexander Lakhin
2025-02-18 15:23:18 +02:00
committed by GitHub
parent 719ec378cd
commit f81259967d
2 changed files with 21 additions and 0 deletions

View File

@@ -64,6 +64,8 @@ VERSIONS_COMBINATIONS = (
# If it is not set or set to a value not equal to "false", LFC is enabled by default. # If it is not set or set to a value not equal to "false", LFC is enabled by default.
USE_LFC = os.environ.get("USE_LFC") != "false" USE_LFC = os.environ.get("USE_LFC") != "false"
WITH_SANITIZERS = os.environ.get("SANITIZERS") == "enabled"
def subprocess_capture( def subprocess_capture(
capture_dir: Path, capture_dir: Path,

View File

@@ -2,6 +2,8 @@ from __future__ import annotations
import pytest import pytest
from fixtures.neon_fixtures import NeonEnvBuilder from fixtures.neon_fixtures import NeonEnvBuilder
from fixtures.pg_version import PgVersion
from fixtures.utils import WITH_SANITIZERS, run_only_on_postgres
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -23,3 +25,20 @@ def test_endpoint_crash(neon_env_builder: NeonEnvBuilder, sql_func: str):
endpoint.safe_psql("CREATE EXTENSION neon_test_utils;") endpoint.safe_psql("CREATE EXTENSION neon_test_utils;")
with pytest.raises(Exception, match="This probably means the server terminated abnormally"): with pytest.raises(Exception, match="This probably means the server terminated abnormally"):
endpoint.safe_psql(f"SELECT {sql_func}();") endpoint.safe_psql(f"SELECT {sql_func}();")
@run_only_on_postgres([PgVersion.V17], "Currently, build vith sanitizers is possible with v17 only")
def test_sanitizers(neon_env_builder: NeonEnvBuilder):
"""
Test that undefined behavior leads to endpoint abort with sanitizers enabled
"""
env = neon_env_builder.init_start()
env.create_branch("test_ubsan")
endpoint = env.endpoints.create_start("test_ubsan")
# Test case based on https://www.postgresql.org/message-id/17167-028026e4ca333817@postgresql.org
if not WITH_SANITIZERS:
endpoint.safe_psql("SELECT 1::int4 << 128")
else:
with pytest.raises(Exception, match="This probably means the server terminated abnormally"):
endpoint.safe_psql("SELECT 1::int4 << 128")