mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2026-02-03 21:23:35 +00:00
Refine ASAN_OPTIONS handling for test discovery and execution
This commit is contained in:
@@ -49,12 +49,21 @@ Write-Host "Build completed successfully!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# Set up ASan options
|
||||
# Priority: 1) Command line parameter, 2) Existing ASAN_OPTIONS env var, 3) Default
|
||||
if ($AsanOptions -ne "") {
|
||||
$env:ASAN_OPTIONS = $AsanOptions
|
||||
Write-Host "Using custom ASAN_OPTIONS: $env:ASAN_OPTIONS" -ForegroundColor Yellow
|
||||
Write-Host "Using ASAN_OPTIONS from command line: $env:ASAN_OPTIONS" -ForegroundColor Yellow
|
||||
}
|
||||
elseif ($env:ASAN_OPTIONS) {
|
||||
Write-Host "Using ASAN_OPTIONS from environment: $env:ASAN_OPTIONS" -ForegroundColor Yellow
|
||||
# Add print_stats=1 if not already specified
|
||||
if ($env:ASAN_OPTIONS -notmatch "print_stats") {
|
||||
$env:ASAN_OPTIONS = "$env:ASAN_OPTIONS`:print_stats=1"
|
||||
Write-Host "Added print_stats=1 to your options" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Default options: detect leaks (if supported), print stats
|
||||
# Default options: print stats (leak detection often not supported on Windows)
|
||||
$env:ASAN_OPTIONS = "print_stats=1"
|
||||
Write-Host "Using default ASAN_OPTIONS: $env:ASAN_OPTIONS" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
@@ -48,9 +48,17 @@ echo -e "${GREEN}Build completed successfully!${NC}"
|
||||
echo ""
|
||||
|
||||
# Set up ASan options
|
||||
# Priority: 1) Command line arg, 2) Existing ASAN_OPTIONS env var, 3) Platform-specific defaults
|
||||
if [ -n "$1" ]; then
|
||||
export ASAN_OPTIONS="$1"
|
||||
echo -e "${YELLOW}Using custom ASAN_OPTIONS: $ASAN_OPTIONS${NC}"
|
||||
echo -e "${YELLOW}Using ASAN_OPTIONS from command line: $ASAN_OPTIONS${NC}"
|
||||
elif [ -n "$ASAN_OPTIONS" ]; then
|
||||
echo -e "${YELLOW}Using ASAN_OPTIONS from environment: $ASAN_OPTIONS${NC}"
|
||||
# Add print_stats=1 if not already specified
|
||||
if [[ ! "$ASAN_OPTIONS" =~ print_stats ]]; then
|
||||
export ASAN_OPTIONS="${ASAN_OPTIONS}:print_stats=1"
|
||||
echo -e "${YELLOW}Added print_stats=1 to your options${NC}"
|
||||
fi
|
||||
else
|
||||
# Default options: print stats, use colors
|
||||
# Note: detect_leaks is not supported on macOS, so we don't enable it by default
|
||||
@@ -60,7 +68,7 @@ else
|
||||
echo -e "${YELLOW}Note: leak detection not supported on macOS${NC}"
|
||||
else
|
||||
export ASAN_OPTIONS="detect_leaks=1:print_stats=1:color=always"
|
||||
echo -e "${YELLOW}Using default ASAN_OPTIONS: $ASAN_OPTIONS${NC}"
|
||||
echo -e "${YELLOW}Using default ASAN_OPTIONS (Linux): $ASAN_OPTIONS${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -125,18 +125,22 @@ include(GoogleTest)
|
||||
|
||||
# Configure test discovery with proper ASAN_OPTIONS
|
||||
if(USE_ASAN)
|
||||
# On macOS, leak detection is not supported and causes abort
|
||||
# Set ASAN_OPTIONS for test discovery to avoid this
|
||||
# On macOS, leak detection is not supported and causes abort during test discovery
|
||||
# We need to set ASAN_OPTIONS only for the discovery phase, not for actual test execution
|
||||
# The discovery phase runs during CMake configuration
|
||||
if(APPLE)
|
||||
set(DISCOVERY_ASAN_OPTIONS "print_stats=0")
|
||||
set(ENV{ASAN_OPTIONS} "print_stats=0")
|
||||
else()
|
||||
set(DISCOVERY_ASAN_OPTIONS "detect_leaks=0:print_stats=0")
|
||||
set(ENV{ASAN_OPTIONS} "detect_leaks=0:print_stats=0")
|
||||
endif()
|
||||
|
||||
# Discover tests - this runs with the ASAN_OPTIONS we just set
|
||||
gtest_discover_tests(tests_run
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES ENVIRONMENT "ASAN_OPTIONS=${DISCOVERY_ASAN_OPTIONS}"
|
||||
)
|
||||
|
||||
# Clear the environment variable so it doesn't affect the actual test runs
|
||||
unset(ENV{ASAN_OPTIONS})
|
||||
else()
|
||||
gtest_discover_tests(tests_run)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user