-
Notifications
You must be signed in to change notification settings - Fork 197
/
misc_loop_drv_test
executable file
·46 lines (39 loc) · 1.24 KB
/
misc_loop_drv_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# The script is intended to be run from user root
RED="\\033[0;31m"
NOCOLOR="\\033[0;39m"
GREEN="\\033[0;32m"
dmesg -c > /dev/null # clear log buffer
# It's supposed you computer doesn't use floppy device.
# misc_loop_drv uses IRQ 6 of floppy device demonstrate IRQ usage.
rmmod floppy 2> /dev/null
rmmod misc_loop_drv 2> /dev/null
insmod ./misc_loop_drv.ko
data=123rw
cat /dev/misc_loop_drv > R.tmp &
sleep 0.1; echo $data > /dev/misc_loop_drv;
sleep 0.5
kill %1; wait %1 2> /dev/null || true
received=`cat R.tmp`
rm -f R.tmp
if [ "$data" == "$received" ]; then
echo -e "${GREEN}misc_loop_drv blocking read/write test passed$NOCOLOR"
else
echo -e "${RED}misc_loop_drv blocking read/write test failed$NOCOLOR"
echo expected $data
echo received $received
fi
data=123nb
echo -n $data > /dev/misc_loop_drv
sleep 0.5
received=`dd iflag=nonblock if=/dev/misc_loop_drv 2> /dev/null `
if [ "$data" == "$received" ]; then
echo -e "${GREEN}misc_loop_drv nonblocking read/write test passed$NOCOLOR"
else
echo -e "${RED}misc_loop_drv nonblock read/write test failed$NOCOLOR"
echo expected $data
echo received $received
fi
rmmod misc_loop_drv.ko
dmesg --notime --show-delta --read-clear 2>/dev/null > kernel.log || \
dmesg -c > kernel.log && echo kernel.log saved