run_sanitizer_tests.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. ################################################################################
  3. # Run OpENer Tests with AddressSanitizer Output
  4. #
  5. # This script runs the OpENer test suite with AddressSanitizer and
  6. # UndefinedBehaviorSanitizer configured for maximum error detection.
  7. #
  8. # Usage:
  9. # ./run_sanitizer_tests.sh [build_dir] [test_filter]
  10. #
  11. # Examples:
  12. # ./run_sanitizer_tests.sh # Run all tests, auto-find build dir
  13. # ./run_sanitizer_tests.sh build_sanitizer
  14. # ./run_sanitizer_tests.sh build_sanitizer NetworkHandlerSecurity
  15. #
  16. ################################################################################
  17. set -e
  18. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  19. # Determine build directory
  20. if [ -n "$1" ] && [ -d "$1" ]; then
  21. BUILD_DIR="$1"
  22. elif [ -d "${SCRIPT_DIR}/build_sanitizer" ]; then
  23. BUILD_DIR="${SCRIPT_DIR}/build_sanitizer"
  24. elif [ -d "${SCRIPT_DIR}/build" ]; then
  25. BUILD_DIR="${SCRIPT_DIR}/build"
  26. else
  27. echo "Error: Cannot find build directory"
  28. echo "Usage: $0 [build_dir] [test_filter]"
  29. exit 1
  30. fi
  31. TEST_FILTER="${2:-}"
  32. TEST_EXECUTABLE="${BUILD_DIR}/tests/OpENer_Tests"
  33. if [ ! -f "$TEST_EXECUTABLE" ]; then
  34. echo "Error: Test executable not found at $TEST_EXECUTABLE"
  35. echo "Build with: ./build_with_sanitizers.sh"
  36. exit 1
  37. fi
  38. echo "=============================================="
  39. echo "OpENer Test Execution with Sanitizers"
  40. echo "=============================================="
  41. echo "Build Directory: $BUILD_DIR"
  42. echo "Test Executable: $TEST_EXECUTABLE"
  43. echo ""
  44. # Configure sanitizer options
  45. export ASAN_OPTIONS="detect_leaks=1:halt_on_error=1:verbosity=2:log_path=asan.log"
  46. export UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1:verbosity=2:log_path=ubsan.log"
  47. echo "Environment:"
  48. echo " ASAN_OPTIONS=$ASAN_OPTIONS"
  49. echo " UBSAN_OPTIONS=$UBSAN_OPTIONS"
  50. echo ""
  51. # Run tests
  52. TEST_ARGS="-v -c"
  53. if [ -n "$TEST_FILTER" ]; then
  54. TEST_ARGS="$TEST_ARGS -g $TEST_FILTER"
  55. echo "Running tests matching: $TEST_FILTER"
  56. else
  57. echo "Running all tests..."
  58. fi
  59. echo ""
  60. "$TEST_EXECUTABLE" "$TEST_ARGS"
  61. TEST_RESULT=$?
  62. echo ""
  63. echo "=============================================="
  64. if [ "$TEST_RESULT" -eq 0 ]; then
  65. echo "✓ All tests passed!"
  66. else
  67. echo "✗ Tests failed with exit code: $TEST_RESULT"
  68. fi
  69. echo "=============================================="
  70. echo ""
  71. # Check for sanitizer logs
  72. if [ -f "asan.log" ]; then
  73. echo "AddressSanitizer detected issues:"
  74. echo "See asan.log for details"
  75. echo ""
  76. fi
  77. if [ -f "ubsan.log" ]; then
  78. echo "UndefinedBehaviorSanitizer detected issues:"
  79. echo "See ubsan.log for details"
  80. echo ""
  81. fi
  82. exit $TEST_RESULT