-
Notifications
You must be signed in to change notification settings - Fork 197
/
ldt-test
executable file
·132 lines (113 loc) · 3.53 KB
/
ldt-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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
#
# LDT - Linux Driver Template
#
# Test script for driver LDT
#
# Copyright (C) 2012 Constantine Shulyupin http://www.makelinux.net/
#
# Licensed under the GPLv2.
#
RED="\\033[0;31m"
NOCOLOR="\\033[0;39m"
GREEN="\\033[0;32m"
set -o errtrace
debugfs=`grep debugfs /proc/mounts | awk '{ print $2; }'`
tracing=$debugfs/tracing
tracing()
{
sudo sh -c "cd $tracing; $1" || true
}
tracing_start()
{
tracing "echo :mod:ldt > set_ftrace_filter"
tracing "echo function > current_tracer" # need for draw_functrace.py
tracing "echo 1 > function_profile_enabled"
}
tracing_stop()
{
( echo Profiling data per CPU
tracing "cat trace_stat/function*" )> trace_stat.log && echo trace_stat.log saved
tracing "echo 0 > function_profile_enabled"
sudo cp $tracing/trace ftrace.log && echo ftrace.log saved
sudo dd iflag=nonblock if=$tracing/trace_pipe 2> /dev/null > trace_pipe.log || true && echo trace_pipe.log saved
tracing "echo nop > current_tracer"
#export PYTHONPATH=/usr/src/linux-headers-$(uname -r)/scripts/tracing/
# draw_functrace.py needs function tracer
python /usr/src/linux-headers-$(uname -r)/scripts/tracing/draw_functrace.py \
< trace_pipe.log > functrace.log && echo functrace.log saved || true
}
sudo dmesg -n 7
sudo rmmod ldt 2> /dev/null
sudo dmesg -c > /dev/null
# configure UART because it is used for demostration of the driver
stty -F /dev/ttyS0 115200
set -o errexit
#
# Check for presence looback on /dev/ttyS0.
# If loopback is not present, switch loopback on in the driver
#
data='loopback?'
received=`echo $data | ./dio --ignore_eof --loops 2 --delay 10 /dev/ttyS0 2> /dev/null`
if [ "$data" == "$received" ]; then
echo -e "Loopback on /dev/ttyS0 detected"
loopback=0
else
echo -e "No loopback behind /dev/ttyS0 detected, running ldt driver with UART in loopback mode"
loopback=1
fi
# clean data
echo | ./dio --ignore_eof --loops 10 --delay 10 /dev/ttyS0 2> /dev/null > /dev/null
sudo insmod ldt.ko loopback=$loopback
tracing_start || true
#. /sys/class/misc/ldt/uevent 2> /dev/null || true # get $MAJOR $MINOR
#. /sys/class/ldt/ldt/uevent 2> /dev/null || true # get $MAJOR $MINOR
#sudo sh -c "rm /dev/ldt;sudo mknod /dev/ldt c $MAJOR $MINOR; chmod o+rw /dev/ldt"
sudo sh -c "chmod go+rw /dev/ldt*"
data=123rw
echo $data > /dev/ldt
sleep 0.5
received=`dd iflag=nonblock if=/dev/ldt 2> /dev/null || true`
if [ "$data" == "$received" ]; then
echo -e "${GREEN}LDT nonblocking read/write test passed$NOCOLOR"
else
echo -e "${RED}LDT nonblock read/write test failed$NOCOLOR"
echo expected $data
echo received $received
fi
data=123bl
cat /dev/ldt > R.tmp &
sleep 0.5; echo $data > /dev/ldt;
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}LDT blocking read/write test passed$NOCOLOR"
else
echo -e "${RED}LDT blocking read/write test failed$NOCOLOR"
echo expected $data
echo received $received
fi
data=123mmap
received=`sudo echo $data | ./dio --mmap /dev/ldt`
if [ "$data" == "$received" ]; then
echo -e "${GREEN}LDT mmap test passed$NOCOLOR"
else
echo -e "${RED}LDT mmap test failed$NOCOLOR"
echo expected $data
echo received $received
fi
data=123ioctl
received=`sudo echo $data | ./dio --ioctl /dev/ldt`
if [ "$data" == "$received" ]; then
echo -e "${GREEN}LDT ioctl test passed$NOCOLOR"
else
echo -e "${RED}LDT ioctl test failed$NOCOLOR"
echo expected $data
echo received $received
fi
sudo ls -l /sys/kernel/debug/ldt
tracing_stop || true
sudo dmesg --notime --show-delta --read-clear 2>/dev/null > kernel.log || \
sudo dmesg -c > kernel.log && echo kernel.log saved