Skip to content

Commit b8ea0d3

Browse files
committed
Added some leak detection checks
1 parent 3bce1f6 commit b8ea0d3

File tree

4 files changed

+234
-24
lines changed

4 files changed

+234
-24
lines changed

demos/websocket/client/package-lock.json

Lines changed: 14 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/lsan.supp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# LeakSanitizer suppressions file for Canopy RPC tests
2+
# Suppresses known false positives in test infrastructure
3+
4+
# Google Protobuf static initialization
5+
leak:google::protobuf::internal::AddDescriptors
6+
leak:google::protobuf::DescriptorPool::InternalAddGeneratedFile
7+
leak:google::protobuf::MessageLite::MessageLite
8+
leak:google::protobuf::Message::Message
9+
10+
# Google Test infrastructure
11+
leak:testing::internal::UnitTestImpl
12+
leak:testing::internal::SetUpTestSuite
13+
leak:testing::internal::TearDownTestSuite
14+
leak:testing::TestInfo::Run
15+
leak:testing::UnitTest::Run
16+
17+
# Static initialization and global objects
18+
leak:__static_initialization_and_destruction
19+
leak:_GLOBAL__sub
20+
leak:__cxx_global_var_init
21+
22+
# libcoro scheduler infrastructure (if any static state)
23+
leak:coro::io_scheduler::make_shared
24+
leak:coro::thread_pool
25+
26+
# C++ standard library static objects
27+
leak:std::__once_callable
28+
leak:std::call_once
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
cd /var/home/edward/projects/Canopy/build_coroutine_debug
3+
4+
# Enable leak detection with suppressions, suppress protobuf container-overflow
5+
export ASAN_OPTIONS="detect_leaks=1:detect_container_overflow=0"
6+
export LSAN_OPTIONS="suppressions=../tests/lsan.supp:print_suppressions=0"
7+
8+
# Get all test names properly
9+
CURRENT_SUITE=""
10+
declare -a TEST_ARRAY
11+
12+
echo "Collecting test list..."
13+
while IFS= read -r line; do
14+
# Check if it's a test suite line (e.g., "type_test/0. # TypeParam...")
15+
if [[ $line =~ ^([A-Za-z0-9_]+)/([0-9]+)\. ]]; then
16+
CURRENT_SUITE="${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
17+
# Check if it's a test case (starts with spaces)
18+
elif [[ $line =~ ^[[:space:]]+([A-Za-z0-9_]+)$ ]]; then
19+
TEST_NAME="${BASH_REMATCH[1]}"
20+
if [ -n "$CURRENT_SUITE" ]; then
21+
TEST_ARRAY+=("${CURRENT_SUITE}.${TEST_NAME}")
22+
fi
23+
fi
24+
done < <(./output/rpc_test --gtest_list_tests 2>&1)
25+
26+
TOTAL_COUNT=${#TEST_ARRAY[@]}
27+
PASSED_COUNT=0
28+
FAILED_COUNT=0
29+
LEAK_COUNT=0
30+
FAILED_TESTS=()
31+
LEAK_TESTS=()
32+
33+
echo "=========================================="
34+
echo "Running AddressSanitizer Tests with Leak Detection (Coroutine)"
35+
echo "Total tests to run: $TOTAL_COUNT"
36+
echo "=========================================="
37+
echo ""
38+
39+
for i in "${!TEST_ARRAY[@]}"; do
40+
FULL_TEST="${TEST_ARRAY[$i]}"
41+
TEST_NUM=$((i + 1))
42+
43+
echo -n "[$TEST_NUM/$TOTAL_COUNT] Running: $FULL_TEST ... "
44+
45+
# Run the test and capture output
46+
if timeout 30 ./output/rpc_test --gtest_filter="$FULL_TEST" > /tmp/test_output_coro_leak.log 2>&1; then
47+
# Check for memory leaks
48+
if grep -q "ERROR: LeakSanitizer: detected memory leaks" /tmp/test_output_coro_leak.log; then
49+
echo "MEMORY LEAK"
50+
LEAK_TESTS+=("$FULL_TEST")
51+
LEAK_COUNT=$((LEAK_COUNT + 1))
52+
cp /tmp/test_output_coro_leak.log "/tmp/leak_coro_${FULL_TEST//\//_}.log"
53+
# Check if AddressSanitizer found any other errors (excluding container-overflow)
54+
elif grep -q "AddressSanitizer.*ERROR" /tmp/test_output_coro_leak.log | grep -v "container-overflow"; then
55+
echo "ASAN ERROR"
56+
FAILED_TESTS+=("$FULL_TEST")
57+
FAILED_COUNT=$((FAILED_COUNT + 1))
58+
cp /tmp/test_output_coro_leak.log "/tmp/asan_coro_leak_error_${FULL_TEST//\//_}.log"
59+
else
60+
echo "PASSED"
61+
PASSED_COUNT=$((PASSED_COUNT + 1))
62+
fi
63+
else
64+
echo "FAILED/TIMEOUT"
65+
FAILED_TESTS+=("$FULL_TEST")
66+
FAILED_COUNT=$((FAILED_COUNT + 1))
67+
cp /tmp/test_output_coro_leak.log "/tmp/asan_coro_leak_error_${FULL_TEST//\//_}.log"
68+
fi
69+
done
70+
71+
echo ""
72+
echo "=========================================="
73+
echo "Summary (Coroutine - Leak Detection Enabled)"
74+
echo "=========================================="
75+
echo "Total tests: $TOTAL_COUNT"
76+
echo "Passed: $PASSED_COUNT"
77+
echo "Failed (ASan errors): $FAILED_COUNT"
78+
echo "Memory leaks detected: $LEAK_COUNT"
79+
echo ""
80+
81+
if [ ${#FAILED_TESTS[@]} -gt 0 ]; then
82+
echo "Failed tests (ASan errors):"
83+
for test in "${FAILED_TESTS[@]}"; do
84+
echo " - $test"
85+
echo " Log: /tmp/asan_coro_leak_error_${test//\//_}.log"
86+
done
87+
echo ""
88+
fi
89+
90+
if [ ${#LEAK_TESTS[@]} -gt 0 ]; then
91+
echo "Tests with memory leaks:"
92+
for test in "${LEAK_TESTS[@]}"; do
93+
echo " - $test"
94+
echo " Log: /tmp/leak_coro_${test//\//_}.log"
95+
done
96+
fi
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
cd /var/home/edward/projects/Canopy/build_debug
3+
4+
# Enable leak detection with suppressions
5+
export ASAN_OPTIONS="detect_leaks=1"
6+
export LSAN_OPTIONS="suppressions=../tests/lsan.supp:print_suppressions=0"
7+
8+
# Get all test names properly
9+
CURRENT_SUITE=""
10+
declare -a TEST_ARRAY
11+
12+
echo "Collecting test list..."
13+
while IFS= read -r line; do
14+
# Check if it's a test suite line (e.g., "type_test/0. # TypeParam...")
15+
if [[ $line =~ ^([A-Za-z0-9_]+)/([0-9]+)\. ]]; then
16+
CURRENT_SUITE="${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
17+
# Check if it's a test case (starts with spaces)
18+
elif [[ $line =~ ^[[:space:]]+([A-Za-z0-9_]+)$ ]]; then
19+
TEST_NAME="${BASH_REMATCH[1]}"
20+
if [ -n "$CURRENT_SUITE" ]; then
21+
TEST_ARRAY+=("${CURRENT_SUITE}.${TEST_NAME}")
22+
fi
23+
fi
24+
done < <(./output/rpc_test --gtest_list_tests 2>&1)
25+
26+
TOTAL_COUNT=${#TEST_ARRAY[@]}
27+
PASSED_COUNT=0
28+
FAILED_COUNT=0
29+
LEAK_COUNT=0
30+
FAILED_TESTS=()
31+
LEAK_TESTS=()
32+
33+
echo "========================================"
34+
echo "Running AddressSanitizer Tests with Leak Detection"
35+
echo "Total tests to run: $TOTAL_COUNT"
36+
echo "========================================"
37+
echo ""
38+
39+
for i in "${!TEST_ARRAY[@]}"; do
40+
FULL_TEST="${TEST_ARRAY[$i]}"
41+
TEST_NUM=$((i + 1))
42+
43+
echo -n "[$TEST_NUM/$TOTAL_COUNT] Running: $FULL_TEST ... "
44+
45+
# Run the test and capture output
46+
if timeout 30 ./output/rpc_test --gtest_filter="$FULL_TEST" > /tmp/test_output_leak.log 2>&1; then
47+
# Check for memory leaks
48+
if grep -q "ERROR: LeakSanitizer: detected memory leaks" /tmp/test_output_leak.log; then
49+
echo "MEMORY LEAK"
50+
LEAK_TESTS+=("$FULL_TEST")
51+
LEAK_COUNT=$((LEAK_COUNT + 1))
52+
cp /tmp/test_output_leak.log "/tmp/leak_${FULL_TEST//\//_}.log"
53+
# Check if AddressSanitizer found any other errors
54+
elif grep -q "AddressSanitizer.*ERROR" /tmp/test_output_leak.log; then
55+
echo "ASAN ERROR"
56+
FAILED_TESTS+=("$FULL_TEST")
57+
FAILED_COUNT=$((FAILED_COUNT + 1))
58+
cp /tmp/test_output_leak.log "/tmp/asan_leak_error_${FULL_TEST//\//_}.log"
59+
else
60+
echo "PASSED"
61+
PASSED_COUNT=$((PASSED_COUNT + 1))
62+
fi
63+
else
64+
echo "FAILED/TIMEOUT"
65+
FAILED_TESTS+=("$FULL_TEST")
66+
FAILED_COUNT=$((FAILED_COUNT + 1))
67+
cp /tmp/test_output_leak.log "/tmp/asan_leak_error_${FULL_TEST//\//_}.log"
68+
fi
69+
done
70+
71+
echo ""
72+
echo "========================================"
73+
echo "Summary (Leak Detection Enabled)"
74+
echo "========================================"
75+
echo "Total tests: $TOTAL_COUNT"
76+
echo "Passed: $PASSED_COUNT"
77+
echo "Failed (ASan errors): $FAILED_COUNT"
78+
echo "Memory leaks detected: $LEAK_COUNT"
79+
echo ""
80+
81+
if [ ${#FAILED_TESTS[@]} -gt 0 ]; then
82+
echo "Failed tests (ASan errors):"
83+
for test in "${FAILED_TESTS[@]}"; do
84+
echo " - $test"
85+
echo " Log: /tmp/asan_leak_error_${test//\//_}.log"
86+
done
87+
echo ""
88+
fi
89+
90+
if [ ${#LEAK_TESTS[@]} -gt 0 ]; then
91+
echo "Tests with memory leaks:"
92+
for test in "${LEAK_TESTS[@]}"; do
93+
echo " - $test"
94+
echo " Log: /tmp/leak_${test//\//_}.log"
95+
done
96+
fi

0 commit comments

Comments
 (0)