]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - gw-tests/lib.sh
Merge branch 'master' of rtime.felk.cvut.cz:/can-benchmark
[can-benchmark.git] / gw-tests / lib.sh
1 set -e
2
3 COUNT=10000
4
5 OPT_TRAFFIC=oneatatime
6
7 error() {
8     echo $1 >&2
9     exit 1
10 }
11
12 while [ $# -gt 0 ]; do
13     case "$1" in
14         -P) OPT_PLOT_DISABLE=1; shift;;
15         -p) OPT_PLOT_ONLY=1; shift;;
16         -X|--no-x11-plot) OPT_NO_X11=1; shift;;
17         -t) case "$2" in
18                 all|flood|50|oneatatime) OPT_TRAFFIC=$2;;
19                 *) error "Unknown traffic specification: $2";;
20             esac;
21             shift 2;;
22     esac
23 done
24
25 PATH=$PWD/../_compiled/bin/:$PATH
26
27 sshgw() {
28     local socket="$HOME/.ssh/cangw-connection"
29
30     if [[ ! -S $socket ]] || ! ssh -x -a -S $socket root@192.168.2.3 true; then
31         # Create master connection to speed up subsequenct command.
32         # The ssh is put into background and the connection is closed
33         # after 10 minutes)
34         ssh -f -M -S $socket root@192.168.2.3 sleep 600 > /dev/null 2>&1
35     fi
36     ssh -x -a -S $socket root@192.168.2.3 "$@"
37 }
38
39 cleanupgw() {
40     sshgw 'cangw -F'
41 }
42
43 _plot() {
44     local testname=`basename $0 .sh`
45
46     plot_cmds | sed -e "/set title/ s/[\"']\(.*\)[\"']/\"\1\\\\n($kvers)\"/" > plot.gp
47     if [ -z "$OPT_NO_X11" ]; then
48         echo "set terminal x11 enhanced; $(< plot.gp)" | gnuplot -persist
49     fi
50     I=''
51     echo 'set terminal postscript color eps enhanced size 6cm,4cm lw 1 "Times-Roman" 10;' \
52         'set lmargin 8;' \
53         "$(< plot.gp)" | gnuplot > ${testname}$I.eps
54     echo "set terminal postscript color eps enhanced;" \
55         "$(< plot.gp)" | gnuplot | epstopdf --filter > ${testname}$I.pdf
56     mkdir -p thumb
57     convert -density 30  -gamma 0.5 -quality 90 -type Palette -depth 8 ${testname}$I.pdf thumb/${testname}$I.png
58     convert -density 150 -gamma 0.7 -quality 90 -type Palette -depth 8 ${testname}$I.pdf ${testname}$I.png
59
60 }
61
62 echo_plot() {
63     plot=$1
64     [[ "$_plot_separator" ]] && echo ", \\"
65     _plot_separator=t
66     echo -n "    " $plot
67 }
68
69 traffic_and_length() {
70     local opts
71     case $OPT_TRAFFIC in
72         flood) opts='';;
73         50)        opts="-p $((2*(44+$1*8)))";;
74         oneatatime)        opts="-o";;
75         *) error "Unknown traffic specification"
76     esac
77     echo $opts -l $1
78 }
79
80 _run() {
81     if [[ ! "$OPT_PLOT_ONLY" ]]
82     then kernel_versions=$(sshgw uname -r)
83     else kernel_versions=$(ls results/by-kern)
84     fi
85     if [[ $OPT_TRAFFIC = all ]]
86     then traffics="flood 50 oneatatime"
87     else traffics=$OPT_TRAFFIC
88     fi
89     for OPT_TRAFFIC in $traffics; do
90     for kvers in $kernel_versions; do
91         dir="results/host-$(uname -r)/$kvers/$OPT_TRAFFIC/$(basename $0 .sh)"
92         mkdir -p $dir
93         script=$PWD/$0
94         cd $dir
95         echo "Working directory: $dir"
96         if [[ ! "$OPT_PLOT_ONLY" ]]; then
97             # Remove data from the last measurement
98             rm -rf *
99             # Set can interfaces up
100             sshgw 'for i in 0 1; do ip link show dev can$i|grep -q UP || ip link set can$i up type can bitrate 1000000; done'
101             # Delete all vcan interfaces
102             sshgw 'for dev in $(ip l|grep -o vcan[^:]\\+); do ip link del dev $dev; done'
103             # Reset priorities
104             sshgw 'chrt -p -f 50 `pidof irq/145-can0` > /dev/null || :'
105             sshgw 'chrt -p -f 50 `pidof irq/146-can1` > /dev/null || :'
106             sshgw 'chrt -p -f 49 `pidof sirq-net-rx/0` > /dev/null || :'
107             sshgw 'chrt -p -f 49 `pidof sirq-net-tx/0` > /dev/null || :'
108             # Set the length of qdisc queue to avoid ENOBUFS errors
109             ifconfig can0 txqueuelen 200
110             cleanupgw
111
112             main
113             cp $script .
114         fi
115         if [[ ! "$OPT_PLOT_DISABLE" ]]; then
116             _plot
117         fi
118         cd -
119     done
120     done
121 }
122
123 test_end() {
124     test_end_called=t
125     exit_ok=
126     _run
127     exit_ok=t
128 }
129
130 _myexit() {
131     code=$?
132     cmd=$BASH_COMMAND
133     if [[ ! "$test_end_called" ]]; then
134         test_end_called=t
135         error "bug in the test script: No test_end called"
136     fi
137     if ! test -n "$exit_ok"; then
138         error "FATAL: Command '$cmd' exit with code $code"
139     fi
140 }
141
142 trap '_myexit' EXIT