Skip to content

Improve module test usage #14

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

Merged
merged 1 commit into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ clear:
# Target to view the kernel log buffer
view:
dmesg

# Run module tests (requires root privileges)
test: all
sudo bash tests/module_test.sh
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ To begin your kernel module development journey, you'll need:
```

5. **Run Tests**:
After building, you can execute the provided test script (requires root privileges) to automatically insert and remove the sample modules:
After building, you can run the provided test script using the Makefile. This step requires root privileges and will automatically insert and remove the sample modules:
```bash
sudo bash tests/module_test.sh
make test
```

### Usage Tips
Expand Down
10 changes: 8 additions & 2 deletions tests/module_test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/bash
set -e

# Ensure the script is executed with root privileges
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root." >&2
exit 1
fi

BUILD_DIR="$(dirname "$0")/../build"
MODULES=(kernel_birthday_list_module kernel_timer_module kernel_workqueue_module)

Expand All @@ -11,8 +17,8 @@ for mod in "${MODULES[@]}"; do
exit 1
fi
echo "Inserting $mod_ko"
sudo insmod "$mod_ko"
insmod "$mod_ko"
echo "Removing $mod"
sudo rmmod "$mod"
rmmod "$mod"
echo
done