Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 6c4ad71246
Fetching contributors…

Cannot retrieve contributors at this time

executable file 152 lines (131 sloc) 4.16 kB
#!/bin/bash
#
# LDT - Linux Driver Template
#
# Test script
#
# Copyright (C) 2012 Constantine Shulyupin http://www.makelinux.net/
#
# Dual BSD/GPL License
#
RED="\\033[0;31m"
NOCOLOR="\\033[0;39m"
GREEN="\\033[0;32m"
GRAY="\\033[0;37m"
set -o errtrace
debugfs=`grep debugfs /proc/mounts | awk '{ print $2; }'`
tracing=$debugfs/tracing
irq=0 # define irq to bind diriver to HW IRQ, WARING: can hung the system
irq=4 # serial port
# irq=`grep ehci_hcd /proc/interrupts | cut -f1 -d:`
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 function_graph > current_tracer"
tracing "echo 1 > function_profile_enabled"
# useful stuff:
#tracing "echo XXX > set_ftrace_notrace"
#sudo cat $tracing/current_tracer
#sudo cat $tracing/set_ftrace_filter
#sudo cat $tracing/function_profile_enabled
# available_filter_functions
# echo $$ > set_ftrace_pid
}
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 rmmod parport_pc parport ppdev lp
sudo dmesg -n 7
sudo rmmod ldt ldt_plat_dev 2> /dev/null
sudo dmesg -c > /dev/null
stty -F /dev/ttyS0 115200
make -s
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 on /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
sudo insmod ldt_plat_dev.ko
tracing_start || true
# lsmod | grep ldt
#id=`grep -w ldt /proc/misc | cut -c -3`
. /sys/class/misc/ldt/uevent || true # get $MAJOR $MINOR
. /sys/class/ldt/ldt/uevent || 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
#grep ldt /proc/interrupts || true
#sudo rmmod ldt ldt_plat_dev 2> /dev/null
tracing_stop || true
sudo dmesg --notime --read-clear 2>/dev/null > kernel.log || \
sudo dmesg -c > kernel.log && echo kernel.log saved
Jump to Line
Something went wrong with that request. Please try again.