Debian Codegraph @

test/integration/scripts/check-asan-logs.sh

raw
1 #!/bin/bash
2 # Check AddressSanitizer logs for memory leaks and errors
3
4 set -e
5
6 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7 DATA_DIR="$SCRIPT_DIR/../data"
8
9 echo "=== Checking AddressSanitizer logs ==="
10 echo ""
11
12 # Find all ASAN log files
13 ASAN_LOGS=$(find "$DATA_DIR" -name "asan.log*" 2>/dev/null)
14
15 if [ -z "$ASAN_LOGS" ]; then
16 echo "No ASAN logs found in $DATA_DIR"
17 exit 0
18 fi
19
20 TOTAL_LEAKS=0
21 TOTAL_ERRORS=0
22
23 for log_file in $ASAN_LOGS; do
24 echo "Analyzing: $log_file"
25 echo "----------------------------------------"
26
27 # Count memory leaks
28 LEAKS=$(grep "LeakSanitizer" "$log_file" 2>/dev/null | wc -l | tr -d ' ')
29 LEAKS=${LEAKS:-0}
30 if [ "$LEAKS" -gt 0 ] 2>/dev/null; then
31 echo " Memory leaks detected: $LEAKS"
32 TOTAL_LEAKS=$((TOTAL_LEAKS + LEAKS))
33
34 # Show leak summary
35 grep -A 10 "LeakSanitizer" "$log_file" | head -20
36 fi
37
38 # Count other errors
39 ERRORS=$(grep "ERROR: AddressSanitizer" "$log_file" 2>/dev/null | wc -l | tr -d ' ')
40 ERRORS=${ERRORS:-0}
41 if [ "$ERRORS" -gt 0 ] 2>/dev/null; then
42 echo " AddressSanitizer errors: $ERRORS"
43 TOTAL_ERRORS=$((TOTAL_ERRORS + ERRORS))
44
45 # Show error summary
46 grep -A 10 "ERROR: AddressSanitizer" "$log_file" | head -20
47 fi
48
49 # Check for heap-use-after-free
50 UAF=$(grep "heap-use-after-free" "$log_file" 2>/dev/null | wc -l | tr -d ' ')
51 UAF=${UAF:-0}
52 if [ "$UAF" -gt 0 ] 2>/dev/null; then
53 echo " Heap-use-after-free: $UAF"
54 fi
55
56 # Check for heap-buffer-overflow
57 OVERFLOW=$(grep "heap-buffer-overflow" "$log_file" 2>/dev/null | wc -l | tr -d ' ')
58 OVERFLOW=${OVERFLOW:-0}
59 if [ "$OVERFLOW" -gt 0 ] 2>/dev/null; then
60 echo " Heap-buffer-overflow: $OVERFLOW"
61 fi
62
63 echo ""
64 done
65
66 echo "========================================"
67 echo "SUMMARY"
68 echo "========================================"
69 echo "Total memory leaks: $TOTAL_LEAKS"
70 echo "Total ASan errors: $TOTAL_ERRORS"
71 echo ""
72
73 if [ "$TOTAL_LEAKS" -gt 0 ] || [ "$TOTAL_ERRORS" -gt 0 ]; then
74 echo "RESULT: FAILED - Memory issues detected"
75 echo ""
76 echo "Full logs available in:"
77 for log_file in $ASAN_LOGS; do
78 echo " - $log_file"
79 done
80 exit 1
81 else
82 echo "RESULT: PASSED - No memory issues detected"
83 exit 0
84 fi