Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fail pre-commit when KUnit tests are not passed #433

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scripts/run_kunit
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fi
### Since agnocast_kunit.ko contains symbols from agnocast.ko,
### symbol conflicts will ocurr if it is already loaded.
if lsmod | grep -q "agnocast"; then
echo "Kernel module 'agnocast' is already loaded. Unload it before kunit test."
exit 1
echo "Kernel module 'agnocast' is already loaded. Unload it before kunit test."
exit 1
fi

AGNOCAST_DIR=$(realpath "$(dirname $(readlink -f $0))/..")
Expand All @@ -37,8 +37,16 @@ cd $AGNOCAST_KMOD_PATH
make clean
make
sudo insmod $AGNOCAST_KMOD_PATH/agnocast_kunit.ko
sleep 3 # HACK
TOTALS_LINE=$(sudo dmesg | tail -n 10 | grep -E "# Totals: pass:[0-9]+ fail:[0-9]+")
FAIL_COUNT=$(echo "$TOTALS_LINE" | awk -F'fail:' '{print $2}' | awk '{print $1}')
sudo rmmod agnocast_kunit

if [ $FAIL_COUNT -ne 0 ]; then
echo "KUnit tests failed. Please check dmesg for more information."
exit 1
fi

sudo lcov --capture --directory /sys/kernel/debug/gcov/$AGNOCAST_KMOD_PATH --output-file $AGNOCAST_DIR/coverage.info
sudo lcov --remove $AGNOCAST_DIR/coverage.info "*linux*" "*kunit*" --output-file $AGNOCAST_DIR/coverage_filtered.info
genhtml $AGNOCAST_DIR/coverage_filtered.info --output-directory $AGNOCAST_DIR/agnocast_kmod_coverage_report
Expand Down