-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): Add core dump watch and analysis
This commit aims to improve the behavior and improve the output of test results. When a core dump occurs, it terminates the test immediately (regardless whether it was SaunaFS or not that caused it, the environment is unreliable for accurate test results). It then uses GDB to analyze the core dump(s). There's a few issues with this: First it requires modifying `/proc/sys/kernel/core_pattern`, which will affect the whole system. While I've tried to ensure that the original pattern is restored after failures and core dumps, I'm not completely confident it will. Second is the fact that GDB might not be needed to print the backtrace: `LD_PRELOAD=/lib/libSegFault.so` may be a better alternative, but I didn't have time to test it. Thus this feature is hidden behind a feature flag as experimental until these issues are solved.
- Loading branch information
1 parent
64acea4
commit 21e7ce8
Showing
6 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
coredump_enabled_= | ||
coredump_dir="/tmp/temp-cores/" | ||
coredump_dir_after="/tmp/sfs-cores/" | ||
coredump_pattern="${coredump_dir}core-%e-%p-%t" | ||
coredump_original_pattern=$(cat /proc/sys/kernel/core_pattern) | ||
coredump_pattern_restore=1 | ||
|
||
|
||
coredump_setup() { | ||
if valgrind_enabled; then | ||
return | ||
fi | ||
|
||
mkdir -p $coredump_dir | ||
chmod 777 $coredump_dir | ||
if [[ $coredump_original_pattern == $coredump_pattern ]]; then | ||
echo "Core pattern is already set, not modifying it" | ||
coredump_enabled_=1 | ||
coredump_pattern_restore=0 | ||
return | ||
fi | ||
|
||
echo $coredump_pattern | sudo tee /proc/sys/kernel/core_pattern || echo "Could not setup coredump" && return | ||
$coredump_enabled_ = 1 | ||
} | ||
|
||
coredump_exists() { | ||
if [ -n "$(ls -A $coredump_dir 2> /dev/null)" ]; then | ||
return 0 | ||
fi | ||
return 1 | ||
} | ||
|
||
coredump_is_enabled() { | ||
test -z $coredump_enabled_ && return 1 || return 0 | ||
} | ||
|
||
coredump_watcher() { | ||
inotifywait -m $coredump_dir -e create -e moved_to | | ||
while read path action file; do | ||
test_add_failure " --- CORE DUMP DETECTED, TERMINATING TEST ---" | ||
test_freeze_result | ||
coredump_analyze | ||
coredump_restore | ||
killall -9 -u $(whoami) | ||
done | ||
} | ||
|
||
coredump_analyze() { | ||
mkdir $coredump_dir_after | ||
for core in $coredump_dir/core*; do | ||
echo " --- CORE DUMP BACKTRACE: ${core} --- " | ||
executable=$(gdb -ex "core-file ${core}" -ex "info proc" -ex "quit" \ | ||
| grep 'Core was generated by' \ | ||
| sed "s/Core was generated by \`\\(.*\\)'\./\\1/" \ | ||
| awk '{print $1}') 2> /dev/null | ||
|
||
gdb -batch -ex "core-file ${core}" -ex "thread apply all bt full" -ex "quit" ${executable} 2> /dev/null | ||
echo " --- CORE DUMP FINISHED FOR: ${core} --- " | ||
mv $core $coredump_dir_after | ||
done | ||
} | ||
|
||
coredump_restore() { | ||
if [[ $coredump_pattern_restore ]]; then | ||
echo $coredump_original_pattern > /proc/sys/kernel/core_pattern || true | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ done | |
. tools/color.sh | ||
. tools/continuous_test.sh | ||
. tools/logs.sh | ||
. tools/gdb.sh |