Added tests with ethernet load
[can-benchmark.git] / tests / _lib.sh
1
2 while [ $# -gt 0 ]; do
3     case "$1" in
4         -p) OPT_PLOT_ONLY=1; shift;;
5         --pdf-only) OPT_PDF_ONLY=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
16 boost_irq_prio() {
17     local P=${1:-50}
18     CAN_IRQ=`sed -ne '/can/ s/:.*//p' /proc/interrupts`
19     if [ -n "$CAN_IRQ" ]; then
20         schedtool -F -p $P `pidof IRQ-${CAN_IRQ/ /}`
21     fi
22 }
23
24 rmmod_can() {
25     modprobe -r lincan kvaser_pci vcan
26 }
27
28 prepare_lincan_hw() {
29     rmmod_can
30     modprobe -C /dev/null lincan hw=pcican-q io=1 baudrate=1000,1000,1000,1000 processlocal=0
31     CAN0=/dev/can0
32     CAN1=/dev/can1
33     DRIVER=lincan
34     sleep 0.1
35 }
36
37 prepare_lincan_virtual() {
38     rmmod_can
39     modprobe -C /dev/null lincan hw=virtual io=0 baudrate=0
40     CAN0=/dev/can0
41     DRIVER=lincan-virtual
42     sleep 0.1
43 }
44
45 prepare_socketcan_hw() {
46     rmmod_can
47     modprobe kvaser_pci
48     echo 1000000 > /sys/class/net/can0/can_bittiming/bitrate
49     ip link set up dev can0
50     echo 1000000 > /sys/class/net/can1/can_bittiming/bitrate
51     ip link set up dev can1
52     echo 1000000 > /sys/class/net/can2/can_bittiming/bitrate
53     ip link set up dev can2
54     echo 1000000 > /sys/class/net/can3/can_bittiming/bitrate
55     ip link set up dev can3
56     CAN0=socketcan:can0
57     CAN1=socketcan:can1
58     DRIVER=socketcan
59 }
60
61 prepare_socketcan_virtual() {
62     rmmod_can
63     modprobe vcan
64     ip link add dev vcan0 type vcan
65     ip link set up dev vcan0
66     CAN0=socketcan:vcan0
67     DRIVER=socketcan-virtual
68 }
69
70 run_tests() {
71     tests=${TESTS:-socketcan_hw lincan_hw}
72     for i in $tests; do
73         cpufreq-set -f 2400MHz
74         boost_irq_prio 50
75         prepare_$i
76         t
77     done
78 }
79
80 plot() {
81     if [ -n "$PLOT_CMD" ]; then
82         echo "set terminal postscript color eps enhanced;
83               $PLOT_CMD" | gnuplot | epstopdf --filter > `basename $0 .sh`.pdf
84         if [ -z "$OPT_PDF_ONLY" ]; then
85             echo "set terminal x11 enhanced; $PLOT_CMD" | gnuplot -persist
86         fi
87     fi
88 }
89
90 go() {
91     d=results/`basename $0 .sh`/`uname -r`
92     mkdir -p $d
93     cd $d
94     
95     [ -n "$OPT_PLOT_ONLY" ] || run_tests
96     plot
97
98 }
99
100 trap 'go' EXIT