HTML report + many modifications
[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=60
15 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     DRIVER=lincan-virtual
48     sleep 0.1
49 }
50
51 prepare_socketcan_hw() {
52     rmmod_can
53     modprobe kvaser_pci
54     echo 1000000 > /sys/class/net/can0/can_bittiming/bitrate
55     ip link set up dev can0
56     echo 1000000 > /sys/class/net/can1/can_bittiming/bitrate
57     ip link set up dev can1
58     echo 1000000 > /sys/class/net/can2/can_bittiming/bitrate
59     ip link set up dev can2
60     echo 1000000 > /sys/class/net/can3/can_bittiming/bitrate
61     ip link set up dev can3
62     CAN0=socketcan:can0
63     CAN1=socketcan:can1
64     DRIVER=socketcan
65 }
66
67 prepare_socketcan_virtual() {
68     rmmod_can
69     modprobe vcan
70     ip link add dev vcan0 type vcan
71     ip link set up dev vcan0
72     CAN0=socketcan:vcan0
73     DRIVER=socketcan-virtual
74 }
75
76 run_tests() {
77     tests=${TESTS:-socketcan_hw lincan_hw}
78     for tst in $tests; do
79         boost_irq_prio 50 || true
80         prepare_$tst
81         t
82     done
83 }
84
85 plot() {
86     for i in "${!PLOT_CMD[@]}"; do
87         cmd="${PLOT_CMD[$i]}";
88         cmd=$(echo "$cmd" | sed -e "/set title/ s/[\"']\(.*\)[\"']/'\1 ($(uname -r), CPU\\\\@${clk}Mhz)'/")
89         if [ -z "$OPT_NO_X11" ]; then
90             echo "set terminal x11 enhanced; ${cmd}" | gnuplot -persist
91         fi
92         I=${i/0/}
93         echo "set terminal postscript color eps enhanced;
94               ${cmd}" | gnuplot | epstopdf --filter > `basename $0 .sh`$I.pdf
95         mkdir -p thumb
96         convert -geometry 1000x100 -gamma 0.3 `basename $0 .sh`$I.pdf thumb/`basename $0 .sh`$I.png
97         convert -density 200 -gamma 0.7 -geometry 1000x500 `basename $0 .sh`$I.pdf `basename $0 .sh`$I.png
98     done
99 }
100
101 create_dirs_and_links() {
102     local test=$1
103     local kver=$2
104     local clck=$3
105
106     local  d=results/by-test/$test/$kver/$clck
107     mkdir -p $d
108     mkdir -p results/by-test/$test/$clck # 1
109     mkdir -p results/by-kern/$kver/$clck # 2
110     mkdir -p results/by-kern/$kver/$test # 3
111     mkdir -p results/by-clck/$clck/$kver # 4
112     mkdir -p results/by-clck/$clck/$test # 5
113     ln -sfT ../../../${d#results/} results/by-test/$test/$clck/$kver # 1
114     ln -sfT ../../../${d#results/} results/by-kern/$kver/$clck/$test # 2
115     ln -sfT ../../../${d#results/} results/by-kern/$kver/$test/$clck # 3
116     ln -sfT ../../../${d#results/} results/by-clck/$clck/$kver/$test # 4
117     ln -sfT ../../../${d#results/} results/by-clck/$clck/$test/$kver # 5
118     echo $d
119 }
120
121 go() {
122     mhz=${MHZ:-2400 300}
123     for clk in $mhz; do
124         dir=$(create_dirs_and_links `basename $0 .sh` `uname -r` $clk)
125         set -x
126         pushd $dir
127
128         if [ ! -n "$OPT_PLOT_ONLY" ]; then
129             cpufreq-set -f ${clk}MHz
130             run_tests
131             cpufreq-set -f 2400MHz
132         fi
133         plot
134         popd
135         set +x
136     done
137
138 }
139
140 trap 'go' EXIT