Skip to content

Commit bac71e5

Browse files
committed
Add convenient test target and script improvements
1 parent 26f0ed1 commit bac71e5

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ clear:
5050
# Target to view the kernel log buffer
5151
view:
5252
dmesg
53+
54+
# Run module tests (requires root privileges)
55+
test: all
56+
sudo bash tests/module_test.sh

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ To begin your kernel module development journey, you'll need:
5858
```
5959

6060
5. **Run Tests**:
61-
After building, you can execute the provided test script (requires root privileges) to automatically insert and remove the sample modules:
61+
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:
6262
```bash
63-
sudo bash tests/module_test.sh
63+
make test
6464
```
6565

6666
### Usage Tips

tests/module_test.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/bin/bash
22
set -e
33

4+
# Ensure the script is executed with root privileges
5+
if [[ $EUID -ne 0 ]]; then
6+
echo "This script must be run as root." >&2
7+
exit 1
8+
fi
9+
410
BUILD_DIR="$(dirname "$0")/../build"
511
MODULES=(kernel_birthday_list_module kernel_timer_module kernel_workqueue_module)
612

@@ -11,8 +17,8 @@ for mod in "${MODULES[@]}"; do
1117
exit 1
1218
fi
1319
echo "Inserting $mod_ko"
14-
sudo insmod "$mod_ko"
20+
insmod "$mod_ko"
1521
echo "Removing $mod"
16-
sudo rmmod "$mod"
22+
rmmod "$mod"
1723
echo
1824
done

0 commit comments

Comments
 (0)