Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 146 lines (127 sloc) 3.983 kb
3726b66 @makelinux ldt-test cleanup
authored
1 #!/bin/bash
2
6825c67 @makelinux small fixes, + static
authored
3 #
3726b66 @makelinux ldt-test cleanup
authored
4 # LDT - Linux Driver Template
5 #
6 # Test script
7 #
8 # Copyright (C) 2012 Constantine Shulyupin http://www.makelinux.net/
9 #
10 # Dual BSD/GPL License
6825c67 @makelinux small fixes, + static
authored
11 #
3726b66 @makelinux ldt-test cleanup
authored
12
13 RED="\\033[0;31m"
14 NOCOLOR="\\033[0;39m"
15 GREEN="\\033[0;32m"
7f7c4a9 @makelinux + blocking io, wait_event_interruptible
authored
16 GRAY="\\033[0;37m"
425337b @makelinux initial sources
authored
17
18 set -o errtrace
62b4c27 @makelinux improved tracing
authored
19 debugfs=`grep debugfs /proc/mounts | awk '{ print $2; }'`
20 tracing=$debugfs/tracing
3726b66 @makelinux ldt-test cleanup
authored
21 irq=0 # define irq to bind diriver to HW IRQ, WARING: can hung the system
f2847cf @makelinux UART disabled
authored
22 irq=4 # serial port
425337b @makelinux initial sources
authored
23 # irq=`grep ehci_hcd /proc/interrupts | cut -f1 -d:`
24
25 tracing()
26 {
e9983bb @makelinux +platform_device and small updates
authored
27 sudo sh -c "cd $tracing; $1" || true
425337b @makelinux initial sources
authored
28 }
29
30 tracing_start()
31 {
32 tracing "echo :mod:ldt > set_ftrace_filter"
6825c67 @makelinux small fixes, + static
authored
33 tracing "echo function > current_tracer" # need for draw_functrace.py
62b4c27 @makelinux improved tracing
authored
34 #tracing "echo function_graph > current_tracer"
425337b @makelinux initial sources
authored
35 tracing "echo 1 > function_profile_enabled"
6825c67 @makelinux small fixes, + static
authored
36 # useful stuff:
62b4c27 @makelinux improved tracing
authored
37 #tracing "echo XXX > set_ftrace_notrace"
3726b66 @makelinux ldt-test cleanup
authored
38 #sudo cat $tracing/current_tracer
39 #sudo cat $tracing/set_ftrace_filter
40 #sudo cat $tracing/function_profile_enabled
62b4c27 @makelinux improved tracing
authored
41 # available_filter_functions
42 # echo $$ > set_ftrace_pid
425337b @makelinux initial sources
authored
43 }
44
e9983bb @makelinux +platform_device and small updates
authored
45 tracing_stop()
62b4c27 @makelinux improved tracing
authored
46
425337b @makelinux initial sources
authored
47 {
3726b66 @makelinux ldt-test cleanup
authored
48 ( echo Profiling data per CPU
9bd51e9 @makelinux +ioctl
authored
49 tracing "cat trace_stat/function*" )> trace_stat.log && echo trace_stat.log saved
425337b @makelinux initial sources
authored
50 tracing "echo 0 > function_profile_enabled"
e9983bb @makelinux +platform_device and small updates
authored
51 sudo cp $tracing/trace ftrace.log && echo ftrace.log saved
62b4c27 @makelinux improved tracing
authored
52 sudo dd iflag=nonblock if=$tracing/trace_pipe 2> /dev/null > trace_pipe.log || true && echo trace_pipe.log saved
53 tracing "echo nop > current_tracer"
54 #export PYTHONPATH=/usr/src/linux-headers-$(uname -r)/scripts/tracing/
6825c67 @makelinux small fixes, + static
authored
55 # draw_functrace.py needs function tracer
62b4c27 @makelinux improved tracing
authored
56 python /usr/src/linux-headers-$(uname -r)/scripts/tracing/draw_functrace.py \
57 < trace_pipe.log > functrace.log && echo functrace.log saved || true
425337b @makelinux initial sources
authored
58 }
59
60 # sudo rmmod parport_pc parport ppdev lp
f2847cf @makelinux UART disabled
authored
61 sudo dmesg -n 7
5492ec7 @makelinux +mmap
authored
62 sudo rmmod ldt ldt_plat_dev 2> /dev/null
9bef4eb @makelinux +checkpatch
authored
63 sudo dmesg -c > /dev/null
4c8f40b @makelinux + loopback test
authored
64 stty -F /dev/ttyS0 115200
3726b66 @makelinux ldt-test cleanup
authored
65 make -s
9fc0000 @makelinux using ldt_resource
authored
66 set -o errexit
67
68 #
69 # Check for presence looback on /dev/ttyS0.
70 # If loopback is not present, switch loopback on in the driver
71 #
72
4c8f40b @makelinux + loopback test
authored
73 data='loopback?'
4e093d3 @makelinux serial errors to /dev/nul
authored
74 received=`echo $data | ./dio --ignore_eof --loops 2 --delay 10 /dev/ttyS0 2> /dev/null`
4c8f40b @makelinux + loopback test
authored
75 if [ "$data" == "$received" ]; then
76 echo -e "Loopback on /dev/ttyS0 detected"
77 loopback=0
78 else
9fc0000 @makelinux using ldt_resource
authored
79 echo -e "No loopback on /dev/ttyS0 detected, running ldt driver with UART in loopback mode"
4c8f40b @makelinux + loopback test
authored
80 loopback=1
81 fi
4e093d3 @makelinux serial errors to /dev/nul
authored
82
83 # clean data
84 echo | ./dio --ignore_eof --loops 10 --delay 10 /dev/ttyS0 2> /dev/null > /dev/null
4c8f40b @makelinux + loopback test
authored
85
86 sudo insmod ldt.ko loopback=$loopback
e9983bb @makelinux +platform_device and small updates
authored
87 sudo insmod ldt_plat_dev.ko
88
89 tracing_start || true
3726b66 @makelinux ldt-test cleanup
authored
90 # lsmod | grep ldt
5842a8d @makelinux +poll
authored
91 #id=`grep -w ldt /proc/misc | cut -c -3`
92 . /sys/class/misc/ldt/uevent # get $MAJOR $MINOR
93 sudo sh -c "rm /dev/ldt;sudo mknod /dev/ldt c $MAJOR $MINOR; chmod o+rw /dev/ldt"
9bd51e9 @makelinux +ioctl
authored
94 data=123rw
4c8f40b @makelinux + loopback test
authored
95 echo $data > /dev/ldt
425337b @makelinux initial sources
authored
96 sleep 0.5
7f7c4a9 @makelinux + blocking io, wait_event_interruptible
authored
97 received=`dd iflag=nonblock if=/dev/ldt 2> /dev/null || true`
3726b66 @makelinux ldt-test cleanup
authored
98 if [ "$data" == "$received" ]; then
7f7c4a9 @makelinux + blocking io, wait_event_interruptible
authored
99 echo -e "${GREEN}LDT nonblocking read/write test passed$NOCOLOR"
3726b66 @makelinux ldt-test cleanup
authored
100 else
7f7c4a9 @makelinux + blocking io, wait_event_interruptible
authored
101 echo -e "${RED}LDT nonblock read/write test failed$NOCOLOR"
102 echo expected $data
103 echo received $received
104 fi
105
106 data=123bl
107 cat /dev/ldt > R.tmp &
4c8f40b @makelinux + loopback test
authored
108 sleep 0.5; echo $data > /dev/ldt;
7f7c4a9 @makelinux + blocking io, wait_event_interruptible
authored
109 sleep 0.5
110 kill %1; wait %1 2> /dev/null || true
111 received=`cat R.tmp`
9bef4eb @makelinux +checkpatch
authored
112 rm -f R.tmp
7f7c4a9 @makelinux + blocking io, wait_event_interruptible
authored
113
114 if [ "$data" == "$received" ]; then
115 echo -e "${GREEN}LDT blocking read/write test passed$NOCOLOR"
116 else
117 echo -e "${RED}LDT blocking read/write test failed$NOCOLOR"
118 echo expected $data
119 echo received $received
f5b5e6f @makelinux +mmap
authored
120 fi
121
9bd51e9 @makelinux +ioctl
authored
122 data=123mmap
4c8f40b @makelinux + loopback test
authored
123 received=`sudo echo $data | ./dio --mmap /dev/ldt`
f5b5e6f @makelinux +mmap
authored
124 if [ "$data" == "$received" ]; then
125 echo -e "${GREEN}LDT mmap test passed$NOCOLOR"
126 else
127 echo -e "${RED}LDT mmap test failed$NOCOLOR"
128 echo expected $data
129 echo received $received
3726b66 @makelinux ldt-test cleanup
authored
130 fi
131
9bd51e9 @makelinux +ioctl
authored
132 data=123ioctl
4c8f40b @makelinux + loopback test
authored
133 received=`sudo echo $data | ./dio --ioctl /dev/ldt`
9bd51e9 @makelinux +ioctl
authored
134 if [ "$data" == "$received" ]; then
135 echo -e "${GREEN}LDT ioctl test passed$NOCOLOR"
136 else
137 echo -e "${RED}LDT ioctl test failed$NOCOLOR"
138 echo expected $data
139 echo received $received
140 fi
141
9bef4eb @makelinux +checkpatch
authored
142 #grep ldt /proc/interrupts || true
e9983bb @makelinux +platform_device and small updates
authored
143 tracing_stop || true
9bef4eb @makelinux +checkpatch
authored
144 sudo dmesg --notime --read-clear 2>/dev/null > kernel.log || \
e9983bb @makelinux +platform_device and small updates
authored
145 sudo dmesg -c > kernel.log && echo kernel.log saved
Something went wrong with that request. Please try again.