Extend preparation of virtual drivers
[can-benchmark.git] / tests / _lib.sh
1
2 while [ $# -gt 0 ]; do
3     case "$1" in
4         -p) OPT_PLOT_ONLY=1; shift;;
5         -X|--no-x11-plot) OPT_NO_X11=1; shift;;
6     esac
7 done
8
9 #set -x
10 set -e
11
12 PATH=$PWD/../_compiled/bin/:$PATH
13
14 RTPRIO=${RTPRIO:-60}
15 COUNT=${COUNT:-10000}
16
17 boost_irq_prio() {
18     local PRIO=${1:-50}
19     CAN_IRQ=`sed -ne '/can/ s/:.*//p' /proc/interrupts`
20     if [ -n "$CAN_IRQ" ]; then
21         IRQ_PID=`pidof IRQ-${CAN_IRQ/ /}` || true
22         if [ -n "$IRQ_PID" ]; then
23             schedtool -F -p $PRIO $IRQ_PID
24             return 0
25         fi
26     fi
27     return 1
28 }
29
30 rmmod_can() {
31     modprobe -r lincan kvaser_pci vcan
32 }
33
34 prepare_lincan_hw() {
35     rmmod_can
36     modprobe -C /dev/null lincan hw=pcican-q io=1 baudrate=1000,1000,1000,1000 processlocal=0
37     CAN0=/dev/can0
38     CAN1=/dev/can1
39     DRIVER=lincan
40     sleep 0.1
41 }
42
43 prepare_lincan_virtual() {
44     rmmod_can
45     modprobe -C /dev/null lincan hw=virtual io=0 baudrate=0
46     CAN0=/dev/can0
47     CAN1=/dev/can0
48     DRIVER=lincan-virtual
49     sleep 0.1
50 }
51
52 prepare_socketcan_hw() {
53     rmmod_can
54     modprobe kvaser_pci
55     echo 1000000 > /sys/class/net/can0/can_bittiming/bitrate
56     ip link set up dev can0
57     echo 1000000 > /sys/class/net/can1/can_bittiming/bitrate
58     ip link set up dev can1
59     echo 1000000 > /sys/class/net/can2/can_bittiming/bitrate
60     ip link set up dev can2
61     echo 1000000 > /sys/class/net/can3/can_bittiming/bitrate
62     ip link set up dev can3
63     CAN0=socketcan:can0
64     CAN1=socketcan:can1
65     DRIVER=socketcan
66 }
67
68 prepare_socketcan_virtual() {
69     rmmod_can
70     modprobe vcan
71     ip link add dev vcan0 type vcan
72     ip link set up dev vcan0
73     CAN0=socketcan:vcan0
74     CAN1=socketcan:vcan0
75     DRIVER=socketcan-virtual
76 }
77
78 run_tests() {
79     tests=${TESTS:-socketcan_hw lincan_hw}
80     for tst in $tests; do
81         boost_irq_prio 50 || true
82         prepare_$tst
83         echo "----------------------"
84         t
85     done
86 }
87
88 plot() {
89     for i in "${!PLOT_CMD[@]}"; do
90         cmd="${PLOT_CMD[$i]}";
91         cmd=$(echo "$cmd" | sed -e "/set title/ s/[\"']\(.*\)[\"']/'\1 ($(uname -r), CPU\\\\@${clk}Mhz)'/")
92         if [ -z "$OPT_NO_X11" ]; then
93             echo "set terminal x11 enhanced; ${cmd}" | gnuplot -persist
94         fi
95         I=${i/0/}
96         echo "set terminal postscript color eps enhanced;
97               ${cmd}" | gnuplot | epstopdf --filter > `basename $0 .sh`$I.pdf
98         mkdir -p thumb
99         convert -geometry 1000x100 -gamma 0.3 `basename $0 .sh`$I.pdf thumb/`basename $0 .sh`$I.png
100         convert -density 200 -gamma 0.7 -geometry 1000x500 `basename $0 .sh`$I.pdf `basename $0 .sh`$I.png
101     done
102 }
103
104 create_dirs_and_links() {
105     local test=$1
106     local kver=$2
107     local clck=$3
108
109     local  d=results/by-test/$test/$kver/$clck
110     mkdir -p $d
111     mkdir -p results/by-test/$test/$clck # 1
112     mkdir -p results/by-kern/$kver/$clck # 2
113     mkdir -p results/by-kern/$kver/$test # 3
114     mkdir -p results/by-clck/$clck/$kver # 4
115     mkdir -p results/by-clck/$clck/$test # 5
116     ln -sfT ../../../${d#results/} results/by-test/$test/$clck/$kver # 1
117     ln -sfT ../../../${d#results/} results/by-kern/$kver/$clck/$test # 2
118     ln -sfT ../../../${d#results/} results/by-kern/$kver/$test/$clck # 3
119     ln -sfT ../../../${d#results/} results/by-clck/$clck/$kver/$test # 4
120     ln -sfT ../../../${d#results/} results/by-clck/$clck/$test/$kver # 5
121     echo $d
122 }
123
124 go() {
125     echo "####################"
126     mhz=${MHZ:-2400 300}
127     for clk in $mhz; do
128     echo "===================="
129         dir=$(create_dirs_and_links `basename $0 .sh` `uname -r` $clk)
130         set -x
131         pushd $dir
132
133         if [ ! -n "$OPT_PLOT_ONLY" ]; then
134             cpufreq-set -f ${clk}MHz
135             run_tests
136             cpufreq-set -f 2400MHz
137         fi
138         plot
139         popd
140         set +x
141     done
142
143 }
144
145 trap 'go' EXIT