Skip to content

Commit

Permalink
Run test under valgrind, and print the output to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
BishrutSubedi committed Jun 27, 2024
1 parent 42103b7 commit 8a0d03c
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 57 deletions.
212 changes: 162 additions & 50 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,78 +122,190 @@ jobs:
run: |
cd up-cpp/build
chmod +x bin/*
echo "Running Memcheck..."
exclude_tests=$(cat valgrind_exclude_test_memcheck.txt | tr '\n' '|' | sed 's/|$//')
echo "Excluding tests: $exclude_tests"
set +e
valgrind --leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--trace-children=yes \
--log-file=valgrind-memcheck.log \
--gen-suppressions=all \
ctest -E "$exclude_tests"
exit_code=$?
set -e
if [ $exit_code -ne 0 ]; then
touch memcheck_failed_output.log
echo "Some tests failed. Capturing the logs..."
cat Testing/Temporary/LastTest.log | tee -a memcheck_failed_output.log
else
echo "No tests failed."
touch memcheck_failed_output.log
fi
mkdir -p valgrind_logs
: > valgrind_logs/valgrind_memcheck_summary.log
declare -A EXCLUDE_TESTS
while IFS= read -r line; do
test_binary=$(echo $line | cut -d'.' -f1)
test_suite=$(echo $line | cut -d'.' -f2)
test_name=$(echo $line | cut -d'.' -f3)
if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then
EXCLUDE_TESTS["$test_binary"]="-"
else
EXCLUDE_TESTS["$test_binary"]+=":"
fi
EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name"
done < valgrind_exclude_test_memcheck.txt
for test_binary in bin/*Test; do
test_binary_name=$(basename $test_binary)
echo "Running Valgrind on $test_binary_name"
if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then
exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}"
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="valgrind_logs/$test_binary_name.log" ./$test_binary --gtest_filter="$exclude_pattern" || true
else
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="valgrind_logs/$test_binary_name.log" ./$test_binary || true
fi
cat "valgrind_logs/$test_binary_name.log" >> valgrind_logs/valgrind_complete_log.log
if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name.log"; then
echo "Valgrind errors found in $test_binary_name:"
grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name.log" >> valgrind_logs/valgrind_memcheck_summary.log
echo "Valgrind log for $test_binary_name:"
cat "valgrind_logs/$test_binary_name.log"
echo "------------------------"
fi
done
echo "Valgrind Memcheck Summary:"
cat valgrind_logs/valgrind_memcheck_summary.log
- name: Run Valgrind ThreadCheck
continue-on-error: true
run: |
cd up-cpp/build
echo "Running ThreadCheck..."
valgrind --tool=drd \
--trace-children=yes \
--log-file=valgrind-threadcheck.log \
ctest
echo "ThreadCheck log:"
cat valgrind-threadcheck.log
chmod +x bin/*
mkdir -p valgrind_logs
: > valgrind_logs/valgrind_threadcheck_summary.log
: > valgrind_logs/valgrind_complete_threadcheck_log.log
declare -A EXCLUDE_TESTS
while IFS= read -r line; do
test_binary=$(echo $line | cut -d'.' -f1)
test_suite=$(echo $line | cut -d'.' -f2)
test_name=$(echo $line | cut -d'.' -f3)
if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then
EXCLUDE_TESTS["$test_binary"]="-"
else
EXCLUDE_TESTS["$test_binary"]+=":"
fi
EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name"
done < valgrind_exclude_test_threadcheck.txt
for test_binary in bin/*Test; do
test_binary_name=$(basename $test_binary)
echo "Running Valgrind ThreadCheck on $test_binary_name"
if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then
exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}"
valgrind --tool=drd --log-file="valgrind_logs/$test_binary_name_threadcheck.log" ./$test_binary --gtest_filter="$exclude_pattern" || true
else
valgrind --tool=drd --log-file="valgrind_logs/$test_binary_name_threadcheck.log" ./$test_binary || true
fi
cat "valgrind_logs/$test_binary_name_threadcheck.log" >> valgrind_logs/valgrind_complete_threadcheck_log.log
if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name_threadcheck.log"; then
echo "Valgrind ThreadCheck errors found in $test_binary_name:"
grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name_threadcheck.log" >> valgrind_logs/valgrind_threadcheck_summary.log
echo "Valgrind ThreadCheck log for $test_binary_name:"
cat "valgrind_logs/$test_binary_name_threadcheck.log"
echo "------------------------"
fi
done
echo "Valgrind ThreadCheck Summary:"
cat valgrind_logs/valgrind_threadcheck_summary.log
- name: Run Valgrind Helgrind
continue-on-error: true
run: |
cd up-cpp/build
echo "Running Helgrind..."
valgrind --tool=helgrind \
--trace-children=yes \
--log-file=valgrind-helgrind.log \
ctest
echo "Helgrind log:"
cat valgrind-helgrind.log
chmod +x bin/*
mkdir -p valgrind_logs
: > valgrind_logs/valgrind_helgrind_summary.log
: > valgrind_logs/valgrind_complete_helgrind_log.log
declare -A EXCLUDE_TESTS
while IFS= read -r line; do
test_binary=$(echo $line | cut -d'.' -f1)
test_suite=$(echo $line | cut -d'.' -f2)
test_name=$(echo $line | cut -d'.' -f3)
if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then
EXCLUDE_TESTS["$test_binary"]="-"
else
EXCLUDE_TESTS["$test_binary"]+=":"
fi
EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name"
done < valgrind_exclude_test_helgrind.txt
for test_binary in bin/*Test; do
test_binary_name=$(basename $test_binary)
echo "Running Valgrind Helgrind on $test_binary_name"
if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then
exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}"
valgrind --tool=helgrind --log-file="valgrind_logs/$test_binary_name_helgrind.log" ./$test_binary --gtest_filter="$exclude_pattern" || true
else
valgrind --tool=helgrind --log-file="valgrind_logs/$test_binary_name_helgrind.log" ./$test_binary || true
fi
cat "valgrind_logs/$test_binary_name_helgrind.log" >> valgrind_logs/valgrind_complete_helgrind_log.log
if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name_helgrind.log"; then
echo "Valgrind Helgrind errors found in $test_binary_name:"
grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name_helgrind.log" >> valgrind_logs/valgrind_helgrind_summary.log
echo "Valgrind Helgrind log for $test_binary_name:"
cat "valgrind_logs/$test_binary_name_helgrind.log"
echo "------------------------"
fi
done
echo "Valgrind Helgrind Summary:"
cat valgrind_logs/valgrind_helgrind_summary.log
- name: Run Valgrind DHAT
continue-on-error: true
run: |
cd up-cpp/build
echo "Running DHAT (Data Address Translation)..."
valgrind --tool=dhat \
--trace-children=yes \
--log-file=valgrind-dhat.log \
ctest
echo "DHAT log:"
cat valgrind-dhat.log
chmod +x bin/*
mkdir -p valgrind_logs
: > valgrind_logs/valgrind_dhat_summary.log
: > valgrind_logs/valgrind_complete_dhat_log.log
declare -A EXCLUDE_TESTS
while IFS= read -r line; do
test_binary=$(echo $line | cut -d'.' -f1)
test_suite=$(echo $line | cut -d'.' -f2)
test_name=$(echo $line | cut -d'.' -f3)
if [[ -z "${EXCLUDE_TESTS["$test_binary"]}" ]]; then
EXCLUDE_TESTS["$test_binary"]="-"
else
EXCLUDE_TESTS["$test_binary"]+=":"
fi
EXCLUDE_TESTS["$test_binary"]+="$test_suite.$test_name"
done < valgrind_exclude_test_dhat.txt
for test_binary in bin/*Test; do
test_binary_name=$(basename $test_binary)
echo "Running Valgrind DHAT on $test_binary_name"
if [[ -n "${EXCLUDE_TESTS[$test_binary_name]}" ]]; then
exclude_pattern="${EXCLUDE_TESTS[$test_binary_name]}"
valgrind --tool=dhat --log-file="valgrind_logs/$test_binary_name_dhat.log" ./$test_binary --gtest_filter="$exclude_pattern" || true
else
valgrind --tool=dhat --log-file="valgrind_logs/$test_binary_name_dhat.log" ./$test_binary || true
fi
cat "valgrind_logs/$test_binary_name_dhat.log" >> valgrind_logs/valgrind_complete_dhat_log.log
if grep -q "ERROR SUMMARY: [^0]" "valgrind_logs/$test_binary_name_dhat.log"; then
echo "Valgrind DHAT errors found in $test_binary_name:"
grep -A1 "ERROR SUMMARY:" "valgrind_logs/$test_binary_name_dhat.log" >> valgrind_logs/valgrind_dhat_summary.log
echo "Valgrind DHAT log for $test_binary_name:"
cat "valgrind_logs/$test_binary_name_dhat.log"
echo "------------------------"
fi
done
echo "Valgrind DHAT Summary:"
cat valgrind_logs/valgrind_dhat_summary.log
- name: Upload Valgrind log
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: valgrind-log
path: |
up-cpp/build/memcheck_failed_output.log
up-cpp/build/valgrind-memcheck-detailed.log
up-cpp/build/valgrind-memcheck.log
up-cpp/build/valgrind-threadcheck.log
up-cpp/build/valgrind-helgrind.log
up-cpp/build/valgrind-dhat.log
up-cpp/build/valgrind_logs/valgrind_complete_log.log
up-cpp/build/valgrind_logs/valgrind_complete_threadcheck_log.log
up-cpp/build/valgrind_logs/valgrind_complete_helgrind_log.log
up-cpp/build/valgrind_logs/valgrind_complete_dhat_log.log
lint:
name: Lint C++ sources
Expand Down
11 changes: 7 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ enable_testing()
find_package(GTest REQUIRED)
include(GoogleTest)

# Copy valgrind_exclude_tests.txt to the binary directory
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sanitizers/valgrind_exclude_test_memcheck.txt
${CMAKE_BINARY_DIR}/valgrind_exclude_test_memcheck.txt
COPYONLY)
# Copy exclude files to the binary directory
file(COPY
${CMAKE_CURRENT_SOURCE_DIR}/sanitizers/valgrind_exclude_test_memcheck.txt
${CMAKE_CURRENT_SOURCE_DIR}/sanitizers/valgrind_exclude_test_threadcheck.txt
${CMAKE_CURRENT_SOURCE_DIR}/sanitizers/valgrind_exclude_test_helgrind.txt
${CMAKE_CURRENT_SOURCE_DIR}/sanitizers/valgrind_exclude_test_dhat.txt
DESTINATION ${CMAKE_BINARY_DIR})

# Invoked as add_coverage_test("SomeName" sources...)
function(add_coverage_test Name)
Expand Down
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions test/sanitizers/valgrind_exclude_test_memcheck.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
UuidBuilderTest.WithIndependentState
UuidBuilderTest.CounterIncrementWithinTimestampTick
TestUuidBuilder.CounterIncrements
UuidBuilderTest.UuidBuilderTest.WithIndependentState
UuidBuilderTest.UuidBuilderTest.CounterIncrementWithinTimestampTick
UuidBuilderTest.TestUuidBuilder.CounterIncrements
Empty file.

0 comments on commit 8a0d03c

Please sign in to comment.